Changeset 2298f728 for src/Parser
- Timestamp:
- Sep 24, 2016, 12:08:02 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, 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:
- 9c23f31
- Parents:
- 1b77274
- Location:
- src/Parser
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r1b77274 r2298f728 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 16 18:17:16201613 // Update Count : 52712 // Last Modified On : Sat Sep 24 11:12:52 2016 13 // Update Count : 627 14 14 // 15 15 … … 46 46 47 47 DeclarationNode::DeclarationNode() : 48 type( 0),48 type( nullptr ), 49 49 storageClass( NoStorageClass ), 50 50 isInline( false ), 51 51 isNoreturn( false ), 52 bitfieldWidth( 0),53 initializer( 0),52 bitfieldWidth( nullptr ), 53 initializer( nullptr ), 54 54 hasEllipsis( false ), 55 55 linkage( ::linkage ), 56 56 extension( false ) { 57 58 variable.name = nullptr; 57 59 variable.tyClass = DeclarationNode::Otype; 58 60 variable.assertions = nullptr; 59 61 62 attr.name = nullptr; 60 63 attr.expr = nullptr; 61 64 attr.type = nullptr; … … 63 66 64 67 DeclarationNode::~DeclarationNode() { 68 delete attr.name; 65 69 delete attr.expr; 66 70 delete attr.type; 71 72 delete variable.name; 73 delete variable.assertions; 74 67 75 delete type; 68 76 delete bitfieldWidth; … … 73 81 DeclarationNode * newnode = new DeclarationNode; 74 82 newnode->type = maybeClone( type ); 75 newnode->name = name ;83 newnode->name = name ? new string( *name ) : nullptr; 76 84 newnode->storageClass = storageClass; 77 85 newnode->isInline = isInline; … … 83 91 newnode->linkage = linkage; 84 92 93 newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr; 85 94 newnode->variable.assertions = maybeClone( variable.assertions ); 86 newnode->variable.name = variable.name;87 95 newnode->variable.tyClass = variable.tyClass; 88 96 97 newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr; 89 98 newnode->attr.expr = maybeClone( attr.expr ); 90 99 newnode->attr.type = maybeClone( attr.type ); … … 98 107 void DeclarationNode::print( std::ostream &os, int indent ) const { 99 108 os << string( indent, ' ' ); 100 if ( name == "" ) { 109 if ( name ) { 110 os << *name << ": "; 111 } else { 101 112 os << "unnamed: "; 102 } else {103 os << name << ": ";104 113 } // if 105 114 … … 122 131 } // if 123 132 124 if ( initializer != 0) {133 if ( initializer ) { 125 134 os << endl << string( indent + 2, ' ' ) << "with initializer "; 126 135 initializer->printOneLine( os ); … … 141 150 DeclarationNode * DeclarationNode::newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) { 142 151 DeclarationNode * newnode = new DeclarationNode; 143 newnode->name = assign_strptr( name );152 newnode->name = name; 144 153 145 154 newnode->type = new TypeData( TypeData::Function ); … … 147 156 newnode->type->function.newStyle = newStyle; 148 157 newnode->type->function.body = body; 149 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 158 // ignore unnamed routine declarations: void p( int (*)(int) ); 159 if ( newnode->name ) { 160 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID ); 161 } // if 150 162 151 163 if ( body ) { … … 155 167 if ( ret ) { 156 168 newnode->type->base = ret->type; 157 ret->type = 0;169 ret->type = nullptr; 158 170 delete ret; 159 171 } // if … … 213 225 DeclarationNode * newnode = new DeclarationNode; 214 226 newnode->type = new TypeData( TypeData::SymbolicInst ); 215 newnode->type->symbolic.name = assign_strptr( name );227 newnode->type->symbolic.name = name ? new string( *name ) : nullptr; 216 228 newnode->type->symbolic.isTypedef = true; 217 newnode->type->symbolic.params = 0;229 newnode->type->symbolic.params = nullptr; 218 230 return newnode; 219 231 } // DeclarationNode::newFromTypedef … … 223 235 newnode->type = new TypeData( TypeData::Aggregate ); 224 236 newnode->type->aggregate.kind = kind; 225 newnode->type->aggregate.name = assign_strptr( name ); 226 if ( newnode->type->aggregate.name == "" ) { // anonymous aggregate ? 227 newnode->type->aggregate.name = anonymous.newName(); 237 if ( name ) { 238 newnode->type->aggregate.name = new string( *name ); 239 } else { // anonymous aggregate ? 240 newnode->type->aggregate.name = new string( anonymous.newName() ); 228 241 } // if 229 242 newnode->type->aggregate.actuals = actuals; … … 235 248 DeclarationNode * DeclarationNode::newEnum( std::string * name, DeclarationNode * constants ) { 236 249 DeclarationNode * newnode = new DeclarationNode; 237 newnode->name = assign_strptr( name );250 newnode->name = name; 238 251 newnode->type = new TypeData( TypeData::Enum ); 239 newnode->type->enumeration.name = newnode->name; 240 if ( newnode->type->enumeration.name == "" ) { // anonymous enumeration ? 241 newnode->type->enumeration.name = DeclarationNode::anonymous.newName(); 252 if ( name ) { 253 newnode->type->enumeration.name = new string( *name ); 254 } else { // anonymous aggregate ? 255 newnode->type->enumeration.name = new string( anonymous.newName() ); 242 256 } // if 243 257 newnode->type->enumeration.constants = constants; … … 247 261 DeclarationNode * DeclarationNode::newEnumConstant( std::string * name, ExpressionNode * constant ) { 248 262 DeclarationNode * newnode = new DeclarationNode; 249 newnode->name = assign_strptr( name );263 newnode->name = name; 250 264 newnode->enumeratorValue.reset( constant ); 251 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );265 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID ); 252 266 return newnode; 253 267 } // DeclarationNode::newEnumConstant … … 255 269 DeclarationNode * DeclarationNode::newName( std::string * name ) { 256 270 DeclarationNode * newnode = new DeclarationNode; 257 newnode->name = assign_strptr( name );271 newnode->name = name; 258 272 return newnode; 259 273 } // DeclarationNode::newName … … 262 276 DeclarationNode * newnode = new DeclarationNode; 263 277 newnode->type = new TypeData( TypeData::SymbolicInst ); 264 newnode->type->symbolic.name = assign_strptr( name );278 newnode->type->symbolic.name = name ? new string( *name ) : nullptr; 265 279 newnode->type->symbolic.isTypedef = false; 266 280 newnode->type->symbolic.actuals = params; … … 270 284 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string * name ) { 271 285 DeclarationNode * newnode = new DeclarationNode; 272 newnode->name = assign_strptr( name );273 newnode->type = new TypeData( TypeData::Variable );274 //newnode->type = nullptr;286 newnode->name = name; 287 // newnode->type = new TypeData( TypeData::Variable ); 288 newnode->type = nullptr; 275 289 newnode->variable.tyClass = tc; 276 newnode->variable.name = newnode->name ;290 newnode->variable.name = newnode->name ? new string( *newnode->name ) : nullptr; 277 291 return newnode; 278 292 } // DeclarationNode::newTypeParam 279 293 280 DeclarationNode * DeclarationNode::newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts ) {294 DeclarationNode * DeclarationNode::newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ) { 281 295 DeclarationNode * newnode = new DeclarationNode; 282 296 newnode->type = new TypeData( TypeData::Aggregate ); 297 newnode->type->aggregate.name = name; 283 298 newnode->type->aggregate.kind = Trait; 284 299 newnode->type->aggregate.params = params; 285 300 newnode->type->aggregate.fields = asserts; 286 newnode->type->aggregate.name = assign_strptr( name );287 301 return newnode; 288 302 } // DeclarationNode::newTrait 289 303 290 DeclarationNode * DeclarationNode::newTraitUse( std::string * name, ExpressionNode * params ) {304 DeclarationNode * DeclarationNode::newTraitUse( const std::string * name, ExpressionNode * params ) { 291 305 DeclarationNode * newnode = new DeclarationNode; 292 306 newnode->type = new TypeData( TypeData::AggregateInst ); 293 307 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 294 308 newnode->type->aggInst.aggregate->aggregate.kind = Trait; 295 newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );309 newnode->type->aggInst.aggregate->aggregate.name = name; 296 310 newnode->type->aggInst.params = params; 297 311 return newnode; … … 300 314 DeclarationNode * DeclarationNode::newTypeDecl( std::string * name, DeclarationNode * typeParams ) { 301 315 DeclarationNode * newnode = new DeclarationNode; 302 newnode->name = assign_strptr( name );316 newnode->name = name; 303 317 newnode->type = new TypeData( TypeData::Symbolic ); 304 318 newnode->type->symbolic.isTypedef = false; … … 319 333 newnode->type->array.dimension = size; 320 334 newnode->type->array.isStatic = isStatic; 321 if ( newnode->type->array.dimension == 0|| newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {335 if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) { 322 336 newnode->type->array.isVarLen = false; 323 337 } else { … … 330 344 DeclarationNode * newnode = new DeclarationNode; 331 345 newnode->type = new TypeData( TypeData::Array ); 332 newnode->type->array.dimension = 0;346 newnode->type->array.dimension = nullptr; 333 347 newnode->type->array.isStatic = false; 334 348 newnode->type->array.isVarLen = true; … … 365 379 DeclarationNode * DeclarationNode::newAttr( std::string * name, ExpressionNode * expr ) { 366 380 DeclarationNode * newnode = new DeclarationNode; 367 newnode->type = new TypeData( TypeData::Attr );368 //newnode->type = nullptr;369 newnode->attr.name = assign_strptr( name );381 // newnode->type = new TypeData( TypeData::Attr ); 382 newnode->type = nullptr; 383 newnode->attr.name = name; 370 384 newnode->attr.expr = expr; 371 385 return newnode; … … 374 388 DeclarationNode * DeclarationNode::newAttr( std::string * name, DeclarationNode * type ) { 375 389 DeclarationNode * newnode = new DeclarationNode; 376 newnode->type = new TypeData( TypeData::Attr );377 //newnode->type = nullptr;378 newnode->attr.name = assign_strptr( name );390 // newnode->type = new TypeData( TypeData::Attr ); 391 newnode->type = nullptr; 392 newnode->attr.name = name; 379 393 newnode->attr.type = type; 380 394 return newnode; … … 429 443 dst->forall = src->forall; 430 444 } // if 431 src->forall = 0;445 src->forall = nullptr; 432 446 } // if 433 447 if ( dst->base ) { … … 435 449 } else if ( dst->kind == TypeData::Function ) { 436 450 dst->base = src; 437 src = 0;451 src = nullptr; 438 452 } else { 439 453 dst->qualifiers |= src->qualifiers; … … 442 456 443 457 DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) { 444 if ( ! q ) return this;458 if ( ! q ) { delete q; return this; } 445 459 446 460 checkStorageClasses( q ); … … 469 483 type->aggregate.params = q->type->forall; 470 484 // change implicit typedef from TYPEDEFname to TYPEGENname 471 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );485 typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG ); 472 486 } else { 473 487 type->forall = q->type->forall; 474 488 } // if 475 489 } // if 476 q->type->forall = 0;490 q->type->forall = nullptr; 477 491 } // if 478 492 delete q; … … 487 501 dst->forall = src->forall; 488 502 } // if 489 src->forall = 0;503 src->forall = nullptr; 490 504 } // if 491 505 if ( dst->base ) { … … 496 510 src->qualifiers |= dst->qualifiers; 497 511 dst = src; 498 src = 0;512 src = nullptr; 499 513 break; 500 514 case TypeData::Basic: … … 536 550 } // if 537 551 dst->base->qualifiers |= src->qualifiers; 538 src = 0;552 src = nullptr; 539 553 break; 540 554 default: … … 544 558 dst->forall = src->forall; 545 559 } // if 546 src->forall = 0;560 src->forall = nullptr; 547 561 dst->base = src; 548 src = 0;562 src = nullptr; 549 563 } // switch 550 564 } // switch … … 568 582 type = o->type; 569 583 } // if 570 o->type = 0;584 o->type = nullptr; 571 585 } else { 572 586 addTypeToType( o->type, type ); … … 588 602 DeclarationNode * DeclarationNode::addTypedef() { 589 603 TypeData * newtype = new TypeData( TypeData::Symbolic ); 590 newtype->symbolic.params = 0;604 newtype->symbolic.params = nullptr; 591 605 newtype->symbolic.isTypedef = true; 592 newtype->symbolic.name = name ;606 newtype->symbolic.name = name ? new string( *name ) : nullptr; 593 607 newtype->base = type; 594 608 type = newtype; … … 597 611 598 612 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 613 if ( variable.name ) { 614 if ( variable.assertions ) { 615 variable.assertions->appendList( assertions ); 616 } else { 617 variable.assertions = assertions; 618 } // if 619 return this; 620 } // if 621 599 622 assert( type ); 600 623 switch ( type->kind ) { … … 606 629 } // if 607 630 break; 608 case TypeData::Variable:609 if ( variable.assertions ) {610 variable.assertions->appendList( assertions );611 } else {612 variable.assertions = assertions;613 } // if614 break;631 // case TypeData::Variable: 632 // if ( variable.assertions ) { 633 // variable.assertions->appendList( assertions ); 634 // } else { 635 // variable.assertions = assertions; 636 // } // if 637 // break; 615 638 default: 616 639 assert( false ); … … 621 644 622 645 DeclarationNode * DeclarationNode::addName( std::string * newname ) { 623 name = assign_strptr( newname ); 646 assert( ! name ); 647 name = newname; 624 648 return this; 625 649 } … … 639 663 assert( type ); 640 664 assert( type->kind == TypeData::Function ); 641 assert( type->function.body == 0);665 assert( ! type->function.body ); 642 666 type->function.body = body; 643 667 type->function.hasBody = true; … … 648 672 assert( type ); 649 673 assert( type->kind == TypeData::Function ); 650 assert( type->function.oldDeclList == 0);674 assert( ! type->function.oldDeclList ); 651 675 type->function.oldDeclList = list; 652 676 return this; … … 657 681 TypeData * prevBase = type; 658 682 TypeData * curBase = type->base; 659 while ( curBase != 0) {683 while ( curBase != nullptr ) { 660 684 prevBase = curBase; 661 685 curBase = curBase->base; … … 671 695 assert( p->type->kind == TypeData::Pointer ); 672 696 setBase( type, p->type ); 673 p->type = 0;697 p->type = nullptr; 674 698 delete p; 675 699 } // if … … 681 705 assert( a->type->kind == TypeData::Array ); 682 706 setBase( type, a->type ); 683 a->type = 0;707 a->type = nullptr; 684 708 delete a; 685 709 } // if … … 705 729 p->type->base = type; 706 730 } // switch 707 type = 0;731 type = nullptr; 708 732 } // if 709 733 delete this; … … 741 765 lastArray->base = type; 742 766 } // switch 743 type = 0;767 type = nullptr; 744 768 } // if 745 769 delete this; … … 770 794 return newtype; 771 795 } // if 772 } 796 } // addIdListToType 773 797 774 798 DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) { … … 778 802 779 803 DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) { 780 //assert781 804 initializer = init; 782 805 return this; 783 }784 785 DeclarationNode * DeclarationNode::cloneBaseType( string * newName ) {786 DeclarationNode * newnode = new DeclarationNode;787 TypeData * srcType = type;788 while ( srcType->base ) {789 srcType = srcType->base;790 } // while791 newnode->type = maybeClone( srcType );792 if ( newnode->type->kind == TypeData::AggregateInst ) {793 // don't duplicate members794 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) {795 delete newnode->type->aggInst.aggregate->enumeration.constants;796 newnode->type->aggInst.aggregate->enumeration.constants = 0;797 } else {798 assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate );799 delete newnode->type->aggInst.aggregate->aggregate.fields;800 newnode->type->aggInst.aggregate->aggregate.fields = 0;801 } // if802 } // if803 newnode->type->forall = maybeClone( type->forall );804 assert( storageClass == NoStorageClass );805 newnode->copyStorageClasses( this );806 newnode->name = assign_strptr( newName );807 return newnode;808 }809 810 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {811 if ( o ) {812 o->copyStorageClasses( this );813 if ( type ) {814 TypeData * srcType = type;815 while ( srcType->base ) {816 srcType = srcType->base;817 } // while818 TypeData * newType = srcType->clone();819 if ( newType->kind == TypeData::AggregateInst ) {820 // don't duplicate members821 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {822 delete newType->aggInst.aggregate->enumeration.constants;823 newType->aggInst.aggregate->enumeration.constants = 0;824 } else {825 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );826 delete newType->aggInst.aggregate->aggregate.fields;827 newType->aggInst.aggregate->aggregate.fields = 0;828 } // if829 } // if830 newType->forall = maybeClone( type->forall );831 if ( ! o->type ) {832 o->type = newType;833 } else {834 addTypeToType( newType, o->type );835 delete newType;836 } // if837 } // if838 } // if839 return o;840 806 } 841 807 … … 846 812 newnode->copyStorageClasses( this ); 847 813 assert( newName ); 848 newnode->name = assign_strptr( newName ); 849 return newnode; 850 } 851 852 DeclarationNode * DeclarationNode::cloneType( DeclarationNode * o ) { 853 if ( o ) { 854 assert( storageClass == NoStorageClass ); 855 o->copyStorageClasses( this ); 856 if ( type ) { 857 TypeData * newType = type->clone(); 858 if ( ! o->type ) { 859 o->type = newType; 814 newnode->name = newName; 815 return newnode; 816 } 817 818 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) { 819 if ( ! o ) return nullptr; 820 821 o->copyStorageClasses( this ); 822 if ( type ) { 823 TypeData * srcType = type; 824 825 while ( srcType->base ) { 826 srcType = srcType->base; 827 } // while 828 829 TypeData * newType = srcType->clone(); 830 if ( newType->kind == TypeData::AggregateInst ) { 831 // don't duplicate members 832 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 833 delete newType->aggInst.aggregate->enumeration.constants; 834 newType->aggInst.aggregate->enumeration.constants = nullptr; 860 835 } else { 861 addTypeToType( newType, o->type ); 862 delete newType; 836 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 837 delete newType->aggInst.aggregate->aggregate.fields; 838 newType->aggInst.aggregate->aggregate.fields = nullptr; 863 839 } // if 864 840 } // if 865 } // if 866 delete o; 841 842 newType->forall = maybeClone( type->forall ); 843 if ( ! o->type ) { 844 o->type = newType; 845 } else { 846 addTypeToType( newType, o->type ); 847 delete newType; 848 } // if 849 } // if 867 850 return o; 868 851 } … … 877 860 } // if 878 861 } // if 879 return 0;862 return nullptr; 880 863 } 881 864 … … 884 867 std::back_insert_iterator< std::list< Declaration * > > out( outputList ); 885 868 const DeclarationNode * cur = firstNode; 869 886 870 while ( cur ) { 887 871 try { … … 894 878 delete extr; 895 879 } // if 880 896 881 Declaration * decl = cur->build(); 897 882 if ( decl ) { … … 903 888 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 904 889 } // while 890 905 891 if ( ! errors.isEmpty() ) { 906 892 throw errors; 907 893 } // if 908 } 894 } // buildList 909 895 910 896 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) { … … 920 906 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) { 921 907 StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 922 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0);908 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 923 909 delete agg; 924 910 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 925 911 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 926 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0);912 * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr ); 927 913 } // if 928 914 } // if … … 935 921 throw errors; 936 922 } // if 937 } 923 } // buildList 938 924 939 925 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) { … … 941 927 std::back_insert_iterator< std::list< Type * > > out( outputList ); 942 928 const DeclarationNode * cur = firstNode; 929 943 930 while ( cur ) { 944 931 try { … … 949 936 cur = dynamic_cast< DeclarationNode * >( cur->get_next() ); 950 937 } // while 938 951 939 if ( ! errors.isEmpty() ) { 952 940 throw errors; 953 941 } // if 954 } 942 } // buildTypeList 955 943 956 944 Declaration * DeclarationNode::build() const { 957 945 if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this ); 946 947 if ( variable.name ) { 948 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 949 TypeDecl * ret = new TypeDecl( *variable.name, DeclarationNode::NoStorageClass, nullptr, kindMap[ variable.tyClass ] ); 950 buildList( variable.assertions, ret->get_assertions() ); 951 return ret; 952 } // if 953 958 954 if ( type ) { 959 if ( type->kind == TypeData::Variable ) { 960 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 961 TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] ); 962 buildList( variable.assertions, ret->get_assertions() ); 963 return ret; 964 } else { 965 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 966 } // if 967 } // if 955 return buildDecl( type, name ? *name : string( "" ), storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 956 } // if 957 968 958 if ( ! isInline && ! isNoreturn ) { 969 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 970 } // if 959 assertf( name, "ObjectDecl are assumed to have names\n" ); 960 return (new ObjectDecl( *name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_extension( extension ); 961 } // if 962 971 963 throw SemanticError( "invalid function specifier ", this ); 972 964 } … … 975 967 assert( type ); 976 968 969 if ( attr.name ) { 970 AttrType * ret; 971 if ( attr.expr ) { 972 ret = new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() ); 973 } else { 974 assert( attr.type ); 975 ret = new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() ); 976 } // if 977 return ret; 978 } // if 979 977 980 switch ( type->kind ) { 978 981 case TypeData::Enum: 979 return new EnumInstType( buildQualifiers( type ), type->enumeration.name );982 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 980 983 case TypeData::Aggregate: { 981 984 ReferenceToType * ret; 982 985 switch ( type->aggregate.kind ) { 983 986 case DeclarationNode::Struct: 984 ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );987 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 985 988 break; 986 989 case DeclarationNode::Union: 987 ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );990 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 988 991 break; 989 992 case DeclarationNode::Trait: 990 ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );993 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 991 994 break; 992 995 default: … … 997 1000 } 998 1001 case TypeData::Symbolic: { 999 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );1002 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false ); 1000 1003 buildList( type->symbolic.actuals, ret->get_parameters() ); 1001 return ret;1002 }1003 case TypeData::Attr: {1004 assert( type->kind == TypeData::Attr );1005 // assert( type->attr );1006 AttrType * ret;1007 if ( attr.expr ) {1008 ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );1009 } else {1010 assert( attr.type );1011 ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );1012 } // if1013 1004 return ret; 1014 1005 } -
src/Parser/ParseNode.h
r1b77274 r2298f728 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 16 15:02:38201613 // Update Count : 6 1312 // Last Modified On : Sat Sep 24 11:12:04 2016 13 // Update Count : 633 14 14 // 15 15 … … 41 41 public: 42 42 ParseNode() {}; 43 virtual ~ParseNode() { delete next; };43 virtual ~ParseNode() { delete next; delete name; }; 44 44 virtual ParseNode * clone() const = 0; 45 45 … … 49 49 ParseNode * get_last() { 50 50 ParseNode * current; 51 for ( current = this; current->get_next() != 0; current = current->get_next() );51 for ( current = this; current->get_next() != nullptr; current = current->get_next() ); 52 52 return current; 53 53 } 54 54 ParseNode * set_last( ParseNode * newlast ) { 55 if ( newlast != 0) get_last()->set_next( newlast );55 if ( newlast != nullptr ) get_last()->set_next( newlast ); 56 56 return this; 57 57 } … … 63 63 64 64 ParseNode * next = nullptr; 65 std::string name;65 std::string * name = nullptr; 66 66 }; // ParseNode 67 67 … … 70 70 class InitializerNode : public ParseNode { 71 71 public: 72 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = 0);73 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0);72 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 73 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 74 74 ~InitializerNode(); 75 75 virtual InitializerNode * clone() const { assert( false ); return nullptr; } … … 178 178 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ); 179 179 Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ); 180 Expression * build_tuple( ExpressionNode * expr_node = 0);180 Expression * build_tuple( ExpressionNode * expr_node = nullptr ); 181 181 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ); 182 182 Expression * build_range( ExpressionNode * low, ExpressionNode * high ); … … 214 214 static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false ); 215 215 static DeclarationNode * newQualifier( Qualifier ); 216 static DeclarationNode * newForall( DeclarationNode * );216 static DeclarationNode * newForall( DeclarationNode * ); 217 217 static DeclarationNode * newStorageClass( StorageClass ); 218 218 static DeclarationNode * newBasicType( BasicType ); … … 221 221 static DeclarationNode * newLength( Length lnth ); 222 222 static DeclarationNode * newBuiltinType( BuiltinType ); 223 static DeclarationNode * newFromTypedef( std::string * );223 static DeclarationNode * newFromTypedef( std::string * ); 224 224 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 225 225 static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants ); 226 226 static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant ); 227 static DeclarationNode * newName( std::string * );227 static DeclarationNode * newName( std::string * ); 228 228 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params ); 229 static DeclarationNode * newTypeParam( TypeClass, std::string * );230 static DeclarationNode * newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts );231 static DeclarationNode * newTraitUse( std::string * name, ExpressionNode * params );229 static DeclarationNode * newTypeParam( TypeClass, std::string * ); 230 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 231 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); 232 232 static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams ); 233 233 static DeclarationNode * newPointer( DeclarationNode * qualifiers ); … … 244 244 DeclarationNode * clone() const; 245 245 246 DeclarationNode * addQualifiers( DeclarationNode * );246 DeclarationNode * addQualifiers( DeclarationNode * ); 247 247 void checkQualifiers( const TypeData *, const TypeData * ); 248 void checkStorageClasses( DeclarationNode * q);249 DeclarationNode * copyStorageClasses( DeclarationNode * );250 DeclarationNode * addType( DeclarationNode * );248 void checkStorageClasses( DeclarationNode * ); 249 DeclarationNode * copyStorageClasses( DeclarationNode * ); 250 DeclarationNode * addType( DeclarationNode * ); 251 251 DeclarationNode * addTypedef(); 252 DeclarationNode * addAssertions( DeclarationNode * );253 DeclarationNode * addName( std::string * );252 DeclarationNode * addAssertions( DeclarationNode * ); 253 DeclarationNode * addName( std::string * ); 254 254 DeclarationNode * addBitfield( ExpressionNode * size ); 255 255 DeclarationNode * addVarArgs(); … … 265 265 266 266 DeclarationNode * cloneType( std::string * newName ); 267 DeclarationNode * cloneType( DeclarationNode * existing );268 DeclarationNode * cloneType( int ) { return cloneType( ( std::string *)0 ); }269 DeclarationNode * cloneBaseType( std::string * newName );270 267 DeclarationNode * cloneBaseType( DeclarationNode * newdecl ); 271 268 … … 290 287 public: 291 288 struct Variable_t { 289 const std::string * name; 292 290 DeclarationNode::TypeClass tyClass; 293 std::string name;294 291 DeclarationNode * assertions; 295 292 }; … … 297 294 298 295 struct Attr_t { 299 std::stringname;296 const std::string * name; 300 297 ExpressionNode * expr; 301 298 DeclarationNode * type; … … 382 379 Statement * build_finally( StatementNode * stmt ); 383 380 Statement * build_compound( StatementNode * first ); 384 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode * gotolabels = 0);381 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 385 382 386 383 //############################################################################## -
src/Parser/TypeData.cc
r1b77274 r2298f728 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 16 15:12:55201613 // Update Count : 38812 // Last Modified On : Sat Sep 24 11:14:26 2016 13 // Update Count : 415 14 14 // 15 15 … … 24 24 #include "SynTree/Statement.h" 25 25 #include "SynTree/Initializer.h" 26 27 TypeData::TypeData( Kind k ) : kind( k ), base( 0 ), forall( 0 ) { 26 using namespace std; 27 28 TypeData::TypeData( Kind k ) : kind( k ), base( nullptr ), forall( nullptr ) { 28 29 switch ( kind ) { 29 30 case Unknown: … … 37 38 case Array: 38 39 // array = new Array_t; 39 array.dimension = 0;40 array.dimension = nullptr; 40 41 array.isVarLen = false; 41 42 array.isStatic = false; … … 43 44 case Function: 44 45 // function = new Function_t; 45 function.params = 0;46 function.idList = 0;47 function.oldDeclList = 0;48 function.body = 0;46 function.params = nullptr; 47 function.idList = nullptr; 48 function.oldDeclList = nullptr; 49 function.body = nullptr; 49 50 function.hasBody = false; 50 51 function.newStyle = false; … … 52 53 case Aggregate: 53 54 // aggregate = new Aggregate_t; 54 aggregate.params = 0; 55 aggregate.actuals = 0; 56 aggregate.fields = 0; 55 aggregate.name = nullptr; 56 aggregate.params = nullptr; 57 aggregate.actuals = nullptr; 58 aggregate.fields = nullptr; 57 59 break; 58 60 case AggregateInst: 59 61 // aggInst = new AggInst_t; 60 aggInst.aggregate = 0;61 aggInst.params = 0;62 aggInst.aggregate = nullptr; 63 aggInst.params = nullptr; 62 64 break; 63 65 case Enum: 64 66 // enumeration = new Enumeration_t; 65 enumeration.constants = 0; 67 enumeration.name = nullptr; 68 enumeration.constants = nullptr; 66 69 break; 67 70 case Symbolic: 68 71 case SymbolicInst: 69 72 // symbolic = new Symbolic_t; 70 symbolic.params = 0; 71 symbolic.actuals = 0; 72 symbolic.assertions = 0; 73 break; 74 case Variable: 75 // variable = new Variable_t; 76 // variable.tyClass = DeclarationNode::Type; 77 // variable.assertions = 0; 73 symbolic.name = nullptr; 74 symbolic.params = nullptr; 75 symbolic.actuals = nullptr; 76 symbolic.assertions = nullptr; 78 77 break; 79 78 case Tuple: … … 84 83 // typeexpr = new Typeof_t; 85 84 typeexpr = nullptr; 86 break;87 case Attr:88 // attr = new Attr_t;89 // attr.expr = nullptr;90 // attr.type = nullptr;91 85 break; 92 86 case Builtin: … … 121 115 break; 122 116 case Aggregate: 117 delete aggregate.name; 123 118 delete aggregate.params; 124 119 delete aggregate.actuals; … … 132 127 break; 133 128 case Enum: 129 delete enumeration.name; 134 130 delete enumeration.constants; 135 131 // delete enumeration; … … 137 133 case Symbolic: 138 134 case SymbolicInst: 135 delete symbolic.name; 139 136 delete symbolic.params; 140 137 delete symbolic.actuals; … … 142 139 // delete symbolic; 143 140 break; 144 case Variable:145 // delete variable.assertions;146 // delete variable;147 break;148 141 case Tuple: 149 142 // delete tuple->members; … … 153 146 // delete typeexpr->expr; 154 147 delete typeexpr; 155 break;156 case Attr:157 // delete attr.expr;158 // delete attr.type;159 // delete attr;160 148 break; 161 149 case Builtin: … … 197 185 break; 198 186 case Aggregate: 187 newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr; 199 188 newtype->aggregate.params = maybeClone( aggregate.params ); 200 189 newtype->aggregate.actuals = maybeClone( aggregate.actuals ); 201 190 newtype->aggregate.fields = maybeClone( aggregate.fields ); 202 newtype->aggregate.name = aggregate.name;203 191 newtype->aggregate.kind = aggregate.kind; 204 192 newtype->aggregate.body = aggregate.body; … … 209 197 break; 210 198 case Enum: 211 newtype->enumeration.name = enumeration.name ;199 newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr; 212 200 newtype->enumeration.constants = maybeClone( enumeration.constants ); 213 201 break; 214 202 case Symbolic: 215 203 case SymbolicInst: 204 newtype->symbolic.name = symbolic.name ? new string( *symbolic.name ) : nullptr; 216 205 newtype->symbolic.params = maybeClone( symbolic.params ); 217 206 newtype->symbolic.actuals = maybeClone( symbolic.actuals ); 218 207 newtype->symbolic.assertions = maybeClone( symbolic.assertions ); 219 208 newtype->symbolic.isTypedef = symbolic.isTypedef; 220 newtype->symbolic.name = symbolic.name;221 break;222 case Variable:223 assert( false );224 // newtype->variable.assertions = maybeClone( variable.assertions );225 // newtype->variable.name = variable.name;226 // newtype->variable.tyClass = variable.tyClass;227 209 break; 228 210 case Tuple: … … 231 213 case Typeof: 232 214 newtype->typeexpr = maybeClone( typeexpr ); 233 break;234 case Attr:235 assert( false );236 // newtype->attr.expr = maybeClone( attr.expr );237 // newtype->attr.type = maybeClone( attr.type );238 215 break; 239 216 case Builtin: … … 245 222 } // TypeData::clone 246 223 247 void TypeData::print( std::ostream &os, int indent ) const { 248 using std::endl; 249 using std::string; 250 224 void TypeData::print( ostream &os, int indent ) const { 251 225 for ( int i = 0; i < DeclarationNode::NoQualifier; i += 1 ) { 252 226 if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' '; … … 326 300 break; 327 301 case Aggregate: 328 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl;302 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << *aggregate.name << endl; 329 303 if ( aggregate.params ) { 330 304 os << string( indent + 2, ' ' ) << "with type parameters " << endl; … … 363 337 break; 364 338 case SymbolicInst: 365 os << "instance of type " << symbolic.name;339 os << "instance of type " << *symbolic.name; 366 340 if ( symbolic.actuals ) { 367 341 os << " with parameters" << endl; … … 389 363 } // if 390 364 break; 391 case Variable:392 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";393 // if ( variable.assertions ) {394 // os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;395 // variable.assertions->printList( os, indent + 4 );396 // os << string( indent + 2, ' ' );397 // } // if398 break;399 365 case Tuple: 400 366 os << "tuple "; … … 410 376 } // if 411 377 break; 412 case Attr:413 // os << "attribute type decl " << attr.name << " applied to ";414 // if ( attr.expr ) {415 // attr.expr->print( os, indent + 2 );416 // } // if417 // if ( attr.type ) {418 // attr.type->print( os, indent + 2 );419 // } // if420 break;421 378 case Builtin: 422 379 os << "gcc builtin type"; … … 428 385 } // TypeData::print 429 386 430 void buildForall( const DeclarationNode * firstNode, std::list< TypeDecl* > &outputList ) {387 void buildForall( const DeclarationNode * firstNode, list< TypeDecl* > &outputList ) { 431 388 buildList( firstNode, outputList ); 432 for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {389 for ( list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) { 433 390 if ( (*i)->get_kind() == TypeDecl::Any ) { 434 391 // add assertion parameters to `type' tyvars in reverse order 435 392 // add dtor: void ^?{}(T *) 436 393 FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false ); 437 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );438 (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, 0, false, false ) );394 dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 395 (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, nullptr, false, false ) ); 439 396 440 397 // add copy ctor: void ?{}(T *, T) 441 398 FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false ); 442 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );443 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0) );444 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, 0, false, false ) );399 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 400 copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) ); 401 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, nullptr, false, false ) ); 445 402 446 403 // add default ctor: void ?{}(T *) 447 404 FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false ); 448 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );449 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, 0, false, false ) );405 ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 406 (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, nullptr, false, false ) ); 450 407 451 408 // add assignment operator: T * ?=?(T *, T) 452 409 FunctionType * assignType = new FunctionType( Type::Qualifiers(), false ); 453 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0) );454 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0) );455 assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0) );456 (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, 0, false, false ) );410 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) ); 411 assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) ); 412 assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) ); 413 (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, nullptr, false, false ) ); 457 414 } // if 458 415 } // for … … 486 443 case TypeData::Builtin: 487 444 return new VarArgsType( buildQualifiers( td ) ); 488 case TypeData::Attr:489 445 case TypeData::Symbolic: 490 446 case TypeData::Enum: 491 447 case TypeData::Aggregate: 492 case TypeData::Variable:493 448 assert( false ); 494 449 } // switch 495 return 0;450 return nullptr; 496 451 } // typebuild 497 452 498 453 TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) { 499 TypeData * ret = 0;454 TypeData * ret = nullptr; 500 455 501 456 switch ( td->kind ) { … … 547 502 case DeclarationNode::Bool: 548 503 if ( td->signedness != DeclarationNode::NoSignedness ) { 549 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );504 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td ); 550 505 } // if 551 506 if ( td->length != DeclarationNode::NoLength ) { 552 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );507 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 553 508 } // if 554 509 … … 563 518 564 519 if ( td->length != DeclarationNode::NoLength ) { 565 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );520 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 566 521 } // if 567 522 … … 593 548 FloatingPoint: ; 594 549 if ( td->signedness != DeclarationNode::NoSignedness ) { 595 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );550 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td ); 596 551 } // if 597 552 if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) { 598 throw SemanticError( st d::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );553 throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td ); 599 554 } // if 600 555 if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) { … … 653 608 switch ( td->aggregate.kind ) { 654 609 case DeclarationNode::Struct: 655 at = new StructDecl( td->aggregate.name );610 at = new StructDecl( *td->aggregate.name ); 656 611 buildForall( td->aggregate.params, at->get_parameters() ); 657 612 break; 658 613 case DeclarationNode::Union: 659 at = new UnionDecl( td->aggregate.name );614 at = new UnionDecl( *td->aggregate.name ); 660 615 buildForall( td->aggregate.params, at->get_parameters() ); 661 616 break; 662 617 case DeclarationNode::Trait: 663 at = new TraitDecl( td->aggregate.name );618 at = new TraitDecl( *td->aggregate.name ); 664 619 buildList( td->aggregate.params, at->get_parameters() ); 665 620 break; … … 679 634 ReferenceToType * ret; 680 635 if ( td->aggInst.aggregate->kind == TypeData::Enum ) { 681 ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name );636 ret = new EnumInstType( buildQualifiers( td ), *td->aggInst.aggregate->enumeration.name ); 682 637 } else { 683 638 assert( td->aggInst.aggregate->kind == TypeData::Aggregate ); 684 639 switch ( td->aggInst.aggregate->aggregate.kind ) { 685 640 case DeclarationNode::Struct: 686 ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 641 assert( td->aggInst.aggregate->aggregate.name ); 642 ret = new StructInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name ); 687 643 break; 688 644 case DeclarationNode::Union: 689 ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );645 ret = new UnionInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name ); 690 646 break; 691 647 case DeclarationNode::Trait: 692 ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );648 ret = new TraitInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name ); 693 649 break; 694 650 default: … … 701 657 } // buildAggInst 702 658 703 NamedTypeDecl * buildSymbolic( const TypeData * td, const st d::string & name, DeclarationNode::StorageClass sc ) {659 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClass sc ) { 704 660 assert( td->kind == TypeData::Symbolic ); 705 661 NamedTypeDecl * ret; … … 715 671 } // buildSymbolic 716 672 717 TypeDecl * buildVariable( const TypeData * td ) {718 assert( false );719 return nullptr;720 // assert( td->kind == TypeData::Variable );721 // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };722 723 // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );724 // buildList( td->variable.assertions, ret->get_assertions() );725 // return ret;726 } // buildSymbolic727 728 673 EnumDecl * buildEnum( const TypeData * td ) { 729 674 assert( td->kind == TypeData::Enum ); 730 EnumDecl * ret = new EnumDecl( td->enumeration.name );675 EnumDecl * ret = new EnumDecl( *td->enumeration.name ); 731 676 buildList( td->enumeration.constants, ret->get_members() ); 732 std::list< Declaration * >::iterator members = ret->get_members().begin();677 list< Declaration * >::iterator members = ret->get_members().begin(); 733 678 for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 734 679 if ( cur->has_enumeratorValue() ) { 735 680 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 736 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) );681 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), list< Expression * >() ) ); 737 682 } // if 738 683 } // for … … 742 687 TypeInstType * buildSymbolicInst( const TypeData * td ) { 743 688 assert( td->kind == TypeData::SymbolicInst ); 744 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false );689 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), *td->symbolic.name, false ); 745 690 buildList( td->symbolic.actuals, ret->get_parameters() ); 746 691 buildForall( td->forall, ret->get_forall() ); … … 763 708 } // buildTypeof 764 709 765 Declaration * buildDecl( const TypeData * td, std::stringname, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) {710 Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) { 766 711 if ( td->kind == TypeData::Function ) { 767 712 FunctionDecl * decl; … … 773 718 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), body, isInline, isNoreturn ); 774 719 } else { 775 // std::list< Label > ls;776 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn );720 // list< Label > ls; 721 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( list< Label >() ), isInline, isNoreturn ); 777 722 } // if 778 723 } else { 779 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );780 } // if 781 for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {782 if ( cur->name != "") {783 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->name );724 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), nullptr, isInline, isNoreturn ); 725 } // if 726 for ( DeclarationNode * cur = td->function.idList; cur != nullptr; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 727 if ( cur->name ) { 728 decl->get_oldIdents().insert( decl->get_oldIdents().end(), *cur->name ); 784 729 } // if 785 730 } // for … … 792 737 } else if ( td->kind == TypeData::Symbolic ) { 793 738 return buildSymbolic( td, name, sc ); 794 } else if ( td->kind == TypeData::Variable ) {795 assert( false );796 return buildVariable( td );797 739 } else { 798 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, std::list< Attribute * >(), isInline, isNoreturn );740 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, list< Attribute * >(), isInline, isNoreturn ); 799 741 } // if 800 return 0;742 return nullptr; 801 743 } // buildDecl 802 744 … … 814 756 break; 815 757 default: 816 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base, "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) );758 ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base, "", DeclarationNode::NoStorageClass, nullptr, false, false, LinkageSpec::Cforall ) ) ); 817 759 } // switch 818 760 } else { 819 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0) );761 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 820 762 } // if 821 763 return ft; -
src/Parser/TypeData.h
r1b77274 r2298f728 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 16 15:17:31201613 // Update Count : 1 3112 // Last Modified On : Sat Sep 24 11:10:38 2016 13 // Update Count : 141 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, Tuple, Typeof, Builtin }; 27 27 28 28 struct Aggregate_t { 29 29 DeclarationNode::Aggregate kind; 30 std::stringname;30 const std::string * name; 31 31 DeclarationNode * params; 32 ExpressionNode 32 ExpressionNode * actuals; // holds actual parameters later applied to AggInst 33 33 DeclarationNode * fields; 34 34 bool body; … … 47 47 48 48 struct Enumeration_t { 49 std::stringname;49 const std::string * name; 50 50 DeclarationNode * constants; 51 51 }; … … 61 61 62 62 struct Symbolic_t { 63 std::stringname;63 const std::string * name; 64 64 bool isTypedef; // false => TYPEGENname, true => TYPEDEFname 65 65 DeclarationNode * params; … … 110 110 TupleType * buildTuple( const TypeData * ); 111 111 TypeofType * buildTypeof( const TypeData * ); 112 Declaration * buildDecl( const TypeData *, std::string, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = 0);112 Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = nullptr ); 113 113 FunctionType * buildFunction( const TypeData * ); 114 114 -
src/Parser/parser.h
r1b77274 r2298f728 262 262 263 263 /* Line 2068 of yacc.c */ 264 #line 11 5"parser.yy"264 #line 116 "parser.yy" 265 265 266 266 Token tok; -
src/Parser/parser.yy
r1b77274 r2298f728 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Sep 16 18:12:21201613 // Update Count : 19 7812 // Last Modified On : Sat Sep 24 11:30:40 2016 13 // Update Count : 1991 14 14 // 15 15 … … 54 54 #include "TypeData.h" 55 55 #include "LinkageSpec.h" 56 using namespace std; 56 57 57 58 extern DeclarationNode * parseTree; … … 59 60 extern TypedefTable typedefTable; 60 61 61 st d::stack< LinkageSpec::Spec > linkageStack;62 63 void appendStr( st d::string *to, std::string *from ) {62 stack< LinkageSpec::Spec > linkageStack; 63 64 void appendStr( string *to, string *from ) { 64 65 // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string. 65 66 to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) ); … … 389 390 { 390 391 Token fn; 391 fn.str = new st d::string( "?{}" );// location undefined392 fn.str = new string( "?{}" ); // location undefined 392 393 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ); 393 394 } … … 666 667 { 667 668 Token fn; 668 fn.str = new st d::string( "^?{}" );// location undefined669 fn.str = new string( "^?{}" ); // location undefined 669 670 $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) ); 670 671 } … … 1467 1468 aggregate_name: 1468 1469 aggregate_key '{' field_declaration_list '}' 1469 { $$ = DeclarationNode::newAggregate( $1, n ew std::string( "" ), nullptr, $3, true ); }1470 { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); } 1470 1471 | aggregate_key no_attr_identifier_or_type_name 1471 1472 { 1472 1473 typedefTable.makeTypedef( *$2 ); 1473 $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );1474 $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false ); 1474 1475 } 1475 1476 | aggregate_key no_attr_identifier_or_type_name … … 1478 1479 { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); } 1479 1480 | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA 1480 { $$ = DeclarationNode::newAggregate( $1, n ew std::string( "" ), $3, $6, false ); }1481 { $$ = DeclarationNode::newAggregate( $1, nullptr, $3, $6, false ); } 1481 1482 | aggregate_key typegen_name // CFA, S/R conflict 1482 1483 { $$ = $2; } … … 1559 1560 enum_name: 1560 1561 enum_key '{' enumerator_list comma_opt '}' 1561 { $$ = DeclarationNode::newEnum( n ew std::string( "" ), $3 ); }1562 { $$ = DeclarationNode::newEnum( nullptr, $3 ); } 1562 1563 | enum_key no_attr_identifier_or_type_name 1563 1564 { … … 2520 2521 abstract_function: 2521 2522 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2522 { $$ = DeclarationNode::newFunction( n ew std::string( "" ), nullptr, $3, nullptr ); }2523 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2523 2524 | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2524 2525 { $$ = $2->addParamList( $6 ); } … … 2589 2590 abstract_parameter_function: 2590 2591 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2591 { $$ = DeclarationNode::newFunction( n ew std::string( "" ), nullptr, $3, nullptr ); }2592 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2592 2593 | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2593 2594 { $$ = $2->addParamList( $6 ); } … … 2793 2794 // empty (void) function return type. 2794 2795 '[' ']' type_specifier 2795 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2796 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2796 2797 | '[' ']' multi_array_dimension type_specifier 2797 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2798 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2798 2799 | multi_array_dimension type_specifier 2799 2800 { $$ = $2->addNewArray( $1 ); } 2800 2801 | '[' ']' new_abstract_ptr 2801 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2802 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2802 2803 | '[' ']' multi_array_dimension new_abstract_ptr 2803 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }2804 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 2804 2805 | multi_array_dimension new_abstract_ptr 2805 2806 { $$ = $2->addNewArray( $1 ); } … … 2813 2814 new_abstract_function: // CFA 2814 2815 '[' ']' '(' new_parameter_type_list_opt ')' 2815 { $$ = DeclarationNode::newFunction( new std::string( "" ), DeclarationNode::newTuple( nullptr ), $4, nullptr ); }2816 { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 2816 2817 | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')' 2817 { $$ = DeclarationNode::newFunction( n ew std::string( "" ), $1, $4, nullptr ); }2818 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2818 2819 | new_function_return '(' push new_parameter_type_list_opt pop ')' 2819 { $$ = DeclarationNode::newFunction( n ew std::string( "" ), $1, $4, nullptr ); }2820 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 2820 2821 ; 2821 2822 … … 2852 2853 2853 2854 void yyerror( const char * ) { 2854 std::cout << "Error ";2855 cout << "Error "; 2855 2856 if ( yyfilename ) { 2856 std::cout << "in file " << yyfilename << " ";2857 cout << "in file " << yyfilename << " "; 2857 2858 } // if 2858 std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;2859 cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl; 2859 2860 } 2860 2861
Note: See TracChangeset
for help on using the changeset viewer.