Changeset 640b3df for src/Parser/DeclarationNode.cc
- Timestamp:
- Feb 21, 2023, 4:24:34 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 257a8f5, ce44c5f
- Parents:
- 1180175 (diff), 9a533ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r1180175 r640b3df 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 8 17:07:00 202213 // Update Count : 1 18512 // Last Modified On : Thu Feb 16 14:12:03 2023 13 // Update Count : 1388 14 14 // 15 15 … … 61 61 variable.initializer = nullptr; 62 62 63 // attr.name = nullptr;64 attr.expr = nullptr;65 attr.type = nullptr;66 67 63 assert.condition = nullptr; 68 64 assert.message = nullptr; … … 70 66 71 67 DeclarationNode::~DeclarationNode() { 72 // delete attr.name;73 delete attr.expr;74 delete attr.type;75 76 68 // delete variable.name; 77 69 delete variable.assertions; … … 115 107 newnode->variable.initializer = maybeClone( variable.initializer ); 116 108 117 // newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;118 newnode->attr.expr = maybeClone( attr.expr );119 newnode->attr.type = maybeClone( attr.type );120 121 109 newnode->assert.condition = maybeClone( assert.condition ); 122 110 newnode->assert.message = maybeClone( assert.message ); … … 154 142 } // if 155 143 156 for ( Attribute * attr: reverseIterate( attributes ) ) { 157 os << string( indent + 2, ' ' ) << "attr " << attr->name.c_str(); 158 } // for 144 if ( ! attributes.empty() ) { 145 os << string( indent + 2, ' ' ) << "with attributes " << endl; 146 for ( Attribute * attr: reverseIterate( attributes ) ) { 147 os << string( indent + 4, ' ' ) << attr->name.c_str() << endl; 148 } // for 149 } // if 159 150 160 151 os << endl; … … 244 235 newnode->type = new TypeData( TypeData::Aggregate ); 245 236 newnode->type->aggregate.kind = kind; 246 newnode->type->aggregate.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name; 237 newnode->type->aggregate.anon = name == nullptr; 238 newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 247 239 newnode->type->aggregate.actuals = actuals; 248 240 newnode->type->aggregate.fields = fields; … … 250 242 newnode->type->aggregate.tagged = false; 251 243 newnode->type->aggregate.parent = nullptr; 252 newnode->type->aggregate.anon = name == nullptr;253 244 return newnode; 254 245 } // DeclarationNode::newAggregate … … 257 248 DeclarationNode * newnode = new DeclarationNode; 258 249 newnode->type = new TypeData( TypeData::Enum ); 259 newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name; 250 newnode->type->enumeration.anon = name == nullptr; 251 newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 260 252 newnode->type->enumeration.constants = constants; 261 253 newnode->type->enumeration.body = body; 262 newnode->type->enumeration.anon = name == nullptr;263 254 newnode->type->enumeration.typed = typed; 264 255 newnode->type->enumeration.hiding = hiding; … … 989 980 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 990 981 try { 991 bool extracted = false; 992 bool anon = false; 982 bool extracted = false, anon = false; 983 AggregateDecl * unionDecl = nullptr; 984 993 985 if ( DeclarationNode * extr = cur->extractAggregate() ) { 994 986 // handle the case where a structure declaration is contained within an object or type declaration 987 995 988 Declaration * decl = extr->build(); 996 989 if ( decl ) { 997 // hoist the structure declaration 990 // Remember the declaration if it is a union aggregate ? 991 unionDecl = dynamic_cast<UnionDecl *>( decl ); 992 998 993 decl->location = cur->location; 999 * 994 *out++ = decl; 1000 995 1001 996 // need to remember the cases where a declaration contains an anonymous aggregate definition … … 1003 998 assert( extr->type ); 1004 999 if ( extr->type->kind == TypeData::Aggregate ) { 1000 // typedef struct { int A } B is the only case? 1005 1001 anon = extr->type->aggregate.anon; 1006 1002 } else if ( extr->type->kind == TypeData::Enum ) { 1007 // xxx - is it useful to have an implicit anonymous enum member?1003 // typedef enum { A } B is the only case? 1008 1004 anon = extr->type->enumeration.anon; 1009 1005 } … … 1014 1010 Declaration * decl = cur->build(); 1015 1011 if ( decl ) { 1012 if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) { 1013 if ( unionDecl ) { // is the typedef alias a union aggregate ? 1014 // This code handles a special issue with the attribute transparent_union. 1015 // 1016 // typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union )) 1017 // 1018 // Here the attribute aligned goes with the typedef_name, so variables declared of this type are 1019 // aligned. However, the attribute transparent_union must be moved from the typedef_name to 1020 // alias union U. Currently, this is the only know attribute that must be moved from typedef to 1021 // alias. 1022 1023 // If typedef is an alias for a union, then its alias type was hoisted above and remembered. 1024 if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) { 1025 // Remove all transparent_union attributes from typedef and move to alias union. 1026 list<Attribute *>::iterator attr; 1027 for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order 1028 if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) { 1029 list<Attribute *>::iterator cur = attr; // remember current node 1030 attr++; // advance iterator 1031 unionDecl->attributes.emplace_back( *cur ); // move current 1032 unionInstType->attributes.erase( cur ); // remove current 1033 } else { 1034 attr++; // advance iterator 1035 } // if 1036 } // for 1037 } // if 1038 } // if 1039 } // if 1040 1016 1041 // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.: 1017 1042 // struct S { … … 1176 1201 assert( type ); 1177 1202 1178 if ( attr.expr ) {1179 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );1180 } else if ( attr.type ) {1181 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );1182 } // if1183 1184 1203 switch ( type->kind ) { 1185 1204 case TypeData::Enum:
Note:
See TracChangeset
for help on using the changeset viewer.