Changes in src/Parser/DeclarationNode.cc [bb7422a:0d0931d]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rbb7422a r0d0931d 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Apr 4 10:28:00 202313 // Update Count : 1 39212 // Last Modified On : Tue Mar 14 11:56:00 2023 13 // Update Count : 1406 14 14 // 15 15 … … 21 21 #include <string> // for string, operator+, allocator, char... 22 22 23 #include "AST/Attribute.hpp" // for Attribute24 #include "AST/Copy.hpp" // for shallowCopy25 #include "AST/Decl.hpp" // for Decl26 #include "AST/Expr.hpp" // for Expr27 #include "AST/Print.hpp" // for print28 #include "AST/Stmt.hpp" // for AsmStmt, DirectiveStmt29 #include "AST/StorageClasses.hpp" // for Storage::Class30 #include "AST/Type.hpp" // for Type31 #include "Common/CodeLocation.h" // for CodeLocation32 #include "Common/Iterate.hpp" // for reverseIterate33 23 #include "Common/SemanticError.h" // for SemanticError 34 24 #include "Common/UniqueName.h" // for UniqueName 35 #include "Common/utility.h" // for maybeClone 25 #include "Common/utility.h" // for maybeClone, maybeBuild, CodeLocation 36 26 #include "Parser/ParseNode.h" // for DeclarationNode, ExpressionNode 27 #include "SynTree/LinkageSpec.h" // for Spec, linkageName, Cforall 28 #include "SynTree/Attribute.h" // for Attribute 29 #include "SynTree/Declaration.h" // for TypeDecl, ObjectDecl, InlineMemberDecl, Declaration 30 #include "SynTree/Expression.h" // for Expression, ConstantExpr 31 #include "SynTree/Statement.h" // for AsmStmt 32 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Type::... 37 33 #include "TypeData.h" // for TypeData, TypeData::Aggregate_t 38 34 #include "TypedefTable.h" // for TypedefTable … … 65 61 UniqueName DeclarationNode::anonymous( "__anonymous" ); 66 62 67 extern ast::Linkage::Spec linkage; // defined in parser.yy63 extern LinkageSpec::Spec linkage; // defined in parser.yy 68 64 69 65 DeclarationNode::DeclarationNode() : … … 71 67 72 68 // variable.name = nullptr; 73 variable.tyClass = ast::TypeDecl::NUMBER_OF_KINDS;69 variable.tyClass = TypeDecl::NUMBER_OF_KINDS; 74 70 variable.assertions = nullptr; 75 71 variable.initializer = nullptr; … … 109 105 newnode->hasEllipsis = hasEllipsis; 110 106 newnode->linkage = linkage; 111 newnode->asmName = maybeC opy( asmName );112 newnode->attributes = attributes;107 newnode->asmName = maybeClone( asmName ); 108 cloneAll( attributes, newnode->attributes ); 113 109 newnode->initializer = maybeClone( initializer ); 114 110 newnode->extension = extension; … … 122 118 123 119 newnode->assert.condition = maybeClone( assert.condition ); 124 newnode->assert.message = maybeC opy( assert.message );120 newnode->assert.message = maybeClone( assert.message ); 125 121 return newnode; 126 122 } // DeclarationNode::clone … … 132 128 } // if 133 129 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 );130 if ( linkage != LinkageSpec::Cforall ) { 131 os << LinkageSpec::name( linkage ) << " "; 132 } // if 133 134 storageClasses.print( os ); 135 funcSpecs.print( os ); 140 136 141 137 if ( type ) { … … 158 154 if ( ! attributes.empty() ) { 159 155 os << string( indent + 2, ' ' ) << "with attributes " << endl; 160 for ( ast::ptr<ast::Attribute> const & attr: reverseIterate( attributes ) ) {156 for ( Attribute * attr: reverseIterate( attributes ) ) { 161 157 os << string( indent + 4, ' ' ) << attr->name.c_str() << endl; 162 158 } // for … … 173 169 } 174 170 175 DeclarationNode * DeclarationNode::newStorageClass( ast::Storage::Classes sc ) {171 DeclarationNode * DeclarationNode::newStorageClass( Type::StorageClasses sc ) { 176 172 DeclarationNode * newnode = new DeclarationNode; 177 173 newnode->storageClasses = sc; … … 179 175 } // DeclarationNode::newStorageClass 180 176 181 DeclarationNode * DeclarationNode::newFuncSpecifier( ast::Function::Specs fs ) {177 DeclarationNode * DeclarationNode::newFuncSpecifier( Type::FuncSpecifiers fs ) { 182 178 DeclarationNode * newnode = new DeclarationNode; 183 179 newnode->funcSpecs = fs; … … 185 181 } // DeclarationNode::newFuncSpecifier 186 182 187 DeclarationNode * DeclarationNode::newTypeQualifier( ast::CV::Qualifiers tq ) {183 DeclarationNode * DeclarationNode::newTypeQualifier( Type::Qualifiers tq ) { 188 184 DeclarationNode * newnode = new DeclarationNode; 189 185 newnode->type = new TypeData(); … … 245 241 } 246 242 247 DeclarationNode * DeclarationNode::newAggregate( ast::AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {243 DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) { 248 244 DeclarationNode * newnode = new DeclarationNode; 249 245 newnode->type = new TypeData( TypeData::Aggregate ); … … 275 271 } // DeclarationNode::newEnum 276 272 273 274 277 275 DeclarationNode * DeclarationNode::newName( const string * name ) { 278 276 DeclarationNode * newnode = new DeclarationNode; … … 326 324 } // DeclarationNode::newFromTypeGen 327 325 328 DeclarationNode * DeclarationNode::newTypeParam( ast::TypeDecl::Kind tc, const string * name ) {326 DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) { 329 327 DeclarationNode * newnode = newName( name ); 330 328 newnode->type = nullptr; … … 338 336 newnode->type = new TypeData( TypeData::Aggregate ); 339 337 newnode->type->aggregate.name = name; 340 newnode->type->aggregate.kind = ast::AggregateDecl::Trait;338 newnode->type->aggregate.kind = AggregateDecl::Trait; 341 339 newnode->type->aggregate.params = params; 342 340 newnode->type->aggregate.fields = asserts; … … 348 346 newnode->type = new TypeData( TypeData::AggregateInst ); 349 347 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 350 newnode->type->aggInst.aggregate->aggregate.kind = ast::AggregateDecl::Trait;348 newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait; 351 349 newnode->type->aggInst.aggregate->aggregate.name = name; 352 350 newnode->type->aggInst.params = params; … … 383 381 newnode->type->array.dimension = size; 384 382 newnode->type->array.isStatic = isStatic; 385 if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType< ast::ConstantExpr *>() ) {383 if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) { 386 384 newnode->type->array.isVarLen = false; 387 385 } else { … … 453 451 DeclarationNode * newnode = new DeclarationNode; 454 452 newnode->type = nullptr; 455 std:: vector<ast::ptr<ast::Expr>> exprs;453 std::list< Expression * > exprs; 456 454 buildList( expr, exprs ); 457 newnode->attributes.push_back( 458 new ast::Attribute( *name, std::move( exprs ) ) ); 455 newnode->attributes.push_back( new Attribute( *name, exprs ) ); 459 456 delete name; 460 457 return newnode; … … 473 470 } 474 471 475 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, ast::Expr* message ) {472 DeclarationNode * DeclarationNode::newStaticAssert( ExpressionNode * condition, Expression * message ) { 476 473 DeclarationNode * newnode = new DeclarationNode; 477 474 newnode->assert.condition = condition; … … 480 477 } 481 478 482 static void appendError( string & dst, const string & src ) { 479 480 void appendError( string & dst, const string & src ) { 483 481 if ( src.empty() ) return; 484 482 if ( dst.empty() ) { dst = src; return; } … … 487 485 488 486 void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) { 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() ); 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 498 495 } // for 499 496 } // DeclarationNode::checkQualifiers 500 497 501 498 void DeclarationNode::checkSpecifiers( DeclarationNode * src ) { 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 } 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 533 521 } // if 534 522 … … 540 528 storageClasses |= q->storageClasses; 541 529 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 530 for ( Attribute * attr: reverseIterate( q->attributes ) ) { 531 attributes.push_front( attr->clone() ); 532 } // for 549 533 return this; 550 534 } // DeclarationNode::copySpecifiers … … 732 716 733 717 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 734 if ( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS ) {718 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 735 719 if ( variable.assertions ) { 736 720 variable.assertions->appendList( assertions ); … … 814 798 DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) { 815 799 if ( a ) { 816 spliceBegin( attributes, a->attributes ); 800 for ( Attribute *attr: reverseIterate( a->attributes ) ) { 801 attributes.push_front( attr ); 802 } // for 817 803 a->attributes.clear(); 818 804 } // if … … 935 921 936 922 DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) { 937 assertf( variable.tyClass != ast::TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." );923 assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." ); 938 924 variable.initializer = init; 939 925 return this; … … 999 985 } 1000 986 1001 void buildList( const DeclarationNode * firstNode, 1002 std::vector<ast::ptr<ast::Decl>> & outputList ) { 987 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ) { 1003 988 SemanticErrorException errors; 1004 std::back_insert_iterator< std::vector<ast::ptr<ast::Decl>>> out( outputList );989 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 1005 990 1006 991 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 1007 992 try { 1008 993 bool extracted = false, anon = false; 1009 ast::AggregateDecl * unionDecl = nullptr;994 AggregateDecl * unionDecl = nullptr; 1010 995 1011 996 if ( DeclarationNode * extr = cur->extractAggregate() ) { … … 1044 1029 } // if 1045 1030 1046 ast::Decl* decl = extr->build();1031 Declaration * decl = extr->build(); 1047 1032 if ( decl ) { 1048 1033 // Remember the declaration if it is a union aggregate ? 1049 unionDecl = dynamic_cast< ast::UnionDecl *>( decl );1034 unionDecl = dynamic_cast<UnionDecl *>( decl ); 1050 1035 1051 1036 decl->location = cur->location; … … 1066 1051 } // if 1067 1052 1068 ast::Decl* decl = cur->build();1053 Declaration * decl = cur->build(); 1069 1054 if ( decl ) { 1070 if ( auto typedefDecl = dynamic_cast<ast::TypedefDecl *>( decl ) ) {1055 if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) { 1071 1056 if ( unionDecl ) { // is the typedef alias a union aggregate ? 1072 1057 // This code handles a special issue with the attribute transparent_union. … … 1080 1065 1081 1066 // If typedef is an alias for a union, then its alias type was hoisted above and remembered. 1082 if ( auto unionInstType = typedefDecl->base.as<ast::UnionInstType>() ) { 1083 auto instType = ast::mutate( unionInstType ); 1067 if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) { 1084 1068 // Remove all transparent_union attributes from typedef and move to alias union. 1085 for ( auto attr = instType->attributes.begin() ; attr != instType->attributes.end() ; ) { // forward order1086 assert( *attr );1069 list<Attribute *>::iterator attr; 1070 for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order 1087 1071 if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) { 1088 unionDecl->attributes.emplace_back( attr->release() ); 1089 attr = instType->attributes.erase( attr ); 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 1090 1076 } else { 1091 attr++; 1077 attr++; // advance iterator 1092 1078 } // if 1093 1079 } // for 1094 typedefDecl->base = instType;1095 1080 } // if 1096 1081 } // if … … 1105 1090 if ( ! (extracted && decl->name == "" && ! anon && ! cur->get_inLine()) ) { 1106 1091 if ( decl->name == "" ) { 1107 if ( auto dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {1108 if ( auto aggr = dynamic_cast<ast::BaseInstType const*>( dwt->get_type() ) ) {1092 if ( DeclarationWithType * dwt = dynamic_cast<DeclarationWithType *>( decl ) ) { 1093 if ( ReferenceToType * aggr = dynamic_cast<ReferenceToType *>( dwt->get_type() ) ) { 1109 1094 if ( aggr->name.find("anonymous") == std::string::npos ) { 1110 1095 if ( ! cur->get_inLine() ) { … … 1132 1117 1133 1118 // currently only builds assertions, function parameters, and return values 1134 void buildList( const DeclarationNode * firstNode, std:: vector<ast::ptr<ast::DeclWithType>> & outputList ) {1119 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ) { 1135 1120 SemanticErrorException errors; 1136 std::back_insert_iterator< std::vector<ast::ptr<ast::DeclWithType>>> out( outputList );1121 std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList ); 1137 1122 1138 1123 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 1139 1124 try { 1140 ast::Decl* decl = cur->build();1125 Declaration * decl = cur->build(); 1141 1126 assert( decl ); 1142 if ( ast::DeclWithType * dwt = dynamic_cast<ast::DeclWithType *>( decl ) ) {1127 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) { 1143 1128 dwt->location = cur->location; 1144 1129 *out++ = dwt; 1145 } else if ( ast::StructDecl * agg = dynamic_cast<ast::StructDecl *>( decl ) ) {1130 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 1146 1131 // e.g., int foo(struct S) {} 1147 auto inst = new ast::StructInstType(agg->name );1148 auto obj = new ast::ObjectDecl( cur->location, "", inst);1149 obj->l inkage = linkage;1132 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name ); 1133 auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr ); 1134 obj->location = cur->location; 1150 1135 *out++ = obj; 1151 1136 delete agg; 1152 } else if ( ast::UnionDecl * agg = dynamic_cast<ast::UnionDecl *>( decl ) ) {1137 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 1153 1138 // e.g., int foo(union U) {} 1154 auto inst = new ast::UnionInstType( agg->name ); 1155 auto obj = new ast::ObjectDecl( cur->location, 1156 "", inst, nullptr, ast::Storage::Classes(), 1157 linkage ); 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; 1158 1142 *out++ = obj; 1159 } else if ( ast::EnumDecl * agg = dynamic_cast<ast::EnumDecl *>( decl ) ) {1143 } else if ( EnumDecl * agg = dynamic_cast< EnumDecl * >( decl ) ) { 1160 1144 // e.g., int foo(enum E) {} 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 ); 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; 1169 1148 *out++ = obj; 1170 1149 } // if … … 1179 1158 } // buildList 1180 1159 1181 void buildTypeList( const DeclarationNode * firstNode, 1182 std::vector<ast::ptr<ast::Type>> & outputList ) { 1160 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ) { 1183 1161 SemanticErrorException errors; 1184 std::back_insert_iterator< std::vector<ast::ptr<ast::Type>>> out( outputList );1162 std::back_insert_iterator< std::list< Type * > > out( outputList ); 1185 1163 const DeclarationNode * cur = firstNode; 1186 1164 … … 1199 1177 } // buildTypeList 1200 1178 1201 ast::Decl* DeclarationNode::build() const {1179 Declaration * DeclarationNode::build() const { 1202 1180 if ( ! error.empty() ) SemanticError( this, error + " in declaration of " ); 1203 1181 1204 1182 if ( asmStmt ) { 1205 auto stmt = strict_dynamic_cast<ast::AsmStmt *>( asmStmt->build() ); 1206 return new ast::AsmDecl( stmt->location, stmt ); 1183 return new AsmDecl( strict_dynamic_cast<AsmStmt *>( asmStmt->build() ) ); 1207 1184 } // if 1208 1185 if ( directiveStmt ) { 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 ) { 1186 return new DirectiveDecl( strict_dynamic_cast<DirectiveStmt *>( directiveStmt->build() ) ); 1187 } // if 1188 1189 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 1214 1190 // otype is internally converted to dtype + otype parameters 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." );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." ); 1217 1193 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 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 ); 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() ); 1227 1196 return ret; 1228 1197 } // if … … 1246 1215 } // if 1247 1216 bool isDelete = initializer && initializer->get_isDelete(); 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 ); 1217 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild(initializer), attributes )->set_extension( extension ); 1259 1218 if ( isDelete ) { 1260 auto dwt = strict_dynamic_cast<ast::DeclWithType *>( decl );1219 DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl ); 1261 1220 dwt->isDeleted = true; 1262 1221 } … … 1265 1224 1266 1225 if ( assert.condition ) { 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 ); 1226 return new StaticAssertDecl( maybeBuild( assert.condition ), strict_dynamic_cast< ConstantExpr * >( maybeClone( assert.message ) ) ); 1270 1227 } 1271 1228 … … 1278 1235 } // if 1279 1236 if ( enumInLine ) { 1280 return new ast::InlineMemberDecl( location, 1281 *name, (ast::Type*)nullptr, storageClasses, linkage ); 1237 return new InlineMemberDecl( *name, storageClasses, linkage, nullptr ); 1282 1238 } // if 1283 1239 assertf( name, "ObjectDecl must a have name\n" ); 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 { 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 { 1298 1244 assert( type ); 1299 1245 … … 1301 1247 case TypeData::Enum: 1302 1248 case TypeData::Aggregate: { 1303 ast::BaseInstType * ret = 1304 buildComAggInst( type, copy( attributes ), linkage ); 1305 buildList( type->aggregate.actuals, ret->params ); 1249 ReferenceToType * ret = buildComAggInst( type, attributes, linkage ); 1250 buildList( type->aggregate.actuals, ret->get_parameters() ); 1306 1251 return ret; 1307 1252 } 1308 1253 case TypeData::Symbolic: { 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 ); 1254 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes ); 1255 buildList( type->symbolic.actuals, ret->get_parameters() ); 1316 1256 return ret; 1317 1257 } 1318 1258 default: 1319 ast::Type * simpletypes = typebuild( type ); 1320 // copy because member is const 1321 simpletypes->attributes = attributes; 1259 Type * simpletypes = typebuild( type ); 1260 simpletypes->get_attributes() = attributes; // copy because member is const 1322 1261 return simpletypes; 1323 1262 } // switch
Note:
See TracChangeset
for help on using the changeset viewer.