Changes in / [621701d:f04a8b81]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r621701d rf04a8b81  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 22:12:44 2016
    13 // Update Count     : 278
     12// Last Modified On : Mon Aug 29 22:30:56 2016
     13// Update Count     : 327
    1414//
    1515
     
    4242
    4343extern LinkageSpec::Spec linkage;                                               // defined in parser.yy
     44
     45DeclarationNode::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
     63DeclarationNode::~DeclarationNode() {
     64        delete attr.expr;
     65        delete attr.type;
     66        delete type;
     67        delete bitfieldWidth;
     68        delete initializer;
     69}
    4470
    4571DeclarationNode *DeclarationNode::clone() const {
     
    5581        newnode->set_next( maybeClone( get_next() ) );
    5682        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 );
    5790        return newnode;
    5891} // DeclarationNode::clone
    59 
    60 DeclarationNode::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 
    73 DeclarationNode::~DeclarationNode() {
    74         delete type;
    75         delete bitfieldWidth;
    76         delete initializer;
    77 }
    7892
    7993bool DeclarationNode::get_hasEllipsis() const {
     
    129143
    130144        newnode->type = new TypeData( TypeData::Function );
    131         newnode->type->function->params = param;
    132         newnode->type->function->newStyle = newStyle;
    133         newnode->type->function->body = body;
     145        newnode->type->function.params = param;
     146        newnode->type->function.newStyle = newStyle;
     147        newnode->type->function.body = body;
    134148        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    135149
    136150        if ( body ) {
    137                 newnode->type->function->hasBody = true;
     151                newnode->type->function.hasBody = true;
    138152        } // if
    139153
     
    175189        DeclarationNode *newnode = new DeclarationNode;
    176190        newnode->type = new TypeData( TypeData::Basic );
    177         newnode->type->basic->typeSpec.push_back( bt );
     191        newnode->type->basic.typeSpec.push_back( bt );
    178192        return newnode;
    179193} // DeclarationNode::newBasicType
     
    182196        DeclarationNode *newnode = new DeclarationNode;
    183197        newnode->type = new TypeData( TypeData::Basic );
    184         newnode->type->basic->modifiers.push_back( mod );
     198        newnode->type->basic.modifiers.push_back( mod );
    185199        return newnode;
    186200} // DeclarationNode::newModifier
    187201
    188 DeclarationNode * 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 
    195202DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
    196203        DeclarationNode *newnode = new DeclarationNode;
    197204        newnode->type = new TypeData( TypeData::SymbolicInst );
    198         newnode->type->symbolic->name = assign_strptr( name );
    199         newnode->type->symbolic->isTypedef = true;
    200         newnode->type->symbolic->params = 0;
     205        newnode->type->symbolic.name = assign_strptr( name );
     206        newnode->type->symbolic.isTypedef = true;
     207        newnode->type->symbolic.params = 0;
    201208        return newnode;
    202209} // DeclarationNode::newFromTypedef
     
    205212        DeclarationNode *newnode = new DeclarationNode;
    206213        newnode->type = new TypeData( TypeData::Aggregate );
    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;
     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;
    215222        return newnode;
    216223} // DeclarationNode::newAggregate
     
    220227        newnode->name = assign_strptr( name );
    221228        newnode->type = new TypeData( TypeData::Enum );
    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;
     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;
    227234        return newnode;
    228235} // DeclarationNode::newEnum
     
    245252        DeclarationNode *newnode = new DeclarationNode;
    246253        newnode->type = new TypeData( TypeData::SymbolicInst );
    247         newnode->type->symbolic->name = assign_strptr( name );
    248         newnode->type->symbolic->isTypedef = false;
    249         newnode->type->symbolic->actuals = params;
     254        newnode->type->symbolic.name = assign_strptr( name );
     255        newnode->type->symbolic.isTypedef = false;
     256        newnode->type->symbolic.actuals = params;
    250257        return newnode;
    251258} // DeclarationNode::newFromTypeGen
     
    255262        newnode->name = assign_strptr( name );
    256263        newnode->type = new TypeData( TypeData::Variable );
    257         newnode->type->variable->tyClass = tc;
    258         newnode->type->variable->name = newnode->name;
     264        newnode->variable.tyClass = tc;
     265        newnode->variable.name = newnode->name;
    259266        return newnode;
    260267} // DeclarationNode::newTypeParam
     
    263270        DeclarationNode *newnode = new DeclarationNode;
    264271        newnode->type = new TypeData( TypeData::Aggregate );
    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 );
     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 );
    269276        return newnode;
    270277} // DeclarationNode::newTrait
     
    273280        DeclarationNode *newnode = new DeclarationNode;
    274281        newnode->type = new TypeData( TypeData::AggregateInst );
    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;
     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;
    279286        return newnode;
    280287} // DeclarationNode::newTraitUse
     
    284291        newnode->name = assign_strptr( name );
    285292        newnode->type = new TypeData( TypeData::Symbolic );
    286         newnode->type->symbolic->isTypedef = false;
    287         newnode->type->symbolic->params = typeParams;
    288         newnode->type->symbolic->name = newnode->name;
     293        newnode->type->symbolic.isTypedef = false;
     294        newnode->type->symbolic.params = typeParams;
     295        newnode->type->symbolic.name = newnode->name;
    289296        return newnode;
    290297} // DeclarationNode::newTypeDecl
     
    299306        DeclarationNode *newnode = new DeclarationNode;
    300307        newnode->type = new TypeData( TypeData::Array );
    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;
     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;
    305312        } else {
    306                 newnode->type->array->isVarLen = true;
     313                newnode->type->array.isVarLen = true;
    307314        } // if
    308315        return newnode->addQualifiers( qualifiers );
     
    312319        DeclarationNode *newnode = new DeclarationNode;
    313320        newnode->type = new TypeData( TypeData::Array );
    314         newnode->type->array->dimension = 0;
    315         newnode->type->array->isStatic = false;
    316         newnode->type->array->isVarLen = true;
     321        newnode->type->array.dimension = 0;
     322        newnode->type->array.isStatic = false;
     323        newnode->type->array.isVarLen = true;
    317324        return newnode->addQualifiers( qualifiers );
    318325}
     
    327334        DeclarationNode *newnode = new DeclarationNode;
    328335        newnode->type = new TypeData( TypeData::Tuple );
    329         newnode->type->tuple->members = members;
     336        newnode->type->tuple = members;
    330337        return newnode;
    331338}
     
    334341        DeclarationNode *newnode = new DeclarationNode;
    335342        newnode->type = new TypeData( TypeData::Typeof );
    336         newnode->type->typeexpr->expr = expr;
    337         return newnode;
    338 }
     343        newnode->type->typeexpr = expr;
     344        return newnode;
     345}
     346
     347DeclarationNode * 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
    339353
    340354DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {
    341355        DeclarationNode *newnode = new DeclarationNode;
    342356        newnode->type = new TypeData( TypeData::Attr );
    343         newnode->type->attr->name = assign_strptr( name );
    344         newnode->type->attr->expr = expr;
     357        newnode->attr.name = assign_strptr( name );
     358        newnode->attr.expr = expr;
    345359        return newnode;
    346360}
     
    349363        DeclarationNode *newnode = new DeclarationNode;
    350364        newnode->type = new TypeData( TypeData::Attr );
    351         newnode->type->attr->name = assign_strptr( name );
    352         newnode->type->attr->type = type;
     365        newnode->attr.name = assign_strptr( name );
     366        newnode->attr.type = type;
    353367        return newnode;
    354368}
     
    407421                                } else {
    408422                                        if ( type->kind == TypeData::Aggregate ) {
    409                                                 type->aggregate->params = q->type->forall;
     423                                                type->aggregate.params = q->type->forall;
    410424                                                // change implicit typedef from TYPEDEFname to TYPEGENname
    411                                                 typedefTable.changeKind( type->aggregate->name, TypedefTable::TG );
     425                                                typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
    412426                                        } else {
    413427                                                type->forall = q->type->forall;
     
    457471                                if ( src->kind != TypeData::Unknown ) {
    458472                                        assert( src->kind == TypeData::Basic );
    459                                         dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers );
    460                                         dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec );
     473                                        dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );
     474                                        dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );
    461475                                } // if
    462476                                break;
     
    466480                                  case TypeData::Enum:
    467481                                        dst->base = new TypeData( TypeData::AggregateInst );
    468                                         dst->base->aggInst->aggregate = src;
     482                                        dst->base->aggInst.aggregate = src;
    469483                                        if ( src->kind == TypeData::Aggregate ) {
    470                                                 dst->base->aggInst->params = maybeClone( src->aggregate->actuals );
     484                                                dst->base->aggInst.params = maybeClone( src->aggregate.actuals );
    471485                                        } // if
    472486                                        dst->base->qualifiers |= src->qualifiers;
     
    495509                                if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) {
    496510                                        type = new TypeData( TypeData::AggregateInst );
    497                                         type->aggInst->aggregate = o->type;
     511                                        type->aggInst.aggregate = o->type;
    498512                                        if ( o->type->kind == TypeData::Aggregate ) {
    499                                                 type->aggInst->params = maybeClone( o->type->aggregate->actuals );
     513                                                type->aggInst.params = maybeClone( o->type->aggregate.actuals );
    500514                                        } // if
    501515                                        type->qualifiers |= o->type->qualifiers;
     
    523537DeclarationNode *DeclarationNode::addTypedef() {
    524538        TypeData *newtype = new TypeData( TypeData::Symbolic );
    525         newtype->symbolic->params = 0;
    526         newtype->symbolic->isTypedef = true;
    527         newtype->symbolic->name = name;
     539        newtype->symbolic.params = 0;
     540        newtype->symbolic.isTypedef = true;
     541        newtype->symbolic.name = name;
    528542        newtype->base = type;
    529543        type = newtype;
     
    535549        switch ( type->kind ) {
    536550          case TypeData::Symbolic:
    537                 if ( type->symbolic->assertions ) {
    538                         type->symbolic->assertions->appendList( assertions );
     551                if ( type->symbolic.assertions ) {
     552                        type->symbolic.assertions->appendList( assertions );
    539553                } else {
    540                         type->symbolic->assertions = assertions;
     554                        type->symbolic.assertions = assertions;
    541555                } // if
    542556                break;
    543557          case TypeData::Variable:
    544                 if ( type->variable->assertions ) {
    545                         type->variable->assertions->appendList( assertions );
     558                if ( variable.assertions ) {
     559                        variable.assertions->appendList( assertions );
    546560                } else {
    547                         type->variable->assertions = assertions;
     561                        variable.assertions = assertions;
    548562                } // if
    549563                break;
     
    574588        assert( type );
    575589        assert( type->kind == TypeData::Function );
    576         assert( type->function->body == 0 );
    577         type->function->body = body;
    578         type->function->hasBody = true;
     590        assert( type->function.body == 0 );
     591        type->function.body = body;
     592        type->function.hasBody = true;
    579593        return this;
    580594}
     
    583597        assert( type );
    584598        assert( type->kind == TypeData::Function );
    585         assert( type->function->oldDeclList == 0 );
    586         type->function->oldDeclList = list;
     599        assert( type->function.oldDeclList == 0 );
     600        type->function.oldDeclList = list;
    587601        return this;
    588602}
     
    630644                          case TypeData::Enum:
    631645                                p->type->base = new TypeData( TypeData::AggregateInst );
    632                                 p->type->base->aggInst->aggregate = type;
     646                                p->type->base->aggInst.aggregate = type;
    633647                                if ( type->kind == TypeData::Aggregate ) {
    634                                         p->type->base->aggInst->params = maybeClone( type->aggregate->actuals );
     648                                        p->type->base->aggInst.params = maybeClone( type->aggregate.actuals );
    635649                                } // if
    636650                                p->type->base->qualifiers |= type->qualifiers;
     
    667681                          case TypeData::Enum:
    668682                                lastArray->base = new TypeData( TypeData::AggregateInst );
    669                                 lastArray->base->aggInst->aggregate = type;
     683                                lastArray->base->aggInst.aggregate = type;
    670684                                if ( type->kind == TypeData::Aggregate ) {
    671                                         lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals );
     685                                        lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals );
    672686                                } // if
    673687                                lastArray->base->qualifiers |= type->qualifiers;
     
    687701DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) {
    688702        TypeData *ftype = new TypeData( TypeData::Function );
    689         ftype->function->params = params;
     703        ftype->function.params = params;
    690704        setBase( type, ftype );
    691705        return this;
     
    697711                        type->base = addIdListToType( type->base, ids );
    698712                } else {
    699                         type->function->idList = ids;
     713                        type->function.idList = ids;
    700714                } // if
    701715                return type;
    702716        } else {
    703717                TypeData *newtype = new TypeData( TypeData::Function );
    704                 newtype->function->idList = ids;
     718                newtype->function.idList = ids;
    705719                return newtype;
    706720        } // if
     
    727741        if ( newnode->type->kind == TypeData::AggregateInst ) {
    728742                // don't duplicate members
    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;
     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;
    732746                } else {
    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;
     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;
    736750                } // if
    737751        } // if
     
    753767                        if ( newType->kind == TypeData::AggregateInst ) {
    754768                                // don't duplicate members
    755                                 if ( newType->aggInst->aggregate->kind == TypeData::Enum ) {
    756                                         delete newType->aggInst->aggregate->enumeration->constants;
    757                                         newType->aggInst->aggregate->enumeration->constants = 0;
     769                                if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
     770                                        delete newType->aggInst.aggregate->enumeration.constants;
     771                                        newType->aggInst.aggregate->enumeration.constants = 0;
    758772                                } else {
    759                                         assert( newType->aggInst->aggregate->kind == TypeData::Aggregate );
    760                                         delete newType->aggInst->aggregate->aggregate->fields;
    761                                         newType->aggInst->aggregate->aggregate->fields = 0;
     773                                        assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
     774                                        delete newType->aggInst.aggregate->aggregate.fields;
     775                                        newType->aggInst.aggregate->aggregate.fields = 0;
    762776                                } // if
    763777                        } // if
     
    896910        if ( ! error.empty() ) throw SemanticError( error, this );
    897911        if ( type ) {
    898                 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     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
    899920        } // if
    900921        if ( ! isInline && ! isNoreturn ) {
     
    909930        switch ( type->kind ) {
    910931          case TypeData::Enum:
    911                 return new EnumInstType( buildQualifiers( type ), type->enumeration->name );
     932                return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
    912933          case TypeData::Aggregate: {
    913934                  ReferenceToType *ret;
    914                   switch ( type->aggregate->kind ) {
     935                  switch ( type->aggregate.kind ) {
    915936                        case DeclarationNode::Struct:
    916                           ret = new StructInstType( buildQualifiers( type ), type->aggregate->name );
     937                          ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );
    917938                          break;
    918939                        case DeclarationNode::Union:
    919                           ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name );
     940                          ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );
    920941                          break;
    921942                        case DeclarationNode::Trait:
    922                           ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name );
     943                          ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );
    923944                          break;
    924945                        default:
    925946                          assert( false );
    926947                  } // switch
    927                   buildList( type->aggregate->actuals, ret->get_parameters() );
     948                  buildList( type->aggregate.actuals, ret->get_parameters() );
    928949                  return ret;
    929950          }
    930951          case TypeData::Symbolic: {
    931                   TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false );
    932                   buildList( type->symbolic->actuals, ret->get_parameters() );
     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
    933966                  return ret;
    934967          }
  • src/Parser/ParseNode.h

    r621701d rf04a8b81  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 21:14:51 2016
    13 // Update Count     : 575
     12// Last Modified On : Mon Aug 29 21:45:43 2016
     13// Update Count     : 583
    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
    292314        TypeData *type;
    293315        std::string name;
  • src/Parser/TypeData.cc

    r621701d rf04a8b81  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 18:28:58 2016
    13 // Update Count     : 223
     12// Last Modified On : Mon Aug 29 22:31:53 2016
     13// Update Count     : 277
    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->members = 0;
     80                // tuple = new Tuple_t;
     81                tuple = nullptr;
    8282                break;
    8383          case Typeof:
    84                 typeexpr = new Typeof_t;
    85                 typeexpr->expr = 0;
     84                // typeexpr = new Typeof_t;
     85                typeexpr = nullptr;
     86                break;
     87          case Attr:
     88                // attr = new Attr_t;
     89                // attr.expr = nullptr;
     90                // attr.type = nullptr;
    8691                break;
    8792          case Builtin:
    88                 builtin = new Builtin_t;
    89                 break;
    90           case Attr:
    91                 attr = new Attr_t;
    92                 attr->expr = 0;
    93                 attr->type = 0;
     93                // builtin = new Builtin_t;
    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 Attr:
     157                // delete attr.expr;
     158                // delete attr.type;
     159                // delete attr;
     160                break;
    156161          case Builtin:
    157                 delete builtin;
    158                 break;
    159           case Attr:
    160                 delete attr->expr;
    161                 delete attr->type;
    162                 delete attr;
     162                // delete builtin;
    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                 newtype->variable->assertions = maybeClone( variable->assertions );
    222                 newtype->variable->name = variable->name;
    223                 newtype->variable->tyClass = variable->tyClass;
     221                assert( false );
     222                // newtype->variable.assertions = maybeClone( variable.assertions );
     223                // newtype->variable.name = variable.name;
     224                // newtype->variable.tyClass = variable.tyClass;
    224225                break;
    225226          case Tuple:
    226                 newtype->tuple->members = maybeClone( tuple->members );
     227                newtype->tuple = maybeClone( tuple );
    227228                break;
    228229          case Typeof:
    229                 newtype->typeexpr->expr = maybeClone( typeexpr->expr );
     230                newtype->typeexpr = maybeClone( typeexpr );
     231                break;
     232          case Attr:
     233                assert( false );
     234                // newtype->attr.expr = maybeClone( attr.expr );
     235                // newtype->attr.type = maybeClone( attr.type );
    230236                break;
    231237          case Builtin:
    232                 newtype->builtin->type = builtin->type;
    233                 break;
    234           case Attr:
    235                 newtype->attr->expr = maybeClone( attr->expr );
    236                 newtype->attr->type = maybeClone( attr->type );
     238                assert( false );
     239                // newtype->builtin = builtin;
    237240                break;
    238241        } // switch
     
    268271                break;
    269272          case Basic:
    270                 printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );
    271                 printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );
     273                printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os );
     274                printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os );
    272275                break;
    273276          case Array:
    274                 if ( array->isStatic ) {
     277                if ( array.isStatic ) {
    275278                        os << "static ";
    276279                } // if
    277                 if ( array->dimension ) {
     280                if ( array.dimension ) {
    278281                        os << "array of ";
    279                         array->dimension->printOneLine( os, indent );
    280                 } else if ( array->isVarLen ) {
     282                        array.dimension->printOneLine( os, indent );
     283                } else if ( array.isVarLen ) {
    281284                        os << "variable-length array of ";
    282285                } else {
     
    289292          case Function:
    290293                os << "function" << endl;
    291                 if ( function->params ) {
     294                if ( function.params ) {
    292295                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
    293                         function->params->printList( os, indent + 4 );
     296                        function.params->printList( os, indent + 4 );
    294297                } else {
    295298                        os << string( indent + 2, ' ' ) << "with no parameters " << endl;
    296299                } // if
    297                 if ( function->idList ) {
     300                if ( function.idList ) {
    298301                        os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl;
    299                         function->idList->printList( os, indent + 4 );
    300                 } // if
    301                 if ( function->oldDeclList ) {
     302                        function.idList->printList( os, indent + 4 );
     303                } // if
     304                if ( function.oldDeclList ) {
    302305                        os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl;
    303                         function->oldDeclList->printList( os, indent + 4 );
     306                        function.oldDeclList->printList( os, indent + 4 );
    304307                } // if
    305308                os << string( indent + 2, ' ' ) << "returning ";
     
    310313                } // if
    311314                os << endl;
    312                 if ( function->hasBody ) {
     315                if ( function.hasBody ) {
    313316                        os << string( indent + 2, ' ' ) << "with body " << endl;
    314317                } // if
    315                 if ( function->body ) {
    316                         function->body->printList( os, indent + 2 );
     318                if ( function.body ) {
     319                        function.body->printList( os, indent + 2 );
    317320                } // if
    318321                break;
    319322          case Aggregate:
    320                 os << DeclarationNode::aggregateName[ aggregate->kind ] << ' ' << aggregate->name << endl;
    321                 if ( aggregate->params ) {
     323                os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl;
     324                if ( aggregate.params ) {
    322325                        os << string( indent + 2, ' ' ) << "with type parameters " << endl;
    323                         aggregate->params->printList( os, indent + 4 );
    324                 } // if
    325                 if ( aggregate->actuals ) {
     326                        aggregate.params->printList( os, indent + 4 );
     327                } // if
     328                if ( aggregate.actuals ) {
    326329                        os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl;
    327                         aggregate->actuals->printList( os, indent + 4 );
    328                 } // if
    329                 if ( aggregate->fields ) {
     330                        aggregate.actuals->printList( os, indent + 4 );
     331                } // if
     332                if ( aggregate.fields ) {
    330333                        os << string( indent + 2, ' ' ) << "with members " << endl;
    331                         aggregate->fields->printList( os, indent + 4 );
    332                 } // if
    333                 if ( aggregate->body ) {
     334                        aggregate.fields->printList( os, indent + 4 );
     335                } // if
     336                if ( aggregate.body ) {
    334337                        os << string( indent + 2, ' ' ) << " with body " << endl;
    335338                } // if
    336339                break;
    337340          case AggregateInst:
    338                 if ( aggInst->aggregate ) {
     341                if ( aggInst.aggregate ) {
    339342                        os << "instance of " ;
    340                         aggInst->aggregate->print( os, indent );
     343                        aggInst.aggregate->print( os, indent );
    341344                } else {
    342345                        os << "instance of an unspecified aggregate ";
    343346                } // if
    344                 if ( aggInst->params ) {
     347                if ( aggInst.params ) {
    345348                        os << string( indent + 2, ' ' ) << "with parameters " << endl;
    346                         aggInst->params->printList( os, indent + 2 );
     349                        aggInst.params->printList( os, indent + 2 );
    347350                } // if
    348351                break;
    349352          case Enum:
    350353                os << "enumeration ";
    351                 if ( enumeration->constants ) {
     354                if ( enumeration.constants ) {
    352355                        os << "with constants" << endl;
    353                         enumeration->constants->printList( os, indent + 2 );
     356                        enumeration.constants->printList( os, indent + 2 );
    354357                } // if
    355358                break;
    356359          case SymbolicInst:
    357                 os << "instance of type " << symbolic->name;
    358                 if ( symbolic->actuals ) {
     360                os << "instance of type " << symbolic.name;
     361                if ( symbolic.actuals ) {
    359362                        os << " with parameters" << endl;
    360                         symbolic->actuals->printList( os, indent + 2 );
     363                        symbolic.actuals->printList( os, indent + 2 );
    361364                } // if
    362365                break;
    363366          case Symbolic:
    364                 if ( symbolic->isTypedef ) {
     367                if ( symbolic.isTypedef ) {
    365368                        os << "typedef definition ";
    366369                } else {
    367370                        os << "type definition ";
    368371                } // if
    369                 if ( symbolic->params ) {
     372                if ( symbolic.params ) {
    370373                        os << endl << string( indent + 2, ' ' ) << "with parameters" << endl;
    371                         symbolic->params->printList( os, indent + 2 );
    372                 } // if
    373                 if ( symbolic->assertions ) {
     374                        symbolic.params->printList( os, indent + 2 );
     375                } // if
     376                if ( symbolic.assertions ) {
    374377                        os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    375                         symbolic->assertions->printList( os, indent + 4 );
     378                        symbolic.assertions->printList( os, indent + 4 );
    376379                        os << string( indent + 2, ' ' );
    377380                } // if
     
    382385                break;
    383386          case Variable:
    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
     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
    390393                break;
    391394          case Tuple:
    392395                os << "tuple ";
    393                 if ( tuple->members ) {
     396                if ( tuple ) {
    394397                        os << "with members " << endl;
    395                         tuple->members->printList( os, indent + 2 );
     398                        tuple->printList( os, indent + 2 );
    396399                } // if
    397400                break;
    398401          case Typeof:
    399402                os << "type-of expression ";
    400                 if ( typeexpr->expr ) {
    401                         typeexpr->expr->print( os, indent + 2 );
     403                if ( typeexpr ) {
     404                        typeexpr->print( os, indent + 2 );
    402405                } // if
    403406                break;
    404407          case Attr:
    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
     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
    412415                break;
    413416          case Builtin:
     
    479482                return new VarArgsType( buildQualifiers( td ) );
    480483          case TypeData::Attr:
     484                assert( false );
    481485                return buildAttr( td );
    482486          case TypeData::Symbolic:
     
    494498        switch ( td->kind ) {
    495499          case TypeData::Aggregate:
    496                 if ( ! toplevel && td->aggregate->fields ) {
     500                if ( ! toplevel && td->aggregate.fields ) {
    497501                        ret = td->clone();
    498502                } // if
    499503                break;
    500504          case TypeData::Enum:
    501                 if ( ! toplevel && td->enumeration->constants ) {
     505                if ( ! toplevel && td->enumeration.constants ) {
    502506                        ret = td->clone();
    503507                } // if
    504508                break;
    505509          case TypeData::AggregateInst:
    506                 if ( td->aggInst->aggregate ) {
    507                         ret = typeextractAggregate( td->aggInst->aggregate, false );
     510                if ( td->aggInst.aggregate ) {
     511                        ret = typeextractAggregate( td->aggInst.aggregate, false );
    508512                } // if
    509513                break;
     
    535539        BasicType::Kind ret;
    536540
    537         for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) {
     541        for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) {
    538542                if ( ! init ) {
    539543                        init = true;
    540544                        if ( *i == DeclarationNode::Void ) {
    541                                 if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) {
     545                                if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) {
    542546                                        throw SemanticError( "invalid type specifier \"void\" in type: ", td );
    543547                                } else {
     
    611615        } // for
    612616
    613         for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) {
     617        for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) {
    614618                switch ( *i ) {
    615619                  case DeclarationNode::Long:
     
    746750        ArrayType * at;
    747751        if ( td->base ) {
    748                 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ),
    749                                                         td->array->isVarLen, td->array->isStatic );
     752                at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array.dimension ),
     753                                                        td->array.isVarLen, td->array.isStatic );
    750754        } else {
    751755                at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
    752                                                         maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic );
     756                                                        maybeBuild< Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic );
    753757        } // if
    754758        buildForall( td->forall, at->get_forall() );
     
    759763        assert( td->kind == TypeData::Aggregate );
    760764        AggregateDecl * at;
    761         switch ( td->aggregate->kind ) {
     765        switch ( td->aggregate.kind ) {
    762766          case DeclarationNode::Struct:
    763                 at = new StructDecl( td->aggregate->name );
    764                 buildForall( td->aggregate->params, at->get_parameters() );
     767                at = new StructDecl( td->aggregate.name );
     768                buildForall( td->aggregate.params, at->get_parameters() );
    765769                break;
    766770          case DeclarationNode::Union:
    767                 at = new UnionDecl( td->aggregate->name );
    768                 buildForall( td->aggregate->params, at->get_parameters() );
     771                at = new UnionDecl( td->aggregate.name );
     772                buildForall( td->aggregate.params, at->get_parameters() );
    769773                break;
    770774          case DeclarationNode::Trait:
    771                 at = new TraitDecl( td->aggregate->name );
    772                 buildList( td->aggregate->params, at->get_parameters() );
     775                at = new TraitDecl( td->aggregate.name );
     776                buildList( td->aggregate.params, at->get_parameters() );
    773777                break;
    774778          default:
     
    776780        } // switch
    777781
    778         buildList( td->aggregate->fields, at->get_members() );
    779         at->set_body( td->aggregate->body );
     782        buildList( td->aggregate.fields, at->get_members() );
     783        at->set_body( td->aggregate.body );
    780784
    781785        return at;
     
    786790
    787791        ReferenceToType * ret;
    788         if ( td->aggInst->aggregate->kind == TypeData::Enum ) {
    789                 ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name );
     792        if ( td->aggInst.aggregate->kind == TypeData::Enum ) {
     793                ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name );
    790794        } else {
    791                 assert( td->aggInst->aggregate->kind == TypeData::Aggregate );
    792                 switch ( td->aggInst->aggregate->aggregate->kind ) {
     795                assert( td->aggInst.aggregate->kind == TypeData::Aggregate );
     796                switch ( td->aggInst.aggregate->aggregate.kind ) {
    793797                  case DeclarationNode::Struct:
    794                         ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     798                        ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
    795799                        break;
    796800                  case DeclarationNode::Union:
    797                         ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     801                        ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
    798802                        break;
    799803                  case DeclarationNode::Trait:
    800                         ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name );
     804                        ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
    801805                        break;
    802806                  default:
     
    804808                } // switch
    805809        } // if
    806         buildList( td->aggInst->params, ret->get_parameters() );
     810        buildList( td->aggInst.params, ret->get_parameters() );
    807811        buildForall( td->forall, ret->get_forall() );
    808812        return ret;
     
    813817        NamedTypeDecl * ret;
    814818        assert( td->base );
    815         if ( td->symbolic->isTypedef ) {
     819        if ( td->symbolic.isTypedef ) {
    816820                ret = new TypedefDecl( name, sc, typebuild( td->base ) );
    817821        } else {
    818822                ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any );
    819823        } // if
    820         buildList( td->symbolic->params, ret->get_parameters() );
    821         buildList( td->symbolic->assertions, ret->get_assertions() );
     824        buildList( td->symbolic.params, ret->get_parameters() );
     825        buildList( td->symbolic.assertions, ret->get_assertions() );
    822826        return ret;
    823827} // buildSymbolic
    824828
    825829TypeDecl * buildVariable( const TypeData * td ) {
    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;
     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;
    832838} // buildSymbolic
    833839
    834840EnumDecl * buildEnum( const TypeData * td ) {
    835841        assert( td->kind == TypeData::Enum );
    836         EnumDecl * ret = new EnumDecl( td->enumeration->name );
    837         buildList( td->enumeration->constants, ret->get_members() );
     842        EnumDecl * ret = new EnumDecl( td->enumeration.name );
     843        buildList( td->enumeration.constants, ret->get_members() );
    838844        std::list< Declaration * >::iterator members = ret->get_members().begin();
    839         for ( const DeclarationNode * cur = td->enumeration-> constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
     845        for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    840846                if ( cur->has_enumeratorValue() ) {
    841847                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
     
    848854TypeInstType * buildSymbolicInst( const TypeData * td ) {
    849855        assert( td->kind == TypeData::SymbolicInst );
    850         TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false );
    851         buildList( td->symbolic->actuals, ret->get_parameters() );
     856        TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false );
     857        buildList( td->symbolic.actuals, ret->get_parameters() );
    852858        buildForall( td->forall, ret->get_forall() );
    853859        return ret;
     
    857863        assert( td->kind == TypeData::Tuple );
    858864        TupleType * ret = new TupleType( buildQualifiers( td ) );
    859         buildTypeList( td->tuple->members, ret->get_types() );
     865        buildTypeList( td->tuple, ret->get_types() );
    860866        buildForall( td->forall, ret->get_forall() );
    861867        return ret;
     
    865871        assert( td->kind == TypeData::Typeof );
    866872        assert( td->typeexpr );
    867         assert( td->typeexpr->expr );
    868         return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() );
     873        // assert( td->typeexpr->expr );
     874        return new TypeofType( buildQualifiers( td ), td->typeexpr->build() );
    869875} // buildTypeof
    870876
    871877AttrType * buildAttr( const TypeData * td ) {
    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;
     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;
    882890} // buildAttr
    883891
     
    885893        if ( td->kind == TypeData::Function ) {
    886894                FunctionDecl * decl;
    887                 if ( td->function->hasBody ) {
    888                         if ( td->function->body ) {
    889                                 Statement * stmt = td->function->body->build();
     895                if ( td->function.hasBody ) {
     896                        if ( td->function.body ) {
     897                                Statement * stmt = td->function.body->build();
    890898                                CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt );
    891899                                assert( body );
     
    898906                        decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );
    899907                } // if
    900                 for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
     908                for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
    901909                        if ( cur->get_name() != "" ) {
    902910                                decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
    903911                        } // if
    904912                } // for
    905                 buildList( td->function->oldDeclList, decl->get_oldDecls() );
     913                buildList( td->function.oldDeclList, decl->get_oldDecls() );
    906914                return decl;
    907915        } else if ( td->kind == TypeData::Aggregate ) {
     
    912920                return buildSymbolic( td, name, sc );
    913921        } else if ( td->kind == TypeData::Variable ) {
     922                assert( false );
    914923                return buildVariable( td );
    915924        } else {
     
    921930FunctionType * buildFunction( const TypeData * td ) {
    922931        assert( td->kind == TypeData::Function );
    923         bool hasEllipsis = td->function->params ? td->function->params->get_hasEllipsis() : true;
    924         if ( ! td->function->params ) hasEllipsis = ! td->function->newStyle;
     932        bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true;
     933        if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle;
    925934        FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis );
    926         buildList( td->function->params, ft->get_parameters() );
     935        buildList( td->function.params, ft->get_parameters() );
    927936        buildForall( td->forall, ft->get_forall() );
    928937        if ( td->base ) {
    929938                switch ( td->base->kind ) {
    930939                  case TypeData::Tuple:
    931                         buildList( td->base->tuple->members, ft->get_returnVals() );
     940                        buildList( td->base->tuple, ft->get_returnVals() );
    932941                        break;
    933942                  default:
  • src/Parser/TypeData.h

    r621701d rf04a8b81  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 28 22:39:00 2016
    13 // Update Count     : 85
     12// Last Modified On : Mon Aug 29 22:31:52 2016
     13// Update Count     : 110
    1414//
    1515
     
    2424struct TypeData {
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    26                                 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;
     26                                Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr };
    2727
    2828        struct Basic_t {
     
    7373        };
    7474
    75         struct Variable_t {
    76                 DeclarationNode::TypeClass tyClass;
    77                 std::string name;
    78                 DeclarationNode * assertions;
    79         };
     75        // struct Tuple_t {
     76        //      DeclarationNode * members;
     77        // };
     78 
     79        // struct Typeof_t {
     80        //      ExpressionNode * expr;
     81        // };
    8082
    81         struct Tuple_t {
    82                 DeclarationNode * members;
    83         };
    84  
    85         struct Typeof_t {
    86                 ExpressionNode * expr;
    87         };
     83        // struct Builtin_t {
     84        //      DeclarationNode::BuiltinType type;
     85        // };
    8886
    89         struct Builtin_t {
    90                 DeclarationNode::BuiltinType type;
    91         };
    92 
    93         struct Attr_t {
    94                 std::string name;
    95                 ExpressionNode * expr;
    96                 DeclarationNode * type;
    97         };
    98 
     87        Kind kind;
    9988        TypeData * base;
    10089        typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers;
     
    10291        DeclarationNode * forall;
    10392
    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         };
     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;
    118104
    119105        TypeData( Kind k = Unknown );
  • src/main.cc

    r621701d rf04a8b81  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug 20 12:52:22 2016
    13 // Update Count     : 403
     12// Last Modified On : Mon Aug 29 17:34:39 2016
     13// Update Count     : 426
    1414//
    1515
     
    7575static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    7676
    77 void sigSegvBusHandler( int sig_num ) {
     77void backtrace( int start ) {                                                   // skip first N stack frames
    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 
    8681        char ** messages = backtrace_symbols( array, size );
    8782
    88         // skip first stack frame (points here)
    89         for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) {
     83        // skip last 2 stack frames after main
     84        for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
    9085                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    9186                for ( char *p = messages[i]; *p; ++p ) {        // find parantheses and +offset
     
    10196
    10297                // if line contains symbol, attempt to demangle
     98                int frameNo = i - start;
    10399                if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
    104100                        *mangled_name++ = '\0';
     
    106102                        *offset_end++ = '\0';
    107103
    108                         int status;
     104                        int status, frameNo = i - start;
    109105                        char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
    110106                        if ( status == 0 ) {                                            // demangling successful ?
    111                                 cerr << "(" << i - 2 << ") " << messages[i] << " : "
     107                                cerr << "(" << frameNo << ") " << messages[i] << " : "
    112108                                         << real_name << "+" << offset_begin << offset_end << endl;
    113109
    114110                        } else {                                                                        // otherwise, output mangled name
    115                                 cerr << "(" << i - 2 << ") " << messages[i] << " : "
     111                                cerr << "(" << frameNo << ") " << messages[i] << " : "
    116112                                         << mangled_name << "+" << offset_begin << offset_end << endl;
    117113                        } // if
    118114                        free( real_name );
    119115                } else {                                                                                // otherwise, print the whole line
    120                         cerr << "(" << i - 2 << ") " << messages[i] << endl;
     116                        cerr << "(" << frameNo << ") " << messages[i] << endl;
    121117                } // if
    122118        } // for
     119
    123120        free( messages );
     121} // backtrace
     122
     123void 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
    124128        exit( EXIT_FAILURE );
    125129} // sigSegvBusHandler
     130
     131void 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
    126137
    127138int main( int argc, char * argv[] ) {
     
    133144        signal( SIGSEGV, sigSegvBusHandler );
    134145        signal( SIGBUS, sigSegvBusHandler );
     146        signal( SIGABRT, sigAbortHandler );
    135147
    136148        parse_cmdline( argc, argv, filename );                          // process command-line arguments
Note: See TracChangeset for help on using the changeset viewer.