Changes in / [f04a8b81:621701d]
- Location:
- src
- Files:
-
- 5 edited
-
Parser/DeclarationNode.cc (modified) (34 diffs)
-
Parser/ParseNode.h (modified) (2 diffs)
-
Parser/TypeData.cc (modified) (25 diffs)
-
Parser/TypeData.h (modified) (4 diffs)
-
main.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rf04a8b81 r621701d 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 } -
src/Parser/ParseNode.h
rf04a8b81 r621701d 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 21:45:43201613 // Update Count : 5 8312 // Last Modified On : Sun Aug 28 21:14:51 2016 13 // Update Count : 575 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 314 292 TypeData *type; 315 293 std::string name; -
src/Parser/TypeData.cc
rf04a8b81 r621701d 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:31:53201613 // Update Count : 2 7712 // Last Modified On : Sun Aug 28 18:28:58 2016 13 // Update Count : 223 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 = nullptr;80 tuple = new Tuple_t; 81 tuple->members = 0; 82 82 break; 83 83 case Typeof: 84 // typeexpr = new Typeof_t; 85 typeexpr = nullptr; 84 typeexpr = new Typeof_t; 85 typeexpr->expr = 0; 86 break; 87 case Builtin: 88 builtin = new Builtin_t; 86 89 break; 87 90 case Attr: 88 // attr = new Attr_t; 89 // attr.expr = nullptr; 90 // attr.type = nullptr; 91 break; 92 case Builtin: 93 // builtin = new Builtin_t; 91 attr = new Attr_t; 92 attr->expr = 0; 93 attr->type = 0; 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 Builtin: 157 delete builtin; 158 break; 156 159 case Attr: 157 // delete attr.expr; 158 // delete attr.type; 159 // delete attr; 160 break; 161 case Builtin: 162 // delete builtin; 160 delete attr->expr; 161 delete attr->type; 162 delete attr; 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 assert( false ); 222 // newtype->variable.assertions = maybeClone( variable.assertions ); 223 // newtype->variable.name = variable.name; 224 // newtype->variable.tyClass = variable.tyClass; 221 newtype->variable->assertions = maybeClone( variable->assertions ); 222 newtype->variable->name = variable->name; 223 newtype->variable->tyClass = variable->tyClass; 225 224 break; 226 225 case Tuple: 227 newtype->tuple = maybeClone( tuple);226 newtype->tuple->members = maybeClone( tuple->members ); 228 227 break; 229 228 case Typeof: 230 newtype->typeexpr = maybeClone( typeexpr ); 229 newtype->typeexpr->expr = maybeClone( typeexpr->expr ); 230 break; 231 case Builtin: 232 newtype->builtin->type = builtin->type; 231 233 break; 232 234 case Attr: 233 assert( false ); 234 // newtype->attr.expr = maybeClone( attr.expr ); 235 // newtype->attr.type = maybeClone( attr.type ); 236 break; 237 case Builtin: 238 assert( false ); 239 // newtype->builtin = builtin; 235 newtype->attr->expr = maybeClone( attr->expr ); 236 newtype->attr->type = maybeClone( attr->type ); 240 237 break; 241 238 } // switch … … 271 268 break; 272 269 case Basic: 273 printEnums( basic .modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os );274 printEnums( basic .typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os );270 printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os ); 271 printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os ); 275 272 break; 276 273 case Array: 277 if ( array .isStatic ) {274 if ( array->isStatic ) { 278 275 os << "static "; 279 276 } // if 280 if ( array .dimension ) {277 if ( array->dimension ) { 281 278 os << "array of "; 282 array .dimension->printOneLine( os, indent );283 } else if ( array .isVarLen ) {279 array->dimension->printOneLine( os, indent ); 280 } else if ( array->isVarLen ) { 284 281 os << "variable-length array of "; 285 282 } else { … … 292 289 case Function: 293 290 os << "function" << endl; 294 if ( function .params ) {291 if ( function->params ) { 295 292 os << string( indent + 2, ' ' ) << "with parameters " << endl; 296 function .params->printList( os, indent + 4 );293 function->params->printList( os, indent + 4 ); 297 294 } else { 298 295 os << string( indent + 2, ' ' ) << "with no parameters " << endl; 299 296 } // if 300 if ( function .idList ) {297 if ( function->idList ) { 301 298 os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl; 302 function .idList->printList( os, indent + 4 );303 } // if 304 if ( function .oldDeclList ) {299 function->idList->printList( os, indent + 4 ); 300 } // if 301 if ( function->oldDeclList ) { 305 302 os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl; 306 function .oldDeclList->printList( os, indent + 4 );303 function->oldDeclList->printList( os, indent + 4 ); 307 304 } // if 308 305 os << string( indent + 2, ' ' ) << "returning "; … … 313 310 } // if 314 311 os << endl; 315 if ( function .hasBody ) {312 if ( function->hasBody ) { 316 313 os << string( indent + 2, ' ' ) << "with body " << endl; 317 314 } // if 318 if ( function .body ) {319 function .body->printList( os, indent + 2 );315 if ( function->body ) { 316 function->body->printList( os, indent + 2 ); 320 317 } // if 321 318 break; 322 319 case Aggregate: 323 os << DeclarationNode::aggregateName[ aggregate .kind ] << ' ' << aggregate.name << endl;324 if ( aggregate .params ) {320 os << DeclarationNode::aggregateName[ aggregate->kind ] << ' ' << aggregate->name << endl; 321 if ( aggregate->params ) { 325 322 os << string( indent + 2, ' ' ) << "with type parameters " << endl; 326 aggregate .params->printList( os, indent + 4 );327 } // if 328 if ( aggregate .actuals ) {323 aggregate->params->printList( os, indent + 4 ); 324 } // if 325 if ( aggregate->actuals ) { 329 326 os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl; 330 aggregate .actuals->printList( os, indent + 4 );331 } // if 332 if ( aggregate .fields ) {327 aggregate->actuals->printList( os, indent + 4 ); 328 } // if 329 if ( aggregate->fields ) { 333 330 os << string( indent + 2, ' ' ) << "with members " << endl; 334 aggregate .fields->printList( os, indent + 4 );335 } // if 336 if ( aggregate .body ) {331 aggregate->fields->printList( os, indent + 4 ); 332 } // if 333 if ( aggregate->body ) { 337 334 os << string( indent + 2, ' ' ) << " with body " << endl; 338 335 } // if 339 336 break; 340 337 case AggregateInst: 341 if ( aggInst .aggregate ) {338 if ( aggInst->aggregate ) { 342 339 os << "instance of " ; 343 aggInst .aggregate->print( os, indent );340 aggInst->aggregate->print( os, indent ); 344 341 } else { 345 342 os << "instance of an unspecified aggregate "; 346 343 } // if 347 if ( aggInst .params ) {344 if ( aggInst->params ) { 348 345 os << string( indent + 2, ' ' ) << "with parameters " << endl; 349 aggInst .params->printList( os, indent + 2 );346 aggInst->params->printList( os, indent + 2 ); 350 347 } // if 351 348 break; 352 349 case Enum: 353 350 os << "enumeration "; 354 if ( enumeration .constants ) {351 if ( enumeration->constants ) { 355 352 os << "with constants" << endl; 356 enumeration .constants->printList( os, indent + 2 );353 enumeration->constants->printList( os, indent + 2 ); 357 354 } // if 358 355 break; 359 356 case SymbolicInst: 360 os << "instance of type " << symbolic .name;361 if ( symbolic .actuals ) {357 os << "instance of type " << symbolic->name; 358 if ( symbolic->actuals ) { 362 359 os << " with parameters" << endl; 363 symbolic .actuals->printList( os, indent + 2 );360 symbolic->actuals->printList( os, indent + 2 ); 364 361 } // if 365 362 break; 366 363 case Symbolic: 367 if ( symbolic .isTypedef ) {364 if ( symbolic->isTypedef ) { 368 365 os << "typedef definition "; 369 366 } else { 370 367 os << "type definition "; 371 368 } // if 372 if ( symbolic .params ) {369 if ( symbolic->params ) { 373 370 os << endl << string( indent + 2, ' ' ) << "with parameters" << endl; 374 symbolic .params->printList( os, indent + 2 );375 } // if 376 if ( symbolic .assertions ) {371 symbolic->params->printList( os, indent + 2 ); 372 } // if 373 if ( symbolic->assertions ) { 377 374 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 378 symbolic .assertions->printList( os, indent + 4 );375 symbolic->assertions->printList( os, indent + 4 ); 379 376 os << string( indent + 2, ' ' ); 380 377 } // if … … 385 382 break; 386 383 case Variable: 387 // 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 //} // if384 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 } // if 393 390 break; 394 391 case Tuple: 395 392 os << "tuple "; 396 if ( tuple ) {393 if ( tuple->members ) { 397 394 os << "with members " << endl; 398 tuple-> printList( os, indent + 2 );395 tuple->members->printList( os, indent + 2 ); 399 396 } // if 400 397 break; 401 398 case Typeof: 402 399 os << "type-of expression "; 403 if ( typeexpr ) {404 typeexpr-> print( os, indent + 2 );400 if ( typeexpr->expr ) { 401 typeexpr->expr->print( os, indent + 2 ); 405 402 } // if 406 403 break; 407 404 case Attr: 408 // os << "attribute type decl " << attr.name << " applied to ";409 // if ( attr.expr ) {410 // attr.expr->print( os, indent + 2 );411 //} // if412 // if ( attr.type ) {413 // attr.type->print( os, indent + 2 );414 //} // if405 os << "attribute type decl " << attr->name << " applied to "; 406 if ( attr->expr ) { 407 attr->expr->print( os, indent + 2 ); 408 } // if 409 if ( attr->type ) { 410 attr->type->print( os, indent + 2 ); 411 } // if 415 412 break; 416 413 case Builtin: … … 482 479 return new VarArgsType( buildQualifiers( td ) ); 483 480 case TypeData::Attr: 484 assert( false );485 481 return buildAttr( td ); 486 482 case TypeData::Symbolic: … … 498 494 switch ( td->kind ) { 499 495 case TypeData::Aggregate: 500 if ( ! toplevel && td->aggregate .fields ) {496 if ( ! toplevel && td->aggregate->fields ) { 501 497 ret = td->clone(); 502 498 } // if 503 499 break; 504 500 case TypeData::Enum: 505 if ( ! toplevel && td->enumeration .constants ) {501 if ( ! toplevel && td->enumeration->constants ) { 506 502 ret = td->clone(); 507 503 } // if 508 504 break; 509 505 case TypeData::AggregateInst: 510 if ( td->aggInst .aggregate ) {511 ret = typeextractAggregate( td->aggInst .aggregate, false );506 if ( td->aggInst->aggregate ) { 507 ret = typeextractAggregate( td->aggInst->aggregate, false ); 512 508 } // if 513 509 break; … … 539 535 BasicType::Kind ret; 540 536 541 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic .typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) {537 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) { 542 538 if ( ! init ) { 543 539 init = true; 544 540 if ( *i == DeclarationNode::Void ) { 545 if ( td->basic .typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) {541 if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) { 546 542 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 547 543 } else { … … 615 611 } // for 616 612 617 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic .modifiers.begin(); i != td->basic.modifiers.end(); ++i ) {613 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) { 618 614 switch ( *i ) { 619 615 case DeclarationNode::Long: … … 750 746 ArrayType * at; 751 747 if ( td->base ) { 752 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array .dimension ),753 td->array .isVarLen, td->array.isStatic );748 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ), 749 td->array->isVarLen, td->array->isStatic ); 754 750 } else { 755 751 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 756 maybeBuild< Expression >( td->array .dimension ), td->array.isVarLen, td->array.isStatic );752 maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic ); 757 753 } // if 758 754 buildForall( td->forall, at->get_forall() ); … … 763 759 assert( td->kind == TypeData::Aggregate ); 764 760 AggregateDecl * at; 765 switch ( td->aggregate .kind ) {761 switch ( td->aggregate->kind ) { 766 762 case DeclarationNode::Struct: 767 at = new StructDecl( td->aggregate .name );768 buildForall( td->aggregate .params, at->get_parameters() );763 at = new StructDecl( td->aggregate->name ); 764 buildForall( td->aggregate->params, at->get_parameters() ); 769 765 break; 770 766 case DeclarationNode::Union: 771 at = new UnionDecl( td->aggregate .name );772 buildForall( td->aggregate .params, at->get_parameters() );767 at = new UnionDecl( td->aggregate->name ); 768 buildForall( td->aggregate->params, at->get_parameters() ); 773 769 break; 774 770 case DeclarationNode::Trait: 775 at = new TraitDecl( td->aggregate .name );776 buildList( td->aggregate .params, at->get_parameters() );771 at = new TraitDecl( td->aggregate->name ); 772 buildList( td->aggregate->params, at->get_parameters() ); 777 773 break; 778 774 default: … … 780 776 } // switch 781 777 782 buildList( td->aggregate .fields, at->get_members() );783 at->set_body( td->aggregate .body );778 buildList( td->aggregate->fields, at->get_members() ); 779 at->set_body( td->aggregate->body ); 784 780 785 781 return at; … … 790 786 791 787 ReferenceToType * ret; 792 if ( td->aggInst .aggregate->kind == TypeData::Enum ) {793 ret = new EnumInstType( buildQualifiers( td ), td->aggInst .aggregate->enumeration.name );788 if ( td->aggInst->aggregate->kind == TypeData::Enum ) { 789 ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name ); 794 790 } else { 795 assert( td->aggInst .aggregate->kind == TypeData::Aggregate );796 switch ( td->aggInst .aggregate->aggregate.kind ) {791 assert( td->aggInst->aggregate->kind == TypeData::Aggregate ); 792 switch ( td->aggInst->aggregate->aggregate->kind ) { 797 793 case DeclarationNode::Struct: 798 ret = new StructInstType( buildQualifiers( td ), td->aggInst .aggregate->aggregate.name );794 ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 799 795 break; 800 796 case DeclarationNode::Union: 801 ret = new UnionInstType( buildQualifiers( td ), td->aggInst .aggregate->aggregate.name );797 ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 802 798 break; 803 799 case DeclarationNode::Trait: 804 ret = new TraitInstType( buildQualifiers( td ), td->aggInst .aggregate->aggregate.name );800 ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 805 801 break; 806 802 default: … … 808 804 } // switch 809 805 } // if 810 buildList( td->aggInst .params, ret->get_parameters() );806 buildList( td->aggInst->params, ret->get_parameters() ); 811 807 buildForall( td->forall, ret->get_forall() ); 812 808 return ret; … … 817 813 NamedTypeDecl * ret; 818 814 assert( td->base ); 819 if ( td->symbolic .isTypedef ) {815 if ( td->symbolic->isTypedef ) { 820 816 ret = new TypedefDecl( name, sc, typebuild( td->base ) ); 821 817 } else { 822 818 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any ); 823 819 } // if 824 buildList( td->symbolic .params, ret->get_parameters() );825 buildList( td->symbolic .assertions, ret->get_assertions() );820 buildList( td->symbolic->params, ret->get_parameters() ); 821 buildList( td->symbolic->assertions, ret->get_assertions() ); 826 822 return ret; 827 823 } // buildSymbolic 828 824 829 825 TypeDecl * buildVariable( const TypeData * td ) { 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; 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; 838 832 } // buildSymbolic 839 833 840 834 EnumDecl * buildEnum( const TypeData * td ) { 841 835 assert( td->kind == TypeData::Enum ); 842 EnumDecl * ret = new EnumDecl( td->enumeration .name );843 buildList( td->enumeration .constants, ret->get_members() );836 EnumDecl * ret = new EnumDecl( td->enumeration->name ); 837 buildList( td->enumeration->constants, ret->get_members() ); 844 838 std::list< Declaration * >::iterator members = ret->get_members().begin(); 845 for ( const DeclarationNode * cur = td->enumeration .constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {839 for ( const DeclarationNode * cur = td->enumeration-> constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 846 840 if ( cur->has_enumeratorValue() ) { 847 841 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); … … 854 848 TypeInstType * buildSymbolicInst( const TypeData * td ) { 855 849 assert( td->kind == TypeData::SymbolicInst ); 856 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic .name, false );857 buildList( td->symbolic .actuals, ret->get_parameters() );850 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false ); 851 buildList( td->symbolic->actuals, ret->get_parameters() ); 858 852 buildForall( td->forall, ret->get_forall() ); 859 853 return ret; … … 863 857 assert( td->kind == TypeData::Tuple ); 864 858 TupleType * ret = new TupleType( buildQualifiers( td ) ); 865 buildTypeList( td->tuple , ret->get_types() );859 buildTypeList( td->tuple->members, ret->get_types() ); 866 860 buildForall( td->forall, ret->get_forall() ); 867 861 return ret; … … 871 865 assert( td->kind == TypeData::Typeof ); 872 866 assert( td->typeexpr ); 873 //assert( td->typeexpr->expr );874 return new TypeofType( buildQualifiers( td ), td->typeexpr-> build() );867 assert( td->typeexpr->expr ); 868 return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() ); 875 869 } // buildTypeof 876 870 877 871 AttrType * buildAttr( const TypeData * td ) { 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; 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; 890 882 } // buildAttr 891 883 … … 893 885 if ( td->kind == TypeData::Function ) { 894 886 FunctionDecl * decl; 895 if ( td->function .hasBody ) {896 if ( td->function .body ) {897 Statement * stmt = td->function .body->build();887 if ( td->function->hasBody ) { 888 if ( td->function->body ) { 889 Statement * stmt = td->function->body->build(); 898 890 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt ); 899 891 assert( body ); … … 906 898 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn ); 907 899 } // if 908 for ( DeclarationNode * cur = td->function .idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {900 for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 909 901 if ( cur->get_name() != "" ) { 910 902 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); 911 903 } // if 912 904 } // for 913 buildList( td->function .oldDeclList, decl->get_oldDecls() );905 buildList( td->function->oldDeclList, decl->get_oldDecls() ); 914 906 return decl; 915 907 } else if ( td->kind == TypeData::Aggregate ) { … … 920 912 return buildSymbolic( td, name, sc ); 921 913 } else if ( td->kind == TypeData::Variable ) { 922 assert( false );923 914 return buildVariable( td ); 924 915 } else { … … 930 921 FunctionType * buildFunction( const TypeData * td ) { 931 922 assert( td->kind == TypeData::Function ); 932 bool hasEllipsis = td->function .params ? td->function.params->get_hasEllipsis() : true;933 if ( ! td->function .params ) hasEllipsis = ! td->function.newStyle;923 bool hasEllipsis = td->function->params ? td->function->params->get_hasEllipsis() : true; 924 if ( ! td->function->params ) hasEllipsis = ! td->function->newStyle; 934 925 FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis ); 935 buildList( td->function .params, ft->get_parameters() );926 buildList( td->function->params, ft->get_parameters() ); 936 927 buildForall( td->forall, ft->get_forall() ); 937 928 if ( td->base ) { 938 929 switch ( td->base->kind ) { 939 930 case TypeData::Tuple: 940 buildList( td->base->tuple , ft->get_returnVals() );931 buildList( td->base->tuple->members, ft->get_returnVals() ); 941 932 break; 942 933 default: -
src/Parser/TypeData.h
rf04a8b81 r621701d 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:31:52201613 // Update Count : 11012 // Last Modified On : Sun Aug 28 22:39:00 2016 13 // Update Count : 85 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 } ;26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind; 27 27 28 28 struct Basic_t { … … 73 73 }; 74 74 75 // struct Tuple_t { 76 // DeclarationNode * members; 77 // }; 75 struct Variable_t { 76 DeclarationNode::TypeClass tyClass; 77 std::string name; 78 DeclarationNode * assertions; 79 }; 80 81 struct Tuple_t { 82 DeclarationNode * members; 83 }; 78 84 79 //struct Typeof_t {80 //ExpressionNode * expr;81 //};85 struct Typeof_t { 86 ExpressionNode * expr; 87 }; 82 88 83 //struct Builtin_t {84 //DeclarationNode::BuiltinType type;85 //};89 struct Builtin_t { 90 DeclarationNode::BuiltinType type; 91 }; 86 92 87 Kind kind; 93 struct Attr_t { 94 std::string name; 95 ExpressionNode * expr; 96 DeclarationNode * type; 97 }; 98 88 99 TypeData * base; 89 100 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; … … 91 102 DeclarationNode * forall; 92 103 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; 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 }; 104 118 105 119 TypeData( Kind k = Unknown ); -
src/main.cc
rf04a8b81 r621701d 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 17:34:39201613 // Update Count : 4 2612 // Last Modified On : Sat Aug 20 12:52:22 2016 13 // Update Count : 403 14 14 // 15 15 … … 75 75 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 76 76 77 void backtrace( int start ) { // skip first N stack frames77 void sigSegvBusHandler( int sig_num ) { 78 78 enum { Frames = 50 }; 79 79 void * array[Frames]; 80 80 int size = backtrace( array, Frames ); 81 82 cerr << "*CFA runtime error* program cfa-cpp terminated with " 83 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 84 << " backtrace:" << endl; 85 81 86 char ** messages = backtrace_symbols( array, size ); 82 87 83 // skip last 2 stack frames after main84 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {88 // skip first stack frame (points here) 89 for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) { 85 90 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 86 91 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset … … 96 101 97 102 // if line contains symbol, attempt to demangle 98 int frameNo = i - start;99 103 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { 100 104 *mangled_name++ = '\0'; … … 102 106 *offset_end++ = '\0'; 103 107 104 int status , frameNo = i - start;108 int status; 105 109 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 106 110 if ( status == 0 ) { // demangling successful ? 107 cerr << "(" << frameNo<< ") " << messages[i] << " : "111 cerr << "(" << i - 2 << ") " << messages[i] << " : " 108 112 << real_name << "+" << offset_begin << offset_end << endl; 109 113 110 114 } else { // otherwise, output mangled name 111 cerr << "(" << frameNo<< ") " << messages[i] << " : "115 cerr << "(" << i - 2 << ") " << messages[i] << " : " 112 116 << mangled_name << "+" << offset_begin << offset_end << endl; 113 117 } // if 114 118 free( real_name ); 115 119 } else { // otherwise, print the whole line 116 cerr << "(" << frameNo<< ") " << messages[i] << endl;120 cerr << "(" << i - 2 << ") " << messages[i] << endl; 117 121 } // if 118 122 } // for 119 120 123 free( messages ); 121 } // backtrace122 123 void sigSegvBusHandler( int sig_num ) {124 cerr << "*CFA runtime error* program cfa-cpp terminated with "125 << (sig_num == SIGSEGV ? "segment fault" : "bus error")126 << " backtrace:" << endl;127 backtrace( 2 ); // skip first 2 stack frames128 124 exit( EXIT_FAILURE ); 129 125 } // sigSegvBusHandler 130 131 void sigAbortHandler( int sig_num ) {132 backtrace( 6 ); // skip first 6 stack frames133 signal( SIGABRT, SIG_DFL); // reset default signal handler134 raise( SIGABRT ); // reraise SIGABRT135 } // sigAbortHandler136 137 126 138 127 int main( int argc, char * argv[] ) { … … 144 133 signal( SIGSEGV, sigSegvBusHandler ); 145 134 signal( SIGBUS, sigSegvBusHandler ); 146 signal( SIGABRT, sigAbortHandler );147 135 148 136 parse_cmdline( argc, argv, filename ); // process command-line arguments
Note:
See TracChangeset
for help on using the changeset viewer.