Changeset 4eb3a7c5 for src/Parser/DeclarationNode.cc
- Timestamp:
- Feb 23, 2024, 6:52:33 PM (6 months ago)
- Branches:
- master
- Children:
- 3d5a8cb
- Parents:
- 624ba3a5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r624ba3a5 r4eb3a7c5 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 14 19:05:17 202313 // Update Count : 1 40712 // Last Modified On : Fri Feb 23 18:25:57 2024 13 // Update Count : 1533 14 14 // 15 15 … … 159 159 160 160 if ( ! attributes.empty() ) { 161 os << string( indent + 2, ' ' ) << "with attributes 161 os << string( indent + 2, ' ' ) << "with attributes" << endl; 162 162 for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( attributes ) ) { 163 os << string( indent + 4, ' ' ) << attr->name.c_str() << endl; 163 os << string( indent + 4, ' ' ); 164 ast::print( os, attr, indent + 2 ); 164 165 } // for 165 166 } // if … … 537 538 } // DeclarationNode::checkSpecifiers 538 539 539 DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q ) {540 DeclarationNode * DeclarationNode::copySpecifiers( DeclarationNode * q, bool copyattr ) { 540 541 funcSpecs |= q->funcSpecs; 541 542 storageClasses |= q->storageClasses; 542 543 543 std::vector<ast::ptr<ast::Attribute>> tmp; 544 tmp.reserve( q->attributes.size() ); 545 for ( auto const & attr : q->attributes ) { 546 tmp.emplace_back( ast::shallowCopy( attr.get() ) ); 547 } 548 spliceBegin( attributes, tmp ); 544 if ( copyattr ) { 545 std::vector<ast::ptr<ast::Attribute>> tmp; 546 tmp.reserve( q->attributes.size() ); 547 for ( auto const & attr : q->attributes ) { 548 tmp.emplace_back( ast::shallowCopy( attr.get() ) ); 549 } // for 550 spliceBegin( attributes, tmp ); 551 } // if 549 552 550 553 return this; … … 681 684 } 682 685 683 DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {686 DeclarationNode * DeclarationNode::addType( DeclarationNode * o, bool copyattr ) { 684 687 if ( o ) { 685 688 checkSpecifiers( o ); 686 copySpecifiers( o );689 copySpecifiers( o, copyattr ); 687 690 if ( o->type ) { 688 691 if ( ! type ) { 689 692 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 693 // Hide type information aggregate instances. 690 694 type = new TypeData( TypeData::AggregateInst ); 691 type->aggInst.aggregate = o->type; 695 type->aggInst.aggregate = o->type; // change ownership 696 type->aggInst.aggregate->aggregate.attributes.swap( o->attributes ); // change ownership 692 697 if ( o->type->kind == TypeData::Aggregate ) { 693 698 type->aggInst.hoistType = o->type->aggregate.body; … … 700 705 type = o->type; 701 706 } // if 702 o->type = nullptr; 707 o->type = nullptr; // change ownership 703 708 } else { 704 709 addTypeToType( o->type, type ); … … 953 958 } 954 959 955 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {960 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o, bool copyattr ) { 956 961 if ( ! o ) return nullptr; 957 962 958 o->copySpecifiers( this );963 o->copySpecifiers( this, copyattr ); 959 964 if ( type ) { 960 965 TypeData * srcType = type; … … 999 1004 DeclarationNode * newnode = new DeclarationNode; 1000 1005 newnode->type = ret; 1006 if ( ret->kind == TypeData::Aggregate ) { 1007 newnode->attributes.swap( ret->aggregate.attributes ); 1008 } // if 1001 1009 return newnode; 1002 1010 } // if … … 1110 1118 if ( extr->type->kind == TypeData::Aggregate ) { 1111 1119 // typedef struct { int A } B is the only case? 1112 extracted_named = ! extr->type->aggregate.anon;1120 extracted_named = ! extr->type->aggregate.anon; 1113 1121 } else if ( extr->type->kind == TypeData::Enum ) { 1114 1122 // typedef enum { A } B is the only case? 1115 extracted_named = ! extr->type->enumeration.anon;1123 extracted_named = ! extr->type->enumeration.anon; 1116 1124 } else { 1117 1125 extracted_named = true;
Note: See TracChangeset
for help on using the changeset viewer.