Changes in src/Parser/DeclarationNode.cc [44a81853:c0aa336]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r44a81853 rc0aa336 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jan 14 14:36:23201713 // Update Count : 66912 // Last Modified On : Mon Feb 6 16:01:29 2017 13 // Update Count : 739 14 14 // 15 15 … … 83 83 DeclarationNode * DeclarationNode::clone() const { 84 84 DeclarationNode * newnode = new DeclarationNode; 85 newnode->set_next( maybeClone( get_next() ) ); 86 newnode->name = name ? new string( *name ) : nullptr; 87 85 88 newnode->type = maybeClone( type ); 86 newnode->name = name ? new string( *name ) : nullptr;87 89 newnode->storageClass = storageClass; 90 newnode->bitfieldWidth = maybeClone( bitfieldWidth ); 88 91 newnode->isInline = isInline; 89 92 newnode->isNoreturn = isNoreturn; 90 newnode-> bitfieldWidth = maybeClone( bitfieldWidth);93 newnode->enumeratorValue.reset( maybeClone( enumeratorValue.get() ) ); 91 94 newnode->hasEllipsis = hasEllipsis; 92 newnode->initializer = maybeClone( initializer );93 newnode->set_next( maybeClone( get_next() ) );94 95 newnode->linkage = linkage; 95 96 newnode->asmName = maybeClone( asmName ); 97 cloneAll( attributes, newnode->attributes ); 98 newnode->initializer = maybeClone( initializer ); 99 newnode->extension = extension; 100 newnode->error = error; 96 101 97 102 // newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr; … … 159 164 newnode->type->function.newStyle = newStyle; 160 165 newnode->type->function.body = body; 166 161 167 // ignore unnamed routine declarations: void p( int (*)(int) ); 162 168 if ( newnode->name ) { … … 436 442 } // if 437 443 appendError( error, q->error ); 438 } // DeclarationNode::c opyStorageClasses444 } // DeclarationNode::checkStorageClasses 439 445 440 446 DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) { … … 446 452 storageClass = q->storageClass; 447 453 } // if 448 attributes.splice( attributes.end(), q->attributes ); 454 455 for ( Attribute *attr: reverseIterate( q->attributes ) ) { 456 attributes.push_front( attr->clone() ); 457 } // for 449 458 return this; 450 459 } // DeclarationNode::copyStorageClasses … … 656 665 } 657 666 658 DeclarationNode * DeclarationNode::addAsmName( ConstantExpr* newname ) {667 DeclarationNode * DeclarationNode::addAsmName( DeclarationNode * newname ) { 659 668 assert( ! asmName ); 660 asmName = newname ;661 return this ;669 asmName = newname ? newname->asmName : nullptr; 670 return this->addQualifiers( newname ); 662 671 } 663 672 … … 690 699 } 691 700 692 static void setBase( TypeData *&type,TypeData * newType ) {701 DeclarationNode * DeclarationNode::setBase( TypeData * newType ) { 693 702 if ( type ) { 694 703 TypeData * prevBase = type; … … 702 711 type = newType; 703 712 } // if 704 } 713 return this; 714 } 715 716 DeclarationNode * DeclarationNode::copyAttribute( DeclarationNode * a ) { 717 if ( a ) { 718 for ( Attribute *attr: reverseIterate( a->attributes ) ) { 719 attributes.push_front( attr ); 720 } // for 721 a->attributes.clear(); 722 } // if 723 return this; 724 } // copyAttribute 705 725 706 726 DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) { 707 727 if ( p ) { 708 728 assert( p->type->kind == TypeData::Pointer ); 709 setBase( type,p->type );729 setBase( p->type ); 710 730 p->type = nullptr; 731 copyAttribute( p ); 711 732 delete p; 712 733 } // if … … 717 738 if ( a ) { 718 739 assert( a->type->kind == TypeData::Array ); 719 setBase( type,a->type );740 setBase( a->type ); 720 741 a->type = nullptr; 742 copyAttribute( a ); 721 743 delete a; 722 744 } // if … … 790 812 TypeData * ftype = new TypeData( TypeData::Function ); 791 813 ftype->function.params = params; 792 setBase( type,ftype );814 setBase( ftype ); 793 815 return this; 794 816 } … … 836 858 TypeData * srcType = type; 837 859 860 // search for the base type by scanning off pointers and array designators 838 861 while ( srcType->base ) { 839 862 srcType = srcType->base; … … 986 1009 if ( attr.expr ) { 987 1010 // return new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() ); 988 return new AttrType( buildQualifiers( type ), *name, attr.expr->build() );1011 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes ); 989 1012 } else if ( attr.type ) { 990 1013 // return new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() ); 991 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType() );1014 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes ); 992 1015 } // if 993 1016 994 1017 switch ( type->kind ) { 995 case TypeData::Enum: 996 return new EnumInstType( buildQualifiers( type ), *type->enumeration.name ); 1018 case TypeData::Enum: { 1019 EnumDecl * typedecl = buildEnum( type, attributes ); 1020 return new EnumInstType( buildQualifiers( type ), typedecl ); 1021 } 997 1022 case TypeData::Aggregate: { 1023 AggregateDecl * typedecl = buildAggregate( type, attributes ); 998 1024 ReferenceToType * ret; 999 1025 switch ( type->aggregate.kind ) { 1000 1026 case DeclarationNode::Struct: 1001 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name);1027 ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl ); 1002 1028 break; 1003 1029 case DeclarationNode::Union: 1004 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name);1030 ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl ); 1005 1031 break; 1006 1032 case DeclarationNode::Trait: 1007 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 1033 assert( false ); 1034 //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl ); 1008 1035 break; 1009 1036 default: … … 1014 1041 } 1015 1042 case TypeData::Symbolic: { 1016 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false );1043 TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false, attributes ); 1017 1044 buildList( type->symbolic.actuals, ret->get_parameters() ); 1018 1045 return ret; 1019 1046 } 1020 1047 default: 1021 return typebuild( type ); 1048 Type * simpletypes = typebuild( type ); 1049 simpletypes->get_attributes() = attributes; // copy because member is const 1050 return simpletypes; 1022 1051 } // switch 1023 1052 }
Note:
See TracChangeset
for help on using the changeset viewer.