Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r28307be r413ad05  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 22:30:56 2016
    13 // Update Count     : 327
     12// Last Modified On : Sun Aug 28 22:12:44 2016
     13// Update Count     : 278
    1414//
    1515
     
    4242
    4343extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
    44 
    45 DeclarationNode::DeclarationNode()
    46                 : type( 0 )
    47                 , storageClass( NoStorageClass )
    48                 , isInline( false )
    49                 , isNoreturn( false )
    50                 , bitfieldWidth( 0 )
    51                 , initializer( 0 )
    52                 , hasEllipsis( false )
    53                 , linkage( ::linkage )
    54                 , extension( false )
    55                 , error() {
    56         attr.expr = nullptr;
    57         attr.type = nullptr;
    58 
    59         variable.tyClass = DeclarationNode::Type;
    60         variable.assertions = nullptr;
    61 }
    62 
    63 DeclarationNode::~DeclarationNode() {
    64         delete attr.expr;
    65         delete attr.type;
    66         delete type;
    67         delete bitfieldWidth;
    68         delete initializer;
    69 }
    7044
    7145DeclarationNode *DeclarationNode::clone() const {
     
    8155        newnode->set_next( maybeClone( get_next() ) );
    8256        newnode->linkage = linkage;
    83 
    84         newnode->variable.assertions = maybeClone( variable.assertions );
    85         newnode->variable.name = variable.name;
    86         newnode->variable.tyClass = variable.tyClass;
    87 
    88         newnode->attr.expr = maybeClone( attr.expr );
    89         newnode->attr.type = maybeClone( attr.type );
    9057        return newnode;
    9158} // DeclarationNode::clone
     59
     60DeclarationNode::DeclarationNode()
     61        : type( 0 )
     62        , storageClass( NoStorageClass )
     63        , isInline( false )
     64        , isNoreturn( false )
     65        , bitfieldWidth( 0 )
     66        , initializer( 0 )
     67        , hasEllipsis( false )
     68        , linkage( ::linkage )
     69        , extension( false )
     70        , error() {
     71}
     72
     73DeclarationNode::~DeclarationNode() {
     74        delete type;
     75        delete bitfieldWidth;
     76        delete initializer;
     77}
    9278
    9379bool DeclarationNode::get_hasEllipsis() const {
     
    143129
    144130        newnode->type = new TypeData( TypeData::Function );
    145         newnode->type->function.params = param;
    146         newnode->type->function.newStyle = newStyle;
    147         newnode->type->function.body = body;
     131        newnode->type->function->params = param;
     132        newnode->type->function->newStyle = newStyle;
     133        newnode->type->function->body = body;
    148134        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    149135
    150136        if ( body ) {
    151                 newnode->type->function.hasBody = true;
     137                newnode->type->function->hasBody = true;
    152138        } // if
    153139
     
    189175        DeclarationNode *newnode = new DeclarationNode;
    190176        newnode->type = new TypeData( TypeData::Basic );
    191         newnode->type->basic.typeSpec.push_back( bt );
     177        newnode->type->basic->typeSpec.push_back( bt );
    192178        return newnode;
    193179} // DeclarationNode::newBasicType
     
    196182        DeclarationNode *newnode = new DeclarationNode;
    197183        newnode->type = new TypeData( TypeData::Basic );
    198         newnode->type->basic.modifiers.push_back( mod );
     184        newnode->type->basic->modifiers.push_back( mod );
    199185        return newnode;
    200186} // DeclarationNode::newModifier
    201187
     188DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
     189        DeclarationNode *newnode = new DeclarationNode;
     190        newnode->type = new TypeData( TypeData::Builtin );
     191        newnode->type->builtin->type = bt;
     192        return newnode;
     193} // DeclarationNode::newBuiltinType
     194
    202195DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
    203196        DeclarationNode *newnode = new DeclarationNode;
    204197        newnode->type = new TypeData( TypeData::SymbolicInst );
    205         newnode->type->symbolic.name = assign_strptr( name );
    206         newnode->type->symbolic.isTypedef = true;
    207         newnode->type->symbolic.params = 0;
     198        newnode->type->symbolic->name = assign_strptr( name );
     199        newnode->type->symbolic->isTypedef = true;
     200        newnode->type->symbolic->params = 0;
    208201        return newnode;
    209202} // DeclarationNode::newFromTypedef
     
    212205        DeclarationNode *newnode = new DeclarationNode;
    213206        newnode->type = new TypeData( TypeData::Aggregate );
    214         newnode->type->aggregate.kind = kind;
    215         newnode->type->aggregate.name = assign_strptr( name );
    216         if ( newnode->type->aggregate.name == "" ) {            // anonymous aggregate ?
    217                 newnode->type->aggregate.name = anonymous.newName();
    218         } // if
    219         newnode->type->aggregate.actuals = actuals;
    220         newnode->type->aggregate.fields = fields;
    221         newnode->type->aggregate.body = body;
     207        newnode->type->aggregate->kind = kind;
     208        newnode->type->aggregate->name = assign_strptr( name );
     209        if ( newnode->type->aggregate->name == "" ) {           // anonymous aggregate ?
     210                newnode->type->aggregate->name = anonymous.newName();
     211        } // if
     212        newnode->type->aggregate->actuals = actuals;
     213        newnode->type->aggregate->fields = fields;
     214        newnode->type->aggregate->body = body;
    222215        return newnode;
    223216} // DeclarationNode::newAggregate
     
    227220        newnode->name = assign_strptr( name );
    228221        newnode->type = new TypeData( TypeData::Enum );
    229         newnode->type->enumeration.name = newnode->name;
    230         if ( newnode->type->enumeration.name == "" ) {          // anonymous enumeration ?
    231                 newnode->type->enumeration.name = DeclarationNode::anonymous.newName();
    232         } // if
    233         newnode->type->enumeration.constants = constants;
     222        newnode->type->enumeration->name = newnode->name;
     223        if ( newnode->type->enumeration->name == "" ) {         // anonymous enumeration ?
     224                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
     225        } // if
     226        newnode->type->enumeration->constants = constants;
    234227        return newnode;
    235228} // DeclarationNode::newEnum
     
    252245        DeclarationNode *newnode = new DeclarationNode;
    253246        newnode->type = new TypeData( TypeData::SymbolicInst );
    254         newnode->type->symbolic.name = assign_strptr( name );
    255         newnode->type->symbolic.isTypedef = false;
    256         newnode->type->symbolic.actuals = params;
     247        newnode->type->symbolic->name = assign_strptr( name );
     248        newnode->type->symbolic->isTypedef = false;
     249        newnode->type->symbolic->actuals = params;
    257250        return newnode;
    258251} // DeclarationNode::newFromTypeGen
     
    262255        newnode->name = assign_strptr( name );
    263256        newnode->type = new TypeData( TypeData::Variable );
    264         newnode->variable.tyClass = tc;
    265         newnode->variable.name = newnode->name;
     257        newnode->type->variable->tyClass = tc;
     258        newnode->type->variable->name = newnode->name;
    266259        return newnode;
    267260} // DeclarationNode::newTypeParam
     
    270263        DeclarationNode *newnode = new DeclarationNode;
    271264        newnode->type = new TypeData( TypeData::Aggregate );
    272         newnode->type->aggregate.kind = Trait;
    273         newnode->type->aggregate.params = params;
    274         newnode->type->aggregate.fields = asserts;
    275         newnode->type->aggregate.name = assign_strptr( name );
     265        newnode->type->aggregate->kind = Trait;
     266        newnode->type->aggregate->params = params;
     267        newnode->type->aggregate->fields = asserts;
     268        newnode->type->aggregate->name = assign_strptr( name );
    276269        return newnode;
    277270} // DeclarationNode::newTrait
     
    280273        DeclarationNode *newnode = new DeclarationNode;
    281274        newnode->type = new TypeData( TypeData::AggregateInst );
    282         newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    283         newnode->type->aggInst.aggregate->aggregate.kind = Trait;
    284         newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );
    285         newnode->type->aggInst.params = params;
     275        newnode->type->aggInst->aggregate = new TypeData( TypeData::Aggregate );
     276        newnode->type->aggInst->aggregate->aggregate->kind = Trait;
     277        newnode->type->aggInst->aggregate->aggregate->name = assign_strptr( name );
     278        newnode->type->aggInst->params = params;
    286279        return newnode;
    287280} // DeclarationNode::newTraitUse
     
    291284        newnode->name = assign_strptr( name );
    292285        newnode->type = new TypeData( TypeData::Symbolic );
    293         newnode->type->symbolic.isTypedef = false;
    294         newnode->type->symbolic.params = typeParams;
    295         newnode->type->symbolic.name = newnode->name;
     286        newnode->type->symbolic->isTypedef = false;
     287        newnode->type->symbolic->params = typeParams;
     288        newnode->type->symbolic->name = newnode->name;
    296289        return newnode;
    297290} // DeclarationNode::newTypeDecl
     
    306299        DeclarationNode *newnode = new DeclarationNode;
    307300        newnode->type = new TypeData( TypeData::Array );
    308         newnode->type->array.dimension = size;
    309         newnode->type->array.isStatic = isStatic;
    310         if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) {
    311                 newnode->type->array.isVarLen = false;
     301        newnode->type->array->dimension = size;
     302        newnode->type->array->isStatic = isStatic;
     303        if ( newnode->type->array->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) {
     304                newnode->type->array->isVarLen = false;
    312305        } else {
    313                 newnode->type->array.isVarLen = true;
     306                newnode->type->array->isVarLen = true;
    314307        } // if
    315308        return newnode->addQualifiers( qualifiers );
     
    319312        DeclarationNode *newnode = new DeclarationNode;
    320313        newnode->type = new TypeData( TypeData::Array );
    321         newnode->type->array.dimension = 0;
    322         newnode->type->array.isStatic = false;
    323         newnode->type->array.isVarLen = true;
     314        newnode->type->array->dimension = 0;
     315        newnode->type->array->isStatic = false;
     316        newnode->type->array->isVarLen = true;
    324317        return newnode->addQualifiers( qualifiers );
    325318}
     
    334327        DeclarationNode *newnode = new DeclarationNode;
    335328        newnode->type = new TypeData( TypeData::Tuple );
    336         newnode->type->tuple = members;
     329        newnode->type->tuple->members = members;
    337330        return newnode;
    338331}
     
    341334        DeclarationNode *newnode = new DeclarationNode;
    342335        newnode->type = new TypeData( TypeData::Typeof );
    343         newnode->type->typeexpr = expr;
    344         return newnode;
    345 }
    346 
    347 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
    348         DeclarationNode *newnode = new DeclarationNode;
    349         newnode->type = new TypeData( TypeData::Builtin );
    350         newnode->builtin = bt;
    351         return newnode;
    352 } // DeclarationNode::newBuiltinType
     336        newnode->type->typeexpr->expr = expr;
     337        return newnode;
     338}
    353339
    354340DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {
    355341        DeclarationNode *newnode = new DeclarationNode;
    356342        newnode->type = new TypeData( TypeData::Attr );
    357         newnode->attr.name = assign_strptr( name );
    358         newnode->attr.expr = expr;
     343        newnode->type->attr->name = assign_strptr( name );
     344        newnode->type->attr->expr = expr;
    359345        return newnode;
    360346}
     
    363349        DeclarationNode *newnode = new DeclarationNode;
    364350        newnode->type = new TypeData( TypeData::Attr );
    365         newnode->attr.name = assign_strptr( name );
    366         newnode->attr.type = type;
     351        newnode->type->attr->name = assign_strptr( name );
     352        newnode->type->attr->type = type;
    367353        return newnode;
    368354}
     
    421407                                } else {
    422408                                        if ( type->kind == TypeData::Aggregate ) {
    423                                                 type->aggregate.params = q->type->forall;
     409                                                type->aggregate->params = q->type->forall;
    424410                                                // change implicit typedef from TYPEDEFname to TYPEGENname
    425                                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
     411                                                typedefTable.changeKind( type->aggregate->name, TypedefTable::TG );
    426412                                        } else {
    427413                                                type->forall = q->type->forall;
     
    471457                                if ( src->kind != TypeData::Unknown ) {
    472458                                        assert( src->kind == TypeData::Basic );
    473                                         dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
    474                                         dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
     459                                        dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers );
     460                                        dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec );
    475461                                } // if
    476462                                break;
     
    480466                                  case TypeData::Enum:
    481467                                        dst->base = new TypeData( TypeData::AggregateInst );
    482                                         dst->base->aggInst.aggregate = src;
     468                                        dst->base->aggInst->aggregate = src;
    483469                                        if ( src->kind == TypeData::Aggregate ) {
    484                                                 dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
     470                                                dst->base->aggInst->params = maybeClone( src->aggregate->actuals );
    485471                                        } // if
    486472                                        dst->base->qualifiers |= src->qualifiers;
     
    509495                                if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
    510496                                        type = new TypeData( TypeData::AggregateInst );
    511                                         type->aggInst.aggregate = o->type;
     497                                        type->aggInst->aggregate = o->type;
    512498                                        if ( o->type->kind == TypeData::Aggregate ) {
    513                                                 type->aggInst.params = maybeClone( o->type->aggregate.actuals );
     499                                                type->aggInst->params = maybeClone( o->type->aggregate->actuals );
    514500                                        } // if
    515501                                        type->qualifiers |= o->type->qualifiers;
     
    537523DeclarationNode *DeclarationNode::addTypedef() {
    538524        TypeData *newtype = new TypeData( TypeData::Symbolic );
    539         newtype->symbolic.params = 0;
    540         newtype->symbolic.isTypedef = true;
    541         newtype->symbolic.name = name;
     525        newtype->symbolic->params = 0;
     526        newtype->symbolic->isTypedef = true;
     527        newtype->symbolic->name = name;
    542528        newtype->base = type;
    543529        type = newtype;
     
    549535        switch ( type->kind ) {
    550536          case TypeData::Symbolic:
    551                 if ( type->symbolic.assertions ) {
    552                         type->symbolic.assertions->appendList( assertions );
     537                if ( type->symbolic->assertions ) {
     538                        type->symbolic->assertions->appendList( assertions );
    553539                } else {
    554                         type->symbolic.assertions = assertions;
     540                        type->symbolic->assertions = assertions;
    555541                } // if
    556542                break;
    557543          case TypeData::Variable:
    558                 if ( variable.assertions ) {
    559                         variable.assertions->appendList( assertions );
     544                if ( type->variable->assertions ) {
     545                        type->variable->assertions->appendList( assertions );
    560546                } else {
    561                         variable.assertions = assertions;
     547                        type->variable->assertions = assertions;
    562548                } // if
    563549                break;
     
    588574        assert( type );
    589575        assert( type->kind == TypeData::Function );
    590         assert( type->function.body == 0 );
    591         type->function.body = body;
    592         type->function.hasBody = true;
     576        assert( type->function->body == 0 );
     577        type->function->body = body;
     578        type->function->hasBody = true;
    593579        return this;
    594580}
     
    597583        assert( type );
    598584        assert( type->kind == TypeData::Function );
    599         assert( type->function.oldDeclList == 0 );
    600         type->function.oldDeclList = list;
     585        assert( type->function->oldDeclList == 0 );
     586        type->function->oldDeclList = list;
    601587        return this;
    602588}
     
    644630                          case TypeData::Enum:
    645631                                p->type->base = new TypeData( TypeData::AggregateInst );
    646                                 p->type->base->aggInst.aggregate = type;
     632                                p->type->base->aggInst->aggregate = type;
    647633                                if ( type->kind == TypeData::Aggregate ) {
    648                                         p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
     634                                        p->type->base->aggInst->params = maybeClone( type->aggregate->actuals );
    649635                                } // if
    650636                                p->type->base->qualifiers |= type->qualifiers;
     
    681667                          case TypeData::Enum:
    682668                                lastArray->base = new TypeData( TypeData::AggregateInst );
    683                                 lastArray->base->aggInst.aggregate = type;
     669                                lastArray->base->aggInst->aggregate = type;
    684670                                if ( type->kind == TypeData::Aggregate ) {
    685                                         lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
     671                                        lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals );
    686672                                } // if
    687673                                lastArray->base->qualifiers |= type->qualifiers;
     
    701687DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) {
    702688        TypeData *ftype = new TypeData( TypeData::Function );
    703         ftype->function.params = params;
     689        ftype->function->params = params;
    704690        setBase( type, ftype );
    705691        return this;
     
    711697                        type->base = addIdListToType( type->base, ids );
    712698                } else {
    713                         type->function.idList = ids;
     699                        type->function->idList = ids;
    714700                } // if
    715701                return type;
    716702        } else {
    717703                TypeData *newtype = new TypeData( TypeData::Function );
    718                 newtype->function.idList = ids;
     704                newtype->function->idList = ids;
    719705                return newtype;
    720706        } // if
     
    741727        if ( newnode->type->kind == TypeData::AggregateInst ) {
    742728                // don't duplicate members
    743                 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) {
    744                         delete newnode->type->aggInst.aggregate->enumeration.constants;
    745                         newnode->type->aggInst.aggregate->enumeration.constants = 0;
     729                if ( newnode->type->aggInst->aggregate->kind == TypeData::Enum ) {
     730                        delete newnode->type->aggInst->aggregate->enumeration->constants;
     731                        newnode->type->aggInst->aggregate->enumeration->constants = 0;
    746732                } else {
    747                         assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate );
    748                         delete newnode->type->aggInst.aggregate->aggregate.fields;
    749                         newnode->type->aggInst.aggregate->aggregate.fields = 0;
     733                        assert( newnode->type->aggInst->aggregate->kind == TypeData::Aggregate );
     734                        delete newnode->type->aggInst->aggregate->aggregate->fields;
     735                        newnode->type->aggInst->aggregate->aggregate->fields = 0;
    750736                } // if
    751737        } // if
     
    767753                        if ( newType->kind == TypeData::AggregateInst ) {
    768754                                // don't duplicate members
    769                                 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
    770                                         delete newType->aggInst.aggregate->enumeration.constants;
    771                                         newType->aggInst.aggregate->enumeration.constants = 0;
     755                                if ( newType->aggInst->aggregate->kind == TypeData::Enum ) {
     756                                        delete newType->aggInst->aggregate->enumeration->constants;
     757                                        newType->aggInst->aggregate->enumeration->constants = 0;
    772758                                } else {
    773                                         assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
    774                                         delete newType->aggInst.aggregate->aggregate.fields;
    775                                         newType->aggInst.aggregate->aggregate.fields = 0;
     759                                        assert( newType->aggInst->aggregate->kind == TypeData::Aggregate );
     760                                        delete newType->aggInst->aggregate->aggregate->fields;
     761                                        newType->aggInst->aggregate->aggregate->fields = 0;
    776762                                } // if
    777763                        } // if
     
    910896        if ( ! error.empty() ) throw SemanticError( error, this );
    911897        if ( type ) {
    912                 if ( type->kind == TypeData::Variable ) {
    913                         static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    914                         TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] );
    915                         buildList( variable.assertions, ret->get_assertions() );
    916                         return ret;
    917                 } else {
    918                         return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    919                 } // if
     898                return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    920899        } // if
    921900        if ( ! isInline && ! isNoreturn ) {
     
    930909        switch ( type->kind ) {
    931910          case TypeData::Enum:
    932                 return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
     911                return new EnumInstType( buildQualifiers( type ), type->enumeration->name );
    933912          case TypeData::Aggregate: {
    934913                  ReferenceToType *ret;
    935                   switch ( type->aggregate.kind ) {
     914                  switch ( type->aggregate->kind ) {
    936915                        case DeclarationNode::Struct:
    937                           ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );
     916                          ret = new StructInstType( buildQualifiers( type ), type->aggregate->name );
    938917                          break;
    939918                        case DeclarationNode::Union:
    940                           ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );
     919                          ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name );
    941920                          break;
    942921                        case DeclarationNode::Trait:
    943                           ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );
     922                          ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name );
    944923                          break;
    945924                        default:
    946925                          assert( false );
    947926                  } // switch
    948                   buildList( type->aggregate.actuals, ret->get_parameters() );
     927                  buildList( type->aggregate->actuals, ret->get_parameters() );
    949928                  return ret;
    950929          }
    951930          case TypeData::Symbolic: {
    952                   TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );
    953                   buildList( type->symbolic.actuals, ret->get_parameters() );
    954                   return ret;
    955           }
    956           case TypeData::Attr: {
    957                   assert( type->kind == TypeData::Attr );
    958                   // assert( type->attr );
    959                   AttrType * ret;
    960                   if ( attr.expr ) {
    961                           ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );
    962                   } else {
    963                           assert( attr.type );
    964                           ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );
    965                   } // if
     931                  TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false );
     932                  buildList( type->symbolic->actuals, ret->get_parameters() );
    966933                  return ret;
    967934          }
Note: See TracChangeset for help on using the changeset viewer.