Changeset ba7aa2d for src/Parser


Ignore:
Timestamp:
Sep 16, 2016, 11:30:05 AM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
1b77274
Parents:
101e0bd
Message:

more refactoring of parser code

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r101e0bd rba7aa2d  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Sep 14 23:13:28 2016
    13 // Update Count     : 502
     12// Last Modified On : Thu Sep 15 23:36:02 2016
     13// Update Count     : 515
    1414//
    1515
     
    3131
    3232// These must remain in the same order as the corresponding DeclarationNode enumerations.
    33 const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
    34 const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" };
    35 const char *DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };
    36 const char *DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };
    37 const char *DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };
    38 const char *DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };
    39 const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    40 const char *DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };
    41 const char *DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
     33const char * DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "NoStorageClass" };
     34const char * DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic", "NoQualifier" };
     35const char * DeclarationNode::basicTypeName[] = { "void", "_Bool", "char", "int", "float", "double", "long double", "NoBasicType" };
     36const char * DeclarationNode::complexTypeName[] = { "_Complex", "_Imaginary", "NoComplexType" };
     37const char * DeclarationNode::signednessName[] = { "signed", "unsigned", "NoSignedness" };
     38const char * DeclarationNode::lengthName[] = { "short", "long", "long long", "NoLength" };
     39const char * DeclarationNode::aggregateName[] = { "struct", "union", "context" };
     40const char * DeclarationNode::typeClassName[] = { "otype", "dtype", "ftype" };
     41const char * DeclarationNode::builtinTypeName[] = { "__builtin_va_list" };
    4242
    4343UniqueName DeclarationNode::anonymous( "__anonymous" );
     
    7070}
    7171
    72 DeclarationNode *DeclarationNode::clone() const {
    73         DeclarationNode *newnode = new DeclarationNode;
     72DeclarationNode * DeclarationNode::clone() const {
     73        DeclarationNode * newnode = new DeclarationNode;
    7474        newnode->type = maybeClone( type );
    7575        newnode->name = name;
     
    139139}
    140140
    141 DeclarationNode *DeclarationNode::newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) {
    142         DeclarationNode *newnode = new DeclarationNode;
     141DeclarationNode * DeclarationNode::newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
     142        DeclarationNode * newnode = new DeclarationNode;
    143143        newnode->name = assign_strptr( name );
    144144
     
    163163
    164164DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) {
    165         DeclarationNode *newnode = new DeclarationNode;
     165        DeclarationNode * newnode = new DeclarationNode;
    166166        newnode->type = new TypeData();
    167167        newnode->type->qualifiers[ q ] = 1;
     
    169169} // DeclarationNode::newQualifier
    170170
    171 DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) {
    172         DeclarationNode *newnode = new DeclarationNode;
     171DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {
     172        DeclarationNode * newnode = new DeclarationNode;
    173173        newnode->type = new TypeData( TypeData::Unknown );
    174174        newnode->type->forall = forall;
     
    177177
    178178DeclarationNode * DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    179         DeclarationNode *newnode = new DeclarationNode;
    180         //switch (sc) {
    181         //      case Inline: newnode->isInline = true; break;
    182         //      case Noreturn: newnode->isNoreturn = true; break;
    183         //      default: newnode->storageClass = sc; break;
    184         //}
     179        DeclarationNode * newnode = new DeclarationNode;
    185180        newnode->storageClass = sc;
    186181        return newnode;
     
    188183
    189184DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
    190         DeclarationNode *newnode = new DeclarationNode;
     185        DeclarationNode * newnode = new DeclarationNode;
    191186        newnode->type = new TypeData( TypeData::Basic );
    192187        newnode->type->basictype = bt;
     
    195190
    196191DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
    197         DeclarationNode *newnode = new DeclarationNode;
     192        DeclarationNode * newnode = new DeclarationNode;
    198193        newnode->type = new TypeData( TypeData::Basic );
    199194        newnode->type->complextype = ct;
     
    202197
    203198DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
    204         DeclarationNode *newnode = new DeclarationNode;
     199        DeclarationNode * newnode = new DeclarationNode;
    205200        newnode->type = new TypeData( TypeData::Basic );
    206201        newnode->type->signedness = sn;
     
    209204
    210205DeclarationNode * DeclarationNode::newLength( Length lnth ) {
    211         DeclarationNode *newnode = new DeclarationNode;
     206        DeclarationNode * newnode = new DeclarationNode;
    212207        newnode->type = new TypeData( TypeData::Basic );
    213208        newnode->type->length = lnth;
     
    215210} // DeclarationNode::newLength
    216211
    217 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
    218         DeclarationNode *newnode = new DeclarationNode;
     212DeclarationNode * DeclarationNode::newFromTypedef( std::string * name ) {
     213        DeclarationNode * newnode = new DeclarationNode;
    219214        newnode->type = new TypeData( TypeData::SymbolicInst );
    220215        newnode->type->symbolic.name = assign_strptr( name );
     
    224219} // DeclarationNode::newFromTypedef
    225220
    226 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
    227         DeclarationNode *newnode = new DeclarationNode;
     221DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     222        DeclarationNode * newnode = new DeclarationNode;
    228223        newnode->type = new TypeData( TypeData::Aggregate );
    229224        newnode->type->aggregate.kind = kind;
     
    238233} // DeclarationNode::newAggregate
    239234
    240 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
    241         DeclarationNode *newnode = new DeclarationNode;
     235DeclarationNode * DeclarationNode::newEnum( std::string * name, DeclarationNode * constants ) {
     236        DeclarationNode * newnode = new DeclarationNode;
    242237        newnode->name = assign_strptr( name );
    243238        newnode->type = new TypeData( TypeData::Enum );
     
    250245} // DeclarationNode::newEnum
    251246
    252 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    253         DeclarationNode *newnode = new DeclarationNode;
     247DeclarationNode * DeclarationNode::newEnumConstant( std::string * name, ExpressionNode * constant ) {
     248        DeclarationNode * newnode = new DeclarationNode;
    254249        newnode->name = assign_strptr( name );
    255250        newnode->enumeratorValue.reset( constant );
     
    258253} // DeclarationNode::newEnumConstant
    259254
    260 DeclarationNode *DeclarationNode::newName( std::string *name ) {
    261         DeclarationNode *newnode = new DeclarationNode;
     255DeclarationNode * DeclarationNode::newName( std::string * name ) {
     256        DeclarationNode * newnode = new DeclarationNode;
    262257        newnode->name = assign_strptr( name );
    263258        return newnode;
    264259} // DeclarationNode::newName
    265260
    266 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
    267         DeclarationNode *newnode = new DeclarationNode;
     261DeclarationNode * DeclarationNode::newFromTypeGen( std::string * name, ExpressionNode * params ) {
     262        DeclarationNode * newnode = new DeclarationNode;
    268263        newnode->type = new TypeData( TypeData::SymbolicInst );
    269264        newnode->type->symbolic.name = assign_strptr( name );
     
    273268} // DeclarationNode::newFromTypeGen
    274269
    275 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
    276         DeclarationNode *newnode = new DeclarationNode;
     270DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string * name ) {
     271        DeclarationNode * newnode = new DeclarationNode;
    277272        newnode->name = assign_strptr( name );
    278273        newnode->type = new TypeData( TypeData::Variable );
     274//      newnode->type = nullptr;
    279275        newnode->variable.tyClass = tc;
    280276        newnode->variable.name = newnode->name;
     
    282278} // DeclarationNode::newTypeParam
    283279
    284 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
    285         DeclarationNode *newnode = new DeclarationNode;
     280DeclarationNode * DeclarationNode::newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts ) {
     281        DeclarationNode * newnode = new DeclarationNode;
    286282        newnode->type = new TypeData( TypeData::Aggregate );
    287283        newnode->type->aggregate.kind = Trait;
     
    292288} // DeclarationNode::newTrait
    293289
    294 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
    295         DeclarationNode *newnode = new DeclarationNode;
     290DeclarationNode * DeclarationNode::newTraitUse( std::string * name, ExpressionNode * params ) {
     291        DeclarationNode * newnode = new DeclarationNode;
    296292        newnode->type = new TypeData( TypeData::AggregateInst );
    297293        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
     
    302298} // DeclarationNode::newTraitUse
    303299
    304 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
    305         DeclarationNode *newnode = new DeclarationNode;
     300DeclarationNode * DeclarationNode::newTypeDecl( std::string * name, DeclarationNode * typeParams ) {
     301        DeclarationNode * newnode = new DeclarationNode;
    306302        newnode->name = assign_strptr( name );
    307303        newnode->type = new TypeData( TypeData::Symbolic );
     
    312308} // DeclarationNode::newTypeDecl
    313309
    314 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
    315         DeclarationNode *newnode = new DeclarationNode;
     310DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers ) {
     311        DeclarationNode * newnode = new DeclarationNode;
    316312        newnode->type = new TypeData( TypeData::Pointer );
    317313        return newnode->addQualifiers( qualifiers );
    318314} // DeclarationNode::newPointer
    319315
    320 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
    321         DeclarationNode *newnode = new DeclarationNode;
     316DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) {
     317        DeclarationNode * newnode = new DeclarationNode;
    322318        newnode->type = new TypeData( TypeData::Array );
    323319        newnode->type->array.dimension = size;
    324320        newnode->type->array.isStatic = isStatic;
    325         if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) {
     321        if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
    326322                newnode->type->array.isVarLen = false;
    327323        } else {
     
    331327} // DeclarationNode::newArray
    332328
    333 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
    334         DeclarationNode *newnode = new DeclarationNode;
     329DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) {
     330        DeclarationNode * newnode = new DeclarationNode;
    335331        newnode->type = new TypeData( TypeData::Array );
    336332        newnode->type->array.dimension = 0;
     
    340336}
    341337
    342 DeclarationNode *DeclarationNode::newBitfield( ExpressionNode *size ) {
    343         DeclarationNode *newnode = new DeclarationNode;
     338DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) {
     339        DeclarationNode * newnode = new DeclarationNode;
    344340        newnode->bitfieldWidth = size;
    345341        return newnode;
    346342}
    347343
    348 DeclarationNode *DeclarationNode::newTuple( DeclarationNode *members ) {
    349         DeclarationNode *newnode = new DeclarationNode;
     344DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) {
     345        DeclarationNode * newnode = new DeclarationNode;
    350346        newnode->type = new TypeData( TypeData::Tuple );
    351347        newnode->type->tuple = members;
     
    353349}
    354350
    355 DeclarationNode *DeclarationNode::newTypeof( ExpressionNode *expr ) {
    356         DeclarationNode *newnode = new DeclarationNode;
     351DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr ) {
     352        DeclarationNode * newnode = new DeclarationNode;
    357353        newnode->type = new TypeData( TypeData::Typeof );
    358354        newnode->type->typeexpr = expr;
     
    361357
    362358DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
    363         DeclarationNode *newnode = new DeclarationNode;
     359        DeclarationNode * newnode = new DeclarationNode;
    364360        newnode->type = new TypeData( TypeData::Builtin );
    365361        newnode->builtin = bt;
     
    367363} // DeclarationNode::newBuiltinType
    368364
    369 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {
    370         DeclarationNode *newnode = new DeclarationNode;
     365DeclarationNode * DeclarationNode::newAttr( std::string * name, ExpressionNode * expr ) {
     366        DeclarationNode * newnode = new DeclarationNode;
    371367        newnode->type = new TypeData( TypeData::Attr );
     368//      newnode->type = nullptr;
    372369        newnode->attr.name = assign_strptr( name );
    373370        newnode->attr.expr = expr;
     
    375372}
    376373
    377 DeclarationNode *DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) {
    378         DeclarationNode *newnode = new DeclarationNode;
     374DeclarationNode * DeclarationNode::newAttr( std::string * name, DeclarationNode * type ) {
     375        DeclarationNode * newnode = new DeclarationNode;
    379376        newnode->type = new TypeData( TypeData::Attr );
     377//      newnode->type = nullptr;
    380378        newnode->attr.name = assign_strptr( name );
    381379        newnode->attr.type = type;
     
    389387} // appendError
    390388
    391 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
     389void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
    392390        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    393391
     
    401399} // DeclarationNode::checkQualifiers
    402400
    403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
     401void DeclarationNode::checkStorageClasses( DeclarationNode * q ) {
    404402        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
    405403                if ( storageClass == q->storageClass ) {                // duplicate qualifier
     
    413411} // DeclarationNode::copyStorageClasses
    414412
    415 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
     413DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) {
    416414        isInline = isInline || q->isInline;
    417415        isNoreturn = isNoreturn || q->isNoreturn;
     
    424422} // DeclarationNode::copyStorageClasses
    425423
    426 static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
     424static void addQualifiersToType( TypeData *&src, TypeData * dst ) {
    427425        if ( src->forall && dst->kind == TypeData::Function ) {
    428426                if ( dst->forall ) {
     
    443441} // addQualifiersToType
    444442
    445 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
     443DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
    446444        if ( ! q ) return this;
    447445
     
    550548}
    551549
    552 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
     550DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
    553551        if ( o ) {
    554552                checkStorageClasses( o );
     
    584582}
    585583
    586 DeclarationNode *DeclarationNode::addTypedef() {
    587         TypeData *newtype = new TypeData( TypeData::Symbolic );
     584DeclarationNode * DeclarationNode::addTypedef() {
     585        TypeData * newtype = new TypeData( TypeData::Symbolic );
    588586        newtype->symbolic.params = 0;
    589587        newtype->symbolic.isTypedef = true;
     
    594592}
    595593
    596 DeclarationNode *DeclarationNode::addAssertions( DeclarationNode *assertions ) {
     594DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
    597595        assert( type );
    598596        switch ( type->kind ) {
     
    618616}
    619617
    620 DeclarationNode *DeclarationNode::addName( std::string *newname ) {
     618DeclarationNode * DeclarationNode::addName( std::string * newname ) {
    621619        name = assign_strptr( newname );
    622620        return this;
    623621}
    624622
    625 DeclarationNode *DeclarationNode::addBitfield( ExpressionNode *size ) {
     623DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) {
    626624        bitfieldWidth = size;
    627625        return this;
    628626}
    629627
    630 DeclarationNode *DeclarationNode::addVarArgs() {
     628DeclarationNode * DeclarationNode::addVarArgs() {
    631629        assert( type );
    632630        hasEllipsis = true;
     
    634632}
    635633
    636 DeclarationNode *DeclarationNode::addFunctionBody( StatementNode *body ) {
     634DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) {
    637635        assert( type );
    638636        assert( type->kind == TypeData::Function );
     
    643641}
    644642
    645 DeclarationNode *DeclarationNode::addOldDeclList( DeclarationNode *list ) {
     643DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) {
    646644        assert( type );
    647645        assert( type->kind == TypeData::Function );
     
    651649}
    652650
    653 static void setBase( TypeData *&type, TypeData *newType ) {
     651static void setBase( TypeData *&type, TypeData * newType ) {
    654652        if ( type ) {
    655                 TypeData *prevBase = type;
    656                 TypeData *curBase = type->base;
     653                TypeData * prevBase = type;
     654                TypeData * curBase = type->base;
    657655                while ( curBase != 0 ) {
    658656                        prevBase = curBase;
     
    665663}
    666664
    667 DeclarationNode *DeclarationNode::addPointer( DeclarationNode *p ) {
     665DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    668666        if ( p ) {
    669667                assert( p->type->kind == TypeData::Pointer );
     
    675673}
    676674
    677 DeclarationNode *DeclarationNode::addArray( DeclarationNode *a ) {
     675DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) {
    678676        if ( a ) {
    679677                assert( a->type->kind == TypeData::Array );
     
    685683}
    686684
    687 DeclarationNode *DeclarationNode::addNewPointer( DeclarationNode *p ) {
     685DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
    688686        if ( p ) {
    689687                assert( p->type->kind == TypeData::Pointer );
     
    712710}
    713711
    714 static TypeData *findLast( TypeData *a ) {
     712static TypeData * findLast( TypeData * a ) {
    715713        assert( a );
    716         TypeData *cur = a;
     714        TypeData * cur = a;
    717715        while ( cur->base ) {
    718716                cur = cur->base;
     
    721719}
    722720
    723 DeclarationNode *DeclarationNode::addNewArray( DeclarationNode *a ) {
     721DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
    724722        if ( a ) {
    725723                assert( a->type->kind == TypeData::Array );
    726                 TypeData *lastArray = findLast( a->type );
     724                TypeData * lastArray = findLast( a->type );
    727725                if ( type ) {
    728726                        switch ( type->kind ) {
     
    748746}
    749747
    750 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) {
    751         TypeData *ftype = new TypeData( TypeData::Function );
     748DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) {
     749        TypeData * ftype = new TypeData( TypeData::Function );
    752750        ftype->function.params = params;
    753751        setBase( type, ftype );
     
    755753}
    756754
    757 static TypeData *addIdListToType( TypeData *type, DeclarationNode *ids ) {
     755static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) {
    758756        if ( type ) {
    759757                if ( type->kind != TypeData::Function ) {
     
    764762                return type;
    765763        } else {
    766                 TypeData *newtype = new TypeData( TypeData::Function );
     764                TypeData * newtype = new TypeData( TypeData::Function );
    767765                newtype->function.idList = ids;
    768766                return newtype;
     
    770768}
    771769
    772 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) {
     770DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
    773771        type = addIdListToType( type, ids );
    774772        return this;
    775773}
    776774
    777 DeclarationNode *DeclarationNode::addInitializer( InitializerNode *init ) {
     775DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
    778776        //assert
    779777        initializer = init;
     
    781779}
    782780
    783 DeclarationNode *DeclarationNode::cloneBaseType( string *newName ) {
    784         DeclarationNode *newnode = new DeclarationNode;
    785         TypeData *srcType = type;
     781DeclarationNode * DeclarationNode::cloneBaseType( string * newName ) {
     782        DeclarationNode * newnode = new DeclarationNode;
     783        TypeData * srcType = type;
    786784        while ( srcType->base ) {
    787785                srcType = srcType->base;
     
    806804}
    807805
    808 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) {
     806DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
    809807        if ( o ) {
    810808                o->copyStorageClasses( this );
    811809                if ( type ) {
    812                         TypeData *srcType = type;
     810                        TypeData * srcType = type;
    813811                        while ( srcType->base ) {
    814812                                srcType = srcType->base;
    815813                        } // while
    816                         TypeData *newType = srcType->clone();
     814                        TypeData * newType = srcType->clone();
    817815                        if ( newType->kind == TypeData::AggregateInst ) {
    818816                                // don't duplicate members
     
    838836}
    839837
    840 DeclarationNode *DeclarationNode::cloneType( string *newName ) {
    841         DeclarationNode *newnode = new DeclarationNode;
     838DeclarationNode * DeclarationNode::cloneType( string * newName ) {
     839        DeclarationNode * newnode = new DeclarationNode;
    842840        newnode->type = maybeClone( type );
    843841        assert( storageClass == NoStorageClass );
    844842        newnode->copyStorageClasses( this );
     843        assert( newName );
    845844        newnode->name = assign_strptr( newName );
    846845        return newnode;
    847846}
    848847
    849 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
     848DeclarationNode * DeclarationNode::cloneType( DeclarationNode * o ) {
    850849        if ( o ) {
    851850                assert( storageClass == NoStorageClass );
    852851                o->copyStorageClasses( this );
    853852                if ( type ) {
    854                         TypeData *newType = type->clone();
     853                        TypeData * newType = type->clone();
    855854                        if ( ! o->type ) {
    856855                                o->type = newType;
     
    865864}
    866865
    867 DeclarationNode *DeclarationNode::extractAggregate() const {
     866DeclarationNode * DeclarationNode::extractAggregate() const {
    868867        if ( type ) {
    869                 TypeData *ret = typeextractAggregate( type );
     868                TypeData * ret = typeextractAggregate( type );
    870869                if ( ret ) {
    871                         DeclarationNode *newnode = new DeclarationNode;
     870                        DeclarationNode * newnode = new DeclarationNode;
    872871                        newnode->type = ret;
    873872                        return newnode;
     
    877876}
    878877
    879 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) {
     878void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {
    880879        SemanticError errors;
    881880        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    882         const DeclarationNode *cur = firstNode;
     881        const DeclarationNode * cur = firstNode;
    883882        while ( cur ) {
    884883                try {
    885                         if ( DeclarationNode *extr = cur->extractAggregate() ) {
     884                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    886885                                // handle the case where a structure declaration is contained within an object or type declaration
    887                                 Declaration *decl = extr->build();
     886                                Declaration * decl = extr->build();
    888887                                if ( decl ) {
    889                                         *out++ = decl;
     888                                        * out++ = decl;
    890889                                } // if
    891890                                delete extr;
    892891                        } // if
    893                         Declaration *decl = cur->build();
     892                        Declaration * decl = cur->build();
    894893                        if ( decl ) {
    895                                 *out++ = decl;
     894                                * out++ = decl;
    896895                        } // if
    897896                } catch( SemanticError &e ) {
     
    905904}
    906905
    907 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {
     906void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
    908907        SemanticError errors;
    909908        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    910         const DeclarationNode *cur = firstNode;
     909        const DeclarationNode * cur = firstNode;
    911910        while ( cur ) {
    912911                try {
    913                         Declaration *decl = cur->build();
     912                        Declaration * decl = cur->build();
    914913                        if ( decl ) {
    915                                 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
    916                                         *out++ = dwt;
    917                                 } else if ( StructDecl *agg = dynamic_cast< StructDecl * >( decl ) ) {
    918                                         StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    919                                         *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
     914                                if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     915                                        * out++ = dwt;
     916                                } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     917                                        StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
     918                                        * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
    920919                                        delete agg;
    921                                 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl * >( decl ) ) {
    922                                         UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    923                                         *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
     920                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     921                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
     922                                        * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
    924923                                } // if
    925924                        } // if
     
    934933}
    935934
    936 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {
     935void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
    937936        SemanticError errors;
    938937        std::back_insert_iterator< std::list< Type * > > out( outputList );
    939         const DeclarationNode *cur = firstNode;
     938        const DeclarationNode * cur = firstNode;
    940939        while ( cur ) {
    941940                try {
    942                         *out++ = cur->buildType();
     941                        * out++ = cur->buildType();
    943942                } catch( SemanticError &e ) {
    944943                        errors.append( e );
     
    951950}
    952951
    953 Declaration *DeclarationNode::build() const {
     952Declaration * DeclarationNode::build() const {
    954953        if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
    955954        if ( type ) {
     
    969968}
    970969
    971 Type *DeclarationNode::buildType() const {
     970Type * DeclarationNode::buildType() const {
    972971        assert( type );
    973972
     
    976975                return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
    977976          case TypeData::Aggregate: {
    978                   ReferenceToType *ret;
     977                  ReferenceToType * ret;
    979978                  switch ( type->aggregate.kind ) {
    980979                        case DeclarationNode::Struct:
     
    994993          }
    995994          case TypeData::Symbolic: {
    996                   TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );
     995                  TypeInstType * ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );
    997996                  buildList( type->symbolic.actuals, ret->get_parameters() );
    998997                  return ret;
  • src/Parser/TypeData.cc

    r101e0bd rba7aa2d  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 12 21:11:22 2016
    13 // Update Count     : 377
     12// Last Modified On : Thu Sep 15 23:05:01 2016
     13// Update Count     : 384
    1414//
    1515
     
    487487                return new VarArgsType( buildQualifiers( td ) );
    488488          case TypeData::Attr:
    489                 assert( false );
    490                 return buildAttr( td );
    491489          case TypeData::Symbolic:
    492490          case TypeData::Enum:
Note: See TracChangeset for help on using the changeset viewer.