Changeset 8f6f47d7 for src/Parser/DeclarationNode.cc
- Timestamp:
- Aug 29, 2016, 5:39:26 PM (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:
- 28307be
- Parents:
- b542bfb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rb542bfb r8f6f47d7 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 15:55:12 2016 13 // Update Count : 311 14 14 // 15 15 … … 129 129 130 130 newnode->type = new TypeData( TypeData::Function ); 131 newnode->type->function ->params = param;132 newnode->type->function ->newStyle = newStyle;133 newnode->type->function ->body = body;131 newnode->type->function.params = param; 132 newnode->type->function.newStyle = newStyle; 133 newnode->type->function.body = body; 134 134 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 135 135 136 136 if ( body ) { 137 newnode->type->function ->hasBody = true;137 newnode->type->function.hasBody = true; 138 138 } // if 139 139 … … 175 175 DeclarationNode *newnode = new DeclarationNode; 176 176 newnode->type = new TypeData( TypeData::Basic ); 177 newnode->type->basic ->typeSpec.push_back( bt );177 newnode->type->basic.typeSpec.push_back( bt ); 178 178 return newnode; 179 179 } // DeclarationNode::newBasicType … … 182 182 DeclarationNode *newnode = new DeclarationNode; 183 183 newnode->type = new TypeData( TypeData::Basic ); 184 newnode->type->basic ->modifiers.push_back( mod );184 newnode->type->basic.modifiers.push_back( mod ); 185 185 return newnode; 186 186 } // DeclarationNode::newModifier 187 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::newBuiltinType194 195 188 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 196 189 DeclarationNode *newnode = new DeclarationNode; 197 190 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;191 newnode->type->symbolic.name = assign_strptr( name ); 192 newnode->type->symbolic.isTypedef = true; 193 newnode->type->symbolic.params = 0; 201 194 return newnode; 202 195 } // DeclarationNode::newFromTypedef … … 205 198 DeclarationNode *newnode = new DeclarationNode; 206 199 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;200 newnode->type->aggregate.kind = kind; 201 newnode->type->aggregate.name = assign_strptr( name ); 202 if ( newnode->type->aggregate.name == "" ) { // anonymous aggregate ? 203 newnode->type->aggregate.name = anonymous.newName(); 204 } // if 205 newnode->type->aggregate.actuals = actuals; 206 newnode->type->aggregate.fields = fields; 207 newnode->type->aggregate.body = body; 215 208 return newnode; 216 209 } // DeclarationNode::newAggregate … … 220 213 newnode->name = assign_strptr( name ); 221 214 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;215 newnode->type->enumeration.name = newnode->name; 216 if ( newnode->type->enumeration.name == "" ) { // anonymous enumeration ? 217 newnode->type->enumeration.name = DeclarationNode::anonymous.newName(); 218 } // if 219 newnode->type->enumeration.constants = constants; 227 220 return newnode; 228 221 } // DeclarationNode::newEnum … … 245 238 DeclarationNode *newnode = new DeclarationNode; 246 239 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;240 newnode->type->symbolic.name = assign_strptr( name ); 241 newnode->type->symbolic.isTypedef = false; 242 newnode->type->symbolic.actuals = params; 250 243 return newnode; 251 244 } // DeclarationNode::newFromTypeGen … … 255 248 newnode->name = assign_strptr( name ); 256 249 newnode->type = new TypeData( TypeData::Variable ); 257 newnode->type->variable ->tyClass = tc;258 newnode->type->variable ->name = newnode->name;250 newnode->type->variable.tyClass = tc; 251 newnode->type->variable.name = newnode->name; 259 252 return newnode; 260 253 } // DeclarationNode::newTypeParam … … 263 256 DeclarationNode *newnode = new DeclarationNode; 264 257 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 );258 newnode->type->aggregate.kind = Trait; 259 newnode->type->aggregate.params = params; 260 newnode->type->aggregate.fields = asserts; 261 newnode->type->aggregate.name = assign_strptr( name ); 269 262 return newnode; 270 263 } // DeclarationNode::newTrait … … 273 266 DeclarationNode *newnode = new DeclarationNode; 274 267 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;268 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 269 newnode->type->aggInst.aggregate->aggregate.kind = Trait; 270 newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name ); 271 newnode->type->aggInst.params = params; 279 272 return newnode; 280 273 } // DeclarationNode::newTraitUse … … 284 277 newnode->name = assign_strptr( name ); 285 278 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;279 newnode->type->symbolic.isTypedef = false; 280 newnode->type->symbolic.params = typeParams; 281 newnode->type->symbolic.name = newnode->name; 289 282 return newnode; 290 283 } // DeclarationNode::newTypeDecl … … 299 292 DeclarationNode *newnode = new DeclarationNode; 300 293 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;294 newnode->type->array.dimension = size; 295 newnode->type->array.isStatic = isStatic; 296 if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) { 297 newnode->type->array.isVarLen = false; 305 298 } else { 306 newnode->type->array ->isVarLen = true;299 newnode->type->array.isVarLen = true; 307 300 } // if 308 301 return newnode->addQualifiers( qualifiers ); … … 312 305 DeclarationNode *newnode = new DeclarationNode; 313 306 newnode->type = new TypeData( TypeData::Array ); 314 newnode->type->array ->dimension = 0;315 newnode->type->array ->isStatic = false;316 newnode->type->array ->isVarLen = true;307 newnode->type->array.dimension = 0; 308 newnode->type->array.isStatic = false; 309 newnode->type->array.isVarLen = true; 317 310 return newnode->addQualifiers( qualifiers ); 318 311 } … … 327 320 DeclarationNode *newnode = new DeclarationNode; 328 321 newnode->type = new TypeData( TypeData::Tuple ); 329 newnode->type->tuple ->members= members;322 newnode->type->tuple = members; 330 323 return newnode; 331 324 } … … 334 327 DeclarationNode *newnode = new DeclarationNode; 335 328 newnode->type = new TypeData( TypeData::Typeof ); 336 newnode->type->typeexpr->expr = expr; 337 return newnode; 338 } 329 newnode->type->typeexpr = expr; 330 return newnode; 331 } 332 333 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) { 334 DeclarationNode *newnode = new DeclarationNode; 335 newnode->type = new TypeData( TypeData::Builtin ); 336 newnode->builtin = bt; 337 return newnode; 338 } // DeclarationNode::newBuiltinType 339 339 340 340 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 341 341 DeclarationNode *newnode = new DeclarationNode; 342 342 newnode->type = new TypeData( TypeData::Attr ); 343 newnode->type->attr ->name = assign_strptr( name );344 newnode->type->attr ->expr = expr;343 newnode->type->attr.name = assign_strptr( name ); 344 newnode->type->attr.expr = expr; 345 345 return newnode; 346 346 } … … 349 349 DeclarationNode *newnode = new DeclarationNode; 350 350 newnode->type = new TypeData( TypeData::Attr ); 351 newnode->type->attr ->name = assign_strptr( name );352 newnode->type->attr ->type = type;351 newnode->type->attr.name = assign_strptr( name ); 352 newnode->type->attr.type = type; 353 353 return newnode; 354 354 } … … 407 407 } else { 408 408 if ( type->kind == TypeData::Aggregate ) { 409 type->aggregate ->params = q->type->forall;409 type->aggregate.params = q->type->forall; 410 410 // change implicit typedef from TYPEDEFname to TYPEGENname 411 typedefTable.changeKind( type->aggregate ->name, TypedefTable::TG );411 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG ); 412 412 } else { 413 413 type->forall = q->type->forall; … … 457 457 if ( src->kind != TypeData::Unknown ) { 458 458 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 );459 dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers ); 460 dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec ); 461 461 } // if 462 462 break; … … 466 466 case TypeData::Enum: 467 467 dst->base = new TypeData( TypeData::AggregateInst ); 468 dst->base->aggInst ->aggregate = src;468 dst->base->aggInst.aggregate = src; 469 469 if ( src->kind == TypeData::Aggregate ) { 470 dst->base->aggInst ->params = maybeClone( src->aggregate->actuals );470 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 471 471 } // if 472 472 dst->base->qualifiers |= src->qualifiers; … … 495 495 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 496 496 type = new TypeData( TypeData::AggregateInst ); 497 type->aggInst ->aggregate = o->type;497 type->aggInst.aggregate = o->type; 498 498 if ( o->type->kind == TypeData::Aggregate ) { 499 type->aggInst ->params = maybeClone( o->type->aggregate->actuals );499 type->aggInst.params = maybeClone( o->type->aggregate.actuals ); 500 500 } // if 501 501 type->qualifiers |= o->type->qualifiers; … … 523 523 DeclarationNode *DeclarationNode::addTypedef() { 524 524 TypeData *newtype = new TypeData( TypeData::Symbolic ); 525 newtype->symbolic ->params = 0;526 newtype->symbolic ->isTypedef = true;527 newtype->symbolic ->name = name;525 newtype->symbolic.params = 0; 526 newtype->symbolic.isTypedef = true; 527 newtype->symbolic.name = name; 528 528 newtype->base = type; 529 529 type = newtype; … … 535 535 switch ( type->kind ) { 536 536 case TypeData::Symbolic: 537 if ( type->symbolic ->assertions ) {538 type->symbolic ->assertions->appendList( assertions );537 if ( type->symbolic.assertions ) { 538 type->symbolic.assertions->appendList( assertions ); 539 539 } else { 540 type->symbolic ->assertions = assertions;540 type->symbolic.assertions = assertions; 541 541 } // if 542 542 break; 543 543 case TypeData::Variable: 544 if ( type->variable ->assertions ) {545 type->variable ->assertions->appendList( assertions );544 if ( type->variable.assertions ) { 545 type->variable.assertions->appendList( assertions ); 546 546 } else { 547 type->variable ->assertions = assertions;547 type->variable.assertions = assertions; 548 548 } // if 549 549 break; … … 574 574 assert( type ); 575 575 assert( type->kind == TypeData::Function ); 576 assert( type->function ->body == 0 );577 type->function ->body = body;578 type->function ->hasBody = true;576 assert( type->function.body == 0 ); 577 type->function.body = body; 578 type->function.hasBody = true; 579 579 return this; 580 580 } … … 583 583 assert( type ); 584 584 assert( type->kind == TypeData::Function ); 585 assert( type->function ->oldDeclList == 0 );586 type->function ->oldDeclList = list;585 assert( type->function.oldDeclList == 0 ); 586 type->function.oldDeclList = list; 587 587 return this; 588 588 } … … 630 630 case TypeData::Enum: 631 631 p->type->base = new TypeData( TypeData::AggregateInst ); 632 p->type->base->aggInst ->aggregate = type;632 p->type->base->aggInst.aggregate = type; 633 633 if ( type->kind == TypeData::Aggregate ) { 634 p->type->base->aggInst ->params = maybeClone( type->aggregate->actuals );634 p->type->base->aggInst.params = maybeClone( type->aggregate.actuals ); 635 635 } // if 636 636 p->type->base->qualifiers |= type->qualifiers; … … 667 667 case TypeData::Enum: 668 668 lastArray->base = new TypeData( TypeData::AggregateInst ); 669 lastArray->base->aggInst ->aggregate = type;669 lastArray->base->aggInst.aggregate = type; 670 670 if ( type->kind == TypeData::Aggregate ) { 671 lastArray->base->aggInst ->params = maybeClone( type->aggregate->actuals );671 lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals ); 672 672 } // if 673 673 lastArray->base->qualifiers |= type->qualifiers; … … 687 687 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 688 688 TypeData *ftype = new TypeData( TypeData::Function ); 689 ftype->function ->params = params;689 ftype->function.params = params; 690 690 setBase( type, ftype ); 691 691 return this; … … 697 697 type->base = addIdListToType( type->base, ids ); 698 698 } else { 699 type->function ->idList = ids;699 type->function.idList = ids; 700 700 } // if 701 701 return type; 702 702 } else { 703 703 TypeData *newtype = new TypeData( TypeData::Function ); 704 newtype->function ->idList = ids;704 newtype->function.idList = ids; 705 705 return newtype; 706 706 } // if … … 727 727 if ( newnode->type->kind == TypeData::AggregateInst ) { 728 728 // 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;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; 732 732 } 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;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; 736 736 } // if 737 737 } // if … … 753 753 if ( newType->kind == TypeData::AggregateInst ) { 754 754 // 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;755 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 756 delete newType->aggInst.aggregate->enumeration.constants; 757 newType->aggInst.aggregate->enumeration.constants = 0; 758 758 } else { 759 assert( newType->aggInst ->aggregate->kind == TypeData::Aggregate );760 delete newType->aggInst ->aggregate->aggregate->fields;761 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; 762 762 } // if 763 763 } // if … … 909 909 switch ( type->kind ) { 910 910 case TypeData::Enum: 911 return new EnumInstType( buildQualifiers( type ), type->enumeration ->name );911 return new EnumInstType( buildQualifiers( type ), type->enumeration.name ); 912 912 case TypeData::Aggregate: { 913 913 ReferenceToType *ret; 914 switch ( type->aggregate ->kind ) {914 switch ( type->aggregate.kind ) { 915 915 case DeclarationNode::Struct: 916 ret = new StructInstType( buildQualifiers( type ), type->aggregate ->name );916 ret = new StructInstType( buildQualifiers( type ), type->aggregate.name ); 917 917 break; 918 918 case DeclarationNode::Union: 919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate ->name );919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name ); 920 920 break; 921 921 case DeclarationNode::Trait: 922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate ->name );922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name ); 923 923 break; 924 924 default: 925 925 assert( false ); 926 926 } // switch 927 buildList( type->aggregate ->actuals, ret->get_parameters() );927 buildList( type->aggregate.actuals, ret->get_parameters() ); 928 928 return ret; 929 929 } 930 930 case TypeData::Symbolic: { 931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic ->name, false );932 buildList( type->symbolic ->actuals, ret->get_parameters() );931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false ); 932 buildList( type->symbolic.actuals, ret->get_parameters() ); 933 933 return ret; 934 934 }
Note: See TracChangeset
for help on using the changeset viewer.