Ignore:
Timestamp:
Mar 22, 2016, 9:57:47 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
94980502
Parents:
a752883
Message:

only implicitly generate typedef for structures if name not in use and overwrite typedef name if explicit name appears, upate parser symbol table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    ra752883 r984dce6  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:26:24 2016
    13 // Update Count     : 134
     12// Last Modified On : Mon Mar 21 21:04:23 2016
     13// Update Count     : 142
    1414//
    1515
     
    4242UniqueName DeclarationNode::anonymous( "__anonymous" );
    4343
    44 extern LinkageSpec::Type linkage;               /* defined in cfa.y */
     44extern LinkageSpec::Type linkage;                                               // defined in parser.yy
    4545
    4646DeclarationNode *DeclarationNode::clone() const {
     
    5555        newnode->linkage = linkage;
    5656        return newnode;
    57 }
     57} // DeclarationNode::clone
    5858
    5959DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
     
    117117        newnode->type->function->newStyle = newStyle;
    118118        newnode->type->function->body = body;
     119        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    119120
    120121        if ( body ) {
     
    129130
    130131        return newnode;
    131 }
     132} // DeclarationNode::newFunction
    132133
    133134DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) {
     
    136137        newnode->type->qualifiers.push_back( q );
    137138        return newnode;
    138 }
     139} // DeclarationNode::newQualifier
    139140
    140141DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     
    142143        newnode->storageClasses.push_back( sc );
    143144        return newnode;
    144 }
     145} // DeclarationNode::newStorageClass
    145146
    146147DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     
    149150        newnode->type->basic->typeSpec.push_back( bt );
    150151        return newnode;
    151 }
     152} // DeclarationNode::newBasicType
    152153
    153154DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) {
     
    156157        newnode->type->builtin->type = bt;
    157158        return newnode;
    158 }
     159} // DeclarationNode::newBuiltinType
    159160
    160161DeclarationNode *DeclarationNode::newModifier( Modifier mod ) {
     
    163164        newnode->type->basic->modifiers.push_back( mod );
    164165        return newnode;
    165 }
     166} // DeclarationNode::newModifier
    166167
    167168DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
     
    170171        newnode->type->forall = forall;
    171172        return newnode;
    172 }
     173} // DeclarationNode::newForall
    173174
    174175DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
     
    179180        newnode->type->symbolic->params = 0;
    180181        return newnode;
    181 }
     182} // DeclarationNode::newFromTypedef
    182183
    183184DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) {
     
    188189        if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
    189190                newnode->type->aggregate->name = DeclarationNode::anonymous.newName();
    190         } else {
    191                 // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified
    192                 // by "struct"
     191        } else if ( ! typedefTable.exists( newnode->type->aggregate->name ) ) {
     192                // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
     193                // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed
     194                // if the name is explicitly used.
    193195                typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD );
    194196                DeclarationNode *typedf = new DeclarationNode;
     
    199201        newnode->type->aggregate->fields = fields;
    200202        return newnode;
    201 }
     203} // DeclarationNode::newAggregate
    202204
    203205DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
     
    208210        if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
    209211                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
    210         } else {
    211                 // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be
    212                 // qualified by "enum"
     212        } else if ( ! typedefTable.exists( newnode->type->enumeration->name ) ) {
     213                // SKULLDUGGERY: Generate a typedef for the enumeration name so the enumeration does not have to be qualified by
     214                // "enum". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if
     215                // the name is explicitly used.
    213216                typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD );
    214217                DeclarationNode *typedf = new DeclarationNode;
     
    218221        newnode->type->enumeration->constants = constants;
    219222        return newnode;
    220 }
     223} // DeclarationNode::newEnum
    221224
    222225DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
     
    224227        newnode->name = assign_strptr( name );
    225228        newnode->enumeratorValue = constant;
    226         return newnode;
    227 }
     229        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     230        return newnode;
     231} // DeclarationNode::newEnumConstant
    228232
    229233DeclarationNode *DeclarationNode::newName( std::string *name ) {
     
    231235        newnode->name = assign_strptr( name );
    232236        return newnode;
    233 }
     237} // DeclarationNode::newName
    234238
    235239DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
     
    240244        newnode->type->symbolic->actuals = params;
    241245        return newnode;
    242 }
     246} // DeclarationNode::newFromTypeGen
    243247
    244248DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
     
    249253        newnode->type->variable->name = newnode->name;
    250254        return newnode;
    251 }
     255} // DeclarationNode::newTypeParam
    252256
    253257DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
     
    259263        newnode->type->aggregate->name = assign_strptr( name );
    260264        return newnode;
    261 }
     265} // DeclarationNode::newTrait
    262266
    263267DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
     
    269273        newnode->type->aggInst->params = params;
    270274        return newnode;
    271 }
     275} // DeclarationNode::newTraitUse
    272276
    273277DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
     
    279283        newnode->type->symbolic->name = newnode->name;
    280284        return newnode;
    281 }
     285} // DeclarationNode::newTypeDecl
    282286
    283287DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
     
    285289        newnode->type = new TypeData( TypeData::Pointer );
    286290        return newnode->addQualifiers( qualifiers );
    287 }
     291} // DeclarationNode::newPointer
    288292
    289293DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
     
    298302        } // if
    299303        return newnode->addQualifiers( qualifiers );
    300 }
     304} // DeclarationNode::newArray
    301305
    302306DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
Note: See TracChangeset for help on using the changeset viewer.