Changes in / [f04a8b81:621701d]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    rf04a8b81 r621701d  
    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          }
  • src/Parser/ParseNode.h

    rf04a8b81 r621701d  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 21:45:43 2016
    13 // Update Count     : 583
     12// Last Modified On : Sun Aug 28 21:14:51 2016
     13// Update Count     : 575
    1414//
    1515
     
    290290        // bool buildFuncSpecifier( StorageClass key ) const;
    291291
    292         struct Enumeration_t {
    293                 std::string name;
    294                 DeclarationNode * constants;
    295         };
    296         Enumeration_t enumeration;
    297 
    298         struct Variable_t {
    299                 DeclarationNode::TypeClass tyClass;
    300                 std::string name;
    301                 DeclarationNode * assertions;
    302         };
    303         Variable_t variable;
    304 
    305         struct Attr_t {
    306                 std::string name;
    307                 ExpressionNode * expr;
    308                 DeclarationNode * type;
    309         };
    310         Attr_t attr;
    311 
    312         BuiltinType builtin;
    313 
    314292        TypeData *type;
    315293        std::string name;
  • src/Parser/TypeData.cc

    rf04a8b81 r621701d  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 22:31:53 2016
    13 // Update Count     : 277
     12// Last Modified On : Sun Aug 28 18:28:58 2016
     13// Update Count     : 223
    1414//
    1515
     
    3333                break;
    3434          case Basic:
    35                 // basic = new Basic_t;
     35                basic = new Basic_t;
    3636                break;
    3737          case Array:
    38                 // array = new Array_t;
    39                 array.dimension = 0;
    40                 array.isVarLen = false;
    41                 array.isStatic = false;
     38                array = new Array_t;
     39                array->dimension = 0;
     40                array->isVarLen = false;
     41                array->isStatic = false;
    4242                break;
    4343          case Function:
    44                 // function = new Function_t;
    45                 function.params = 0;
    46                 function.idList = 0;
    47                 function.oldDeclList = 0;
    48                 function.body = 0;
    49                 function.hasBody = false;
    50                 function.newStyle = false;
     44                function = new Function_t;
     45                function->params = 0;
     46                function->idList = 0;
     47                function->oldDeclList = 0;
     48                function->body = 0;
     49                function->hasBody = false;
     50                function->newStyle = false;
    5151                break;
    5252          case Aggregate:
    53                 // aggregate = new Aggregate_t;
    54                 aggregate.params = 0;
    55                 aggregate.actuals = 0;
    56                 aggregate.fields = 0;
     53                aggregate = new Aggregate_t;
     54                aggregate->params = 0;
     55                aggregate->actuals = 0;
     56                aggregate->fields = 0;
    5757                break;
    5858          case AggregateInst:
    59                 // aggInst = new AggInst_t;
    60                 aggInst.aggregate = 0;
    61                 aggInst.params = 0;
     59                aggInst = new AggInst_t;
     60                aggInst->aggregate = 0;
     61                aggInst->params = 0;
    6262                break;
    6363          case Enum:
    64                 // enumeration = new Enumeration_t;
    65                 enumeration.constants = 0;
     64                enumeration = new Enumeration_t;
     65                enumeration->constants = 0;
    6666                break;
    6767          case Symbolic:
    6868          case SymbolicInst:
    69                 // symbolic = new Symbolic_t;
    70                 symbolic.params = 0;
    71                 symbolic.actuals = 0;
    72                 symbolic.assertions = 0;
     69                symbolic = new Symbolic_t;
     70                symbolic->params = 0;
     71                symbolic->actuals = 0;
     72                symbolic->assertions = 0;
    7373                break;
    7474          case Variable:
    75                 // variable = new Variable_t;
    76                 // variable.tyClass = DeclarationNode::Type;
    77                 // variable.assertions = 0;
     75                variable = new Variable_t;
     76                variable->tyClass = DeclarationNode::Type;
     77                variable->assertions = 0;
    7878                break;
    7979          case Tuple:
    80                 // tuple = new Tuple_t;
    81                 tuple = nullptr;
     80                tuple = new Tuple_t;
     81                tuple->members = 0;
    8282                break;
    8383          case Typeof:
    84                 // typeexpr = new Typeof_t;
    85                 typeexpr = nullptr;
     84                typeexpr = new Typeof_t;
     85                typeexpr->expr = 0;
     86                break;
     87          case Builtin:
     88                builtin = new Builtin_t;
    8689                break;
    8790          case Attr:
    88                 // attr = new Attr_t;
    89                 // attr.expr = nullptr;
    90                 // attr.type = nullptr;
    91                 break;
    92           case Builtin:
    93                 // builtin = new Builtin_t;
     91                attr = new Attr_t;
     92                attr->expr = 0;
     93                attr->type = 0;
    9494                break;
    9595        } // switch
     
    107107                break;
    108108          case Basic:
    109                 // delete basic;
     109                delete basic;
    110110                break;
    111111          case Array:
    112                 delete array.dimension;
    113                 // delete array;
     112                delete array->dimension;
     113                delete array;
    114114                break;
    115115          case Function:
    116                 delete function.params;
    117                 delete function.idList;
    118                 delete function.oldDeclList;
    119                 delete function.body;
    120                 // delete function;
     116                delete function->params;
     117                delete function->idList;
     118                delete function->oldDeclList;
     119                delete function->body;
     120                delete function;
    121121                break;
    122122          case Aggregate:
    123                 delete aggregate.params;
    124                 delete aggregate.actuals;
    125                 delete aggregate.fields;
    126                 // delete aggregate;
     123                delete aggregate->params;
     124                delete aggregate->actuals;
     125                delete aggregate->fields;
     126                delete aggregate;
    127127                break;
    128128          case AggregateInst:
    129                 delete aggInst.aggregate;
    130                 delete aggInst.params;
    131                 // delete aggInst;
     129                delete aggInst->aggregate;
     130                delete aggInst->params;
     131                delete aggInst;
    132132                break;
    133133          case Enum:
    134                 delete enumeration.constants;
    135                 // delete enumeration;
     134                delete enumeration->constants;
     135                delete enumeration;
    136136                break;
    137137          case Symbolic:
    138138          case SymbolicInst:
    139                 delete symbolic.params;
    140                 delete symbolic.actuals;
    141                 delete symbolic.assertions;
    142                 // delete symbolic;
     139                delete symbolic->params;
     140                delete symbolic->actuals;
     141                delete symbolic->assertions;
     142                delete symbolic;
    143143                break;
    144144          case Variable:
    145                 // delete variable.assertions;
    146                 // delete variable;
     145                delete variable->assertions;
     146                delete variable;
    147147                break;
    148148          case Tuple:
    149                 // delete tuple->members;
     149                delete tuple->members;
    150150                delete tuple;
    151151                break;
    152152          case Typeof:
    153                 // delete typeexpr->expr;
     153                delete typeexpr->expr;
    154154                delete typeexpr;
    155155                break;
     156          case Builtin:
     157                delete builtin;
     158                break;
    156159          case Attr:
    157                 // delete attr.expr;
    158                 // delete attr.type;
    159                 // delete attr;
    160                 break;
    161           case Builtin:
    162                 // delete builtin;
     160                delete attr->expr;
     161                delete attr->type;
     162                delete attr;
    163163                break;
    164164        } // switch
     
    178178                break;
    179179          case Basic:
    180                 newtype->basic.typeSpec = basic.typeSpec;
    181                 newtype->basic.modifiers = basic.modifiers;
     180                newtype->basic->typeSpec = basic->typeSpec;
     181                newtype->basic->modifiers = basic->modifiers;
    182182                break;
    183183          case Array:
    184                 newtype->array.dimension = maybeClone( array.dimension );
    185                 newtype->array.isVarLen = array.isVarLen;
    186                 newtype->array.isStatic = array.isStatic;
     184                newtype->array->dimension = maybeClone( array->dimension );
     185                newtype->array->isVarLen = array->isVarLen;
     186                newtype->array->isStatic = array->isStatic;
    187187                break;
    188188          case Function:
    189                 newtype->function.params = maybeClone( function.params );
    190                 newtype->function.idList = maybeClone( function.idList );
    191                 newtype->function.oldDeclList = maybeClone( function.oldDeclList );
    192                 newtype->function.body = maybeClone( function.body );
    193                 newtype->function.hasBody = function.hasBody;
    194                 newtype->function.newStyle = function.newStyle;
     189                newtype->function->params = maybeClone( function->params );
     190                newtype->function->idList = maybeClone( function->idList );
     191                newtype->function->oldDeclList = maybeClone( function->oldDeclList );
     192                newtype->function->body = maybeClone( function->body );
     193                newtype->function->hasBody = function->hasBody;
     194                newtype->function->newStyle = function->newStyle;
    195195                break;
    196196          case Aggregate:
    197                 newtype->aggregate.params = maybeClone( aggregate.params );
    198                 newtype->aggregate.actuals = maybeClone( aggregate.actuals );
    199                 newtype->aggregate.fields = maybeClone( aggregate.fields );
    200                 newtype->aggregate.name = aggregate.name;
    201                 newtype->aggregate.kind = aggregate.kind;
    202                 newtype->aggregate.body = aggregate.body;
     197                newtype->aggregate->params = maybeClone( aggregate->params );
     198                newtype->aggregate->actuals = maybeClone( aggregate->actuals );
     199                newtype->aggregate->fields = maybeClone( aggregate->fields );
     200                newtype->aggregate->name = aggregate->name;
     201                newtype->aggregate->kind = aggregate->kind;
     202                newtype->aggregate->body = aggregate->body;
    203203                break;
    204204          case AggregateInst:
    205                 newtype->aggInst.aggregate = maybeClone( aggInst.aggregate );
    206                 newtype->aggInst.params = maybeClone( aggInst.params );
     205                newtype->aggInst->aggregate = maybeClone( aggInst->aggregate );
     206                newtype->aggInst->params = maybeClone( aggInst->params );
    207207                break;
    208208          case Enum:
    209                 newtype->enumeration.name = enumeration.name;
    210                 newtype->enumeration.constants = maybeClone( enumeration.constants );
     209                newtype->enumeration->name = enumeration->name;
     210                newtype->enumeration->constants = maybeClone( enumeration->constants );
    211211                break;
    212212          case Symbolic:
    213213          case SymbolicInst:
    214                 newtype->symbolic.params = maybeClone( symbolic.params );
    215                 newtype->symbolic.actuals = maybeClone( symbolic.actuals );
    216                 newtype->symbolic.assertions = maybeClone( symbolic.assertions );
    217                 newtype->symbolic.isTypedef = symbolic.isTypedef;
    218                 newtype->symbolic.name = symbolic.name;
     214                newtype->symbolic->params = maybeClone( symbolic->params );
     215                newtype->symbolic->actuals = maybeClone( symbolic->actuals );
     216                newtype->symbolic->assertions = maybeClone( symbolic->assertions );
     217                newtype->symbolic->isTypedef = symbolic->isTypedef;
     218                newtype->symbolic->name = symbolic->name;
    219219                break;
    220220          case Variable:
    221                 assert( false );
    222                 // newtype->variable.assertions = maybeClone( variable.assertions );
    223                 // newtype->variable.name = variable.name;
    224                 // newtype->variable.tyClass = variable.tyClass;
     221                newtype->variable->assertions = maybeClone( variable->assertions );
     222                newtype->variable->name = variable->name;
     223                newtype->variable->tyClass = variable->tyClass;
    225224                break;
    226225          case Tuple:
    227                 newtype->tuple = maybeClone( tuple );
     226                newtype->tuple->members = maybeClone( tuple->members );
    228227                break;
    229228          case Typeof:
    230                 newtype->typeexpr = maybeClone( typeexpr );
     229                newtype->typeexpr->expr = maybeClone( typeexpr->expr );
     230                break;
     231          case Builtin:
     232                newtype->builtin->type = builtin->type;
    231233                break;
    232234          case Attr:
    233                 assert( false );
    234                 // newtype->attr.expr = maybeClone( attr.expr );
    235                 // newtype->attr.type = maybeClone( attr.type );
    236                 break;
    237           case Builtin:
    238                 assert( false );
    239                 // newtype->builtin = builtin;
     235                newtype->attr->expr = maybeClone( attr->expr );
     236                newtype->attr->type = maybeClone( attr->type );
    240237                break;
    241238        } // switch
     
    271268                break;
    272269          case Basic:
    273                 printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os );
    274                 printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os );
     270                printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );
     271                printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );
    275272                break;
    276273          case Array:
    277                 if ( array.isStatic ) {
     274                if ( array->isStatic ) {
    278275                        os << "static ";
    279276                } // if
    280                 if ( array.dimension ) {
     277                if ( array->dimension ) {
    281278                        os << "array of ";
    282                         array.dimension->printOneLine( os, indent );
    283                 } else if ( array.isVarLen ) {
     279                        array->dimension->printOneLine( os, indent );
     280                } else if ( array->isVarLen ) {
    284281                        os << "variable-length array of ";
    285282                } else {
     
    292289          case Function:
    293290                os << "function" << endl;
    294                 if ( function.params ) {
     291                if ( function->params ) {
    295292                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
    296                         function.params->printList( os, indent + 4 );
     293                        function->params->printList( os, indent + 4 );
    297294                } else {
    298295                        os << string( indent + 2, ' ' ) << "with no parameters " << endl;
    299296                } // if
    300                 if ( function.idList ) {
     297                if ( function->idList ) {
    301298                        os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl;
    302                         function.idList->printList( os, indent + 4 );
    303                 } // if
    304                 if ( function.oldDeclList ) {
     299                        function->idList->printList( os, indent + 4 );
     300                } // if
     301                if ( function->oldDeclList ) {
    305302                        os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl;
    306                         function.oldDeclList->printList( os, indent + 4 );
     303                        function->oldDeclList->printList( os, indent + 4 );
    307304                } // if
    308305                os << string( indent + 2, ' ' ) << "returning ";
     
    313310                } // if
    314311                os << endl;
    315                 if ( function.hasBody ) {
     312                if ( function->hasBody ) {
    316313                        os << string( indent + 2, ' ' ) << "with body " << endl;
    317314                } // if
    318                 if ( function.body ) {
    319                         function.body->printList( os, indent + 2 );
     315                if ( function->body ) {
     316                        function->body->printList( os, indent + 2 );
    320317                } // if
    321318                break;
    322319          case Aggregate:
    323                 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl;
    324                 if ( aggregate.params ) {
     320                os << DeclarationNode::aggregateName[ aggregate->kind ] << ' ' << aggregate->name << endl;
     321                if ( aggregate->params ) {
    325322                        os << string( indent + 2, ' ' ) << "with type parameters " << endl;
    326                         aggregate.params->printList( os, indent + 4 );
    327                 } // if
    328                 if ( aggregate.actuals ) {
     323                        aggregate->params->printList( os, indent + 4 );
     324                } // if
     325                if ( aggregate->actuals ) {
    329326                        os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl;
    330                         aggregate.actuals->printList( os, indent + 4 );
    331                 } // if
    332                 if ( aggregate.fields ) {
     327                        aggregate->actuals->printList( os, indent + 4 );
     328                } // if
     329                if ( aggregate->fields ) {
    333330                        os << string( indent + 2, ' ' ) << "with members " << endl;
    334                         aggregate.fields->printList( os, indent + 4 );
    335                 } // if
    336                 if ( aggregate.body ) {
     331                        aggregate->fields->printList( os, indent + 4 );
     332                } // if
     333                if ( aggregate->body ) {
    337334                        os << string( indent + 2, ' ' ) << " with body " << endl;
    338335                } // if
    339336                break;
    340337          case AggregateInst:
    341                 if ( aggInst.aggregate ) {
     338                if ( aggInst->aggregate ) {
    342339                        os << "instance of " ;
    343                         aggInst.aggregate->print( os, indent );
     340                        aggInst->aggregate->print( os, indent );
    344341                } else {
    345342                        os << "instance of an unspecified aggregate ";
    346343                } // if
    347                 if ( aggInst.params ) {
     344                if ( aggInst->params ) {
    348345                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
    349                         aggInst.params->printList( os, indent + 2 );
     346                        aggInst->params->printList( os, indent + 2 );
    350347                } // if
    351348                break;
    352349          case Enum:
    353350                os << "enumeration ";
    354                 if ( enumeration.constants ) {
     351                if ( enumeration->constants ) {
    355352                        os << "with constants" << endl;
    356                         enumeration.constants->printList( os, indent + 2 );
     353                        enumeration->constants->printList( os, indent + 2 );
    357354                } // if
    358355                break;
    359356          case SymbolicInst:
    360                 os << "instance of type " << symbolic.name;
    361                 if ( symbolic.actuals ) {
     357                os << "instance of type " << symbolic->name;
     358                if ( symbolic->actuals ) {
    362359                        os << " with parameters" << endl;
    363                         symbolic.actuals->printList( os, indent + 2 );
     360                        symbolic->actuals->printList( os, indent + 2 );
    364361                } // if
    365362                break;
    366363          case Symbolic:
    367                 if ( symbolic.isTypedef ) {
     364                if ( symbolic->isTypedef ) {
    368365                        os << "typedef definition ";
    369366                } else {
    370367                        os << "type definition ";
    371368                } // if
    372                 if ( symbolic.params ) {
     369                if ( symbolic->params ) {
    373370                        os << endl << string( indent + 2, ' ' ) << "with parameters" << endl;
    374                         symbolic.params->printList( os, indent + 2 );
    375                 } // if
    376                 if ( symbolic.assertions ) {
     371                        symbolic->params->printList( os, indent + 2 );
     372                } // if
     373                if ( symbolic->assertions ) {
    377374                        os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    378                         symbolic.assertions->printList( os, indent + 4 );
     375                        symbolic->assertions->printList( os, indent + 4 );
    379376                        os << string( indent + 2, ' ' );
    380377                } // if
     
    385382                break;
    386383          case Variable:
    387                 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";
    388                 // if ( variable.assertions ) {
    389                 //      os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    390                 //      variable.assertions->printList( os, indent + 4 );
    391                 //      os << string( indent + 2, ' ' );
    392                 // } // if
     384                os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable ";
     385                if ( variable->assertions ) {
     386                        os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
     387                        variable->assertions->printList( os, indent + 4 );
     388                        os << string( indent + 2, ' ' );
     389                } // if
    393390                break;
    394391          case Tuple:
    395392                os << "tuple ";
    396                 if ( tuple ) {
     393                if ( tuple->members ) {
    397394                        os << "with members " << endl;
    398                         tuple->printList( os, indent + 2 );
     395                        tuple->members->printList( os, indent + 2 );
    399396                } // if
    400397                break;
    401398          case Typeof:
    402399                os << "type-of expression ";
    403                 if ( typeexpr ) {
    404                         typeexpr->print( os, indent + 2 );
     400                if ( typeexpr->expr ) {
     401                        typeexpr->expr->print( os, indent + 2 );
    405402                } // if
    406403                break;
    407404          case Attr:
    408                 // os << "attribute type decl " << attr.name << " applied to ";
    409                 // if ( attr.expr ) {
    410                 //      attr.expr->print( os, indent + 2 );
    411                 // } // if
    412                 // if ( attr.type ) {
    413                 //      attr.type->print( os, indent + 2 );
    414                 // } // if
     405                os << "attribute type decl " << attr->name << " applied to ";
     406                if ( attr->expr ) {
     407                        attr->expr->print( os, indent + 2 );
     408                } // if
     409                if ( attr->type ) {
     410                        attr->type->print( os, indent + 2 );
     411                } // if
    415412                break;
    416413          case Builtin:
     
    482479                return new VarArgsType( buildQualifiers( td ) );
    483480          case TypeData::Attr:
    484                 assert( false );
    485481                return buildAttr( td );
    486482          case TypeData::Symbolic:
     
    498494        switch ( td->kind ) {
    499495          case TypeData::Aggregate:
    500                 if ( ! toplevel && td->aggregate.fields ) {
     496                if ( ! toplevel && td->aggregate->fields ) {
    501497                        ret = td->clone();
    502498                } // if
    503499                break;
    504500          case TypeData::Enum:
    505                 if ( ! toplevel && td->enumeration.constants ) {
     501                if ( ! toplevel && td->enumeration->constants ) {
    506502                        ret = td->clone();
    507503                } // if
    508504                break;
    509505          case TypeData::AggregateInst:
    510                 if ( td->aggInst.aggregate ) {
    511                         ret = typeextractAggregate( td->aggInst.aggregate, false );
     506                if ( td->aggInst->aggregate ) {
     507                        ret = typeextractAggregate( td->aggInst->aggregate, false );
    512508                } // if
    513509                break;
     
    539535        BasicType::Kind ret;
    540536
    541         for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) {
     537        for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) {
    542538                if ( ! init ) {
    543539                        init = true;
    544540                        if ( *i == DeclarationNode::Void ) {
    545                                 if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) {
     541                                if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) {
    546542                                        throw SemanticError( "invalid type specifier \"void\" in type: ", td );
    547543                                } else {
     
    615611        } // for
    616612
    617         for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) {
     613        for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) {
    618614                switch ( *i ) {
    619615                  case DeclarationNode::Long:
     
    750746        ArrayType * at;
    751747        if ( td->base ) {
    752                 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array.dimension ),
    753                                                         td->array.isVarLen, td->array.isStatic );
     748                at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ),
     749                                                        td->array->isVarLen, td->array->isStatic );
    754750        } else {
    755751                at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
    756                                                         maybeBuild< Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic );
     752                                                        maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic );
    757753        } // if
    758754        buildForall( td->forall, at->get_forall() );
     
    763759        assert( td->kind == TypeData::Aggregate );
    764760        AggregateDecl * at;
    765         switch ( td->aggregate.kind ) {
     761        switch ( td->aggregate->kind ) {
    766762          case DeclarationNode::Struct:
    767                 at = new StructDecl( td->aggregate.name );
    768                 buildForall( td->aggregate.params, at->get_parameters() );
     763                at = new StructDecl( td->aggregate->name );
     764                buildForall( td->aggregate->params, at->get_parameters() );
    769765                break;
    770766          case DeclarationNode::Union:
    771                 at = new UnionDecl( td->aggregate.name );
    772                 buildForall( td->aggregate.params, at->get_parameters() );
     767                at = new UnionDecl( td->aggregate->name );
     768                buildForall( td->aggregate->params, at->get_parameters() );
    773769                break;
    774770          case DeclarationNode::Trait:
    775                 at = new TraitDecl( td->aggregate.name );
    776                 buildList( td->aggregate.params, at->get_parameters() );
     771                at = new TraitDecl( td->aggregate->name );
     772                buildList( td->aggregate->params, at->get_parameters() );
    777773                break;
    778774          default:
     
    780776        } // switch
    781777
    782         buildList( td->aggregate.fields, at->get_members() );
    783         at->set_body( td->aggregate.body );
     778        buildList( td->aggregate->fields, at->get_members() );
     779        at->set_body( td->aggregate->body );
    784780
    785781        return at;
     
    790786
    791787        ReferenceToType * ret;
    792         if ( td->aggInst.aggregate->kind == TypeData::Enum ) {
    793                 ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name );
     788        if ( td->aggInst->aggregate->kind == TypeData::Enum ) {
     789                ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name );
    794790        } else {
    795                 assert( td->aggInst.aggregate->kind == TypeData::Aggregate );
    796                 switch ( td->aggInst.aggregate->aggregate.kind ) {
     791                assert( td->aggInst->aggregate->kind == TypeData::Aggregate );
     792                switch ( td->aggInst->aggregate->aggregate->kind ) {
    797793                  case DeclarationNode::Struct:
    798                         ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
     794                        ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
    799795                        break;
    800796                  case DeclarationNode::Union:
    801                         ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
     797                        ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
    802798                        break;
    803799                  case DeclarationNode::Trait:
    804                         ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
     800                        ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
    805801                        break;
    806802                  default:
     
    808804                } // switch
    809805        } // if
    810         buildList( td->aggInst.params, ret->get_parameters() );
     806        buildList( td->aggInst->params, ret->get_parameters() );
    811807        buildForall( td->forall, ret->get_forall() );
    812808        return ret;
     
    817813        NamedTypeDecl * ret;
    818814        assert( td->base );
    819         if ( td->symbolic.isTypedef ) {
     815        if ( td->symbolic->isTypedef ) {
    820816                ret = new TypedefDecl( name, sc, typebuild( td->base ) );
    821817        } else {
    822818                ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any );
    823819        } // if
    824         buildList( td->symbolic.params, ret->get_parameters() );
    825         buildList( td->symbolic.assertions, ret->get_assertions() );
     820        buildList( td->symbolic->params, ret->get_parameters() );
     821        buildList( td->symbolic->assertions, ret->get_assertions() );
    826822        return ret;
    827823} // buildSymbolic
    828824
    829825TypeDecl * buildVariable( const TypeData * td ) {
    830         assert( false );
    831         return nullptr;
    832         // assert( td->kind == TypeData::Variable );
    833         // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    834 
    835         // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );
    836         // buildList( td->variable.assertions, ret->get_assertions() );
    837         // return ret;
     826        assert( td->kind == TypeData::Variable );
     827        static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     828
     829        TypeDecl * ret = new TypeDecl( td->variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable->tyClass ] );
     830        buildList( td->variable->assertions, ret->get_assertions() );
     831        return ret;
    838832} // buildSymbolic
    839833
    840834EnumDecl * buildEnum( const TypeData * td ) {
    841835        assert( td->kind == TypeData::Enum );
    842         EnumDecl * ret = new EnumDecl( td->enumeration.name );
    843         buildList( td->enumeration.constants, ret->get_members() );
     836        EnumDecl * ret = new EnumDecl( td->enumeration->name );
     837        buildList( td->enumeration->constants, ret->get_members() );
    844838        std::list< Declaration * >::iterator members = ret->get_members().begin();
    845         for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     839        for ( const DeclarationNode * cur = td->enumeration-> constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    846840                if ( cur->has_enumeratorValue() ) {
    847841                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
     
    854848TypeInstType * buildSymbolicInst( const TypeData * td ) {
    855849        assert( td->kind == TypeData::SymbolicInst );
    856         TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false );
    857         buildList( td->symbolic.actuals, ret->get_parameters() );
     850        TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false );
     851        buildList( td->symbolic->actuals, ret->get_parameters() );
    858852        buildForall( td->forall, ret->get_forall() );
    859853        return ret;
     
    863857        assert( td->kind == TypeData::Tuple );
    864858        TupleType * ret = new TupleType( buildQualifiers( td ) );
    865         buildTypeList( td->tuple, ret->get_types() );
     859        buildTypeList( td->tuple->members, ret->get_types() );
    866860        buildForall( td->forall, ret->get_forall() );
    867861        return ret;
     
    871865        assert( td->kind == TypeData::Typeof );
    872866        assert( td->typeexpr );
    873         // assert( td->typeexpr->expr );
    874         return new TypeofType( buildQualifiers( td ), td->typeexpr->build() );
     867        assert( td->typeexpr->expr );
     868        return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() );
    875869} // buildTypeof
    876870
    877871AttrType * buildAttr( const TypeData * td ) {
    878         assert( false );
    879         return nullptr;
    880         // assert( td->kind == TypeData::Attr );
    881         // // assert( td->attr );
    882         // AttrType * ret;
    883         // if ( td->attr.expr ) {
    884         //      ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() );
    885         // } else {
    886         //      assert( td->attr.type );
    887         //      ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() );
    888         // } // if
    889         // return ret;
     872        assert( td->kind == TypeData::Attr );
     873        assert( td->attr );
     874        AttrType * ret;
     875        if ( td->attr->expr ) {
     876                ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->expr->build() );
     877        } else {
     878                assert( td->attr->type );
     879                ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->type->buildType() );
     880        } // if
     881        return ret;
    890882} // buildAttr
    891883
     
    893885        if ( td->kind == TypeData::Function ) {
    894886                FunctionDecl * decl;
    895                 if ( td->function.hasBody ) {
    896                         if ( td->function.body ) {
    897                                 Statement * stmt = td->function.body->build();
     887                if ( td->function->hasBody ) {
     888                        if ( td->function->body ) {
     889                                Statement * stmt = td->function->body->build();
    898890                                CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt );
    899891                                assert( body );
     
    906898                        decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );
    907899                } // if
    908                 for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
     900                for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
    909901                        if ( cur->get_name() != "" ) {
    910902                                decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
    911903                        } // if
    912904                } // for
    913                 buildList( td->function.oldDeclList, decl->get_oldDecls() );
     905                buildList( td->function->oldDeclList, decl->get_oldDecls() );
    914906                return decl;
    915907        } else if ( td->kind == TypeData::Aggregate ) {
     
    920912                return buildSymbolic( td, name, sc );
    921913        } else if ( td->kind == TypeData::Variable ) {
    922                 assert( false );
    923914                return buildVariable( td );
    924915        } else {
     
    930921FunctionType * buildFunction( const TypeData * td ) {
    931922        assert( td->kind == TypeData::Function );
    932         bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true;
    933         if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle;
     923        bool hasEllipsis = td->function->params ? td->function->params->get_hasEllipsis() : true;
     924        if ( ! td->function->params ) hasEllipsis = ! td->function->newStyle;
    934925        FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis );
    935         buildList( td->function.params, ft->get_parameters() );
     926        buildList( td->function->params, ft->get_parameters() );
    936927        buildForall( td->forall, ft->get_forall() );
    937928        if ( td->base ) {
    938929                switch ( td->base->kind ) {
    939930                  case TypeData::Tuple:
    940                         buildList( td->base->tuple, ft->get_returnVals() );
     931                        buildList( td->base->tuple->members, ft->get_returnVals() );
    941932                        break;
    942933                  default:
  • src/Parser/TypeData.h

    rf04a8b81 r621701d  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 22:31:52 2016
    13 // Update Count     : 110
     12// Last Modified On : Sun Aug 28 22:39:00 2016
     13// Update Count     : 85
    1414//
    1515
     
    2424struct TypeData {
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    26                                 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr };
     26                                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;
    2727
    2828        struct Basic_t {
     
    7373        };
    7474
    75         // struct Tuple_t {
    76         //      DeclarationNode * members;
    77         // };
     75        struct Variable_t {
     76                DeclarationNode::TypeClass tyClass;
     77                std::string name;
     78                DeclarationNode * assertions;
     79        };
     80
     81        struct Tuple_t {
     82                DeclarationNode * members;
     83        };
    7884 
    79         // struct Typeof_t {
    80         //      ExpressionNode * expr;
    81         // };
     85        struct Typeof_t {
     86                ExpressionNode * expr;
     87        };
    8288
    83         // struct Builtin_t {
    84         //      DeclarationNode::BuiltinType type;
    85         // };
     89        struct Builtin_t {
     90                DeclarationNode::BuiltinType type;
     91        };
    8692
    87         Kind kind;
     93        struct Attr_t {
     94                std::string name;
     95                ExpressionNode * expr;
     96                DeclarationNode * type;
     97        };
     98
    8899        TypeData * base;
    89100        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
     
    91102        DeclarationNode * forall;
    92103
    93                 Basic_t basic;
    94                 Aggregate_t aggregate;
    95                 AggInst_t aggInst;
    96                 Array_t array;
    97                 Enumeration_t enumeration;
    98                 Function_t function;
    99                 Symbolic_t symbolic;
    100                 DeclarationNode * tuple;
    101                 ExpressionNode * typeexpr;
    102                 //Attr_t attr;
    103                 // DeclarationNode::BuiltinType builtin;
     104        union {
     105                Basic_t * basic;
     106                Aggregate_t * aggregate;
     107                AggInst_t * aggInst;
     108                Array_t * array;
     109                Enumeration_t * enumeration;
     110                Function_t * function;
     111                Symbolic_t * symbolic;
     112                Variable_t * variable;
     113                Tuple_t * tuple;
     114                Typeof_t * typeexpr;
     115                Attr_t * attr;
     116                Builtin_t * builtin;
     117        };
    104118
    105119        TypeData( Kind k = Unknown );
  • src/main.cc

    rf04a8b81 r621701d  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 17:34:39 2016
    13 // Update Count     : 426
     12// Last Modified On : Sat Aug 20 12:52:22 2016
     13// Update Count     : 403
    1414//
    1515
     
    7575static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    7676
    77 void backtrace( int start ) {                                                   // skip first N stack frames
     77void sigSegvBusHandler( int sig_num ) {
    7878        enum { Frames = 50 };
    7979        void * array[Frames];
    8080        int size = backtrace( array, Frames );
     81
     82        cerr << "*CFA runtime error* program cfa-cpp terminated with "
     83                 <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
     84                 << " backtrace:" << endl;
     85
    8186        char ** messages = backtrace_symbols( array, size );
    8287
    83         // skip last 2 stack frames after main
    84         for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
     88        // skip first stack frame (points here)
     89        for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) {
    8590                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    8691                for ( char *p = messages[i]; *p; ++p ) {        // find parantheses and +offset
     
    96101
    97102                // if line contains symbol, attempt to demangle
    98                 int frameNo = i - start;
    99103                if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
    100104                        *mangled_name++ = '\0';
     
    102106                        *offset_end++ = '\0';
    103107
    104                         int status, frameNo = i - start;
     108                        int status;
    105109                        char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
    106110                        if ( status == 0 ) {                                            // demangling successful ?
    107                                 cerr << "(" << frameNo << ") " << messages[i] << " : "
     111                                cerr << "(" << i - 2 << ") " << messages[i] << " : "
    108112                                         << real_name << "+" << offset_begin << offset_end << endl;
    109113
    110114                        } else {                                                                        // otherwise, output mangled name
    111                                 cerr << "(" << frameNo << ") " << messages[i] << " : "
     115                                cerr << "(" << i - 2 << ") " << messages[i] << " : "
    112116                                         << mangled_name << "+" << offset_begin << offset_end << endl;
    113117                        } // if
    114118                        free( real_name );
    115119                } else {                                                                                // otherwise, print the whole line
    116                         cerr << "(" << frameNo << ") " << messages[i] << endl;
     120                        cerr << "(" << i - 2 << ") " << messages[i] << endl;
    117121                } // if
    118122        } // for
    119 
    120123        free( messages );
    121 } // backtrace
    122 
    123 void sigSegvBusHandler( int sig_num ) {
    124         cerr << "*CFA runtime error* program cfa-cpp terminated with "
    125                  <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
    126                  << " backtrace:" << endl;
    127         backtrace( 2 );                                                                         // skip first 2 stack frames
    128124        exit( EXIT_FAILURE );
    129125} // sigSegvBusHandler
    130 
    131 void sigAbortHandler( int sig_num ) {
    132         backtrace( 6 );                                                                         // skip first 6 stack frames
    133         signal( SIGABRT, SIG_DFL);                                                      // reset default signal handler
    134     raise( SIGABRT );                                                                   // reraise SIGABRT
    135 } // sigAbortHandler
    136 
    137126
    138127int main( int argc, char * argv[] ) {
     
    144133        signal( SIGSEGV, sigSegvBusHandler );
    145134        signal( SIGBUS, sigSegvBusHandler );
    146         signal( SIGABRT, sigAbortHandler );
    147135
    148136        parse_cmdline( argc, argv, filename );                          // process command-line arguments
Note: See TracChangeset for help on using the changeset viewer.