Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r5d125e4 r1db21619  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // DeclarationNode.cc --
     7// DeclarationNode.cc -- 
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 20:49:31 2016
    13 // Update Count     : 164
     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 ) {
     
    9796                os << endl << string( indent + 2, ' ' ) << "with initializer ";
    9897                initializer->printOneLine( os );
    99                 os << " maybe constructed? " << initializer->get_maybeConstructed();
    100 
    10198        } // if
    10299
     
    119116        newnode->type->function->newStyle = newStyle;
    120117        newnode->type->function->body = body;
    121         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    122118
    123119        if ( body ) {
     
    132128
    133129        return newnode;
    134 } // DeclarationNode::newFunction
     130}
    135131
    136132DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) {
     
    139135        newnode->type->qualifiers.push_back( q );
    140136        return newnode;
    141 } // DeclarationNode::newQualifier
     137}
    142138
    143139DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     
    145141        newnode->storageClasses.push_back( sc );
    146142        return newnode;
    147 } // DeclarationNode::newStorageClass
     143}
    148144
    149145DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     
    152148        newnode->type->basic->typeSpec.push_back( bt );
    153149        return newnode;
    154 } // DeclarationNode::newBasicType
    155 
    156 DeclarationNode *DeclarationNode::newBuiltinType( BuiltinType bt ) {
    157         DeclarationNode *newnode = new DeclarationNode;
    158         newnode->type = new TypeData( TypeData::Builtin );
    159         newnode->type->builtin->type = bt;
    160         return newnode;
    161 } // DeclarationNode::newBuiltinType
     150}
    162151
    163152DeclarationNode *DeclarationNode::newModifier( Modifier mod ) {
     
    166155        newnode->type->basic->modifiers.push_back( mod );
    167156        return newnode;
    168 } // DeclarationNode::newModifier
     157}
    169158
    170159DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
     
    173162        newnode->type->forall = forall;
    174163        return newnode;
    175 } // DeclarationNode::newForall
     164}
    176165
    177166DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
     
    182171        newnode->type->symbolic->params = 0;
    183172        return newnode;
    184 } // DeclarationNode::newFromTypedef
    185 
    186 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
     173}
     174
     175DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) {
    187176        DeclarationNode *newnode = new DeclarationNode;
    188177        newnode->type = new TypeData( TypeData::Aggregate );
     
    190179        newnode->type->aggregate->name = assign_strptr( name );
    191180        if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
    192                 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() );
    193189        } // if
    194190        newnode->type->aggregate->actuals = actuals;
    195191        newnode->type->aggregate->fields = fields;
    196         newnode->type->aggregate->body = body;
    197         return newnode;
    198 } // DeclarationNode::newAggregate
     192        return newnode;
     193}
    199194
    200195DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
     
    205200        if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
    206201                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() );
    207209        } // if
    208210        newnode->type->enumeration->constants = constants;
    209211        return newnode;
    210 } // DeclarationNode::newEnum
     212}
    211213
    212214DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    213215        DeclarationNode *newnode = new DeclarationNode;
    214216        newnode->name = assign_strptr( name );
    215         newnode->enumeratorValue = constant;
    216         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    217         return newnode;
    218 } // DeclarationNode::newEnumConstant
     217        // do something with the constant
     218        return newnode;
     219}
    219220
    220221DeclarationNode *DeclarationNode::newName( std::string *name ) {
     
    222223        newnode->name = assign_strptr( name );
    223224        return newnode;
    224 } // DeclarationNode::newName
     225}
    225226
    226227DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
     
    231232        newnode->type->symbolic->actuals = params;
    232233        return newnode;
    233 } // DeclarationNode::newFromTypeGen
     234}
    234235
    235236DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
     
    240241        newnode->type->variable->name = newnode->name;
    241242        return newnode;
    242 } // DeclarationNode::newTypeParam
    243 
    244 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
     243}
     244
     245DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
    245246        DeclarationNode *newnode = new DeclarationNode;
    246247        newnode->type = new TypeData( TypeData::Aggregate );
    247         newnode->type->aggregate->kind = Trait;
     248        newnode->type->aggregate->kind = Context;
    248249        newnode->type->aggregate->params = params;
    249250        newnode->type->aggregate->fields = asserts;
    250251        newnode->type->aggregate->name = assign_strptr( name );
    251252        return newnode;
    252 } // DeclarationNode::newTrait
    253 
    254 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
     253}
     254
     255DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) {
    255256        DeclarationNode *newnode = new DeclarationNode;
    256257        newnode->type = new TypeData( TypeData::AggregateInst );
    257258        newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate );
    258         newnode->type->aggInst->aggregate->aggregate->kind = Trait;
     259        newnode->type->aggInst->aggregate->aggregate->kind = Context;
    259260        newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name );
    260261        newnode->type->aggInst->params = params;
    261262        return newnode;
    262 } // DeclarationNode::newTraitUse
     263}
    263264
    264265DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
     
    270271        newnode->type->symbolic->name = newnode->name;
    271272        return newnode;
    272 } // DeclarationNode::newTypeDecl
     273}
    273274
    274275DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
     
    276277        newnode->type = new TypeData( TypeData::Pointer );
    277278        return newnode->addQualifiers( qualifiers );
    278 } // DeclarationNode::newPointer
     279}
    279280
    280281DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
     
    289290        } // if
    290291        return newnode->addQualifiers( qualifiers );
    291 } // DeclarationNode::newArray
     292}
    292293
    293294DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
     
    356357        } // if
    357358}
    358 
     359         
    359360DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    360361        if ( q ) {
     
    507508                assert( false );
    508509        } // switch
    509 
     510       
    510511        return this;
    511512}
     
    618619                assert( a->type->kind == TypeData::Array );
    619620                TypeData *lastArray = findLast( a->type );
    620                 if ( type ) {
     621                if ( type ) { 
    621622                        switch ( type->kind ) {
    622623                          case TypeData::Aggregate:
     
    662663        } // if
    663664}
    664 
     665       
    665666DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) {
    666667        type = addIdListToType( type, ids );
     
    793794                        errors.append( e );
    794795                } // try
    795                 cur = dynamic_cast<DeclarationNode *>( cur->get_link() );
     796                cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
    796797        } // while
    797798        if ( ! errors.isEmpty() ) {
     
    856857Declaration *DeclarationNode::build() const {
    857858        if ( type ) {
    858                 return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     859                Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) );
     860                return newDecl;
    859861        } // if
    860862        if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
    861                 return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
     863                return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) );
    862864        } // if
    863865        throw SemanticError( "invalid function specifier in declaration of ", this );
     
    866868Type *DeclarationNode::buildType() const {
    867869        assert( type );
    868 
     870 
    869871        switch ( type->kind ) {
    870872          case TypeData::Enum:
     
    879881                          ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
    880882                          break;
    881                         case DeclarationNode::Trait:
    882                           ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );
     883                        case DeclarationNode::Context:
     884                          ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );
    883885                          break;
    884886                        default:
Note: See TracChangeset for help on using the changeset viewer.