Changes in src/Parser/DeclarationNode.cc [28307be:413ad05]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r28307be r413ad05 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:30:56201613 // Update Count : 32712 // Last Modified On : Sun Aug 28 22:12:44 2016 13 // Update Count : 278 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 }70 44 71 45 DeclarationNode *DeclarationNode::clone() const { … … 81 55 newnode->set_next( maybeClone( get_next() ) ); 82 56 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 );90 57 return newnode; 91 58 } // 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 } 92 78 93 79 bool DeclarationNode::get_hasEllipsis() const { … … 143 129 144 130 newnode->type = new TypeData( TypeData::Function ); 145 newnode->type->function .params = param;146 newnode->type->function .newStyle = newStyle;147 newnode->type->function .body = body;131 newnode->type->function->params = param; 132 newnode->type->function->newStyle = newStyle; 133 newnode->type->function->body = body; 148 134 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 149 135 150 136 if ( body ) { 151 newnode->type->function .hasBody = true;137 newnode->type->function->hasBody = true; 152 138 } // if 153 139 … … 189 175 DeclarationNode *newnode = new DeclarationNode; 190 176 newnode->type = new TypeData( TypeData::Basic ); 191 newnode->type->basic .typeSpec.push_back( bt );177 newnode->type->basic->typeSpec.push_back( bt ); 192 178 return newnode; 193 179 } // DeclarationNode::newBasicType … … 196 182 DeclarationNode *newnode = new DeclarationNode; 197 183 newnode->type = new TypeData( TypeData::Basic ); 198 newnode->type->basic .modifiers.push_back( mod );184 newnode->type->basic->modifiers.push_back( mod ); 199 185 return newnode; 200 186 } // DeclarationNode::newModifier 201 187 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::newBuiltinType 194 202 195 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 203 196 DeclarationNode *newnode = new DeclarationNode; 204 197 newnode->type = new TypeData( TypeData::SymbolicInst ); 205 newnode->type->symbolic .name = assign_strptr( name );206 newnode->type->symbolic .isTypedef = true;207 newnode->type->symbolic .params = 0;198 newnode->type->symbolic->name = assign_strptr( name ); 199 newnode->type->symbolic->isTypedef = true; 200 newnode->type->symbolic->params = 0; 208 201 return newnode; 209 202 } // DeclarationNode::newFromTypedef … … 212 205 DeclarationNode *newnode = new DeclarationNode; 213 206 newnode->type = new TypeData( TypeData::Aggregate ); 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;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; 222 215 return newnode; 223 216 } // DeclarationNode::newAggregate … … 227 220 newnode->name = assign_strptr( name ); 228 221 newnode->type = new TypeData( TypeData::Enum ); 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;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; 234 227 return newnode; 235 228 } // DeclarationNode::newEnum … … 252 245 DeclarationNode *newnode = new DeclarationNode; 253 246 newnode->type = new TypeData( TypeData::SymbolicInst ); 254 newnode->type->symbolic .name = assign_strptr( name );255 newnode->type->symbolic .isTypedef = false;256 newnode->type->symbolic .actuals = params;247 newnode->type->symbolic->name = assign_strptr( name ); 248 newnode->type->symbolic->isTypedef = false; 249 newnode->type->symbolic->actuals = params; 257 250 return newnode; 258 251 } // DeclarationNode::newFromTypeGen … … 262 255 newnode->name = assign_strptr( name ); 263 256 newnode->type = new TypeData( TypeData::Variable ); 264 newnode-> variable.tyClass = tc;265 newnode-> variable.name = newnode->name;257 newnode->type->variable->tyClass = tc; 258 newnode->type->variable->name = newnode->name; 266 259 return newnode; 267 260 } // DeclarationNode::newTypeParam … … 270 263 DeclarationNode *newnode = new DeclarationNode; 271 264 newnode->type = new TypeData( TypeData::Aggregate ); 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 );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 ); 276 269 return newnode; 277 270 } // DeclarationNode::newTrait … … 280 273 DeclarationNode *newnode = new DeclarationNode; 281 274 newnode->type = new TypeData( TypeData::AggregateInst ); 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;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; 286 279 return newnode; 287 280 } // DeclarationNode::newTraitUse … … 291 284 newnode->name = assign_strptr( name ); 292 285 newnode->type = new TypeData( TypeData::Symbolic ); 293 newnode->type->symbolic .isTypedef = false;294 newnode->type->symbolic .params = typeParams;295 newnode->type->symbolic .name = newnode->name;286 newnode->type->symbolic->isTypedef = false; 287 newnode->type->symbolic->params = typeParams; 288 newnode->type->symbolic->name = newnode->name; 296 289 return newnode; 297 290 } // DeclarationNode::newTypeDecl … … 306 299 DeclarationNode *newnode = new DeclarationNode; 307 300 newnode->type = new TypeData( TypeData::Array ); 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;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; 312 305 } else { 313 newnode->type->array .isVarLen = true;306 newnode->type->array->isVarLen = true; 314 307 } // if 315 308 return newnode->addQualifiers( qualifiers ); … … 319 312 DeclarationNode *newnode = new DeclarationNode; 320 313 newnode->type = new TypeData( TypeData::Array ); 321 newnode->type->array .dimension = 0;322 newnode->type->array .isStatic = false;323 newnode->type->array .isVarLen = true;314 newnode->type->array->dimension = 0; 315 newnode->type->array->isStatic = false; 316 newnode->type->array->isVarLen = true; 324 317 return newnode->addQualifiers( qualifiers ); 325 318 } … … 334 327 DeclarationNode *newnode = new DeclarationNode; 335 328 newnode->type = new TypeData( TypeData::Tuple ); 336 newnode->type->tuple = members;329 newnode->type->tuple->members = members; 337 330 return newnode; 338 331 } … … 341 334 DeclarationNode *newnode = new DeclarationNode; 342 335 newnode->type = new TypeData( TypeData::Typeof ); 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 336 newnode->type->typeexpr->expr = expr; 337 return newnode; 338 } 353 339 354 340 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 355 341 DeclarationNode *newnode = new DeclarationNode; 356 342 newnode->type = new TypeData( TypeData::Attr ); 357 newnode-> attr.name = assign_strptr( name );358 newnode-> attr.expr = expr;343 newnode->type->attr->name = assign_strptr( name ); 344 newnode->type->attr->expr = expr; 359 345 return newnode; 360 346 } … … 363 349 DeclarationNode *newnode = new DeclarationNode; 364 350 newnode->type = new TypeData( TypeData::Attr ); 365 newnode-> attr.name = assign_strptr( name );366 newnode-> attr.type = type;351 newnode->type->attr->name = assign_strptr( name ); 352 newnode->type->attr->type = type; 367 353 return newnode; 368 354 } … … 421 407 } else { 422 408 if ( type->kind == TypeData::Aggregate ) { 423 type->aggregate .params = q->type->forall;409 type->aggregate->params = q->type->forall; 424 410 // change implicit typedef from TYPEDEFname to TYPEGENname 425 typedefTable.changeKind( type->aggregate .name, TypedefTable::TG );411 typedefTable.changeKind( type->aggregate->name, TypedefTable::TG ); 426 412 } else { 427 413 type->forall = q->type->forall; … … 471 457 if ( src->kind != TypeData::Unknown ) { 472 458 assert( src->kind == TypeData::Basic ); 473 dst->basic .modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );474 dst->basic .typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );459 dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers ); 460 dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec ); 475 461 } // if 476 462 break; … … 480 466 case TypeData::Enum: 481 467 dst->base = new TypeData( TypeData::AggregateInst ); 482 dst->base->aggInst .aggregate = src;468 dst->base->aggInst->aggregate = src; 483 469 if ( src->kind == TypeData::Aggregate ) { 484 dst->base->aggInst .params = maybeClone( src->aggregate.actuals );470 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 485 471 } // if 486 472 dst->base->qualifiers |= src->qualifiers; … … 509 495 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 510 496 type = new TypeData( TypeData::AggregateInst ); 511 type->aggInst .aggregate = o->type;497 type->aggInst->aggregate = o->type; 512 498 if ( o->type->kind == TypeData::Aggregate ) { 513 type->aggInst .params = maybeClone( o->type->aggregate.actuals );499 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 514 500 } // if 515 501 type->qualifiers |= o->type->qualifiers; … … 537 523 DeclarationNode *DeclarationNode::addTypedef() { 538 524 TypeData *newtype = new TypeData( TypeData::Symbolic ); 539 newtype->symbolic .params = 0;540 newtype->symbolic .isTypedef = true;541 newtype->symbolic .name = name;525 newtype->symbolic->params = 0; 526 newtype->symbolic->isTypedef = true; 527 newtype->symbolic->name = name; 542 528 newtype->base = type; 543 529 type = newtype; … … 549 535 switch ( type->kind ) { 550 536 case TypeData::Symbolic: 551 if ( type->symbolic .assertions ) {552 type->symbolic .assertions->appendList( assertions );537 if ( type->symbolic->assertions ) { 538 type->symbolic->assertions->appendList( assertions ); 553 539 } else { 554 type->symbolic .assertions = assertions;540 type->symbolic->assertions = assertions; 555 541 } // if 556 542 break; 557 543 case TypeData::Variable: 558 if ( variable.assertions ) {559 variable.assertions->appendList( assertions );544 if ( type->variable->assertions ) { 545 type->variable->assertions->appendList( assertions ); 560 546 } else { 561 variable.assertions = assertions;547 type->variable->assertions = assertions; 562 548 } // if 563 549 break; … … 588 574 assert( type ); 589 575 assert( type->kind == TypeData::Function ); 590 assert( type->function .body == 0 );591 type->function .body = body;592 type->function .hasBody = true;576 assert( type->function->body == 0 ); 577 type->function->body = body; 578 type->function->hasBody = true; 593 579 return this; 594 580 } … … 597 583 assert( type ); 598 584 assert( type->kind == TypeData::Function ); 599 assert( type->function .oldDeclList == 0 );600 type->function .oldDeclList = list;585 assert( type->function->oldDeclList == 0 ); 586 type->function->oldDeclList = list; 601 587 return this; 602 588 } … … 644 630 case TypeData::Enum: 645 631 p->type->base = new TypeData( TypeData::AggregateInst ); 646 p->type->base->aggInst .aggregate = type;632 p->type->base->aggInst->aggregate = type; 647 633 if ( type->kind == TypeData::Aggregate ) { 648 p->type->base->aggInst .params = maybeClone( type->aggregate.actuals );634 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 649 635 } // if 650 636 p->type->base->qualifiers |= type->qualifiers; … … 681 667 case TypeData::Enum: 682 668 lastArray->base = new TypeData( TypeData::AggregateInst ); 683 lastArray->base->aggInst .aggregate = type;669 lastArray->base->aggInst->aggregate = type; 684 670 if ( type->kind == TypeData::Aggregate ) { 685 lastArray->base->aggInst .params = maybeClone( type->aggregate.actuals );671 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 686 672 } // if 687 673 lastArray->base->qualifiers |= type->qualifiers; … … 701 687 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 702 688 TypeData *ftype = new TypeData( TypeData::Function ); 703 ftype->function .params = params;689 ftype->function->params = params; 704 690 setBase( type, ftype ); 705 691 return this; … … 711 697 type->base = addIdListToType( type->base, ids ); 712 698 } else { 713 type->function .idList = ids;699 type->function->idList = ids; 714 700 } // if 715 701 return type; 716 702 } else { 717 703 TypeData *newtype = new TypeData( TypeData::Function ); 718 newtype->function .idList = ids;704 newtype->function->idList = ids; 719 705 return newtype; 720 706 } // if … … 741 727 if ( newnode->type->kind == TypeData::AggregateInst ) { 742 728 // don't duplicate members 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;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; 746 732 } else { 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;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; 750 736 } // if 751 737 } // if … … 767 753 if ( newType->kind == TypeData::AggregateInst ) { 768 754 // don't duplicate members 769 if ( newType->aggInst .aggregate->kind == TypeData::Enum ) {770 delete newType->aggInst .aggregate->enumeration.constants;771 newType->aggInst .aggregate->enumeration.constants = 0;755 if ( newType->aggInst->aggregate->kind == TypeData::Enum ) { 756 delete newType->aggInst->aggregate->enumeration->constants; 757 newType->aggInst->aggregate->enumeration->constants = 0; 772 758 } else { 773 assert( newType->aggInst .aggregate->kind == TypeData::Aggregate );774 delete newType->aggInst .aggregate->aggregate.fields;775 newType->aggInst .aggregate->aggregate.fields = 0;759 assert( newType->aggInst->aggregate->kind == TypeData::Aggregate ); 760 delete newType->aggInst->aggregate->aggregate->fields; 761 newType->aggInst->aggregate->aggregate->fields = 0; 776 762 } // if 777 763 } // if … … 910 896 if ( ! error.empty() ) throw SemanticError( error, this ); 911 897 if ( type ) { 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 898 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 920 899 } // if 921 900 if ( ! isInline && ! isNoreturn ) { … … 930 909 switch ( type->kind ) { 931 910 case TypeData::Enum: 932 return new EnumInstType( buildQualifiers( type ), type->enumeration .name );911 return new EnumInstType( buildQualifiers( type ), type->enumeration->name ); 933 912 case TypeData::Aggregate: { 934 913 ReferenceToType *ret; 935 switch ( type->aggregate .kind ) {914 switch ( type->aggregate->kind ) { 936 915 case DeclarationNode::Struct: 937 ret = new StructInstType( buildQualifiers( type ), type->aggregate .name );916 ret = new StructInstType( buildQualifiers( type ), type->aggregate->name ); 938 917 break; 939 918 case DeclarationNode::Union: 940 ret = new UnionInstType( buildQualifiers( type ), type->aggregate .name );919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name ); 941 920 break; 942 921 case DeclarationNode::Trait: 943 ret = new TraitInstType( buildQualifiers( type ), type->aggregate .name );922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name ); 944 923 break; 945 924 default: 946 925 assert( false ); 947 926 } // switch 948 buildList( type->aggregate .actuals, ret->get_parameters() );927 buildList( type->aggregate->actuals, ret->get_parameters() ); 949 928 return ret; 950 929 } 951 930 case TypeData::Symbolic: { 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 931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false ); 932 buildList( type->symbolic->actuals, ret->get_parameters() ); 966 933 return ret; 967 934 }
Note:
See TracChangeset
for help on using the changeset viewer.