Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r1db21619 r5d125e4  
    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 14 14:46:32 2015
    13 // Update Count     : 126
     12// Last Modified On : Tue Jul 12 20:49:31 2016
     13// Update Count     : 164
    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" };
     40const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4041
    4142UniqueName DeclarationNode::anonymous( "__anonymous" );
    4243
    43 extern LinkageSpec::Type linkage;               /* defined in cfa.y */
     44extern LinkageSpec::Type linkage;                                               // defined in parser.yy
    4445
    4546DeclarationNode *DeclarationNode::clone() const {
     
    5455        newnode->linkage = linkage;
    5556        return newnode;
    56 }
     57} // DeclarationNode::clone
    5758
    5859DeclarationNode::DeclarationNode() : type( 0 ), bitfieldWidth( 0 ), initializer( 0 ), hasEllipsis( false ), linkage( ::linkage ) {
     
    9697                os << endl << string( indent + 2, ' ' ) << "with initializer ";
    9798                initializer->printOneLine( os );
     99                os << " maybe constructed? " << initializer->get_maybeConstructed();
     100
    98101        } // if
    99102
     
    116119        newnode->type->function->newStyle = newStyle;
    117120        newnode->type->function->body = body;
     121        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    118122
    119123        if ( body ) {
     
    128132
    129133        return newnode;
    130 }
     134} // DeclarationNode::newFunction
    131135
    132136DeclarationNode *DeclarationNode::newQualifier( Qualifier q ) {
     
    135139        newnode->type->qualifiers.push_back( q );
    136140        return newnode;
    137 }
     141} // DeclarationNode::newQualifier
    138142
    139143DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
     
    141145        newnode->storageClasses.push_back( sc );
    142146        return newnode;
    143 }
     147} // DeclarationNode::newStorageClass
    144148
    145149DeclarationNode *DeclarationNode::newBasicType( BasicType bt ) {
     
    148152        newnode->type->basic->typeSpec.push_back( bt );
    149153        return newnode;
    150 }
     154} // DeclarationNode::newBasicType
     155
     156DeclarationNode *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
    151162
    152163DeclarationNode *DeclarationNode::newModifier( Modifier mod ) {
     
    155166        newnode->type->basic->modifiers.push_back( mod );
    156167        return newnode;
    157 }
     168} // DeclarationNode::newModifier
    158169
    159170DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
     
    162173        newnode->type->forall = forall;
    163174        return newnode;
    164 }
     175} // DeclarationNode::newForall
    165176
    166177DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
     
    171182        newnode->type->symbolic->params = 0;
    172183        return newnode;
    173 }
    174 
    175 DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ) {
     184} // DeclarationNode::newFromTypedef
     185
     186DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
    176187        DeclarationNode *newnode = new DeclarationNode;
    177188        newnode->type = new TypeData( TypeData::Aggregate );
     
    179190        newnode->type->aggregate->name = assign_strptr( name );
    180191        if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
    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() );
     192                newnode->type->aggregate->name = anonymous.newName();
    189193        } // if
    190194        newnode->type->aggregate->actuals = actuals;
    191195        newnode->type->aggregate->fields = fields;
    192         return newnode;
    193 }
     196        newnode->type->aggregate->body = body;
     197        return newnode;
     198} // DeclarationNode::newAggregate
    194199
    195200DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
     
    200205        if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
    201206                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() );
    209207        } // if
    210208        newnode->type->enumeration->constants = constants;
    211209        return newnode;
    212 }
     210} // DeclarationNode::newEnum
    213211
    214212DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    215213        DeclarationNode *newnode = new DeclarationNode;
    216214        newnode->name = assign_strptr( name );
    217         // do something with the constant
    218         return newnode;
    219 }
     215        newnode->enumeratorValue = constant;
     216        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     217        return newnode;
     218} // DeclarationNode::newEnumConstant
    220219
    221220DeclarationNode *DeclarationNode::newName( std::string *name ) {
     
    223222        newnode->name = assign_strptr( name );
    224223        return newnode;
    225 }
     224} // DeclarationNode::newName
    226225
    227226DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
     
    232231        newnode->type->symbolic->actuals = params;
    233232        return newnode;
    234 }
     233} // DeclarationNode::newFromTypeGen
    235234
    236235DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
     
    241240        newnode->type->variable->name = newnode->name;
    242241        return newnode;
    243 }
    244 
    245 DeclarationNode *DeclarationNode::newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
     242} // DeclarationNode::newTypeParam
     243
     244DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
    246245        DeclarationNode *newnode = new DeclarationNode;
    247246        newnode->type = new TypeData( TypeData::Aggregate );
    248         newnode->type->aggregate->kind = Context;
     247        newnode->type->aggregate->kind = Trait;
    249248        newnode->type->aggregate->params = params;
    250249        newnode->type->aggregate->fields = asserts;
    251250        newnode->type->aggregate->name = assign_strptr( name );
    252251        return newnode;
    253 }
    254 
    255 DeclarationNode *DeclarationNode::newContextUse( std::string *name, ExpressionNode *params ) {
     252} // DeclarationNode::newTrait
     253
     254DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
    256255        DeclarationNode *newnode = new DeclarationNode;
    257256        newnode->type = new TypeData( TypeData::AggregateInst );
    258257        newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate );
    259         newnode->type->aggInst->aggregate->aggregate->kind = Context;
     258        newnode->type->aggInst->aggregate->aggregate->kind = Trait;
    260259        newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name );
    261260        newnode->type->aggInst->params = params;
    262261        return newnode;
    263 }
     262} // DeclarationNode::newTraitUse
    264263
    265264DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
     
    271270        newnode->type->symbolic->name = newnode->name;
    272271        return newnode;
    273 }
     272} // DeclarationNode::newTypeDecl
    274273
    275274DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
     
    277276        newnode->type = new TypeData( TypeData::Pointer );
    278277        return newnode->addQualifiers( qualifiers );
    279 }
     278} // DeclarationNode::newPointer
    280279
    281280DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
     
    290289        } // if
    291290        return newnode->addQualifiers( qualifiers );
    292 }
     291} // DeclarationNode::newArray
    293292
    294293DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
     
    357356        } // if
    358357}
    359          
     358
    360359DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    361360        if ( q ) {
     
    508507                assert( false );
    509508        } // switch
    510        
     509
    511510        return this;
    512511}
     
    619618                assert( a->type->kind == TypeData::Array );
    620619                TypeData *lastArray = findLast( a->type );
    621                 if ( type ) { 
     620                if ( type ) {
    622621                        switch ( type->kind ) {
    623622                          case TypeData::Aggregate:
     
    663662        } // if
    664663}
    665        
     664
    666665DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) {
    667666        type = addIdListToType( type, ids );
     
    794793                        errors.append( e );
    795794                } // try
    796                 cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
     795                cur = dynamic_cast<DeclarationNode *>( cur->get_link() );
    797796        } // while
    798797        if ( ! errors.isEmpty() ) {
     
    857856Declaration *DeclarationNode::build() const {
    858857        if ( type ) {
    859                 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) );
    860                 return newDecl;
     858                return type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    861859        } // if
    862860        if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
    863                 return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) );
     861                return (new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    864862        } // if
    865863        throw SemanticError( "invalid function specifier in declaration of ", this );
     
    868866Type *DeclarationNode::buildType() const {
    869867        assert( type );
    870  
     868
    871869        switch ( type->kind ) {
    872870          case TypeData::Enum:
     
    881879                          ret = new UnionInstType( type->buildQualifiers(), type->aggregate->name );
    882880                          break;
    883                         case DeclarationNode::Context:
    884                           ret = new ContextInstType( type->buildQualifiers(), type->aggregate->name );
     881                        case DeclarationNode::Trait:
     882                          ret = new TraitInstType( type->buildQualifiers(), type->aggregate->name );
    885883                          break;
    886884                        default:
Note: See TracChangeset for help on using the changeset viewer.