Changeset 67467a3 for src/Parser/DeclarationNode.cc
- Timestamp:
- Mar 26, 2024, 3:17:51 PM (3 months ago)
- Branches:
- master
- Children:
- 544b799
- Parents:
- 84886499
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r84886499 r67467a3 189 189 190 190 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base, EnumHiding hiding ) { 191 DeclarationNode * newnode = new DeclarationNode; 192 newnode->type = new TypeData( TypeData::Enum ); 193 newnode->type->enumeration.anon = name == nullptr; 194 newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name; 195 newnode->type->enumeration.constants = constants; 196 newnode->type->enumeration.body = body; 197 newnode->type->enumeration.typed = typed; 198 newnode->type->enumeration.hiding = hiding; 191 DeclarationNode * newnode = newAggregate( ast::AggregateDecl::Enum, name, nullptr, constants, body ); 192 newnode->type->aggregate.typed = typed; 193 newnode->type->aggregate.hiding = hiding; 199 194 if ( base ) { 200 195 assert( typed ); … … 549 544 newaggr->aggregate.body = false; 550 545 newaggr->aggregate.anon = oldaggr->aggregate.anon; 546 newaggr->aggregate.typed = oldaggr->aggregate.typed; 547 newaggr->aggregate.hiding = oldaggr->aggregate.hiding; 551 548 swap( newaggr, oldaggr ); 552 549 … … 558 555 559 556 moveUnionAttribute( olddecl, newdecl ); 560 561 return newdecl;562 }563 564 // Helper for addTypedef, handles the case where the typedef wraps an565 // enumeration declaration (not a type), returns a chain of nodes.566 static DeclarationNode * addTypedefEnum(567 DeclarationNode * olddecl, TypeData * newtype ) {568 TypeData *& oldenum = olddecl->type->aggInst.aggregate;569 570 // Handle anonymous enumeration: typedef enum { A, B, C } foo571 // Give the typedefed type a consistent name across translation units.572 if ( oldenum->enumeration.anon ) {573 delete oldenum->enumeration.name;574 oldenum->enumeration.name = new string( "__anonymous_" + *olddecl->name );575 oldenum->enumeration.anon = false;576 oldenum->qualifiers.reset();577 }578 579 // Replace the wrapped TypeData with a forward declaration.580 TypeData * newenum = new TypeData( TypeData::Enum );581 newenum->enumeration.name = oldenum->enumeration.name ? new string( *oldenum->enumeration.name ) : nullptr;582 newenum->enumeration.body = false;583 newenum->enumeration.anon = oldenum->enumeration.anon;584 newenum->enumeration.typed = oldenum->enumeration.typed;585 newenum->enumeration.hiding = oldenum->enumeration.hiding;586 swap( newenum, oldenum );587 588 newtype->base = olddecl->type;589 olddecl->type = newtype;590 DeclarationNode * newdecl = new DeclarationNode;591 newdecl->type = newenum;592 newdecl->next = olddecl;593 557 594 558 return newdecl; … … 610 574 && type->aggInst.aggregate->aggregate.body ) { 611 575 return addTypedefAggr( this, newtype ); 612 // If this typedef is wrapping an enumeration, separate them out.613 } else if ( TypeData::AggregateInst == type->kind614 && TypeData::Enum == type->aggInst.aggregate->kind615 && type->aggInst.aggregate->enumeration.body ) {616 return addTypedefEnum( this, newtype );617 576 // There is no internal declaration, just a type. 618 577 } else { … … 854 813 // typedef struct { int A } B is the only case? 855 814 extracted_named = ! extr->type->aggregate.anon; 856 } else if ( extr->type->kind == TypeData::Enum ) {857 // typedef enum { A } B is the only case?858 extracted_named = ! extr->type->enumeration.anon;859 815 } else { 860 816 extracted_named = true; … … 1063 1019 1064 1020 switch ( type->kind ) { 1065 case TypeData::Enum:1066 1021 case TypeData::Aggregate: { 1067 1022 ast::BaseInstType * ret =
Note: See TracChangeset
for help on using the changeset viewer.