- Timestamp:
- Dec 16, 2019, 2:30:41 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- bffcd66
- Parents:
- ab5c0008
- git-author:
- Peter A. Buhr <pabuhr@…> (12/16/19 14:23:00)
- git-committer:
- Peter A. Buhr <pabuhr@…> (12/16/19 14:30:41)
- Location:
- src/AST
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rab5c0008 r07de76b 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 10 22:20:10201913 // Update Count : 3 212 // Last Modified On : Wed Dec 11 21:39:32 2019 13 // Update Count : 33 14 14 // 15 15 … … 1223 1223 cv( node ), 1224 1224 node->name, 1225 node->kind == ast::Type Var::Ftype,1225 node->kind == ast::TypeDecl::Ftype, 1226 1226 get<Attribute>().acceptL( node->attributes ) 1227 1227 }; … … 1578 1578 { old->storageClasses.val }, 1579 1579 GET_ACCEPT_1(base, Type), 1580 (ast::Type Var::Kind)(unsigned)old->kind,1580 (ast::TypeDecl::Kind)(unsigned)old->kind, 1581 1581 old->sized, 1582 1582 GET_ACCEPT_1(init, Type) … … 2561 2561 ty = new ast::TypeInstType{ 2562 2562 old->name, 2563 old->isFtype ? ast::Type Var::Ftype : ast::TypeVar::Dtype,2563 old->isFtype ? ast::TypeDecl::Ftype : ast::TypeDecl::Dtype, 2564 2564 cv( old ), 2565 2565 GET_ACCEPT_V( attributes, Attribute ) -
src/AST/Decl.cpp
rab5c0008 r07de76b 10 10 // Created On : Thu May 9 10:00:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:41:39201913 // Update Count : 1812 // Last Modified On : Fri Dec 13 16:23:15 2019 13 // Update Count : 20 14 14 // 15 15 … … 26 26 #include "Node.hpp" // for readonly 27 27 #include "Type.hpp" // for readonly 28 #include "Parser/ParseNode.h" // for DeclarationNode29 28 30 29 namespace ast { … … 56 55 57 56 const char * TypeDecl::typeString() const { 58 static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" }; 59 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, 60 "typeString: kindNames is out of sync." ); 61 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); 57 static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" }; 58 static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." ); 59 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); 62 60 return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0' 63 61 } 64 62 65 63 const char * TypeDecl::genTypeString() const { 66 static const char * kindNames[] = { "dtype", " ftype", "ttype" };67 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );68 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl'skind is out of bounds." );64 static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" }; 65 static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." ); 66 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); 69 67 return kindNames[ kind ]; 70 68 } -
src/AST/Decl.hpp
rab5c0008 r07de76b 10 10 // Created On : Thu May 9 10:00:00 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 08:20:20201913 // Update Count : 1612 // Last Modified On : Fri Dec 13 17:38:33 2019 13 // Update Count : 29 14 14 // 15 15 … … 20 20 #include <unordered_map> 21 21 #include <vector> 22 #include <algorithm> 22 23 23 24 #include "FunctionSpec.hpp" … … 27 28 #include "ParseNode.hpp" 28 29 #include "StorageClasses.hpp" 29 #include "TypeVar.hpp"30 30 #include "Visitor.hpp" 31 #include "Parser/ParseNode.h" // for DeclarationNode::Aggregate 31 #include "Common/utility.h" 32 #include "Common/SemanticError.h" // error_str 32 33 33 34 // Must be included in *all* AST classes; should be #undef'd at the end of the file … … 125 126 std::vector< ptr<Expr> > withExprs; 126 127 127 FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,128 FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type, 128 129 CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, 129 130 std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}) … … 136 137 bool has_body() const { return stmts; } 137 138 138 const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }139 const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); } 139 140 private: 140 141 FunctionDecl * clone() const override { return new FunctionDecl( *this ); } … … 163 164 /// Cforall type variable: `dtype T` 164 165 class TypeDecl final : public NamedTypeDecl { 165 public: 166 TypeVar::Kind kind; 166 public: 167 enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS }; 168 169 Kind kind; 167 170 bool sized; 168 171 ptr<Type> init; … … 170 173 /// Data extracted from a type decl 171 174 struct Data { 172 TypeVar::Kind kind;175 Kind kind; 173 176 bool isComplete; 174 177 175 Data() : kind( (TypeVar::Kind)-1), isComplete( false ) {}178 Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {} 176 179 Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {} 177 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}180 Data( Kind k, bool c ) : kind( k ), isComplete( c ) {} 178 181 Data( const Data & d1, const Data & d2 ) 179 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 180 181 bool operator== ( const Data & o ) const { 182 return kind == o.kind && isComplete == o.isComplete; 183 } 184 bool operator!= ( const Data & o ) const { return !(*this == o); } 182 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 183 184 bool operator==( const Data & o ) const { return kind == o.kind && isComplete == o.isComplete; } 185 bool operator!=( const Data & o ) const { return !(*this == o); } 185 186 }; 186 187 187 TypeDecl( const CodeLocation & loc, const std::string& name, Storage::Classes storage, Type* b,188 TypeVar::Kind k, bool s, Type* i = nullptr )189 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ),190 188 TypeDecl( const CodeLocation & loc, const std::string & name, Storage::Classes storage, Type * b, 189 Kind k, bool s, Type * i = nullptr ) 190 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == Ttype || s ), 191 init( i ) {} 191 192 192 193 const char * typeString() const override; … … 198 199 199 200 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 200 private:201 private: 201 202 TypeDecl * clone() const override { return new TypeDecl{ *this }; } 202 203 MUTATE_FRIEND … … 343 344 ptr<AsmStmt> stmt; 344 345 345 AsmDecl( const CodeLocation & loc, AsmStmt * stmt )346 AsmDecl( const CodeLocation & loc, AsmStmt * stmt ) 346 347 : Decl( loc, "", {}, {} ), stmt(stmt) {} 347 348 348 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }349 private: 350 AsmDecl * clone() const override { return new AsmDecl( *this ); }349 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); } 350 private: 351 AsmDecl * clone() const override { return new AsmDecl( *this ); } 351 352 MUTATE_FRIEND 352 353 }; … … 360 361 : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {} 361 362 362 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }363 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); } 363 364 private: 364 365 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } -
src/AST/Print.cpp
rab5c0008 r07de76b 1359 1359 preprint( node ); 1360 1360 os << "instance of type " << node->name 1361 << " (" << (node->kind == ast::Type Var::Ftype ? "" : "not ") << "function type)";1361 << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)"; 1362 1362 print( node->params ); 1363 1363 -
src/AST/Type.hpp
rab5c0008 r07de76b 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu May 9 10:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 21:56:46 2019 13 // Update Count : 5 14 14 // 15 15 … … 26 26 #include "Fwd.hpp" 27 27 #include "Node.hpp" // for Node, ptr, ptr_base 28 #include "TypeVar.hpp"29 28 #include "Visitor.hpp" 30 29 … … 423 422 public: 424 423 readonly<TypeDecl> base; 425 Type Var::Kind kind;424 TypeDecl::Kind kind; 426 425 427 426 TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 428 427 std::vector<ptr<Attribute>> && as = {} ) 429 428 : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} 430 TypeInstType( const std::string& n, Type Var::Kind k, CV::Qualifiers q = {},429 TypeInstType( const std::string& n, TypeDecl::Kind k, CV::Qualifiers q = {}, 431 430 std::vector<ptr<Attribute>> && as = {} ) 432 431 : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {} -
src/AST/TypeEnvironment.cpp
rab5c0008 r07de76b 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 29 11:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Wed May 29 11:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 21:49:13 2019 13 // Update Count : 4 14 14 // 15 15 … … 240 240 return true; 241 241 } else if ( auto typeInst = dynamic_cast< const TypeInstType * >( type ) ) { 242 return typeInst->kind == Type Var::Ftype;242 return typeInst->kind == TypeDecl::Ftype; 243 243 } else return false; 244 244 } … … 248 248 bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) { 249 249 switch ( data.kind ) { 250 case Type Var::Dtype:250 case TypeDecl::Dtype: 251 251 // to bind to an object type variable, the type must not be a function type. 252 252 // if the type variable is specified to be a complete type then the incoming … … 254 254 // xxx - should this also check that type is not a tuple type and that it's not a ttype? 255 255 return ! isFtype( type ) && ( ! data.isComplete || type->isComplete() ); 256 case Type Var::Ftype:256 case TypeDecl::Ftype: 257 257 return isFtype( type ); 258 case Type Var::Ttype:258 case TypeDecl::Ttype: 259 259 // ttype unifies with any tuple type 260 260 return dynamic_cast< const TupleType * >( type ) || Tuples::isTtype( type ); -
src/AST/TypeEnvironment.hpp
rab5c0008 r07de76b 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 29 11:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Wed May 29 11:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 21:55:54 2019 13 // Update Count : 3 14 14 // 15 15 … … 28 28 #include "Type.hpp" 29 29 #include "TypeSubstitution.hpp" 30 #include "TypeVar.hpp"31 30 #include "Common/Indenter.h" 32 31 #include "ResolvExpr/WidenMode.h" … … 107 106 /// Singleton class constructor from substitution 108 107 EqvClass( const std::string & v, const Type * b ) 109 : vars{ v }, bound( b ), allowWidening( false ), data( Type Var::Dtype, false ) {}108 : vars{ v }, bound( b ), allowWidening( false ), data( TypeDecl::Dtype, false ) {} 110 109 111 110 /// Single-var constructor (strips qualifiers from bound type) -
src/AST/module.mk
rab5c0008 r07de76b 10 10 ## Author : Thierry Delisle 11 11 ## Created On : Thu May 09 16:05:36 2019 12 ## Last Modified By : 13 ## Last Modified On : 14 ## Update Count : 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Sat Dec 14 07:29:10 2019 14 ## Update Count : 3 15 15 ############################################################################### 16 16 … … 34 34 AST/TypeSubstitution.cpp 35 35 36 37 38 36 SRC += $(SRC_AST) 39 37 SRCDEMANGLE += $(SRC_AST)
Note: See TracChangeset
for help on using the changeset viewer.