Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r284da8c rc194661  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  6 06:56:08 2018
    13 // Update Count     : 1088
     12// Last Modified On : Thu Jun  7 12:08:55 2018
     13// Update Count     : 1079
    1414//
    1515
     
    254254} // DeclarationNode::newFromTypedef
    255255
     256DeclarationNode * DeclarationNode::newFromGlobalScope() {
     257        DeclarationNode * newnode = new DeclarationNode;
     258        newnode->type = new TypeData( TypeData::GlobalScope );
     259        return newnode;
     260}
     261
     262DeclarationNode * DeclarationNode::newQualifiedType( DeclarationNode * parent, DeclarationNode * child) {
     263        DeclarationNode * newnode = new DeclarationNode;
     264        newnode->type = new TypeData( TypeData::Qualified );
     265        newnode->type->qualified.parent = parent->type;
     266        newnode->type->qualified.child = child->type;
     267        parent->type = nullptr;
     268        child->type = nullptr;
     269        delete parent;
     270        delete child;
     271        return newnode;
     272}
     273
    256274DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    257275        assert( name );
     
    504522
    505523static void addQualifiersToType( TypeData *&src, TypeData * dst ) {
     524        if ( src->forall && dst->kind == TypeData::Function ) {
     525                if ( dst->forall ) {
     526                        dst->forall->appendList( src->forall );
     527                } else {
     528                        dst->forall = src->forall;
     529                } // if
     530                src->forall = nullptr;
     531        } // if
    506532        if ( dst->base ) {
    507533                addQualifiersToType( src, dst->base );
     
    9851011                try {
    9861012                        Declaration * decl = cur->build();
    987                         if ( decl ) {
    988                                 if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    989                                         dwt->location = cur->location;
    990                                         * out++ = dwt;
    991                                 } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    992                                         StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    993                                         auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    994                                         obj->location = cur->location;
    995                                         * out++ = obj;
    996                                         delete agg;
    997                                 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    998                                         UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    999                                         auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
    1000                                         obj->location = cur->location;
    1001                                         * out++ = obj;
    1002                                 } // if
     1013                        assert( decl );
     1014                        if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     1015                                dwt->location = cur->location;
     1016                                * out++ = dwt;
     1017                        } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     1018                                // xxx - this might be where anonymous struct members are added - should be conditional on struct name
     1019                                StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->name );
     1020                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1021                                obj->location = cur->location;
     1022                                * out++ = obj;
     1023                                delete agg;
     1024                        } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     1025                                UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->name );
     1026                                auto obj = new ObjectDecl( "", Type::StorageClasses(), linkage, nullptr, inst, nullptr );
     1027                                obj->location = cur->location;
     1028                                * out++ = obj;
    10031029                        } // if
    10041030                } catch( SemanticErrorException &e ) {
     
    10561082                if ( type->kind != TypeData::Function && funcSpecs.any() ) {
    10571083                        SemanticError( this, "invalid function specifier for " );
    1058                 } // if
    1059                 // Forall qualifier can only appear on a function/aggregate definition/declaration.
    1060                 //
    1061                 //    forall int f();                                   // allowed
    1062                 //    forall int g( int i );                    // allowed
    1063                 //    forall int i;                                             // disallowed
    1064                 if ( type->kind != TypeData::Function && type->forall ) {
    1065                         SemanticError( this, "invalid type qualifier for " );
    10661084                } // if
    10671085                bool isDelete = initializer && initializer->get_isDelete();
Note: See TracChangeset for help on using the changeset viewer.