Changeset f04a8b81 for src/Parser/DeclarationNode.cc
- Timestamp:
- Sep 5, 2016, 10:09:56 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1ced874, 5fda714
- Parents:
- 621701d (diff), 3403534 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r621701d rf04a8b81 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 22:12:44201613 // Update Count : 27812 // Last Modified On : Mon Aug 29 22:30:56 2016 13 // Update Count : 327 14 14 // 15 15 … … 42 42 43 43 extern LinkageSpec::Spec linkage; // defined in parser.yy 44 45 DeclarationNode::DeclarationNode() 46 : type( 0 ) 47 , storageClass( NoStorageClass ) 48 , isInline( false ) 49 , isNoreturn( false ) 50 , bitfieldWidth( 0 ) 51 , initializer( 0 ) 52 , hasEllipsis( false ) 53 , linkage( ::linkage ) 54 , extension( false ) 55 , error() { 56 attr.expr = nullptr; 57 attr.type = nullptr; 58 59 variable.tyClass = DeclarationNode::Type; 60 variable.assertions = nullptr; 61 } 62 63 DeclarationNode::~DeclarationNode() { 64 delete attr.expr; 65 delete attr.type; 66 delete type; 67 delete bitfieldWidth; 68 delete initializer; 69 } 44 70 45 71 DeclarationNode *DeclarationNode::clone() const { … … 55 81 newnode->set_next( maybeClone( get_next() ) ); 56 82 newnode->linkage = linkage; 83 84 newnode->variable.assertions = maybeClone( variable.assertions ); 85 newnode->variable.name = variable.name; 86 newnode->variable.tyClass = variable.tyClass; 87 88 newnode->attr.expr = maybeClone( attr.expr ); 89 newnode->attr.type = maybeClone( attr.type ); 57 90 return newnode; 58 91 } // DeclarationNode::clone 59 60 DeclarationNode::DeclarationNode()61 : type( 0 )62 , storageClass( NoStorageClass )63 , isInline( false )64 , isNoreturn( false )65 , bitfieldWidth( 0 )66 , initializer( 0 )67 , hasEllipsis( false )68 , linkage( ::linkage )69 , extension( false )70 , error() {71 }72 73 DeclarationNode::~DeclarationNode() {74 delete type;75 delete bitfieldWidth;76 delete initializer;77 }78 92 79 93 bool DeclarationNode::get_hasEllipsis() const { … … 129 143 130 144 newnode->type = new TypeData( TypeData::Function ); 131 newnode->type->function ->params = param;132 newnode->type->function ->newStyle = newStyle;133 newnode->type->function ->body = body;145 newnode->type->function.params = param; 146 newnode->type->function.newStyle = newStyle; 147 newnode->type->function.body = body; 134 148 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 135 149 136 150 if ( body ) { 137 newnode->type->function ->hasBody = true;151 newnode->type->function.hasBody = true; 138 152 } // if 139 153 … … 175 189 DeclarationNode *newnode = new DeclarationNode; 176 190 newnode->type = new TypeData( TypeData::Basic ); 177 newnode->type->basic ->typeSpec.push_back( bt );191 newnode->type->basic.typeSpec.push_back( bt ); 178 192 return newnode; 179 193 } // DeclarationNode::newBasicType … … 182 196 DeclarationNode *newnode = new DeclarationNode; 183 197 newnode->type = new TypeData( TypeData::Basic ); 184 newnode->type->basic ->modifiers.push_back( mod );198 newnode->type->basic.modifiers.push_back( mod ); 185 199 return newnode; 186 200 } // DeclarationNode::newModifier 187 201 188 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {189 DeclarationNode *newnode = new DeclarationNode;190 newnode->type = new TypeData( TypeData::Builtin );191 newnode->type->builtin->type = bt;192 return newnode;193 } // DeclarationNode::newBuiltinType194 195 202 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 196 203 DeclarationNode *newnode = new DeclarationNode; 197 204 newnode->type = new TypeData( TypeData::SymbolicInst ); 198 newnode->type->symbolic ->name = assign_strptr( name );199 newnode->type->symbolic ->isTypedef = true;200 newnode->type->symbolic ->params = 0;205 newnode->type->symbolic.name = assign_strptr( name ); 206 newnode->type->symbolic.isTypedef = true; 207 newnode->type->symbolic.params = 0; 201 208 return newnode; 202 209 } // DeclarationNode::newFromTypedef … … 205 212 DeclarationNode *newnode = new DeclarationNode; 206 213 newnode->type = new TypeData( TypeData::Aggregate ); 207 newnode->type->aggregate ->kind = kind;208 newnode->type->aggregate ->name = assign_strptr( name );209 if ( newnode->type->aggregate ->name == "" ) { // anonymous aggregate ?210 newnode->type->aggregate ->name = anonymous.newName();211 } // if 212 newnode->type->aggregate ->actuals = actuals;213 newnode->type->aggregate ->fields = fields;214 newnode->type->aggregate ->body = body;214 newnode->type->aggregate.kind = kind; 215 newnode->type->aggregate.name = assign_strptr( name ); 216 if ( newnode->type->aggregate.name == "" ) { // anonymous aggregate ? 217 newnode->type->aggregate.name = anonymous.newName(); 218 } // if 219 newnode->type->aggregate.actuals = actuals; 220 newnode->type->aggregate.fields = fields; 221 newnode->type->aggregate.body = body; 215 222 return newnode; 216 223 } // DeclarationNode::newAggregate … … 220 227 newnode->name = assign_strptr( name ); 221 228 newnode->type = new TypeData( TypeData::Enum ); 222 newnode->type->enumeration ->name = newnode->name;223 if ( newnode->type->enumeration ->name == "" ) { // anonymous enumeration ?224 newnode->type->enumeration ->name = DeclarationNode::anonymous.newName();225 } // if 226 newnode->type->enumeration ->constants = constants;229 newnode->type->enumeration.name = newnode->name; 230 if ( newnode->type->enumeration.name == "" ) { // anonymous enumeration ? 231 newnode->type->enumeration.name = DeclarationNode::anonymous.newName(); 232 } // if 233 newnode->type->enumeration.constants = constants; 227 234 return newnode; 228 235 } // DeclarationNode::newEnum … … 245 252 DeclarationNode *newnode = new DeclarationNode; 246 253 newnode->type = new TypeData( TypeData::SymbolicInst ); 247 newnode->type->symbolic ->name = assign_strptr( name );248 newnode->type->symbolic ->isTypedef = false;249 newnode->type->symbolic ->actuals = params;254 newnode->type->symbolic.name = assign_strptr( name ); 255 newnode->type->symbolic.isTypedef = false; 256 newnode->type->symbolic.actuals = params; 250 257 return newnode; 251 258 } // DeclarationNode::newFromTypeGen … … 255 262 newnode->name = assign_strptr( name ); 256 263 newnode->type = new TypeData( TypeData::Variable ); 257 newnode-> type->variable->tyClass = tc;258 newnode-> type->variable->name = newnode->name;264 newnode->variable.tyClass = tc; 265 newnode->variable.name = newnode->name; 259 266 return newnode; 260 267 } // DeclarationNode::newTypeParam … … 263 270 DeclarationNode *newnode = new DeclarationNode; 264 271 newnode->type = new TypeData( TypeData::Aggregate ); 265 newnode->type->aggregate ->kind = Trait;266 newnode->type->aggregate ->params = params;267 newnode->type->aggregate ->fields = asserts;268 newnode->type->aggregate ->name = assign_strptr( name );272 newnode->type->aggregate.kind = Trait; 273 newnode->type->aggregate.params = params; 274 newnode->type->aggregate.fields = asserts; 275 newnode->type->aggregate.name = assign_strptr( name ); 269 276 return newnode; 270 277 } // DeclarationNode::newTrait … … 273 280 DeclarationNode *newnode = new DeclarationNode; 274 281 newnode->type = new TypeData( TypeData::AggregateInst ); 275 newnode->type->aggInst ->aggregate = new TypeData( TypeData::Aggregate );276 newnode->type->aggInst ->aggregate->aggregate->kind = Trait;277 newnode->type->aggInst ->aggregate->aggregate->name = assign_strptr( name );278 newnode->type->aggInst ->params = params;282 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 283 newnode->type->aggInst.aggregate->aggregate.kind = Trait; 284 newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name ); 285 newnode->type->aggInst.params = params; 279 286 return newnode; 280 287 } // DeclarationNode::newTraitUse … … 284 291 newnode->name = assign_strptr( name ); 285 292 newnode->type = new TypeData( TypeData::Symbolic ); 286 newnode->type->symbolic ->isTypedef = false;287 newnode->type->symbolic ->params = typeParams;288 newnode->type->symbolic ->name = newnode->name;293 newnode->type->symbolic.isTypedef = false; 294 newnode->type->symbolic.params = typeParams; 295 newnode->type->symbolic.name = newnode->name; 289 296 return newnode; 290 297 } // DeclarationNode::newTypeDecl … … 299 306 DeclarationNode *newnode = new DeclarationNode; 300 307 newnode->type = new TypeData( TypeData::Array ); 301 newnode->type->array ->dimension = size;302 newnode->type->array ->isStatic = isStatic;303 if ( newnode->type->array ->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) {304 newnode->type->array ->isVarLen = false;308 newnode->type->array.dimension = size; 309 newnode->type->array.isStatic = isStatic; 310 if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) { 311 newnode->type->array.isVarLen = false; 305 312 } else { 306 newnode->type->array ->isVarLen = true;313 newnode->type->array.isVarLen = true; 307 314 } // if 308 315 return newnode->addQualifiers( qualifiers ); … … 312 319 DeclarationNode *newnode = new DeclarationNode; 313 320 newnode->type = new TypeData( TypeData::Array ); 314 newnode->type->array ->dimension = 0;315 newnode->type->array ->isStatic = false;316 newnode->type->array ->isVarLen = true;321 newnode->type->array.dimension = 0; 322 newnode->type->array.isStatic = false; 323 newnode->type->array.isVarLen = true; 317 324 return newnode->addQualifiers( qualifiers ); 318 325 } … … 327 334 DeclarationNode *newnode = new DeclarationNode; 328 335 newnode->type = new TypeData( TypeData::Tuple ); 329 newnode->type->tuple ->members= members;336 newnode->type->tuple = members; 330 337 return newnode; 331 338 } … … 334 341 DeclarationNode *newnode = new DeclarationNode; 335 342 newnode->type = new TypeData( TypeData::Typeof ); 336 newnode->type->typeexpr->expr = expr; 337 return newnode; 338 } 343 newnode->type->typeexpr = expr; 344 return newnode; 345 } 346 347 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) { 348 DeclarationNode *newnode = new DeclarationNode; 349 newnode->type = new TypeData( TypeData::Builtin ); 350 newnode->builtin = bt; 351 return newnode; 352 } // DeclarationNode::newBuiltinType 339 353 340 354 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 341 355 DeclarationNode *newnode = new DeclarationNode; 342 356 newnode->type = new TypeData( TypeData::Attr ); 343 newnode-> type->attr->name = assign_strptr( name );344 newnode-> type->attr->expr = expr;357 newnode->attr.name = assign_strptr( name ); 358 newnode->attr.expr = expr; 345 359 return newnode; 346 360 } … … 349 363 DeclarationNode *newnode = new DeclarationNode; 350 364 newnode->type = new TypeData( TypeData::Attr ); 351 newnode-> type->attr->name = assign_strptr( name );352 newnode-> type->attr->type = type;365 newnode->attr.name = assign_strptr( name ); 366 newnode->attr.type = type; 353 367 return newnode; 354 368 } … … 407 421 } else { 408 422 if ( type->kind == TypeData::Aggregate ) { 409 type->aggregate ->params = q->type->forall;423 type->aggregate.params = q->type->forall; 410 424 // change implicit typedef from TYPEDEFname to TYPEGENname 411 typedefTable.changeKind( type->aggregate ->name, TypedefTable::TG );425 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG ); 412 426 } else { 413 427 type->forall = q->type->forall; … … 457 471 if ( src->kind != TypeData::Unknown ) { 458 472 assert( src->kind == TypeData::Basic ); 459 dst->basic ->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers );460 dst->basic ->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec );473 dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers ); 474 dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec ); 461 475 } // if 462 476 break; … … 466 480 case TypeData::Enum: 467 481 dst->base = new TypeData( TypeData::AggregateInst ); 468 dst->base->aggInst ->aggregate = src;482 dst->base->aggInst.aggregate = src; 469 483 if ( src->kind == TypeData::Aggregate ) { 470 dst->base->aggInst ->params = maybeClone( src->aggregate->actuals );484 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 471 485 } // if 472 486 dst->base->qualifiers |= src->qualifiers; … … 495 509 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 496 510 type = new TypeData( TypeData::AggregateInst ); 497 type->aggInst ->aggregate = o->type;511 type->aggInst.aggregate = o->type; 498 512 if ( o->type->kind == TypeData::Aggregate ) { 499 type->aggInst ->params = maybeClone( o->type->aggregate->actuals );513 type->aggInst.params = maybeClone( o->type->aggregate.actuals ); 500 514 } // if 501 515 type->qualifiers |= o->type->qualifiers; … … 523 537 DeclarationNode *DeclarationNode::addTypedef() { 524 538 TypeData *newtype = new TypeData( TypeData::Symbolic ); 525 newtype->symbolic ->params = 0;526 newtype->symbolic ->isTypedef = true;527 newtype->symbolic ->name = name;539 newtype->symbolic.params = 0; 540 newtype->symbolic.isTypedef = true; 541 newtype->symbolic.name = name; 528 542 newtype->base = type; 529 543 type = newtype; … … 535 549 switch ( type->kind ) { 536 550 case TypeData::Symbolic: 537 if ( type->symbolic ->assertions ) {538 type->symbolic ->assertions->appendList( assertions );551 if ( type->symbolic.assertions ) { 552 type->symbolic.assertions->appendList( assertions ); 539 553 } else { 540 type->symbolic ->assertions = assertions;554 type->symbolic.assertions = assertions; 541 555 } // if 542 556 break; 543 557 case TypeData::Variable: 544 if ( type->variable->assertions ) {545 type->variable->assertions->appendList( assertions );558 if ( variable.assertions ) { 559 variable.assertions->appendList( assertions ); 546 560 } else { 547 type->variable->assertions = assertions;561 variable.assertions = assertions; 548 562 } // if 549 563 break; … … 574 588 assert( type ); 575 589 assert( type->kind == TypeData::Function ); 576 assert( type->function ->body == 0 );577 type->function ->body = body;578 type->function ->hasBody = true;590 assert( type->function.body == 0 ); 591 type->function.body = body; 592 type->function.hasBody = true; 579 593 return this; 580 594 } … … 583 597 assert( type ); 584 598 assert( type->kind == TypeData::Function ); 585 assert( type->function ->oldDeclList == 0 );586 type->function ->oldDeclList = list;599 assert( type->function.oldDeclList == 0 ); 600 type->function.oldDeclList = list; 587 601 return this; 588 602 } … … 630 644 case TypeData::Enum: 631 645 p->type->base = new TypeData( TypeData::AggregateInst ); 632 p->type->base->aggInst ->aggregate = type;646 p->type->base->aggInst.aggregate = type; 633 647 if ( type->kind == TypeData::Aggregate ) { 634 p->type->base->aggInst ->params = maybeClone( type->aggregate->actuals );648 p->type->base->aggInst.params = maybeClone( type->aggregate.actuals ); 635 649 } // if 636 650 p->type->base->qualifiers |= type->qualifiers; … … 667 681 case TypeData::Enum: 668 682 lastArray->base = new TypeData( TypeData::AggregateInst ); 669 lastArray->base->aggInst ->aggregate = type;683 lastArray->base->aggInst.aggregate = type; 670 684 if ( type->kind == TypeData::Aggregate ) { 671 lastArray->base->aggInst ->params = maybeClone( type->aggregate->actuals );685 lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals ); 672 686 } // if 673 687 lastArray->base->qualifiers |= type->qualifiers; … … 687 701 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 688 702 TypeData *ftype = new TypeData( TypeData::Function ); 689 ftype->function ->params = params;703 ftype->function.params = params; 690 704 setBase( type, ftype ); 691 705 return this; … … 697 711 type->base = addIdListToType( type->base, ids ); 698 712 } else { 699 type->function ->idList = ids;713 type->function.idList = ids; 700 714 } // if 701 715 return type; 702 716 } else { 703 717 TypeData *newtype = new TypeData( TypeData::Function ); 704 newtype->function ->idList = ids;718 newtype->function.idList = ids; 705 719 return newtype; 706 720 } // if … … 727 741 if ( newnode->type->kind == TypeData::AggregateInst ) { 728 742 // don't duplicate members 729 if ( newnode->type->aggInst ->aggregate->kind == TypeData::Enum ) {730 delete newnode->type->aggInst ->aggregate->enumeration->constants;731 newnode->type->aggInst ->aggregate->enumeration->constants = 0;743 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) { 744 delete newnode->type->aggInst.aggregate->enumeration.constants; 745 newnode->type->aggInst.aggregate->enumeration.constants = 0; 732 746 } else { 733 assert( newnode->type->aggInst ->aggregate->kind == TypeData::Aggregate );734 delete newnode->type->aggInst ->aggregate->aggregate->fields;735 newnode->type->aggInst ->aggregate->aggregate->fields = 0;747 assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate ); 748 delete newnode->type->aggInst.aggregate->aggregate.fields; 749 newnode->type->aggInst.aggregate->aggregate.fields = 0; 736 750 } // if 737 751 } // if … … 753 767 if ( newType->kind == TypeData::AggregateInst ) { 754 768 // don't duplicate members 755 if ( newType->aggInst ->aggregate->kind == TypeData::Enum ) {756 delete newType->aggInst ->aggregate->enumeration->constants;757 newType->aggInst ->aggregate->enumeration->constants = 0;769 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 770 delete newType->aggInst.aggregate->enumeration.constants; 771 newType->aggInst.aggregate->enumeration.constants = 0; 758 772 } else { 759 assert( newType->aggInst ->aggregate->kind == TypeData::Aggregate );760 delete newType->aggInst ->aggregate->aggregate->fields;761 newType->aggInst ->aggregate->aggregate->fields = 0;773 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 774 delete newType->aggInst.aggregate->aggregate.fields; 775 newType->aggInst.aggregate->aggregate.fields = 0; 762 776 } // if 763 777 } // if … … 896 910 if ( ! error.empty() ) throw SemanticError( error, this ); 897 911 if ( type ) { 898 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 912 if ( type->kind == TypeData::Variable ) { 913 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 914 TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] ); 915 buildList( variable.assertions, ret->get_assertions() ); 916 return ret; 917 } else { 918 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 919 } // if 899 920 } // if 900 921 if ( ! isInline && ! isNoreturn ) { … … 909 930 switch ( type->kind ) { 910 931 case TypeData::Enum: 911 return new EnumInstType( buildQualifiers( type ), type->enumeration ->name );932 return new EnumInstType( buildQualifiers( type ), type->enumeration.name ); 912 933 case TypeData::Aggregate: { 913 934 ReferenceToType *ret; 914 switch ( type->aggregate ->kind ) {935 switch ( type->aggregate.kind ) { 915 936 case DeclarationNode::Struct: 916 ret = new StructInstType( buildQualifiers( type ), type->aggregate ->name );937 ret = new StructInstType( buildQualifiers( type ), type->aggregate.name ); 917 938 break; 918 939 case DeclarationNode::Union: 919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate ->name );940 ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name ); 920 941 break; 921 942 case DeclarationNode::Trait: 922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate ->name );943 ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name ); 923 944 break; 924 945 default: 925 946 assert( false ); 926 947 } // switch 927 buildList( type->aggregate ->actuals, ret->get_parameters() );948 buildList( type->aggregate.actuals, ret->get_parameters() ); 928 949 return ret; 929 950 } 930 951 case TypeData::Symbolic: { 931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false ); 932 buildList( type->symbolic->actuals, ret->get_parameters() ); 952 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false ); 953 buildList( type->symbolic.actuals, ret->get_parameters() ); 954 return ret; 955 } 956 case TypeData::Attr: { 957 assert( type->kind == TypeData::Attr ); 958 // assert( type->attr ); 959 AttrType * ret; 960 if ( attr.expr ) { 961 ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() ); 962 } else { 963 assert( attr.type ); 964 ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() ); 965 } // if 933 966 return ret; 934 967 }
Note: See TracChangeset
for help on using the changeset viewer.