Changes in src/Parser/DeclarationNode.cc [59db689:68cd1ce]
- File:
-
- 1 edited
-
src/Parser/DeclarationNode.cc (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r59db689 r68cd1ce 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 6 23:29:13 201513 // Update Count : 2312 // Last Modified On : Sat Jun 13 08:02:03 2015 13 // Update Count : 58 14 14 // 15 15 … … 21 21 22 22 #include "TypeData.h" 23 24 #include "SynTree/Declaration.h" 23 25 #include "SynTree/Expression.h" 24 26 25 26 27 using namespace std; 27 28 28 29 // These must remain in the same order as the corresponding DeclarationNode enumerations. 30 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" }; 29 31 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" }; 30 32 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" }; 31 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" };32 const char *DeclarationNode:: tyConName[] = { "struct", "union", "context" };33 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" }; 34 const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" }; 33 35 const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" }; 34 36 … … 63 65 } 64 66 65 const char *storageClassName[] = {66 // order must correspond with DeclarationNode::StorageClass67 "extern",68 "static",69 "auto",70 "register",71 "inline",72 "fortran",73 };74 75 67 void DeclarationNode::print( std::ostream &os, int indent ) const { 76 68 os << string( indent, ' ' ); … … 79 71 } else { 80 72 os << name << ": "; 81 } 73 } // if 82 74 83 75 if ( linkage != LinkageSpec::Cforall ) { 84 76 os << LinkageSpec::toString( linkage ) << " "; 85 } 86 87 printEnums( storageClasses.begin(), storageClasses.end(), storageClassName, os );77 } // if 78 79 printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os ); 88 80 if ( type ) { 89 81 type->print( os, indent ); 90 82 } else { 91 83 os << "untyped entity "; 92 } 84 } // if 93 85 94 86 if ( bitfieldWidth ) { 95 87 os << endl << string( indent + 2, ' ' ) << "with bitfield width "; 96 88 bitfieldWidth->printOneLine( os ); 97 } 89 } // if 98 90 99 91 if ( initializer != 0 ) { 100 92 os << endl << string( indent + 2, ' ' ) << "with initializer "; 101 93 initializer->printOneLine( os ); 102 } 94 } // if 103 95 104 96 os << endl; … … 109 101 if ( hasEllipsis ) { 110 102 os << string( indent, ' ' ) << "and a variable number of other arguments" << endl; 111 } 103 } // if 112 104 } 113 105 … … 123 115 if ( body ) { 124 116 newnode->type->function->hasBody = true; 125 } 117 } // if 126 118 127 119 if ( ret ) { … … 129 121 ret->type = 0; 130 122 delete ret; 131 } 123 } // if 132 124 133 125 return newnode; … … 141 133 } 142 134 143 DeclarationNode *DeclarationNode::newStorageClass( StorageClass sc ) {135 DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) { 144 136 DeclarationNode *newnode = new DeclarationNode; 145 137 newnode->storageClasses.push_back( sc ); … … 177 169 } 178 170 179 DeclarationNode *DeclarationNode::newAggregate( TyConkind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ) {171 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ) { 180 172 DeclarationNode *newnode = new DeclarationNode; 181 173 newnode->type = new TypeData( TypeData::Aggregate ); … … 184 176 if ( newnode->type->aggregate->name == "" ) { 185 177 newnode->type->aggregate->name = DeclarationNode::anonymous.newName(); 186 } 178 } // if 187 179 newnode->type->aggregate->params = formals; 188 180 newnode->type->aggregate->actuals = actuals; … … 198 190 if ( newnode->type->enumeration->name == "" ) { 199 191 newnode->type->enumeration->name = DeclarationNode::anonymous.newName(); 200 } 192 } // if 201 193 newnode->type->enumeration->constants = constants; 202 194 return newnode; … … 331 323 } else { 332 324 dst->forall = src->forall; 333 } 325 } // if 334 326 src->forall = 0; 335 } 327 } // if 336 328 if ( dst->base ) { 337 329 addQualifiersToType( src, dst->base ); … … 341 333 } else { 342 334 dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers ); 343 } 344 } 335 } // if 336 } // if 345 337 } 346 338 … … 351 343 if ( ! type ) { 352 344 type = new TypeData; 353 } 345 } // if 354 346 addQualifiersToType( q->type, type ); 355 347 if ( q->type && q->type->forall ) { … … 357 349 type->forall->appendList( q->type->forall ); 358 350 } else { 359 type->forall = q->type->forall; 360 } 351 if ( type->kind == TypeData::Aggregate ) { 352 type->aggregate->params = q->type->forall; 353 } else { 354 type->forall = q->type->forall; 355 } // if 356 } // if 361 357 q->type->forall = 0; 362 } 363 } 364 } 358 } // if 359 } // if 360 } // if 365 361 delete q; 366 362 return this; … … 379 375 } else { 380 376 dst->forall = src->forall; 381 } 377 } // if 382 378 src->forall = 0; 383 } 379 } // if 384 380 if ( dst->base ) { 385 381 addTypeToType( src, dst->base ); … … 398 394 dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers ); 399 395 dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec ); 400 } 396 } // if 401 397 break; 402 398 … … 409 405 if ( src->kind == TypeData::Aggregate ) { 410 406 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 411 } 407 } // if 412 408 dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers ); 413 409 src = 0; … … 419 415 } else { 420 416 dst->forall = src->forall; 421 } 417 } // if 422 418 src->forall = 0; 423 419 dst->base = src; 424 420 src = 0; 425 } 426 } 427 } 428 } 421 } // switch 422 } // switch 423 } // if 424 } // if 429 425 } 430 426 … … 439 435 if ( o->type->kind == TypeData::Aggregate ) { 440 436 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 441 } 437 } // if 442 438 type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers ); 443 439 } else { 444 440 type = o->type; 445 } 441 } // if 446 442 o->type = 0; 447 443 } else { 448 444 addTypeToType( o->type, type ); 449 } 450 } 445 } // if 446 } // if 451 447 if ( o->bitfieldWidth ) { 452 448 bitfieldWidth = o->bitfieldWidth; 453 } 454 } 449 } // if 450 } // if 455 451 delete o; 456 452 return this; … … 475 471 } else { 476 472 type->symbolic->assertions = assertions; 477 } 473 } // if 478 474 break; 479 480 475 case TypeData::Variable: 481 476 if ( type->variable->assertions ) { … … 483 478 } else { 484 479 type->variable->assertions = assertions; 485 } 480 } // if 486 481 break; 487 488 482 default: 489 483 assert( false ); 490 } 484 } // switch 491 485 492 486 return this; … … 526 520 } 527 521 528 static void 529 setBase( TypeData *&type, TypeData *newType ) { 522 static void setBase( TypeData *&type, TypeData *newType ) { 530 523 if ( type ) { 531 524 TypeData *prevBase = type; … … 534 527 prevBase = curBase; 535 528 curBase = curBase->base; 536 } 529 } // while 537 530 prevBase->base = newType; 538 531 } else { 539 532 type = newType; 540 } 533 } // if 541 534 } 542 535 … … 547 540 p->type = 0; 548 541 delete p; 549 } 542 } // if 550 543 return this; 551 544 } … … 557 550 a->type = 0; 558 551 delete a; 559 } 552 } // if 560 553 return this; 561 554 } … … 572 565 if ( type->kind == TypeData::Aggregate ) { 573 566 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 574 } 567 } // if 575 568 p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers ); 576 569 break; … … 578 571 default: 579 572 p->type->base = type; 580 } 573 } // switch 581 574 type = 0; 582 } 575 } // if 583 576 delete this; 584 577 return p; 585 578 } else { 586 579 return this; 587 } 580 } // if 588 581 } 589 582 … … 593 586 while ( cur->base ) { 594 587 cur = cur->base; 595 } 588 } // while 596 589 return cur; 597 590 } … … 609 602 if ( type->kind == TypeData::Aggregate ) { 610 603 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 611 } 604 } // if 612 605 lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers ); 613 606 break; 614 607 default: 615 608 lastArray->base = type; 616 } 609 } // switch 617 610 type = 0; 618 } 611 } // if 619 612 delete this; 620 613 return a; 621 614 } else { 622 615 return this; 623 } 616 } // if 624 617 } 625 618 … … 637 630 } else { 638 631 type->function->idList = ids; 639 } 632 } // if 640 633 return type; 641 634 } else { … … 643 636 newtype->function->idList = ids; 644 637 return newtype; 645 } 638 } // if 646 639 } 647 640 … … 662 655 while ( srcType->base ) { 663 656 srcType = srcType->base; 664 } 657 } // while 665 658 newnode->type = maybeClone( srcType ); 666 659 if ( newnode->type->kind == TypeData::AggregateInst ) { … … 673 666 delete newnode->type->aggInst->aggregate->aggregate->members; 674 667 newnode->type->aggInst->aggregate->aggregate->members = 0; 675 } 676 } 668 } // if 669 } // if 677 670 newnode->type->forall = maybeClone( type->forall ); 678 671 newnode->storageClasses = storageClasses; … … 688 681 while ( srcType->base ) { 689 682 srcType = srcType->base; 690 } 683 } // while 691 684 TypeData *newType = srcType->clone(); 692 685 if ( newType->kind == TypeData::AggregateInst ) { … … 699 692 delete newType->aggInst->aggregate->aggregate->members; 700 693 newType->aggInst->aggregate->aggregate->members = 0; 701 } 702 } 694 } // if 695 } // if 703 696 newType->forall = maybeClone( type->forall ); 704 697 if ( ! o->type ) { … … 707 700 addTypeToType( newType, o->type ); 708 701 delete newType; 709 } 710 } 711 } 702 } // if 703 } // if 704 } // if 712 705 return o; 713 706 } … … 731 724 addTypeToType( newType, o->type ); 732 725 delete newType; 733 } 734 } 735 } 726 } // if 727 } // if 728 } // if 736 729 return o; 737 730 } … … 740 733 if ( node != 0 ) { 741 734 set_link( node ); 742 } 735 } // if 743 736 return this; 744 737 } … … 803 796 } else if ( StructDecl *agg = dynamic_cast< StructDecl *>( decl ) ) { 804 797 StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() ); 805 *out++ = new ObjectDecl( "", Declaration ::NoStorageClass, linkage, 0, inst, 0 );798 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 806 799 delete agg; 807 800 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl *>( decl ) ) { 808 801 UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); 809 *out++ = new ObjectDecl( "", Declaration ::NoStorageClass, linkage, 0, inst, 0 );802 *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 ); 810 803 } // if 811 804 } // if … … 882 875 } 883 876 884 Declaration::StorageClass DeclarationNode::buildStorageClass() const { 885 static const Declaration::StorageClass scMap[] = { 886 Declaration::Extern, 887 Declaration::Static, 888 Declaration::Auto, 889 Declaration::Register, 890 Declaration::Inline, 891 Declaration::Fortran 892 }; 893 894 Declaration::StorageClass ret = Declaration::NoStorageClass; 895 for ( std::list< StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 896 assert( unsigned( *i ) < sizeof( scMap ) / sizeof( scMap[0] ) ); 897 if ( *i == Inline ) continue; 898 if ( ret != Declaration::NoStorageClass ) { 877 DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const { 878 DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass; 879 for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) { 880 if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers 881 882 if ( ret != DeclarationNode::NoStorageClass ) { // already have a valid storage class ? 899 883 throw SemanticError( "invalid combination of storage classes in declaration of ", this ); 900 } 901 ret = scMap[ *i ];902 } 884 } // if 885 ret = *i; 886 } // for 903 887 return ret; 904 888 } 905 889 906 890 bool DeclarationNode::buildInline() const { 907 std::list< StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(),Inline );891 std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), DeclarationNode::Inline ); 908 892 if ( first == storageClasses.end() ) return false; 909 std::list< StorageClass >::const_iterator next = std::find( ++first, storageClasses.end(),Inline );893 std::list< DeclarationNode::StorageClass >::const_iterator next = std::find( ++first, storageClasses.end(), DeclarationNode::Inline ); 910 894 if ( next == storageClasses.end() ) return true; 911 895 throw SemanticError( "duplicate inline specification in declaration of ", this );
Note:
See TracChangeset
for help on using the changeset viewer.