Changeset bb7422a for src/Parser/DeclarationNode.cc
- Timestamp:
- Apr 4, 2023, 2:25:52 PM (16 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- beeff61e, e02e13f
- Parents:
- 4541b09
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r4541b09 rbb7422a 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Mar 14 11:56:00 202313 // Update Count : 1 40612 // Last Modified On : Tue Apr 4 10:28:00 2023 13 // Update Count : 1392 14 14 // 15 15 … … 21 21 #include <string> // for string, operator+, allocator, char... 22 22 23 #include "AST/Attribute.hpp" // for Attribute 24 #include "AST/Copy.hpp" // for shallowCopy 25 #include "AST/Decl.hpp" // for Decl 26 #include "AST/Expr.hpp" // for Expr 27 #include "AST/Print.hpp" // for print 28 #include "AST/Stmt.hpp" // for AsmStmt, DirectiveStmt 29 #include "AST/StorageClasses.hpp" // for Storage::Class 30 #include "AST/Type.hpp" // for Type 31 #include "Common/CodeLocation.h" // for CodeLocation 32 #include "Common/Iterate.hpp" // for reverseIterate 23 33 #include "Common/SemanticError.h" // for SemanticError 24 34 #include "Common/UniqueName.h" // for UniqueName 25 #include "Common/utility.h" // for maybeClone , maybeBuild, CodeLocation35 #include "Common/utility.h" // for maybeClone 26 36 #include "Parser/ParseNode.h" // for DeclarationNode, ExpressionNode 27 #include "SynTree/LinkageSpec.h" // for Spec, linkageName, Cforall28 #include "SynTree/Attribute.h" // for Attribute29 #include "SynTree/Declaration.h" // for TypeDecl, ObjectDecl, InlineMemberDecl, Declaration30 #include "SynTree/Expression.h" // for Expression, ConstantExpr31 #include "SynTree/Statement.h" // for AsmStmt32 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Type::...33 37 #include "TypeData.h" // for TypeData, TypeData::Aggregate_t 34 38 #include "TypedefTable.h" // for TypedefTable … … 61 65 UniqueName DeclarationNode::anonymous( "__anonymous" ); 62 66 63 extern LinkageSpec::Spec linkage; // defined in parser.yy67 extern ast::Linkage::Spec linkage; // defined in parser.yy 64 68 65 69 DeclarationNode::DeclarationNode() : … … 67 71 68 72 // variable.name = nullptr; 69 variable.tyClass = TypeDecl::NUMBER_OF_KINDS;73 variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS; 70 74 variable.assertions = nullptr; 71 75 variable.initializer = nullptr; … … 105 109 newnode->hasEllipsis = hasEllipsis; 106 110 newnode->linkage = linkage; 107 newnode->asmName = maybeC lone( asmName );108 cloneAll( attributes, newnode->attributes );111 newnode->asmName = maybeCopy( asmName ); 112 newnode->attributes = attributes; 109 113 newnode->initializer = maybeClone( initializer ); 110 114 newnode->extension = extension; … … 118 122 119 123 newnode->assert.condition = maybeClone( assert.condition ); 120 newnode->assert.message = maybeC lone( assert.message );124 newnode->assert.message = maybeCopy( assert.message ); 121 125 return newnode; 122 126 } // DeclarationNode::clone … … 128 132 } // if 129 133 130 if ( linkage != LinkageSpec::Cforall ) {131 os << LinkageSpec::name( linkage ) << " ";132 } // if 133 134 storageClasses.print( os );135 funcSpecs.print( os );134 if ( linkage != ast::Linkage::Cforall ) { 135 os << ast::Linkage::name( linkage ) << " "; 136 } // if 137 138 ast::print( os, storageClasses ); 139 ast::print( os, funcSpecs ); 136 140 137 141 if ( type ) { … … 154 158 if ( ! attributes.empty() ) { 155 159 os << string( indent + 2, ' ' ) << "with attributes " << endl; 156 for ( Attribute * attr: reverseIterate( attributes ) ) {160 for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) { 157 161 os << string( indent + 4, ' ' ) << attr->name.c_str() << endl; 158 162 } // for … … 169 173 } 170 174 171 DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) {175 DeclarationNode * DeclarationNode::newStorageClass( ast::Storage::Classes sc ) { 172 176 DeclarationNode * newnode = new DeclarationNode; 173 177 newnode->storageClasses = sc; … … 175 179 } // DeclarationNode::newStorageClass 176 180 177 DeclarationNode * DeclarationNode::newFuncSpecifier( Type::FuncSpecifiers fs ) {181 DeclarationNode * DeclarationNode::newFuncSpecifier( ast::Function::Specs fs ) { 178 182 DeclarationNode * newnode = new DeclarationNode; 179 183 newnode->funcSpecs = fs; … … 181 185 } // DeclarationNode::newFuncSpecifier 182 186 183 DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) {187 DeclarationNode * DeclarationNode::newTypeQualifier( ast::CV::Qualifiers tq ) { 184 188 DeclarationNode * newnode = new DeclarationNode; 185 189 newnode->type = new TypeData(); … … 241 245 } 242 246 243 DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {247 DeclarationNode * DeclarationNode::newAggregate( ast::AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) { 244 248 DeclarationNode * newnode = new DeclarationNode; 245 249 newnode->type = new TypeData( TypeData::Aggregate ); … … 271 275 } // DeclarationNode::newEnum 272 276 273 274 275 277 DeclarationNode * DeclarationNode::newName( const string * name ) { 276 278 DeclarationNode * newnode = new DeclarationNode; … … 324 326 } // DeclarationNode::newFromTypeGen 325 327 326 DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) {328 DeclarationNode * DeclarationNode::newTypeParam( ast::TypeDecl::Kind tc, const string * name ) { 327 329 DeclarationNode * newnode = newName( name ); 328 330 newnode->type = nullptr; … … 336 338 newnode->type = new TypeData( TypeData::Aggregate ); 337 339 newnode->type->aggregate.name = name; 338 newnode->type->aggregate.kind = AggregateDecl::Trait;340 newnode->type->aggregate.kind = ast::AggregateDecl::Trait; 339 341 newnode->type->aggregate.params = params; 340 342 newnode->type->aggregate.fields = asserts; … … 346 348 newnode->type = new TypeData( TypeData::AggregateInst ); 347 349 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 348 newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait;350 newnode->type->aggInst.aggregate->aggregate.kind = ast::AggregateDecl::Trait; 349 351 newnode->type->aggInst.aggregate->aggregate.name = name; 350 352 newnode->type->aggInst.params = params; … … 381 383 newnode->type->array.dimension = size; 382 384 newnode->type->array.isStatic = isStatic; 383 if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType< ConstantExpr *>() ) {385 if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ast::ConstantExpr *>() ) { 384 386 newnode->type->array.isVarLen = false; 385 387 } else { … … 451 453 DeclarationNode * newnode = new DeclarationNode; 452 454 newnode->type = nullptr; 453 std:: list< Expression *> exprs;455 std::vector<ast::ptr<ast::Expr>> exprs; 454 456 buildList( expr, exprs ); 455 newnode->attributes.push_back( new Attribute( *name, exprs ) ); 457 newnode->attributes.push_back( 458 new ast::Attribute( *name, std::move( exprs ) ) ); 456 459 delete name; 457 460 return newnode; … … 470 473 } 471 474 472 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression* message ) {475 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, ast::Expr * message ) { 473 476 DeclarationNode * newnode = new DeclarationNode; 474 477 newnode->assert.condition = condition; … … 477 480 } 478 481 479 480 void appendError( string & dst, const string & src ) { 482 static void appendError( string & dst, const string & src ) { 481 483 if ( src.empty() ) return; 482 484 if ( dst.empty() ) { dst = src; return; } … … 485 487 486 488 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) { 487 const Type::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 488 489 if ( (qsrc & qdst).any() ) { // duplicates ? 490 for ( unsigned int i = 0; i < Type::NumTypeQualifier; i += 1 ) { // find duplicates 491 if ( qsrc[i] && qdst[i] ) { 492 appendError( error, string( "duplicate " ) + Type::QualifiersNames[i] ); 493 } // if 494 } // for 489 const ast::CV::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization 490 const ast::CV::Qualifiers duplicates = qsrc & qdst; 491 492 if ( duplicates.any() ) { 493 std::stringstream str; 494 str << "duplicate "; 495 ast::print( str, duplicates ); 496 str << "qualifier(s)"; 497 appendError( error, str.str() ); 495 498 } // for 496 499 } // DeclarationNode::checkQualifiers 497 500 498 501 void DeclarationNode::checkSpecifiers( DeclarationNode * src ) { 499 if ( (funcSpecs & src->funcSpecs).any() ) { // duplicates ? 500 for ( unsigned int i = 0; i < Type::NumFuncSpecifier; i += 1 ) { // find duplicates 501 if ( funcSpecs[i] && src->funcSpecs[i] ) { 502 appendError( error, string( "duplicate " ) + Type::FuncSpecifiersNames[i] ); 503 } // if 504 } // for 505 } // if 506 507 if ( storageClasses.any() && src->storageClasses.any() ) { // any reason to check ? 508 if ( (storageClasses & src->storageClasses ).any() ) { // duplicates ? 509 for ( unsigned int i = 0; i < Type::NumStorageClass; i += 1 ) { // find duplicates 510 if ( storageClasses[i] && src->storageClasses[i] ) { 511 appendError( error, string( "duplicate " ) + Type::StorageClassesNames[i] ); 512 } // if 513 } // for 514 // src is the new item being added and has a single bit 515 } else if ( ! src->storageClasses.is_threadlocal_any() ) { // conflict ? 516 appendError( error, string( "conflicting " ) 517 + Type::StorageClassesNames[storageClasses.ffs()] 518 + " & " + Type::StorageClassesNames[src->storageClasses.ffs()] ); 519 src->storageClasses.reset(); // FIX to preserve invariant of one basic storage specifier 520 } // if 502 ast::Function::Specs fsDups = funcSpecs & src->funcSpecs; 503 if ( fsDups.any() ) { 504 std::stringstream str; 505 str << "duplicate "; 506 ast::print( str, fsDups ); 507 str << "function specifier(s)"; 508 appendError( error, str.str() ); 509 } // if 510 511 // Skip if everything is unset. 512 if ( storageClasses.any() && src->storageClasses.any() ) { 513 ast::Storage::Classes dups = storageClasses & src->storageClasses; 514 // Check for duplicates. 515 if ( dups.any() ) { 516 std::stringstream str; 517 str << "duplicate "; 518 ast::print( str, dups ); 519 str << "storage class(es)"; 520 appendError( error, str.str() ); 521 // Check for conflicts. 522 } else if ( !src->storageClasses.is_threadlocal_any() ) { 523 std::stringstream str; 524 str << "conflicting "; 525 ast::print( str, ast::Storage::Classes( 1 << storageClasses.ffs() ) ); 526 str << "& "; 527 ast::print( str, ast::Storage::Classes( 1 << src->storageClasses.ffs() ) ); 528 str << "storage classes"; 529 appendError( error, str.str() ); 530 // FIX to preserve invariant of one basic storage specifier 531 src->storageClasses.reset(); 532 } 521 533 } // if 522 534 … … 528 540 storageClasses |= q->storageClasses; 529 541 530 for ( Attribute * attr: reverseIterate( q->attributes ) ) { 531 attributes.push_front( attr->clone() ); 532 } // for 542 std::vector<ast::ptr<ast::Attribute>> tmp; 543 tmp.reserve( q->attributes.size() ); 544 for ( auto const & attr : q->attributes ) { 545 tmp.emplace_back( ast::shallowCopy( attr.get() ) ); 546 } 547 spliceBegin( attributes, tmp ); 548 533 549 return this; 534 550 } // DeclarationNode::copySpecifiers … … 716 732 717 733 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 718 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) {734 if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) { 719 735 if ( variable.assertions ) { 720 736 variable.assertions->appendList( assertions ); … … 798 814 DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) { 799 815 if ( a ) { 800 for ( Attribute *attr: reverseIterate( a->attributes ) ) { 801 attributes.push_front( attr ); 802 } // for 816 spliceBegin( attributes, a->attributes ); 803 817 a->attributes.clear(); 804 818 } // if … … 921 935 922 936 DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) { 923 assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );937 assertf( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." ); 924 938 variable.initializer = init; 925 939 return this; … … 985 999 } 986 1000 987 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) { 1001 void buildList( const DeclarationNode * firstNode, 1002 std::vector<ast::ptr<ast::Decl>> & outputList ) { 988 1003 SemanticErrorException errors; 989 std::back_insert_iterator< std::list< Declaration * >> out( outputList );1004 std::back_insert_iterator<std::vector<ast::ptr<ast::Decl>>> out( outputList ); 990 1005 991 1006 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 992 1007 try { 993 1008 bool extracted = false, anon = false; 994 AggregateDecl * unionDecl = nullptr;1009 ast::AggregateDecl * unionDecl = nullptr; 995 1010 996 1011 if ( DeclarationNode * extr = cur->extractAggregate() ) { … … 1029 1044 } // if 1030 1045 1031 Declaration* decl = extr->build();1046 ast::Decl * decl = extr->build(); 1032 1047 if ( decl ) { 1033 1048 // Remember the declaration if it is a union aggregate ? 1034 unionDecl = dynamic_cast< UnionDecl *>( decl );1049 unionDecl = dynamic_cast<ast::UnionDecl *>( decl ); 1035 1050 1036 1051 decl->location = cur->location; … … 1051 1066 } // if 1052 1067 1053 Declaration* decl = cur->build();1068 ast::Decl * decl = cur->build(); 1054 1069 if ( decl ) { 1055 if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) {1070 if ( auto typedefDecl = dynamic_cast<ast::TypedefDecl *>( decl ) ) { 1056 1071 if ( unionDecl ) { // is the typedef alias a union aggregate ? 1057 1072 // This code handles a special issue with the attribute transparent_union. … … 1065 1080 1066 1081 // If typedef is an alias for a union, then its alias type was hoisted above and remembered. 1067 if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) { 1082 if ( auto unionInstType = typedefDecl->base.as<ast::UnionInstType>() ) { 1083 auto instType = ast::mutate( unionInstType ); 1068 1084 // Remove all transparent_union attributes from typedef and move to alias union. 1069 list<Attribute *>::iterator attr;1070 for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order1085 for ( auto attr = instType->attributes.begin() ; attr != instType->attributes.end() ; ) { // forward order 1086 assert( *attr ); 1071 1087 if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) { 1072 list<Attribute *>::iterator cur = attr; // remember current node 1073 attr++; // advance iterator 1074 unionDecl->attributes.emplace_back( *cur ); // move current 1075 unionInstType->attributes.erase( cur ); // remove current 1088 unionDecl->attributes.emplace_back( attr->release() ); 1089 attr = instType->attributes.erase( attr ); 1076 1090 } else { 1077 attr++; // advance iterator1091 attr++; 1078 1092 } // if 1079 1093 } // for 1094 typedefDecl->base = instType; 1080 1095 } // if 1081 1096 } // if … … 1090 1105 if ( ! (extracted && decl->name == "" && ! anon && ! cur->get_inLine()) ) { 1091 1106 if ( decl->name == "" ) { 1092 if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>( decl ) ) {1093 if ( ReferenceToType * aggr = dynamic_cast<ReferenceToType*>( dwt->get_type() ) ) {1107 if ( auto dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) { 1108 if ( auto aggr = dynamic_cast<ast::BaseInstType const *>( dwt->get_type() ) ) { 1094 1109 if ( aggr->name.find("anonymous") == std::string::npos ) { 1095 1110 if ( ! cur->get_inLine() ) { … … 1117 1132 1118 1133 // currently only builds assertions, function parameters, and return values 1119 void buildList( const DeclarationNode * firstNode, std:: list< DeclarationWithType *> & outputList ) {1134 void buildList( const DeclarationNode * firstNode, std::vector<ast::ptr<ast::DeclWithType>> & outputList ) { 1120 1135 SemanticErrorException errors; 1121 std::back_insert_iterator< std::list< DeclarationWithType * >> out( outputList );1136 std::back_insert_iterator<std::vector<ast::ptr<ast::DeclWithType>>> out( outputList ); 1122 1137 1123 1138 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 1124 1139 try { 1125 Declaration* decl = cur->build();1140 ast::Decl * decl = cur->build(); 1126 1141 assert( decl ); 1127 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType *>( decl ) ) {1142 if ( ast::DeclWithType * dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) { 1128 1143 dwt->location = cur->location; 1129 1144 *out++ = dwt; 1130 } else if ( StructDecl * agg = dynamic_cast< StructDecl *>( decl ) ) {1145 } else if ( ast::StructDecl * agg = dynamic_cast<ast::StructDecl *>( decl ) ) { 1131 1146 // e.g., int foo(struct S) {} 1132 StructInstType * inst = new StructInstType( Type::Qualifiers(),agg->name );1133 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr);1134 obj->l ocation = cur->location;1147 auto inst = new ast::StructInstType( agg->name ); 1148 auto obj = new ast::ObjectDecl( cur->location, "", inst ); 1149 obj->linkage = linkage; 1135 1150 *out++ = obj; 1136 1151 delete agg; 1137 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl *>( decl ) ) {1152 } else if ( ast::UnionDecl * agg = dynamic_cast<ast::UnionDecl *>( decl ) ) { 1138 1153 // e.g., int foo(union U) {} 1139 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name ); 1140 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1141 obj->location = cur->location; 1154 auto inst = new ast::UnionInstType( agg->name ); 1155 auto obj = new ast::ObjectDecl( cur->location, 1156 "", inst, nullptr, ast::Storage::Classes(), 1157 linkage ); 1142 1158 *out++ = obj; 1143 } else if ( EnumDecl * agg = dynamic_cast< EnumDecl *>( decl ) ) {1159 } else if ( ast::EnumDecl * agg = dynamic_cast<ast::EnumDecl *>( decl ) ) { 1144 1160 // e.g., int foo(enum E) {} 1145 EnumInstType * inst = new EnumInstType( Type::Qualifiers(), agg->name ); 1146 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1147 obj->location = cur->location; 1161 auto inst = new ast::EnumInstType( agg->name ); 1162 auto obj = new ast::ObjectDecl( cur->location, 1163 "", 1164 inst, 1165 nullptr, 1166 ast::Storage::Classes(), 1167 linkage 1168 ); 1148 1169 *out++ = obj; 1149 1170 } // if … … 1158 1179 } // buildList 1159 1180 1160 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) { 1181 void buildTypeList( const DeclarationNode * firstNode, 1182 std::vector<ast::ptr<ast::Type>> & outputList ) { 1161 1183 SemanticErrorException errors; 1162 std::back_insert_iterator< std::list< Type * >> out( outputList );1184 std::back_insert_iterator<std::vector<ast::ptr<ast::Type>>> out( outputList ); 1163 1185 const DeclarationNode * cur = firstNode; 1164 1186 … … 1177 1199 } // buildTypeList 1178 1200 1179 Declaration* DeclarationNode::build() const {1201 ast::Decl * DeclarationNode::build() const { 1180 1202 if ( ! error.empty() ) SemanticError( this, error + " in declaration of " ); 1181 1203 1182 1204 if ( asmStmt ) { 1183 return new AsmDecl( strict_dynamic_cast<AsmStmt *>( asmStmt->build() ) ); 1205 auto stmt = strict_dynamic_cast<ast::AsmStmt *>( asmStmt->build() ); 1206 return new ast::AsmDecl( stmt->location, stmt ); 1184 1207 } // if 1185 1208 if ( directiveStmt ) { 1186 return new DirectiveDecl( strict_dynamic_cast<DirectiveStmt *>( directiveStmt->build() ) ); 1187 } // if 1188 1189 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 1209 auto stmt = strict_dynamic_cast<ast::DirectiveStmt *>( directiveStmt->build() ); 1210 return new ast::DirectiveDecl( stmt->location, stmt ); 1211 } // if 1212 1213 if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) { 1190 1214 // otype is internally converted to dtype + otype parameters 1191 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype,TypeDecl::Dimension };1192 static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." );1215 static const ast::TypeDecl::Kind kindMap[] = { ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Dtype, ast::TypeDecl::Ftype, ast::TypeDecl::Ttype, ast::TypeDecl::Dimension }; 1216 static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == ast::TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." ); 1193 1217 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1194 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::DStype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1195 buildList( variable.assertions, ret->get_assertions() ); 1218 ast::TypeDecl * ret = new ast::TypeDecl( location, 1219 *name, 1220 ast::Storage::Classes(), 1221 (ast::Type *)nullptr, 1222 kindMap[ variable.tyClass ], 1223 variable.tyClass == ast::TypeDecl::Otype || variable.tyClass == ast::TypeDecl::DStype, 1224 variable.initializer ? variable.initializer->buildType() : nullptr 1225 ); 1226 buildList( variable.assertions, ret->assertions ); 1196 1227 return ret; 1197 1228 } // if … … 1215 1246 } // if 1216 1247 bool isDelete = initializer && initializer->get_isDelete(); 1217 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild(initializer), attributes )->set_extension( extension ); 1248 ast::Decl * decl = buildDecl( 1249 type, 1250 name ? *name : string( "" ), 1251 storageClasses, 1252 maybeBuild( bitfieldWidth ), 1253 funcSpecs, 1254 linkage, 1255 asmName, 1256 isDelete ? nullptr : maybeBuild( initializer ), 1257 copy( attributes ) 1258 )->set_extension( extension ); 1218 1259 if ( isDelete ) { 1219 DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );1260 auto dwt = strict_dynamic_cast<ast::DeclWithType *>( decl ); 1220 1261 dwt->isDeleted = true; 1221 1262 } … … 1224 1265 1225 1266 if ( assert.condition ) { 1226 return new StaticAssertDecl( maybeBuild( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) ); 1267 auto cond = maybeBuild( assert.condition ); 1268 auto msg = strict_dynamic_cast<ast::ConstantExpr *>( maybeCopy( assert.message ) ); 1269 return new ast::StaticAssertDecl( location, cond, msg ); 1227 1270 } 1228 1271 … … 1235 1278 } // if 1236 1279 if ( enumInLine ) { 1237 return new InlineMemberDecl( *name, storageClasses, linkage, nullptr ); 1280 return new ast::InlineMemberDecl( location, 1281 *name, (ast::Type*)nullptr, storageClasses, linkage ); 1238 1282 } // if 1239 1283 assertf( name, "ObjectDecl must a have name\n" ); 1240 return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild( bitfieldWidth ), nullptr, maybeBuild( initializer ) ))->set_asmName( asmName )->set_extension( extension ); 1241 } 1242 1243 Type * DeclarationNode::buildType() const { 1284 auto ret = new ast::ObjectDecl( location, 1285 *name, 1286 (ast::Type*)nullptr, 1287 maybeBuild( initializer ), 1288 storageClasses, 1289 linkage, 1290 maybeBuild( bitfieldWidth ) 1291 ); 1292 ret->asmName = asmName; 1293 ret->extension = extension; 1294 return ret; 1295 } 1296 1297 ast::Type * DeclarationNode::buildType() const { 1244 1298 assert( type ); 1245 1299 … … 1247 1301 case TypeData::Enum: 1248 1302 case TypeData::Aggregate: { 1249 ReferenceToType * ret = buildComAggInst( type, attributes, linkage ); 1250 buildList( type->aggregate.actuals, ret->get_parameters() ); 1303 ast::BaseInstType * ret = 1304 buildComAggInst( type, copy( attributes ), linkage ); 1305 buildList( type->aggregate.actuals, ret->params ); 1251 1306 return ret; 1252 1307 } 1253 1308 case TypeData::Symbolic: { 1254 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes ); 1255 buildList( type->symbolic.actuals, ret->get_parameters() ); 1309 ast::TypeInstType * ret = new ast::TypeInstType( 1310 *type->symbolic.name, 1311 // This is just a default, the true value is not known yet. 1312 ast::TypeDecl::Dtype, 1313 buildQualifiers( type ), 1314 copy( attributes ) ); 1315 buildList( type->symbolic.actuals, ret->params ); 1256 1316 return ret; 1257 1317 } 1258 1318 default: 1259 Type * simpletypes = typebuild( type ); 1260 simpletypes->get_attributes() = attributes; // copy because member is const 1319 ast::Type * simpletypes = typebuild( type ); 1320 // copy because member is const 1321 simpletypes->attributes = attributes; 1261 1322 return simpletypes; 1262 1323 } // switch
Note: See TracChangeset
for help on using the changeset viewer.