Changeset 692c1cc
- Timestamp:
- Feb 16, 2023, 4:44:53 PM (21 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 14f6a3cb
- Parents:
- f8729be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rf8729be r692c1cc 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 … … 154 154 } // if 155 155 156 for ( Attribute * attr: reverseIterate( attributes ) ) { 157 os << string( indent + 2, ' ' ) << "attr " << attr->name.c_str(); 158 } // for 156 if ( ! attributes.empty() ) { 157 os << string( indent + 2, ' ' ) << "with attributes " << endl; 158 for ( Attribute * attr: reverseIterate( attributes ) ) { 159 os << string( indent + 4, ' ' ) << attr->name.c_str() << endl; 160 } // for 161 } // if 159 162 160 163 os << endl; … … 244 247 newnode->type = new TypeData( TypeData::Aggregate ); 245 248 newnode->type->aggregate.kind = kind; 246 newnode->type->aggregate.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name; 249 newnode->type->aggregate.anon = name == nullptr; 250 newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 247 251 newnode->type->aggregate.actuals = actuals; 248 252 newnode->type->aggregate.fields = fields; … … 250 254 newnode->type->aggregate.tagged = false; 251 255 newnode->type->aggregate.parent = nullptr; 252 newnode->type->aggregate.anon = name == nullptr;253 256 return newnode; 254 257 } // DeclarationNode::newAggregate … … 257 260 DeclarationNode * newnode = new DeclarationNode; 258 261 newnode->type = new TypeData( TypeData::Enum ); 259 newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name; 262 newnode->type->enumeration.anon = name == nullptr; 263 newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 260 264 newnode->type->enumeration.constants = constants; 261 265 newnode->type->enumeration.body = body; 262 newnode->type->enumeration.anon = name == nullptr;263 266 newnode->type->enumeration.typed = typed; 264 267 newnode->type->enumeration.hiding = hiding; … … 989 992 for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) { 990 993 try { 991 bool extracted = false; 992 bool anon = false; 994 bool extracted = false, anon = false; 995 AggregateDecl * unionDecl = nullptr; 996 993 997 if ( DeclarationNode * extr = cur->extractAggregate() ) { 994 998 // handle the case where a structure declaration is contained within an object or type declaration 999 995 1000 Declaration * decl = extr->build(); 996 1001 if ( decl ) { 997 // hoist the structure declaration 1002 // Remember the declaration if it is a union aggregate ? 1003 unionDecl = dynamic_cast<UnionDecl *>( decl ); 1004 998 1005 decl->location = cur->location; 999 * 1006 *out++ = decl; 1000 1007 1001 1008 // need to remember the cases where a declaration contains an anonymous aggregate definition … … 1003 1010 assert( extr->type ); 1004 1011 if ( extr->type->kind == TypeData::Aggregate ) { 1012 // typedef struct { int A } B is the only case? 1005 1013 anon = extr->type->aggregate.anon; 1006 1014 } else if ( extr->type->kind == TypeData::Enum ) { 1007 // xxx - is it useful to have an implicit anonymous enum member?1015 // typedef enum { A } B is the only case? 1008 1016 anon = extr->type->enumeration.anon; 1009 1017 } … … 1014 1022 Declaration * decl = cur->build(); 1015 1023 if ( decl ) { 1024 if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) { 1025 if ( unionDecl ) { // is the typedef alias a union aggregate ? 1026 // This code handles a special issue with the attribute transparent_union. 1027 // 1028 // typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union )) 1029 // 1030 // Here the attribute aligned goes with the typedef_name, so variables declared of this type are 1031 // aligned. However, the attribute transparent_union must be moved from the typedef_name to 1032 // alias union U. Currently, this is the only know attribute that must be moved from typedef to 1033 // alias. 1034 1035 // If typedef is an alias for a union, then its alias type was hoisted above and remembered. 1036 if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) { 1037 // Remove all transparent_union attributes from typedef and move to alias union. 1038 list<Attribute *>::iterator attr; 1039 for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order 1040 if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) { 1041 list<Attribute *>::iterator cur = attr; // remember current node 1042 attr++; // advance iterator 1043 unionDecl->attributes.emplace_back( *cur ); // move current 1044 unionInstType->attributes.erase( cur ); // remove current 1045 } else { 1046 attr++; // advance iterator 1047 } // if 1048 } // for 1049 } // if 1050 } // if 1051 } // if 1052 1016 1053 // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.: 1017 1054 // struct S {
Note: See TracChangeset
for help on using the changeset viewer.