Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r45161b4d r1db21619  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Apr 13 16:53:17 2016
    13 // Update Count     : 161
     12// Last Modified On : Tue Jul 14 14:46:32 2015
     13// Update Count     : 126
    1414//
    1515
     
    3434const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" };
    3535const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    36 const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary", };
     36const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" };
    3737const char *DeclarationNode::modifierName[]  = { "signed", "unsigned", "short", "long" };
    3838const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    3939const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
    40 const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4140
    4241UniqueName DeclarationNode::anonymous( "__anonymous" );
    4342
    44 extern LinkageSpec::Type linkage;                                               // defined in parser.yy
     43extern LinkageSpec::Type linkage;               /* defined in cfa.y */
    4544
    4645DeclarationNode *DeclarationNode::clone() const {
     
    5554        newnode->linkage = linkage;
    5655        return newnode;
    57 } // DeclarationNode::clone
     56}
    5857
    5958DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
     
    117116        newnode->type->function->newStyle = newStyle;
    118117        newnode->type->function->body = body;
    119         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    120118
    121119        if ( body ) {
     
    130128
    131129        return newnode;
    132 } // DeclarationNode::newFunction
     130}
    133131
    134132DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) {
     
    137135        newnode->type->qualifiers.push_back( q );
    138136        return newnode;
    139 } // DeclarationNode::newQualifier
     137}
    140138
    141139DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     
    143141        newnode->storageClasses.push_back( sc );
    144142        return newnode;
    145 } // DeclarationNode::newStorageClass
     143}
    146144
    147145DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     
    150148        newnode->type->basic->typeSpec.push_back( bt );
    151149        return newnode;
    152 } // DeclarationNode::newBasicType
    153 
    154 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) {
    155         DeclarationNode *newnode = new DeclarationNode;
    156         newnode->type = new TypeData( TypeData::Builtin );
    157         newnode->type->builtin->type = bt;
    158         return newnode;
    159 } // DeclarationNode::newBuiltinType
     150}
    160151
    161152DeclarationNode *DeclarationNode::newModifier( Modifier mod ) {
     
    164155        newnode->type->basic->modifiers.push_back( mod );
    165156        return newnode;
    166 } // DeclarationNode::newModifier
     157}
    167158
    168159DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
     
    171162        newnode->type->forall = forall;
    172163        return newnode;
    173 } // DeclarationNode::newForall
     164}
    174165
    175166DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
     
    180171        newnode->type->symbolic->params = 0;
    181172        return newnode;
    182 } // DeclarationNode::newFromTypedef
     173}
    183174
    184175DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) {
     
    188179        newnode->type->aggregate->name = assign_strptr( name );
    189180        if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
    190                 newnode->type->aggregate->name = anonymous.newName();
     181                newnode->type->aggregate->name = DeclarationNode::anonymous.newName();
     182        } else {
     183                // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified
     184                // by "struct"
     185                typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD );
     186                DeclarationNode *typedf = new DeclarationNode;
     187                typedf->name = newnode->type->aggregate->name;
     188                newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );
    191189        } // if
    192190        newnode->type->aggregate->actuals = actuals;
    193191        newnode->type->aggregate->fields = fields;
    194192        return newnode;
    195 } // DeclarationNode::newAggregate
     193}
    196194
    197195DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
     
    202200        if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
    203201                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
     202        } else {
     203                // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be
     204                // qualified by "enum"
     205                typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD );
     206                DeclarationNode *typedf = new DeclarationNode;
     207                typedf->name = newnode->type->enumeration->name;
     208                newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );
    204209        } // if
    205210        newnode->type->enumeration->constants = constants;
    206211        return newnode;
    207 } // DeclarationNode::newEnum
     212}
    208213
    209214DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    210215        DeclarationNode *newnode = new DeclarationNode;
    211216        newnode->name = assign_strptr( name );
    212         newnode->enumeratorValue = constant;
    213         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    214         return newnode;
    215 } // DeclarationNode::newEnumConstant
     217        // do something with the constant
     218        return newnode;
     219}
    216220
    217221DeclarationNode *DeclarationNode::newName( std::string *name ) {
     
    219223        newnode->name = assign_strptr( name );
    220224        return newnode;
    221 } // DeclarationNode::newName
     225}
    222226
    223227DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
     
    228232        newnode->type->symbolic->actuals = params;
    229233        return newnode;
    230 } // DeclarationNode::newFromTypeGen
     234}
    231235
    232236DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
     
    237241        newnode->type->variable->name = newnode->name;
    238242        return newnode;
    239 } // DeclarationNode::newTypeParam
    240 
    241 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
     243}
     244
     245DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
    242246        DeclarationNode *newnode = new DeclarationNode;
    243247        newnode->type = new TypeData( TypeData::Aggregate );
    244         newnode->type->aggregate->kind = Trait;
     248        newnode->type->aggregate->kind = Context;
    245249        newnode->type->aggregate->params = params;
    246250        newnode->type->aggregate->fields = asserts;
    247251        newnode->type->aggregate->name = assign_strptr( name );
    248252        return newnode;
    249 } // DeclarationNode::newTrait
    250 
    251 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
     253}
     254
     255DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) {
    252256        DeclarationNode *newnode = new DeclarationNode;
    253257        newnode->type = new TypeData( TypeData::AggregateInst );
    254258        newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate );
    255         newnode->type->aggInst->aggregate->aggregate->kind = Trait;
     259        newnode->type->aggInst->aggregate->aggregate->kind = Context;
    256260        newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name );
    257261        newnode->type->aggInst->params = params;
    258262        return newnode;
    259 } // DeclarationNode::newTraitUse
     263}
    260264
    261265DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
     
    267271        newnode->type->symbolic->name = newnode->name;
    268272        return newnode;
    269 } // DeclarationNode::newTypeDecl
     273}
    270274
    271275DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
     
    273277        newnode->type = new TypeData( TypeData::Pointer );
    274278        return newnode->addQualifiers( qualifiers );
    275 } // DeclarationNode::newPointer
     279}
    276280
    277281DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
     
    286290        } // if
    287291        return newnode->addQualifiers( qualifiers );
    288 } // DeclarationNode::newArray
     292}
    289293
    290294DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
     
    790794                        errors.append( e );
    791795                } // try
    792                 cur = dynamic_cast<DeclarationNode *>( cur->get_link() );
     796                cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
    793797        } // while
    794798        if ( ! errors.isEmpty() ) {
     
    877881                          ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
    878882                          break;
    879                         case DeclarationNode::Trait:
    880                           ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );
     883                        case DeclarationNode::Context:
     884                          ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );
    881885                          break;
    882886                        default:
Note: See TracChangeset for help on using the changeset viewer.