Changeset f04a8b81 for src/Parser
- Timestamp:
- Sep 5, 2016, 10:09:56 AM (9 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, 5fda7143
- 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. - Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified 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 } -
TabularUnified src/Parser/ParseNode.h ¶
r621701d rf04a8b81 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 21:14:51201613 // Update Count : 5 7512 // Last Modified On : Mon Aug 29 21:45:43 2016 13 // Update Count : 583 14 14 // 15 15 … … 290 290 // bool buildFuncSpecifier( StorageClass key ) const; 291 291 292 struct Enumeration_t { 293 std::string name; 294 DeclarationNode * constants; 295 }; 296 Enumeration_t enumeration; 297 298 struct Variable_t { 299 DeclarationNode::TypeClass tyClass; 300 std::string name; 301 DeclarationNode * assertions; 302 }; 303 Variable_t variable; 304 305 struct Attr_t { 306 std::string name; 307 ExpressionNode * expr; 308 DeclarationNode * type; 309 }; 310 Attr_t attr; 311 312 BuiltinType builtin; 313 292 314 TypeData *type; 293 315 std::string name; -
TabularUnified src/Parser/TypeData.cc ¶
r621701d rf04a8b81 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 18:28:58201613 // Update Count : 2 2312 // Last Modified On : Mon Aug 29 22:31:53 2016 13 // Update Count : 277 14 14 // 15 15 … … 33 33 break; 34 34 case Basic: 35 basic = new Basic_t;35 // basic = new Basic_t; 36 36 break; 37 37 case Array: 38 array = new Array_t;39 array ->dimension = 0;40 array ->isVarLen = false;41 array ->isStatic = false;38 // array = new Array_t; 39 array.dimension = 0; 40 array.isVarLen = false; 41 array.isStatic = false; 42 42 break; 43 43 case Function: 44 function = new Function_t;45 function ->params = 0;46 function ->idList = 0;47 function ->oldDeclList = 0;48 function ->body = 0;49 function ->hasBody = false;50 function ->newStyle = false;44 // function = new Function_t; 45 function.params = 0; 46 function.idList = 0; 47 function.oldDeclList = 0; 48 function.body = 0; 49 function.hasBody = false; 50 function.newStyle = false; 51 51 break; 52 52 case Aggregate: 53 aggregate = new Aggregate_t;54 aggregate ->params = 0;55 aggregate ->actuals = 0;56 aggregate ->fields = 0;53 // aggregate = new Aggregate_t; 54 aggregate.params = 0; 55 aggregate.actuals = 0; 56 aggregate.fields = 0; 57 57 break; 58 58 case AggregateInst: 59 aggInst = new AggInst_t;60 aggInst ->aggregate = 0;61 aggInst ->params = 0;59 // aggInst = new AggInst_t; 60 aggInst.aggregate = 0; 61 aggInst.params = 0; 62 62 break; 63 63 case Enum: 64 enumeration = new Enumeration_t;65 enumeration ->constants = 0;64 // enumeration = new Enumeration_t; 65 enumeration.constants = 0; 66 66 break; 67 67 case Symbolic: 68 68 case SymbolicInst: 69 symbolic = new Symbolic_t;70 symbolic ->params = 0;71 symbolic ->actuals = 0;72 symbolic ->assertions = 0;69 // symbolic = new Symbolic_t; 70 symbolic.params = 0; 71 symbolic.actuals = 0; 72 symbolic.assertions = 0; 73 73 break; 74 74 case Variable: 75 variable = new Variable_t;76 variable->tyClass = DeclarationNode::Type;77 variable->assertions = 0;75 // variable = new Variable_t; 76 // variable.tyClass = DeclarationNode::Type; 77 // variable.assertions = 0; 78 78 break; 79 79 case Tuple: 80 tuple = new Tuple_t;81 tuple ->members = 0;80 // tuple = new Tuple_t; 81 tuple = nullptr; 82 82 break; 83 83 case Typeof: 84 typeexpr = new Typeof_t; 85 typeexpr->expr = 0; 84 // typeexpr = new Typeof_t; 85 typeexpr = nullptr; 86 break; 87 case Attr: 88 // attr = new Attr_t; 89 // attr.expr = nullptr; 90 // attr.type = nullptr; 86 91 break; 87 92 case Builtin: 88 builtin = new Builtin_t; 89 break; 90 case Attr: 91 attr = new Attr_t; 92 attr->expr = 0; 93 attr->type = 0; 93 // builtin = new Builtin_t; 94 94 break; 95 95 } // switch … … 107 107 break; 108 108 case Basic: 109 delete basic;109 // delete basic; 110 110 break; 111 111 case Array: 112 delete array ->dimension;113 delete array;112 delete array.dimension; 113 // delete array; 114 114 break; 115 115 case Function: 116 delete function ->params;117 delete function ->idList;118 delete function ->oldDeclList;119 delete function ->body;120 delete function;116 delete function.params; 117 delete function.idList; 118 delete function.oldDeclList; 119 delete function.body; 120 // delete function; 121 121 break; 122 122 case Aggregate: 123 delete aggregate ->params;124 delete aggregate ->actuals;125 delete aggregate ->fields;126 delete aggregate;123 delete aggregate.params; 124 delete aggregate.actuals; 125 delete aggregate.fields; 126 // delete aggregate; 127 127 break; 128 128 case AggregateInst: 129 delete aggInst ->aggregate;130 delete aggInst ->params;131 delete aggInst;129 delete aggInst.aggregate; 130 delete aggInst.params; 131 // delete aggInst; 132 132 break; 133 133 case Enum: 134 delete enumeration ->constants;135 delete enumeration;134 delete enumeration.constants; 135 // delete enumeration; 136 136 break; 137 137 case Symbolic: 138 138 case SymbolicInst: 139 delete symbolic ->params;140 delete symbolic ->actuals;141 delete symbolic ->assertions;142 delete symbolic;139 delete symbolic.params; 140 delete symbolic.actuals; 141 delete symbolic.assertions; 142 // delete symbolic; 143 143 break; 144 144 case Variable: 145 delete variable->assertions;146 delete variable;145 // delete variable.assertions; 146 // delete variable; 147 147 break; 148 148 case Tuple: 149 delete tuple->members;149 // delete tuple->members; 150 150 delete tuple; 151 151 break; 152 152 case Typeof: 153 delete typeexpr->expr;153 // delete typeexpr->expr; 154 154 delete typeexpr; 155 155 break; 156 case Attr: 157 // delete attr.expr; 158 // delete attr.type; 159 // delete attr; 160 break; 156 161 case Builtin: 157 delete builtin; 158 break; 159 case Attr: 160 delete attr->expr; 161 delete attr->type; 162 delete attr; 162 // delete builtin; 163 163 break; 164 164 } // switch … … 178 178 break; 179 179 case Basic: 180 newtype->basic ->typeSpec = basic->typeSpec;181 newtype->basic ->modifiers = basic->modifiers;180 newtype->basic.typeSpec = basic.typeSpec; 181 newtype->basic.modifiers = basic.modifiers; 182 182 break; 183 183 case Array: 184 newtype->array ->dimension = maybeClone( array->dimension );185 newtype->array ->isVarLen = array->isVarLen;186 newtype->array ->isStatic = array->isStatic;184 newtype->array.dimension = maybeClone( array.dimension ); 185 newtype->array.isVarLen = array.isVarLen; 186 newtype->array.isStatic = array.isStatic; 187 187 break; 188 188 case Function: 189 newtype->function ->params = maybeClone( function->params );190 newtype->function ->idList = maybeClone( function->idList );191 newtype->function ->oldDeclList = maybeClone( function->oldDeclList );192 newtype->function ->body = maybeClone( function->body );193 newtype->function ->hasBody = function->hasBody;194 newtype->function ->newStyle = function->newStyle;189 newtype->function.params = maybeClone( function.params ); 190 newtype->function.idList = maybeClone( function.idList ); 191 newtype->function.oldDeclList = maybeClone( function.oldDeclList ); 192 newtype->function.body = maybeClone( function.body ); 193 newtype->function.hasBody = function.hasBody; 194 newtype->function.newStyle = function.newStyle; 195 195 break; 196 196 case Aggregate: 197 newtype->aggregate ->params = maybeClone( aggregate->params );198 newtype->aggregate ->actuals = maybeClone( aggregate->actuals );199 newtype->aggregate ->fields = maybeClone( aggregate->fields );200 newtype->aggregate ->name = aggregate->name;201 newtype->aggregate ->kind = aggregate->kind;202 newtype->aggregate ->body = aggregate->body;197 newtype->aggregate.params = maybeClone( aggregate.params ); 198 newtype->aggregate.actuals = maybeClone( aggregate.actuals ); 199 newtype->aggregate.fields = maybeClone( aggregate.fields ); 200 newtype->aggregate.name = aggregate.name; 201 newtype->aggregate.kind = aggregate.kind; 202 newtype->aggregate.body = aggregate.body; 203 203 break; 204 204 case AggregateInst: 205 newtype->aggInst ->aggregate = maybeClone( aggInst->aggregate );206 newtype->aggInst ->params = maybeClone( aggInst->params );205 newtype->aggInst.aggregate = maybeClone( aggInst.aggregate ); 206 newtype->aggInst.params = maybeClone( aggInst.params ); 207 207 break; 208 208 case Enum: 209 newtype->enumeration ->name = enumeration->name;210 newtype->enumeration ->constants = maybeClone( enumeration->constants );209 newtype->enumeration.name = enumeration.name; 210 newtype->enumeration.constants = maybeClone( enumeration.constants ); 211 211 break; 212 212 case Symbolic: 213 213 case SymbolicInst: 214 newtype->symbolic ->params = maybeClone( symbolic->params );215 newtype->symbolic ->actuals = maybeClone( symbolic->actuals );216 newtype->symbolic ->assertions = maybeClone( symbolic->assertions );217 newtype->symbolic ->isTypedef = symbolic->isTypedef;218 newtype->symbolic ->name = symbolic->name;214 newtype->symbolic.params = maybeClone( symbolic.params ); 215 newtype->symbolic.actuals = maybeClone( symbolic.actuals ); 216 newtype->symbolic.assertions = maybeClone( symbolic.assertions ); 217 newtype->symbolic.isTypedef = symbolic.isTypedef; 218 newtype->symbolic.name = symbolic.name; 219 219 break; 220 220 case Variable: 221 newtype->variable->assertions = maybeClone( variable->assertions ); 222 newtype->variable->name = variable->name; 223 newtype->variable->tyClass = variable->tyClass; 221 assert( false ); 222 // newtype->variable.assertions = maybeClone( variable.assertions ); 223 // newtype->variable.name = variable.name; 224 // newtype->variable.tyClass = variable.tyClass; 224 225 break; 225 226 case Tuple: 226 newtype->tuple ->members = maybeClone( tuple->members);227 newtype->tuple = maybeClone( tuple ); 227 228 break; 228 229 case Typeof: 229 newtype->typeexpr->expr = maybeClone( typeexpr->expr ); 230 newtype->typeexpr = maybeClone( typeexpr ); 231 break; 232 case Attr: 233 assert( false ); 234 // newtype->attr.expr = maybeClone( attr.expr ); 235 // newtype->attr.type = maybeClone( attr.type ); 230 236 break; 231 237 case Builtin: 232 newtype->builtin->type = builtin->type; 233 break; 234 case Attr: 235 newtype->attr->expr = maybeClone( attr->expr ); 236 newtype->attr->type = maybeClone( attr->type ); 238 assert( false ); 239 // newtype->builtin = builtin; 237 240 break; 238 241 } // switch … … 268 271 break; 269 272 case Basic: 270 printEnums( basic ->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );271 printEnums( basic ->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );273 printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os ); 274 printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os ); 272 275 break; 273 276 case Array: 274 if ( array ->isStatic ) {277 if ( array.isStatic ) { 275 278 os << "static "; 276 279 } // if 277 if ( array ->dimension ) {280 if ( array.dimension ) { 278 281 os << "array of "; 279 array ->dimension->printOneLine( os, indent );280 } else if ( array ->isVarLen ) {282 array.dimension->printOneLine( os, indent ); 283 } else if ( array.isVarLen ) { 281 284 os << "variable-length array of "; 282 285 } else { … … 289 292 case Function: 290 293 os << "function" << endl; 291 if ( function ->params ) {294 if ( function.params ) { 292 295 os << string( indent + 2, ' ' ) << "with parameters " << endl; 293 function ->params->printList( os, indent + 4 );296 function.params->printList( os, indent + 4 ); 294 297 } else { 295 298 os << string( indent + 2, ' ' ) << "with no parameters " << endl; 296 299 } // if 297 if ( function ->idList ) {300 if ( function.idList ) { 298 301 os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl; 299 function ->idList->printList( os, indent + 4 );300 } // if 301 if ( function ->oldDeclList ) {302 function.idList->printList( os, indent + 4 ); 303 } // if 304 if ( function.oldDeclList ) { 302 305 os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl; 303 function ->oldDeclList->printList( os, indent + 4 );306 function.oldDeclList->printList( os, indent + 4 ); 304 307 } // if 305 308 os << string( indent + 2, ' ' ) << "returning "; … … 310 313 } // if 311 314 os << endl; 312 if ( function ->hasBody ) {315 if ( function.hasBody ) { 313 316 os << string( indent + 2, ' ' ) << "with body " << endl; 314 317 } // if 315 if ( function ->body ) {316 function ->body->printList( os, indent + 2 );318 if ( function.body ) { 319 function.body->printList( os, indent + 2 ); 317 320 } // if 318 321 break; 319 322 case Aggregate: 320 os << DeclarationNode::aggregateName[ aggregate ->kind ] << ' ' << aggregate->name << endl;321 if ( aggregate ->params ) {323 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl; 324 if ( aggregate.params ) { 322 325 os << string( indent + 2, ' ' ) << "with type parameters " << endl; 323 aggregate ->params->printList( os, indent + 4 );324 } // if 325 if ( aggregate ->actuals ) {326 aggregate.params->printList( os, indent + 4 ); 327 } // if 328 if ( aggregate.actuals ) { 326 329 os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl; 327 aggregate ->actuals->printList( os, indent + 4 );328 } // if 329 if ( aggregate ->fields ) {330 aggregate.actuals->printList( os, indent + 4 ); 331 } // if 332 if ( aggregate.fields ) { 330 333 os << string( indent + 2, ' ' ) << "with members " << endl; 331 aggregate ->fields->printList( os, indent + 4 );332 } // if 333 if ( aggregate ->body ) {334 aggregate.fields->printList( os, indent + 4 ); 335 } // if 336 if ( aggregate.body ) { 334 337 os << string( indent + 2, ' ' ) << " with body " << endl; 335 338 } // if 336 339 break; 337 340 case AggregateInst: 338 if ( aggInst ->aggregate ) {341 if ( aggInst.aggregate ) { 339 342 os << "instance of " ; 340 aggInst ->aggregate->print( os, indent );343 aggInst.aggregate->print( os, indent ); 341 344 } else { 342 345 os << "instance of an unspecified aggregate "; 343 346 } // if 344 if ( aggInst ->params ) {347 if ( aggInst.params ) { 345 348 os << string( indent + 2, ' ' ) << "with parameters " << endl; 346 aggInst ->params->printList( os, indent + 2 );349 aggInst.params->printList( os, indent + 2 ); 347 350 } // if 348 351 break; 349 352 case Enum: 350 353 os << "enumeration "; 351 if ( enumeration ->constants ) {354 if ( enumeration.constants ) { 352 355 os << "with constants" << endl; 353 enumeration ->constants->printList( os, indent + 2 );356 enumeration.constants->printList( os, indent + 2 ); 354 357 } // if 355 358 break; 356 359 case SymbolicInst: 357 os << "instance of type " << symbolic ->name;358 if ( symbolic ->actuals ) {360 os << "instance of type " << symbolic.name; 361 if ( symbolic.actuals ) { 359 362 os << " with parameters" << endl; 360 symbolic ->actuals->printList( os, indent + 2 );363 symbolic.actuals->printList( os, indent + 2 ); 361 364 } // if 362 365 break; 363 366 case Symbolic: 364 if ( symbolic ->isTypedef ) {367 if ( symbolic.isTypedef ) { 365 368 os << "typedef definition "; 366 369 } else { 367 370 os << "type definition "; 368 371 } // if 369 if ( symbolic ->params ) {372 if ( symbolic.params ) { 370 373 os << endl << string( indent + 2, ' ' ) << "with parameters" << endl; 371 symbolic ->params->printList( os, indent + 2 );372 } // if 373 if ( symbolic ->assertions ) {374 symbolic.params->printList( os, indent + 2 ); 375 } // if 376 if ( symbolic.assertions ) { 374 377 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 375 symbolic ->assertions->printList( os, indent + 4 );378 symbolic.assertions->printList( os, indent + 4 ); 376 379 os << string( indent + 2, ' ' ); 377 380 } // if … … 382 385 break; 383 386 case Variable: 384 os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable ";385 if ( variable->assertions ) {386 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;387 variable->assertions->printList( os, indent + 4 );388 os << string( indent + 2, ' ' );389 } // if387 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable "; 388 // if ( variable.assertions ) { 389 // os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 390 // variable.assertions->printList( os, indent + 4 ); 391 // os << string( indent + 2, ' ' ); 392 // } // if 390 393 break; 391 394 case Tuple: 392 395 os << "tuple "; 393 if ( tuple ->members) {396 if ( tuple ) { 394 397 os << "with members " << endl; 395 tuple-> members->printList( os, indent + 2 );398 tuple->printList( os, indent + 2 ); 396 399 } // if 397 400 break; 398 401 case Typeof: 399 402 os << "type-of expression "; 400 if ( typeexpr ->expr) {401 typeexpr-> expr->print( os, indent + 2 );403 if ( typeexpr ) { 404 typeexpr->print( os, indent + 2 ); 402 405 } // if 403 406 break; 404 407 case Attr: 405 os << "attribute type decl " << attr->name << " applied to ";406 if ( attr->expr ) {407 attr->expr->print( os, indent + 2 );408 } // if409 if ( attr->type ) {410 attr->type->print( os, indent + 2 );411 } // if408 // os << "attribute type decl " << attr.name << " applied to "; 409 // if ( attr.expr ) { 410 // attr.expr->print( os, indent + 2 ); 411 // } // if 412 // if ( attr.type ) { 413 // attr.type->print( os, indent + 2 ); 414 // } // if 412 415 break; 413 416 case Builtin: … … 479 482 return new VarArgsType( buildQualifiers( td ) ); 480 483 case TypeData::Attr: 484 assert( false ); 481 485 return buildAttr( td ); 482 486 case TypeData::Symbolic: … … 494 498 switch ( td->kind ) { 495 499 case TypeData::Aggregate: 496 if ( ! toplevel && td->aggregate ->fields ) {500 if ( ! toplevel && td->aggregate.fields ) { 497 501 ret = td->clone(); 498 502 } // if 499 503 break; 500 504 case TypeData::Enum: 501 if ( ! toplevel && td->enumeration ->constants ) {505 if ( ! toplevel && td->enumeration.constants ) { 502 506 ret = td->clone(); 503 507 } // if 504 508 break; 505 509 case TypeData::AggregateInst: 506 if ( td->aggInst ->aggregate ) {507 ret = typeextractAggregate( td->aggInst ->aggregate, false );510 if ( td->aggInst.aggregate ) { 511 ret = typeextractAggregate( td->aggInst.aggregate, false ); 508 512 } // if 509 513 break; … … 535 539 BasicType::Kind ret; 536 540 537 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic ->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) {541 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) { 538 542 if ( ! init ) { 539 543 init = true; 540 544 if ( *i == DeclarationNode::Void ) { 541 if ( td->basic ->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) {545 if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) { 542 546 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 543 547 } else { … … 611 615 } // for 612 616 613 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic ->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) {617 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) { 614 618 switch ( *i ) { 615 619 case DeclarationNode::Long: … … 746 750 ArrayType * at; 747 751 if ( td->base ) { 748 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array ->dimension ),749 td->array ->isVarLen, td->array->isStatic );752 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array.dimension ), 753 td->array.isVarLen, td->array.isStatic ); 750 754 } else { 751 755 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 752 maybeBuild< Expression >( td->array ->dimension ), td->array->isVarLen, td->array->isStatic );756 maybeBuild< Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic ); 753 757 } // if 754 758 buildForall( td->forall, at->get_forall() ); … … 759 763 assert( td->kind == TypeData::Aggregate ); 760 764 AggregateDecl * at; 761 switch ( td->aggregate ->kind ) {765 switch ( td->aggregate.kind ) { 762 766 case DeclarationNode::Struct: 763 at = new StructDecl( td->aggregate ->name );764 buildForall( td->aggregate ->params, at->get_parameters() );767 at = new StructDecl( td->aggregate.name ); 768 buildForall( td->aggregate.params, at->get_parameters() ); 765 769 break; 766 770 case DeclarationNode::Union: 767 at = new UnionDecl( td->aggregate ->name );768 buildForall( td->aggregate ->params, at->get_parameters() );771 at = new UnionDecl( td->aggregate.name ); 772 buildForall( td->aggregate.params, at->get_parameters() ); 769 773 break; 770 774 case DeclarationNode::Trait: 771 at = new TraitDecl( td->aggregate ->name );772 buildList( td->aggregate ->params, at->get_parameters() );775 at = new TraitDecl( td->aggregate.name ); 776 buildList( td->aggregate.params, at->get_parameters() ); 773 777 break; 774 778 default: … … 776 780 } // switch 777 781 778 buildList( td->aggregate ->fields, at->get_members() );779 at->set_body( td->aggregate ->body );782 buildList( td->aggregate.fields, at->get_members() ); 783 at->set_body( td->aggregate.body ); 780 784 781 785 return at; … … 786 790 787 791 ReferenceToType * ret; 788 if ( td->aggInst ->aggregate->kind == TypeData::Enum ) {789 ret = new EnumInstType( buildQualifiers( td ), td->aggInst ->aggregate->enumeration->name );792 if ( td->aggInst.aggregate->kind == TypeData::Enum ) { 793 ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name ); 790 794 } else { 791 assert( td->aggInst ->aggregate->kind == TypeData::Aggregate );792 switch ( td->aggInst ->aggregate->aggregate->kind ) {795 assert( td->aggInst.aggregate->kind == TypeData::Aggregate ); 796 switch ( td->aggInst.aggregate->aggregate.kind ) { 793 797 case DeclarationNode::Struct: 794 ret = new StructInstType( buildQualifiers( td ), td->aggInst ->aggregate->aggregate->name );798 ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 795 799 break; 796 800 case DeclarationNode::Union: 797 ret = new UnionInstType( buildQualifiers( td ), td->aggInst ->aggregate->aggregate->name );801 ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 798 802 break; 799 803 case DeclarationNode::Trait: 800 ret = new TraitInstType( buildQualifiers( td ), td->aggInst ->aggregate->aggregate->name );804 ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 801 805 break; 802 806 default: … … 804 808 } // switch 805 809 } // if 806 buildList( td->aggInst ->params, ret->get_parameters() );810 buildList( td->aggInst.params, ret->get_parameters() ); 807 811 buildForall( td->forall, ret->get_forall() ); 808 812 return ret; … … 813 817 NamedTypeDecl * ret; 814 818 assert( td->base ); 815 if ( td->symbolic ->isTypedef ) {819 if ( td->symbolic.isTypedef ) { 816 820 ret = new TypedefDecl( name, sc, typebuild( td->base ) ); 817 821 } else { 818 822 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any ); 819 823 } // if 820 buildList( td->symbolic ->params, ret->get_parameters() );821 buildList( td->symbolic ->assertions, ret->get_assertions() );824 buildList( td->symbolic.params, ret->get_parameters() ); 825 buildList( td->symbolic.assertions, ret->get_assertions() ); 822 826 return ret; 823 827 } // buildSymbolic 824 828 825 829 TypeDecl * buildVariable( const TypeData * td ) { 826 assert( td->kind == TypeData::Variable ); 827 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 828 829 TypeDecl * ret = new TypeDecl( td->variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable->tyClass ] ); 830 buildList( td->variable->assertions, ret->get_assertions() ); 831 return ret; 830 assert( false ); 831 return nullptr; 832 // assert( td->kind == TypeData::Variable ); 833 // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 834 835 // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] ); 836 // buildList( td->variable.assertions, ret->get_assertions() ); 837 // return ret; 832 838 } // buildSymbolic 833 839 834 840 EnumDecl * buildEnum( const TypeData * td ) { 835 841 assert( td->kind == TypeData::Enum ); 836 EnumDecl * ret = new EnumDecl( td->enumeration ->name );837 buildList( td->enumeration ->constants, ret->get_members() );842 EnumDecl * ret = new EnumDecl( td->enumeration.name ); 843 buildList( td->enumeration.constants, ret->get_members() ); 838 844 std::list< Declaration * >::iterator members = ret->get_members().begin(); 839 for ( const DeclarationNode * cur = td->enumeration ->constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {845 for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 840 846 if ( cur->has_enumeratorValue() ) { 841 847 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); … … 848 854 TypeInstType * buildSymbolicInst( const TypeData * td ) { 849 855 assert( td->kind == TypeData::SymbolicInst ); 850 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic ->name, false );851 buildList( td->symbolic ->actuals, ret->get_parameters() );856 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false ); 857 buildList( td->symbolic.actuals, ret->get_parameters() ); 852 858 buildForall( td->forall, ret->get_forall() ); 853 859 return ret; … … 857 863 assert( td->kind == TypeData::Tuple ); 858 864 TupleType * ret = new TupleType( buildQualifiers( td ) ); 859 buildTypeList( td->tuple ->members, ret->get_types() );865 buildTypeList( td->tuple, ret->get_types() ); 860 866 buildForall( td->forall, ret->get_forall() ); 861 867 return ret; … … 865 871 assert( td->kind == TypeData::Typeof ); 866 872 assert( td->typeexpr ); 867 assert( td->typeexpr->expr );868 return new TypeofType( buildQualifiers( td ), td->typeexpr-> expr->build() );873 // assert( td->typeexpr->expr ); 874 return new TypeofType( buildQualifiers( td ), td->typeexpr->build() ); 869 875 } // buildTypeof 870 876 871 877 AttrType * buildAttr( const TypeData * td ) { 872 assert( td->kind == TypeData::Attr ); 873 assert( td->attr ); 874 AttrType * ret; 875 if ( td->attr->expr ) { 876 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->expr->build() ); 877 } else { 878 assert( td->attr->type ); 879 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->type->buildType() ); 880 } // if 881 return ret; 878 assert( false ); 879 return nullptr; 880 // assert( td->kind == TypeData::Attr ); 881 // // assert( td->attr ); 882 // AttrType * ret; 883 // if ( td->attr.expr ) { 884 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() ); 885 // } else { 886 // assert( td->attr.type ); 887 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() ); 888 // } // if 889 // return ret; 882 890 } // buildAttr 883 891 … … 885 893 if ( td->kind == TypeData::Function ) { 886 894 FunctionDecl * decl; 887 if ( td->function ->hasBody ) {888 if ( td->function ->body ) {889 Statement * stmt = td->function ->body->build();895 if ( td->function.hasBody ) { 896 if ( td->function.body ) { 897 Statement * stmt = td->function.body->build(); 890 898 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt ); 891 899 assert( body ); … … 898 906 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn ); 899 907 } // if 900 for ( DeclarationNode * cur = td->function ->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {908 for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 901 909 if ( cur->get_name() != "" ) { 902 910 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); 903 911 } // if 904 912 } // for 905 buildList( td->function ->oldDeclList, decl->get_oldDecls() );913 buildList( td->function.oldDeclList, decl->get_oldDecls() ); 906 914 return decl; 907 915 } else if ( td->kind == TypeData::Aggregate ) { … … 912 920 return buildSymbolic( td, name, sc ); 913 921 } else if ( td->kind == TypeData::Variable ) { 922 assert( false ); 914 923 return buildVariable( td ); 915 924 } else { … … 921 930 FunctionType * buildFunction( const TypeData * td ) { 922 931 assert( td->kind == TypeData::Function ); 923 bool hasEllipsis = td->function ->params ? td->function->params->get_hasEllipsis() : true;924 if ( ! td->function ->params ) hasEllipsis = ! td->function->newStyle;932 bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true; 933 if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle; 925 934 FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis ); 926 buildList( td->function ->params, ft->get_parameters() );935 buildList( td->function.params, ft->get_parameters() ); 927 936 buildForall( td->forall, ft->get_forall() ); 928 937 if ( td->base ) { 929 938 switch ( td->base->kind ) { 930 939 case TypeData::Tuple: 931 buildList( td->base->tuple ->members, ft->get_returnVals() );940 buildList( td->base->tuple, ft->get_returnVals() ); 932 941 break; 933 942 default: -
TabularUnified src/Parser/TypeData.h ¶
r621701d rf04a8b81 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 22:39:00201613 // Update Count : 8512 // Last Modified On : Mon Aug 29 22:31:52 2016 13 // Update Count : 110 14 14 // 15 15 … … 24 24 struct TypeData { 25 25 enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst, 26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr }; 27 27 28 28 struct Basic_t { … … 73 73 }; 74 74 75 struct Variable_t { 76 DeclarationNode::TypeClass tyClass; 77 std::string name; 78 DeclarationNode * assertions; 79 }; 75 // struct Tuple_t { 76 // DeclarationNode * members; 77 // }; 78 79 // struct Typeof_t { 80 // ExpressionNode * expr; 81 // }; 80 82 81 struct Tuple_t { 82 DeclarationNode * members; 83 }; 84 85 struct Typeof_t { 86 ExpressionNode * expr; 87 }; 83 // struct Builtin_t { 84 // DeclarationNode::BuiltinType type; 85 // }; 88 86 89 struct Builtin_t { 90 DeclarationNode::BuiltinType type; 91 }; 92 93 struct Attr_t { 94 std::string name; 95 ExpressionNode * expr; 96 DeclarationNode * type; 97 }; 98 87 Kind kind; 99 88 TypeData * base; 100 89 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; … … 102 91 DeclarationNode * forall; 103 92 104 union { 105 Basic_t * basic; 106 Aggregate_t * aggregate; 107 AggInst_t * aggInst; 108 Array_t * array; 109 Enumeration_t * enumeration; 110 Function_t * function; 111 Symbolic_t * symbolic; 112 Variable_t * variable; 113 Tuple_t * tuple; 114 Typeof_t * typeexpr; 115 Attr_t * attr; 116 Builtin_t * builtin; 117 }; 93 Basic_t basic; 94 Aggregate_t aggregate; 95 AggInst_t aggInst; 96 Array_t array; 97 Enumeration_t enumeration; 98 Function_t function; 99 Symbolic_t symbolic; 100 DeclarationNode * tuple; 101 ExpressionNode * typeexpr; 102 //Attr_t attr; 103 // DeclarationNode::BuiltinType builtin; 118 104 119 105 TypeData( Kind k = Unknown );
Note: See TracChangeset
for help on using the changeset viewer.