Ignore:
Timestamp:
Oct 4, 2016, 11:25:00 AM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
40744af8, a7976d79
Parents:
6295081 (diff), 4b1fd2c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r6295081 r19b5d6b  
    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 : Mon Sep 26 22:18:40 2016
     13// Update Count     : 640
    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" );
     
    4646
    4747DeclarationNode::DeclarationNode() :
    48                 type( 0 ),
     48                type( nullptr ),
    4949                storageClass( NoStorageClass ),
    5050                isInline( false ),
    5151                isNoreturn( false ),
    52                 bitfieldWidth( 0 ),
    53                 initializer( 0 ),
     52                bitfieldWidth( nullptr ),
     53                initializer( nullptr ),
    5454                hasEllipsis( false ),
    5555                linkage( ::linkage ),
    5656                extension( false ) {
     57
     58        variable.name = nullptr;
    5759        variable.tyClass = DeclarationNode::Otype;
    5860        variable.assertions = nullptr;
    5961
     62        attr.name = nullptr;
    6063        attr.expr = nullptr;
    6164        attr.type = nullptr;
     
    6366
    6467DeclarationNode::~DeclarationNode() {
     68        delete attr.name;
    6569        delete attr.expr;
    6670        delete attr.type;
     71
     72        delete variable.name;
     73        delete variable.assertions;
     74
    6775        delete type;
    6876        delete bitfieldWidth;
     
    7078}
    7179
    72 DeclarationNode *DeclarationNode::clone() const {
    73         DeclarationNode *newnode = new DeclarationNode;
     80DeclarationNode * DeclarationNode::clone() const {
     81        DeclarationNode * newnode = new DeclarationNode;
    7482        newnode->type = maybeClone( type );
    75         newnode->name = name;
     83        newnode->name = name ? new string( *name ) : nullptr;
    7684        newnode->storageClass = storageClass;
    7785        newnode->isInline = isInline;
     
    8391        newnode->linkage = linkage;
    8492
     93        newnode->variable.name = variable.name ? new string( *variable.name ) : nullptr;
     94        newnode->variable.tyClass = variable.tyClass;
    8595        newnode->variable.assertions = maybeClone( variable.assertions );
    86         newnode->variable.name = variable.name;
    87         newnode->variable.tyClass = variable.tyClass;
    88 
     96
     97        newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
    8998        newnode->attr.expr = maybeClone( attr.expr );
    9099        newnode->attr.type = maybeClone( attr.type );
     
    98107void DeclarationNode::print( std::ostream &os, int indent ) const {
    99108        os << string( indent, ' ' );
    100         if ( name == "" ) {
     109        if ( name ) {
     110                os << *name << ": ";
     111        } else {
    101112                os << "unnamed: ";
    102         } else {
    103                 os << name << ": ";
    104113        } // if
    105114
     
    122131        } // if
    123132
    124         if ( initializer != 0 ) {
     133        if ( initializer ) {
    125134                os << endl << string( indent + 2, ' ' ) << "with initializer ";
    126135                initializer->printOneLine( os );
     
    139148}
    140149
    141 DeclarationNode *DeclarationNode::newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle ) {
    142         DeclarationNode *newnode = new DeclarationNode;
    143         newnode->name = assign_strptr( name );
    144 
     150DeclarationNode * DeclarationNode::newFunction( string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
     151        DeclarationNode * newnode = new DeclarationNode;
     152        newnode->name = name;
    145153        newnode->type = new TypeData( TypeData::Function );
    146154        newnode->type->function.params = param;
    147155        newnode->type->function.newStyle = newStyle;
    148156        newnode->type->function.body = body;
    149         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     157        // ignore unnamed routine declarations: void p( int (*)(int) );
     158        if ( newnode->name ) {
     159                typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
     160        } // if
    150161
    151162        if ( body ) {
     
    155166        if ( ret ) {
    156167                newnode->type->base = ret->type;
    157                 ret->type = 0;
     168                ret->type = nullptr;
    158169                delete ret;
    159170        } // if
     
    163174
    164175DeclarationNode * DeclarationNode::newQualifier( Qualifier q ) {
    165         DeclarationNode *newnode = new DeclarationNode;
     176        DeclarationNode * newnode = new DeclarationNode;
    166177        newnode->type = new TypeData();
    167178        newnode->type->qualifiers[ q ] = 1;
     
    169180} // DeclarationNode::newQualifier
    170181
    171 DeclarationNode * DeclarationNode::newForall( DeclarationNode *forall ) {
    172         DeclarationNode *newnode = new DeclarationNode;
     182DeclarationNode * DeclarationNode::newForall( DeclarationNode * forall ) {
     183        DeclarationNode * newnode = new DeclarationNode;
    173184        newnode->type = new TypeData( TypeData::Unknown );
    174185        newnode->type->forall = forall;
     
    177188
    178189DeclarationNode * 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         //}
     190        DeclarationNode * newnode = new DeclarationNode;
    185191        newnode->storageClass = sc;
    186192        return newnode;
     
    188194
    189195DeclarationNode * DeclarationNode::newBasicType( BasicType bt ) {
    190         DeclarationNode *newnode = new DeclarationNode;
     196        DeclarationNode * newnode = new DeclarationNode;
    191197        newnode->type = new TypeData( TypeData::Basic );
    192198        newnode->type->basictype = bt;
     
    195201
    196202DeclarationNode * DeclarationNode::newComplexType( ComplexType ct ) {
    197         DeclarationNode *newnode = new DeclarationNode;
     203        DeclarationNode * newnode = new DeclarationNode;
    198204        newnode->type = new TypeData( TypeData::Basic );
    199205        newnode->type->complextype = ct;
     
    202208
    203209DeclarationNode * DeclarationNode::newSignedNess( Signedness sn ) {
    204         DeclarationNode *newnode = new DeclarationNode;
     210        DeclarationNode * newnode = new DeclarationNode;
    205211        newnode->type = new TypeData( TypeData::Basic );
    206212        newnode->type->signedness = sn;
     
    209215
    210216DeclarationNode * DeclarationNode::newLength( Length lnth ) {
    211         DeclarationNode *newnode = new DeclarationNode;
     217        DeclarationNode * newnode = new DeclarationNode;
    212218        newnode->type = new TypeData( TypeData::Basic );
    213219        newnode->type->length = lnth;
     
    215221} // DeclarationNode::newLength
    216222
    217 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) {
    218         DeclarationNode *newnode = new DeclarationNode;
     223DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
     224        DeclarationNode * newnode = new DeclarationNode;
    219225        newnode->type = new TypeData( TypeData::SymbolicInst );
    220         newnode->type->symbolic.name = assign_strptr( name );
     226        newnode->type->symbolic.name = name;
    221227        newnode->type->symbolic.isTypedef = true;
    222         newnode->type->symbolic.params = 0;
     228        newnode->type->symbolic.params = nullptr;
    223229        return newnode;
    224230} // DeclarationNode::newFromTypedef
    225231
    226 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body ) {
    227         DeclarationNode *newnode = new DeclarationNode;
     232DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     233        DeclarationNode * newnode = new DeclarationNode;
    228234        newnode->type = new TypeData( TypeData::Aggregate );
    229235        newnode->type->aggregate.kind = kind;
    230         newnode->type->aggregate.name = assign_strptr( name );
    231         if ( newnode->type->aggregate.name == "" ) {            // anonymous aggregate ?
    232                 newnode->type->aggregate.name = anonymous.newName();
     236        if ( name ) {
     237                newnode->type->aggregate.name = name;
     238        } else {                                                                                        // anonymous aggregate ?
     239                newnode->type->aggregate.name = new string( anonymous.newName() );
    233240        } // if
    234241        newnode->type->aggregate.actuals = actuals;
     
    238245} // DeclarationNode::newAggregate
    239246
    240 DeclarationNode *DeclarationNode::newEnum( std::string *name, DeclarationNode *constants ) {
    241         DeclarationNode *newnode = new DeclarationNode;
    242         newnode->name = assign_strptr( name );
     247DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants ) {
     248        DeclarationNode * newnode = new DeclarationNode;
    243249        newnode->type = new TypeData( TypeData::Enum );
    244         newnode->type->enumeration.name = newnode->name;
    245         if ( newnode->type->enumeration.name == "" ) {          // anonymous enumeration ?
    246                 newnode->type->enumeration.name = DeclarationNode::anonymous.newName();
     250        if ( name ) {
     251                newnode->type->enumeration.name = name;
     252        } else {                                                                                        // anonymous aggregate ?
     253                newnode->type->enumeration.name = new string( anonymous.newName() );
    247254        } // if
    248255        newnode->type->enumeration.constants = constants;
     
    250257} // DeclarationNode::newEnum
    251258
    252 DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    253         DeclarationNode *newnode = new DeclarationNode;
    254         newnode->name = assign_strptr( name );
     259DeclarationNode * DeclarationNode::newEnumConstant( string * name, ExpressionNode * constant ) {
     260        DeclarationNode * newnode = new DeclarationNode;
     261        newnode->name = name;
    255262        newnode->enumeratorValue.reset( constant );
    256         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     263        typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
    257264        return newnode;
    258265} // DeclarationNode::newEnumConstant
    259266
    260 DeclarationNode *DeclarationNode::newName( std::string *name ) {
    261         DeclarationNode *newnode = new DeclarationNode;
    262         newnode->name = assign_strptr( name );
     267DeclarationNode * DeclarationNode::newName( string * name ) {
     268        DeclarationNode * newnode = new DeclarationNode;
     269        newnode->name = name;
    263270        return newnode;
    264271} // DeclarationNode::newName
    265272
    266 DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
    267         DeclarationNode *newnode = new DeclarationNode;
     273DeclarationNode * DeclarationNode::newFromTypeGen( string * name, ExpressionNode * params ) {
     274        DeclarationNode * newnode = new DeclarationNode;
    268275        newnode->type = new TypeData( TypeData::SymbolicInst );
    269         newnode->type->symbolic.name = assign_strptr( name );
     276        newnode->type->symbolic.name = name;
    270277        newnode->type->symbolic.isTypedef = false;
    271278        newnode->type->symbolic.actuals = params;
     
    273280} // DeclarationNode::newFromTypeGen
    274281
    275 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
    276         DeclarationNode *newnode = new DeclarationNode;
    277         newnode->name = assign_strptr( name );
    278         newnode->type = new TypeData( TypeData::Variable );
     282DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, string * name ) {
     283        DeclarationNode * newnode = new DeclarationNode;
     284        newnode->type = nullptr;
    279285        newnode->variable.tyClass = tc;
    280         newnode->variable.name = newnode->name;
     286        newnode->variable.name = name;
    281287        return newnode;
    282288} // DeclarationNode::newTypeParam
    283289
    284 DeclarationNode *DeclarationNode::newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ) {
    285         DeclarationNode *newnode = new DeclarationNode;
     290DeclarationNode * DeclarationNode::newTrait( const string * name, DeclarationNode * params, DeclarationNode * asserts ) {
     291        DeclarationNode * newnode = new DeclarationNode;
    286292        newnode->type = new TypeData( TypeData::Aggregate );
     293        newnode->type->aggregate.name = name;
    287294        newnode->type->aggregate.kind = Trait;
    288295        newnode->type->aggregate.params = params;
    289296        newnode->type->aggregate.fields = asserts;
    290         newnode->type->aggregate.name = assign_strptr( name );
    291297        return newnode;
    292298} // DeclarationNode::newTrait
    293299
    294 DeclarationNode *DeclarationNode::newTraitUse( std::string *name, ExpressionNode *params ) {
    295         DeclarationNode *newnode = new DeclarationNode;
     300DeclarationNode * DeclarationNode::newTraitUse( const string * name, ExpressionNode * params ) {
     301        DeclarationNode * newnode = new DeclarationNode;
    296302        newnode->type = new TypeData( TypeData::AggregateInst );
    297303        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    298304        newnode->type->aggInst.aggregate->aggregate.kind = Trait;
    299         newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );
     305        newnode->type->aggInst.aggregate->aggregate.name = name;
    300306        newnode->type->aggInst.params = params;
    301307        return newnode;
    302308} // DeclarationNode::newTraitUse
    303309
    304 DeclarationNode *DeclarationNode::newTypeDecl( std::string *name, DeclarationNode *typeParams ) {
    305         DeclarationNode *newnode = new DeclarationNode;
    306         newnode->name = assign_strptr( name );
     310DeclarationNode * DeclarationNode::newTypeDecl( string * name, DeclarationNode * typeParams ) {
     311        DeclarationNode * newnode = new DeclarationNode;
    307312        newnode->type = new TypeData( TypeData::Symbolic );
    308313        newnode->type->symbolic.isTypedef = false;
    309314        newnode->type->symbolic.params = typeParams;
    310         newnode->type->symbolic.name = newnode->name;
     315        newnode->type->symbolic.name = name;
    311316        return newnode;
    312317} // DeclarationNode::newTypeDecl
    313318
    314 DeclarationNode *DeclarationNode::newPointer( DeclarationNode *qualifiers ) {
    315         DeclarationNode *newnode = new DeclarationNode;
     319DeclarationNode * DeclarationNode::newPointer( DeclarationNode * qualifiers ) {
     320        DeclarationNode * newnode = new DeclarationNode;
    316321        newnode->type = new TypeData( TypeData::Pointer );
    317322        return newnode->addQualifiers( qualifiers );
    318323} // DeclarationNode::newPointer
    319324
    320 DeclarationNode *DeclarationNode::newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ) {
    321         DeclarationNode *newnode = new DeclarationNode;
     325DeclarationNode * DeclarationNode::newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ) {
     326        DeclarationNode * newnode = new DeclarationNode;
    322327        newnode->type = new TypeData( TypeData::Array );
    323328        newnode->type->array.dimension = size;
    324329        newnode->type->array.isStatic = isStatic;
    325         if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) {
     330        if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
    326331                newnode->type->array.isVarLen = false;
    327332        } else {
     
    331336} // DeclarationNode::newArray
    332337
    333 DeclarationNode *DeclarationNode::newVarArray( DeclarationNode *qualifiers ) {
    334         DeclarationNode *newnode = new DeclarationNode;
     338DeclarationNode * DeclarationNode::newVarArray( DeclarationNode * qualifiers ) {
     339        DeclarationNode * newnode = new DeclarationNode;
    335340        newnode->type = new TypeData( TypeData::Array );
    336         newnode->type->array.dimension = 0;
     341        newnode->type->array.dimension = nullptr;
    337342        newnode->type->array.isStatic = false;
    338343        newnode->type->array.isVarLen = true;
     
    340345}
    341346
    342 DeclarationNode *DeclarationNode::newBitfield( ExpressionNode *size ) {
    343         DeclarationNode *newnode = new DeclarationNode;
     347DeclarationNode * DeclarationNode::newBitfield( ExpressionNode * size ) {
     348        DeclarationNode * newnode = new DeclarationNode;
    344349        newnode->bitfieldWidth = size;
    345350        return newnode;
    346351}
    347352
    348 DeclarationNode *DeclarationNode::newTuple( DeclarationNode *members ) {
    349         DeclarationNode *newnode = new DeclarationNode;
     353DeclarationNode * DeclarationNode::newTuple( DeclarationNode * members ) {
     354        DeclarationNode * newnode = new DeclarationNode;
    350355        newnode->type = new TypeData( TypeData::Tuple );
    351356        newnode->type->tuple = members;
     
    353358}
    354359
    355 DeclarationNode *DeclarationNode::newTypeof( ExpressionNode *expr ) {
    356         DeclarationNode *newnode = new DeclarationNode;
     360DeclarationNode * DeclarationNode::newTypeof( ExpressionNode * expr ) {
     361        DeclarationNode * newnode = new DeclarationNode;
    357362        newnode->type = new TypeData( TypeData::Typeof );
    358363        newnode->type->typeexpr = expr;
     
    361366
    362367DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {
    363         DeclarationNode *newnode = new DeclarationNode;
     368        DeclarationNode * newnode = new DeclarationNode;
    364369        newnode->type = new TypeData( TypeData::Builtin );
    365370        newnode->builtin = bt;
     
    367372} // DeclarationNode::newBuiltinType
    368373
    369 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) {
    370         DeclarationNode *newnode = new DeclarationNode;
    371         newnode->type = new TypeData( TypeData::Attr );
    372         newnode->attr.name = assign_strptr( name );
     374DeclarationNode * DeclarationNode::newAttr( string * name, ExpressionNode * expr ) {
     375        DeclarationNode * newnode = new DeclarationNode;
     376        newnode->type = nullptr;
     377        newnode->attr.name = name;
    373378        newnode->attr.expr = expr;
    374379        return newnode;
    375380}
    376381
    377 DeclarationNode *DeclarationNode::newAttr( std::string *name, DeclarationNode *type ) {
    378         DeclarationNode *newnode = new DeclarationNode;
    379         newnode->type = new TypeData( TypeData::Attr );
    380         newnode->attr.name = assign_strptr( name );
     382DeclarationNode * DeclarationNode::newAttr( string * name, DeclarationNode * type ) {
     383        DeclarationNode * newnode = new DeclarationNode;
     384        newnode->type = nullptr;
     385        newnode->attr.name = name;
    381386        newnode->attr.type = type;
    382387        return newnode;
     
    389394} // appendError
    390395
    391 void DeclarationNode::checkQualifiers( const TypeData *src, const TypeData *dst ) {
     396void DeclarationNode::checkQualifiers( const TypeData * src, const TypeData * dst ) {
    392397        TypeData::Qualifiers qsrc = src->qualifiers, qdst = dst->qualifiers; // optimization
    393398
     
    401406} // DeclarationNode::checkQualifiers
    402407
    403 void DeclarationNode::checkStorageClasses( DeclarationNode *q ) {
     408void DeclarationNode::checkStorageClasses( DeclarationNode * q ) {
    404409        if ( storageClass != NoStorageClass && q->storageClass != NoStorageClass ) {
    405410                if ( storageClass == q->storageClass ) {                // duplicate qualifier
     
    413418} // DeclarationNode::copyStorageClasses
    414419
    415 DeclarationNode *DeclarationNode::copyStorageClasses( DeclarationNode *q ) {
     420DeclarationNode * DeclarationNode::copyStorageClasses( DeclarationNode * q ) {
    416421        isInline = isInline || q->isInline;
    417422        isNoreturn = isNoreturn || q->isNoreturn;
     
    424429} // DeclarationNode::copyStorageClasses
    425430
    426 static void addQualifiersToType( TypeData *&src, TypeData *dst ) {
     431static void addQualifiersToType( TypeData *&src, TypeData * dst ) {
    427432        if ( src->forall && dst->kind == TypeData::Function ) {
    428433                if ( dst->forall ) {
     
    431436                        dst->forall = src->forall;
    432437                } // if
    433                 src->forall = 0;
     438                src->forall = nullptr;
    434439        } // if
    435440        if ( dst->base ) {
     
    437442        } else if ( dst->kind == TypeData::Function ) {
    438443                dst->base = src;
    439                 src = 0;
     444                src = nullptr;
    440445        } else {
    441446                dst->qualifiers |= src->qualifiers;
     
    443448} // addQualifiersToType
    444449
    445 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) {
    446         if ( ! q ) return this;
     450DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
     451        if ( ! q ) { delete q; return this; }
    447452
    448453        checkStorageClasses( q );
    449454        copyStorageClasses( q );
    450455
    451         if ( ! q->type ) { delete q; return this; }
     456        if ( ! q->type ) {
     457                delete q;
     458                return this;
     459        } // if
    452460
    453461        if ( ! type ) {
    454 //              type = new TypeData;
    455                 type = q->type;
     462                type = q->type;                                                                 // reuse this structure
     463                q->type = nullptr;
     464                delete q;
    456465                return this;
    457466        } // if
     
    467476                                type->aggregate.params = q->type->forall;
    468477                                // change implicit typedef from TYPEDEFname to TYPEGENname
    469                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
     478                                typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG );
    470479                        } else {
    471480                                type->forall = q->type->forall;
    472481                        } // if
    473482                } // if
    474                 q->type->forall = 0;
     483                q->type->forall = nullptr;
    475484        } // if
    476485        delete q;
     
    485494                        dst->forall = src->forall;
    486495                } // if
    487                 src->forall = 0;
     496                src->forall = nullptr;
    488497        } // if
    489498        if ( dst->base ) {
     
    494503                        src->qualifiers |= dst->qualifiers;
    495504                        dst = src;
    496                         src = 0;
     505                        src = nullptr;
    497506                        break;
    498507                  case TypeData::Basic:
     
    504513                                        dst->basictype = src->basictype;
    505514                                } else if ( src->basictype != DeclarationNode::NoBasicType )
    506                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
     515                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::basicTypeName[ src->basictype ] + " in type: ", src );
    507516
    508517                                if ( dst->complextype == DeclarationNode::NoComplexType ) {
    509518                                        dst->complextype = src->complextype;
    510519                                } else if ( src->complextype != DeclarationNode::NoComplexType )
    511                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
     520                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::complexTypeName[ src->complextype ] + " in type: ", src );
    512521
    513522                                if ( dst->signedness == DeclarationNode::NoSignedness ) {
    514523                                        dst->signedness = src->signedness;
    515524                                } else if ( src->signedness != DeclarationNode::NoSignedness )
    516                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
     525                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::signednessName[ src->signedness ] + " in type: ", src );
    517526
    518527                                if ( dst->length == DeclarationNode::NoLength ) {
     
    521530                                        dst->length = DeclarationNode::LongLong;
    522531                                } else if ( src->length != DeclarationNode::NoLength )
    523                                         throw SemanticError( std::string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
     532                                        throw SemanticError( string( "conflicting type specifier " ) + DeclarationNode::lengthName[ src->length ] + " in type: ", src );
    524533                        } // if
    525534                        break;
     
    534543                                } // if
    535544                                dst->base->qualifiers |= src->qualifiers;
    536                                 src = 0;
     545                                src = nullptr;
    537546                                break;
    538547                          default:
     
    542551                                        dst->forall = src->forall;
    543552                                } // if
    544                                 src->forall = 0;
     553                                src->forall = nullptr;
    545554                                dst->base = src;
    546                                 src = 0;
     555                                src = nullptr;
    547556                        } // switch
    548557                } // switch
     
    550559}
    551560
    552 DeclarationNode *DeclarationNode::addType( DeclarationNode *o ) {
     561DeclarationNode * DeclarationNode::addType( DeclarationNode * o ) {
    553562        if ( o ) {
    554563                checkStorageClasses( o );
     
    566575                                        type = o->type;
    567576                                } // if
    568                                 o->type = 0;
     577                                o->type = nullptr;
    569578                        } else {
    570579                                addTypeToType( o->type, type );
     
    584593}
    585594
    586 DeclarationNode *DeclarationNode::addTypedef() {
    587         TypeData *newtype = new TypeData( TypeData::Symbolic );
    588         newtype->symbolic.params = 0;
     595DeclarationNode * DeclarationNode::addTypedef() {
     596        TypeData * newtype = new TypeData( TypeData::Symbolic );
     597        newtype->symbolic.params = nullptr;
    589598        newtype->symbolic.isTypedef = true;
    590         newtype->symbolic.name = name;
     599        newtype->symbolic.name = name ? new string( *name ) : nullptr;
    591600        newtype->base = type;
    592601        type = newtype;
     
    594603}
    595604
    596 DeclarationNode *DeclarationNode::addAssertions( DeclarationNode *assertions ) {
     605DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
     606        if ( variable.name ) {
     607                if ( variable.assertions ) {
     608                        variable.assertions->appendList( assertions );
     609                } else {
     610                        variable.assertions = assertions;
     611                } // if
     612                return this;
     613        } // if
     614
    597615        assert( type );
    598616        switch ( type->kind ) {
     
    604622                } // if
    605623                break;
    606           case TypeData::Variable:
    607                 if ( variable.assertions ) {
    608                         variable.assertions->appendList( assertions );
    609                 } else {
    610                         variable.assertions = assertions;
    611                 } // if
    612                 break;
     624          // case TypeData::Variable:
     625          //    if ( variable.assertions ) {
     626          //            variable.assertions->appendList( assertions );
     627          //    } else {
     628          //            variable.assertions = assertions;
     629          //    } // if
     630          //    break;
    613631          default:
    614632                assert( false );
     
    618636}
    619637
    620 DeclarationNode *DeclarationNode::addName( std::string *newname ) {
    621         name = assign_strptr( newname );
    622         return this;
    623 }
    624 
    625 DeclarationNode *DeclarationNode::addBitfield( ExpressionNode *size ) {
     638DeclarationNode * DeclarationNode::addName( string * newname ) {
     639        assert( ! name );
     640        name = newname;
     641        return this;
     642}
     643
     644DeclarationNode * DeclarationNode::addBitfield( ExpressionNode * size ) {
    626645        bitfieldWidth = size;
    627646        return this;
    628647}
    629648
    630 DeclarationNode *DeclarationNode::addVarArgs() {
     649DeclarationNode * DeclarationNode::addVarArgs() {
    631650        assert( type );
    632651        hasEllipsis = true;
     
    634653}
    635654
    636 DeclarationNode *DeclarationNode::addFunctionBody( StatementNode *body ) {
     655DeclarationNode * DeclarationNode::addFunctionBody( StatementNode * body ) {
    637656        assert( type );
    638657        assert( type->kind == TypeData::Function );
    639         assert( type->function.body == 0 );
     658        assert( ! type->function.body );
    640659        type->function.body = body;
    641660        type->function.hasBody = true;
     
    643662}
    644663
    645 DeclarationNode *DeclarationNode::addOldDeclList( DeclarationNode *list ) {
     664DeclarationNode * DeclarationNode::addOldDeclList( DeclarationNode * list ) {
    646665        assert( type );
    647666        assert( type->kind == TypeData::Function );
    648         assert( type->function.oldDeclList == 0 );
     667        assert( ! type->function.oldDeclList );
    649668        type->function.oldDeclList = list;
    650669        return this;
    651670}
    652671
    653 static void setBase( TypeData *&type, TypeData *newType ) {
     672static void setBase( TypeData *&type, TypeData * newType ) {
    654673        if ( type ) {
    655                 TypeData *prevBase = type;
    656                 TypeData *curBase = type->base;
    657                 while ( curBase != 0 ) {
     674                TypeData * prevBase = type;
     675                TypeData * curBase = type->base;
     676                while ( curBase != nullptr ) {
    658677                        prevBase = curBase;
    659678                        curBase = curBase->base;
     
    665684}
    666685
    667 DeclarationNode *DeclarationNode::addPointer( DeclarationNode *p ) {
     686DeclarationNode * DeclarationNode::addPointer( DeclarationNode * p ) {
    668687        if ( p ) {
    669688                assert( p->type->kind == TypeData::Pointer );
    670689                setBase( type, p->type );
    671                 p->type = 0;
     690                p->type = nullptr;
    672691                delete p;
    673692        } // if
     
    675694}
    676695
    677 DeclarationNode *DeclarationNode::addArray( DeclarationNode *a ) {
     696DeclarationNode * DeclarationNode::addArray( DeclarationNode * a ) {
    678697        if ( a ) {
    679698                assert( a->type->kind == TypeData::Array );
    680699                setBase( type, a->type );
    681                 a->type = 0;
     700                a->type = nullptr;
    682701                delete a;
    683702        } // if
     
    685704}
    686705
    687 DeclarationNode *DeclarationNode::addNewPointer( DeclarationNode *p ) {
     706DeclarationNode * DeclarationNode::addNewPointer( DeclarationNode * p ) {
    688707        if ( p ) {
    689708                assert( p->type->kind == TypeData::Pointer );
     
    703722                                p->type->base = type;
    704723                        } // switch
    705                         type = 0;
     724                        type = nullptr;
    706725                } // if
    707726                delete this;
     
    712731}
    713732
    714 static TypeData *findLast( TypeData *a ) {
     733static TypeData * findLast( TypeData * a ) {
    715734        assert( a );
    716         TypeData *cur = a;
     735        TypeData * cur = a;
    717736        while ( cur->base ) {
    718737                cur = cur->base;
     
    721740}
    722741
    723 DeclarationNode *DeclarationNode::addNewArray( DeclarationNode *a ) {
     742DeclarationNode * DeclarationNode::addNewArray( DeclarationNode * a ) {
    724743        if ( a ) {
    725744                assert( a->type->kind == TypeData::Array );
    726                 TypeData *lastArray = findLast( a->type );
     745                TypeData * lastArray = findLast( a->type );
    727746                if ( type ) {
    728747                        switch ( type->kind ) {
     
    739758                                lastArray->base = type;
    740759                        } // switch
    741                         type = 0;
     760                        type = nullptr;
    742761                } // if
    743762                delete this;
     
    748767}
    749768
    750 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) {
    751         TypeData *ftype = new TypeData( TypeData::Function );
     769DeclarationNode * DeclarationNode::addParamList( DeclarationNode * params ) {
     770        TypeData * ftype = new TypeData( TypeData::Function );
    752771        ftype->function.params = params;
    753772        setBase( type, ftype );
     
    755774}
    756775
    757 static TypeData *addIdListToType( TypeData *type, DeclarationNode *ids ) {
     776static TypeData * addIdListToType( TypeData * type, DeclarationNode * ids ) {
    758777        if ( type ) {
    759778                if ( type->kind != TypeData::Function ) {
     
    764783                return type;
    765784        } else {
    766                 TypeData *newtype = new TypeData( TypeData::Function );
     785                TypeData * newtype = new TypeData( TypeData::Function );
    767786                newtype->function.idList = ids;
    768787                return newtype;
    769788        } // if
    770 }
    771 
    772 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) {
     789} // addIdListToType
     790
     791DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
    773792        type = addIdListToType( type, ids );
    774793        return this;
    775794}
    776795
    777 DeclarationNode *DeclarationNode::addInitializer( InitializerNode *init ) {
    778         //assert
     796DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
    779797        initializer = init;
    780798        return this;
    781799}
    782800
    783 DeclarationNode *DeclarationNode::cloneBaseType( string *newName ) {
    784         DeclarationNode *newnode = new DeclarationNode;
    785         TypeData *srcType = type;
    786         while ( srcType->base ) {
    787                 srcType = srcType->base;
    788         } // while
    789         newnode->type = maybeClone( srcType );
    790         if ( newnode->type->kind == TypeData::AggregateInst ) {
    791                 // don't duplicate members
    792                 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) {
    793                         delete newnode->type->aggInst.aggregate->enumeration.constants;
    794                         newnode->type->aggInst.aggregate->enumeration.constants = 0;
    795                 } else {
    796                         assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate );
    797                         delete newnode->type->aggInst.aggregate->aggregate.fields;
    798                         newnode->type->aggInst.aggregate->aggregate.fields = 0;
    799                 } // if
    800         } // if
    801         newnode->type->forall = maybeClone( type->forall );
    802         assert( storageClass == NoStorageClass );
    803         newnode->copyStorageClasses( this );
    804         newnode->name = assign_strptr( newName );
    805         return newnode;
    806 }
    807 
    808 DeclarationNode *DeclarationNode::cloneBaseType( DeclarationNode *o ) {
    809         if ( o ) {
    810                 o->copyStorageClasses( this );
    811                 if ( type ) {
    812                         TypeData *srcType = type;
    813                         while ( srcType->base ) {
    814                                 srcType = srcType->base;
    815                         } // while
    816                         TypeData *newType = srcType->clone();
    817                         if ( newType->kind == TypeData::AggregateInst ) {
    818                                 // don't duplicate members
    819                                 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
    820                                         delete newType->aggInst.aggregate->enumeration.constants;
    821                                         newType->aggInst.aggregate->enumeration.constants = 0;
    822                                 } else {
    823                                         assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
    824                                         delete newType->aggInst.aggregate->aggregate.fields;
    825                                         newType->aggInst.aggregate->aggregate.fields = 0;
    826                                 } // if
    827                         } // if
    828                         newType->forall = maybeClone( type->forall );
    829                         if ( ! o->type ) {
    830                                 o->type = newType;
    831                         } else {
    832                                 addTypeToType( newType, o->type );
    833                                 delete newType;
    834                         } // if
    835                 } // if
    836         } // if
    837         return o;
    838 }
    839 
    840 DeclarationNode *DeclarationNode::cloneType( string *newName ) {
    841         DeclarationNode *newnode = new DeclarationNode;
     801DeclarationNode * DeclarationNode::cloneType( string * newName ) {
     802        DeclarationNode * newnode = new DeclarationNode;
    842803        newnode->type = maybeClone( type );
    843804        assert( storageClass == NoStorageClass );
    844805        newnode->copyStorageClasses( this );
    845         newnode->name = assign_strptr( newName );
    846         return newnode;
    847 }
    848 
    849 DeclarationNode *DeclarationNode::cloneType( DeclarationNode *o ) {
    850         if ( o ) {
    851                 assert( storageClass == NoStorageClass );
    852                 o->copyStorageClasses( this );
    853                 if ( type ) {
    854                         TypeData *newType = type->clone();
    855                         if ( ! o->type ) {
    856                                 o->type = newType;
     806        assert( newName );
     807        newnode->name = newName;
     808        return newnode;
     809}
     810
     811DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
     812        if ( ! o ) return nullptr;
     813
     814        o->copyStorageClasses( this );
     815        if ( type ) {
     816                TypeData * srcType = type;
     817
     818                while ( srcType->base ) {
     819                        srcType = srcType->base;
     820                } // while
     821
     822                TypeData * newType = srcType->clone();
     823                if ( newType->kind == TypeData::AggregateInst ) {
     824                        // don't duplicate members
     825                        if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
     826                                delete newType->aggInst.aggregate->enumeration.constants;
     827                                newType->aggInst.aggregate->enumeration.constants = nullptr;
    857828                        } else {
    858                                 addTypeToType( newType, o->type );
    859                                 delete newType;
     829                                assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
     830                                delete newType->aggInst.aggregate->aggregate.fields;
     831                                newType->aggInst.aggregate->aggregate.fields = nullptr;
    860832                        } // if
    861833                } // if
    862         } // if
    863         delete o;
     834
     835                newType->forall = maybeClone( type->forall );
     836                if ( ! o->type ) {
     837                        o->type = newType;
     838                } else {
     839                        addTypeToType( newType, o->type );
     840                        delete newType;
     841                } // if
     842        } // if
    864843        return o;
    865844}
    866845
    867 DeclarationNode *DeclarationNode::extractAggregate() const {
     846DeclarationNode * DeclarationNode::extractAggregate() const {
    868847        if ( type ) {
    869                 TypeData *ret = typeextractAggregate( type );
     848                TypeData * ret = typeextractAggregate( type );
    870849                if ( ret ) {
    871                         DeclarationNode *newnode = new DeclarationNode;
     850                        DeclarationNode * newnode = new DeclarationNode;
    872851                        newnode->type = ret;
    873852                        return newnode;
    874853                } // if
    875854        } // if
    876         return 0;
    877 }
    878 
    879 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) {
     855        return nullptr;
     856}
     857
     858void buildList( const DeclarationNode * firstNode, std::list< Declaration * > &outputList ) {
    880859        SemanticError errors;
    881860        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    882         const DeclarationNode *cur = firstNode;
     861        const DeclarationNode * cur = firstNode;
     862
    883863        while ( cur ) {
    884864                try {
    885                         if ( DeclarationNode *extr = cur->extractAggregate() ) {
     865                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    886866                                // handle the case where a structure declaration is contained within an object or type declaration
    887                                 Declaration *decl = extr->build();
     867                                Declaration * decl = extr->build();
    888868                                if ( decl ) {
    889                                         *out++ = decl;
     869                                        * out++ = decl;
    890870                                } // if
    891871                                delete extr;
    892872                        } // if
    893                         Declaration *decl = cur->build();
     873
     874                        Declaration * decl = cur->build();
    894875                        if ( decl ) {
    895                                 *out++ = decl;
     876                                * out++ = decl;
    896877                        } // if
    897878                } catch( SemanticError &e ) {
     
    900881                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    901882        } // while
     883
    902884        if ( ! errors.isEmpty() ) {
    903885                throw errors;
    904886        } // if
    905 }
    906 
    907 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ) {
     887} // buildList
     888
     889void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
    908890        SemanticError errors;
    909891        std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
    910         const DeclarationNode *cur = firstNode;
     892        const DeclarationNode * cur = firstNode;
    911893        while ( cur ) {
    912894                try {
    913                         Declaration *decl = cur->build();
     895                        Declaration * decl = cur->build();
    914896                        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 );
     897                                if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( decl ) ) {
     898                                        * out++ = dwt;
     899                                } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
     900                                        StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
     901                                        * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
    920902                                        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 );
     903                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
     904                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
     905                                        * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
    924906                                } // if
    925907                        } // if
     
    932914                throw errors;
    933915        } // if
    934 }
    935 
    936 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ) {
     916} // buildList
     917
     918void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
    937919        SemanticError errors;
    938920        std::back_insert_iterator< std::list< Type * > > out( outputList );
    939         const DeclarationNode *cur = firstNode;
     921        const DeclarationNode * cur = firstNode;
     922
    940923        while ( cur ) {
    941924                try {
    942                         *out++ = cur->buildType();
     925                        * out++ = cur->buildType();
    943926                } catch( SemanticError &e ) {
    944927                        errors.append( e );
     
    946929                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    947930        } // while
     931
    948932        if ( ! errors.isEmpty() ) {
    949933                throw errors;
    950934        } // if
    951 }
    952 
    953 Declaration *DeclarationNode::build() const {
     935} // buildTypeList
     936
     937Declaration * DeclarationNode::build() const {
    954938        if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
     939
     940        if ( variable.name ) {
     941                static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     942                TypeDecl * ret = new TypeDecl( *variable.name, DeclarationNode::NoStorageClass, nullptr, kindMap[ variable.tyClass ] );
     943                buildList( variable.assertions, ret->get_assertions() );
     944                return ret;
     945        } // if
     946
    955947        if ( type ) {
    956                 if ( type->kind == TypeData::Variable ) {
    957                         static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    958                         TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] );
    959                         buildList( variable.assertions, ret->get_assertions() );
    960                         return ret;
     948                return buildDecl( type, name ? *name : string( "" ), storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     949        } // if
     950
     951        if ( ! isInline && ! isNoreturn ) {
     952                assertf( name, "ObjectDecl are assumed to have names\n" );
     953                return (new ObjectDecl( *name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
     954        } // if
     955
     956        throw SemanticError( "invalid function specifier ", this );
     957}
     958
     959Type * DeclarationNode::buildType() const {
     960        assert( type );
     961
     962        if ( attr.name ) {
     963                AttrType * ret;
     964                if ( attr.expr ) {
     965                        ret = new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() );
    961966                } else {
    962                         return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    963                 } // if
    964         } // if
    965         if ( ! isInline && ! isNoreturn ) {
    966                 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    967         } // if
    968         throw SemanticError( "invalid function specifier ", this );
    969 }
    970 
    971 Type *DeclarationNode::buildType() const {
    972         assert( type );
     967                        assert( attr.type );
     968                        ret = new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() );
     969                } // if
     970                return ret;
     971        } // if
    973972
    974973        switch ( type->kind ) {
    975974          case TypeData::Enum:
    976                 return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
     975                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:
    981                           ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );
     980                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    982981                          break;
    983982                        case DeclarationNode::Union:
    984                           ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );
     983                          ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    985984                          break;
    986985                        case DeclarationNode::Trait:
    987                           ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );
     986                          ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    988987                          break;
    989988                        default:
     
    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() );
    998                   return ret;
    999           }
    1000           case TypeData::Attr: {
    1001                   assert( type->kind == TypeData::Attr );
    1002                   // assert( type->attr );
    1003                   AttrType * ret;
    1004                   if ( attr.expr ) {
    1005                           ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );
    1006                   } else {
    1007                           assert( attr.type );
    1008                           ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );
    1009                   } // if
    1010997                  return ret;
    1011998          }
Note: See TracChangeset for help on using the changeset viewer.