Changeset 2298f728 for src


Ignore:
Timestamp:
Sep 24, 2016, 12:08:02 PM (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:
9c23f31
Parents:
1b77274
Message:

more refactoring of parser code

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r1b77274 r2298f728  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 19:13:21 2016
    13 // Update Count     : 26
     12// Last Modified On : Fri Sep 23 11:46:47 2016
     13// Update Count     : 28
    1414//
    1515
     
    102102                } // if
    103103        } // for
    104 }
    105 
    106 static inline std::string assign_strptr( const std::string *str ) {
    107         std::string tmp( *str );
    108         delete str;
    109         return tmp;
    110104}
    111105
     
    137131
    138132template < typename T >
    139 void toString_single ( std::ostream & os, const T & value ) {
     133void toString_single( std::ostream & os, const T & value ) {
    140134        os << value;
    141135}
    142136
    143137template < typename T, typename... Params >
    144 void toString_single ( std::ostream & os, const T & value, const Params & ... params ) {
     138void toString_single( std::ostream & os, const T & value, const Params & ... params ) {
    145139        os << value;
    146140        toString_single( os, params ... );
     
    148142
    149143template < typename ... Params >
    150 std::string toString ( const Params & ... params ) {
     144std::string toString( const Params & ... params ) {
    151145        std::ostringstream os;
    152146        toString_single( os, params... );
  • src/Parser/DeclarationNode.cc

    r1b77274 r2298f728  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 18:17:16 2016
    13 // Update Count     : 527
     12// Last Modified On : Sat Sep 24 11:12:52 2016
     13// Update Count     : 627
    1414//
    1515
     
    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;
     
    7381        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;
    8594        newnode->variable.assertions = maybeClone( variable.assertions );
    86         newnode->variable.name = variable.name;
    8795        newnode->variable.tyClass = variable.tyClass;
    8896
     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 );
     
    141150DeclarationNode * DeclarationNode::newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle ) {
    142151        DeclarationNode * newnode = new DeclarationNode;
    143         newnode->name = assign_strptr( name );
     152        newnode->name = name;
    144153
    145154        newnode->type = new TypeData( TypeData::Function );
     
    147156        newnode->type->function.newStyle = newStyle;
    148157        newnode->type->function.body = body;
    149         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     158        // ignore unnamed routine declarations: void p( int (*)(int) );
     159        if ( newnode->name ) {
     160                typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
     161        } // if
    150162
    151163        if ( body ) {
     
    155167        if ( ret ) {
    156168                newnode->type->base = ret->type;
    157                 ret->type = 0;
     169                ret->type = nullptr;
    158170                delete ret;
    159171        } // if
     
    213225        DeclarationNode * newnode = new DeclarationNode;
    214226        newnode->type = new TypeData( TypeData::SymbolicInst );
    215         newnode->type->symbolic.name = assign_strptr( name );
     227        newnode->type->symbolic.name = name ? new string( *name ) : nullptr;
    216228        newnode->type->symbolic.isTypedef = true;
    217         newnode->type->symbolic.params = 0;
     229        newnode->type->symbolic.params = nullptr;
    218230        return newnode;
    219231} // DeclarationNode::newFromTypedef
     
    223235        newnode->type = new TypeData( TypeData::Aggregate );
    224236        newnode->type->aggregate.kind = kind;
    225         newnode->type->aggregate.name = assign_strptr( name );
    226         if ( newnode->type->aggregate.name == "" ) {            // anonymous aggregate ?
    227                 newnode->type->aggregate.name = anonymous.newName();
     237        if ( name ) {
     238                newnode->type->aggregate.name = new string( *name );
     239        } else {                                                                                        // anonymous aggregate ?
     240                newnode->type->aggregate.name = new string( anonymous.newName() );
    228241        } // if
    229242        newnode->type->aggregate.actuals = actuals;
     
    235248DeclarationNode * DeclarationNode::newEnum( std::string * name, DeclarationNode * constants ) {
    236249        DeclarationNode * newnode = new DeclarationNode;
    237         newnode->name = assign_strptr( name );
     250        newnode->name = name;
    238251        newnode->type = new TypeData( TypeData::Enum );
    239         newnode->type->enumeration.name = newnode->name;
    240         if ( newnode->type->enumeration.name == "" ) {          // anonymous enumeration ?
    241                 newnode->type->enumeration.name = DeclarationNode::anonymous.newName();
     252        if ( name ) {
     253                newnode->type->enumeration.name = new string( *name );
     254        } else {                                                                                        // anonymous aggregate ?
     255                newnode->type->enumeration.name = new string( anonymous.newName() );
    242256        } // if
    243257        newnode->type->enumeration.constants = constants;
     
    247261DeclarationNode * DeclarationNode::newEnumConstant( std::string * name, ExpressionNode * constant ) {
    248262        DeclarationNode * newnode = new DeclarationNode;
    249         newnode->name = assign_strptr( name );
     263        newnode->name = name;
    250264        newnode->enumeratorValue.reset( constant );
    251         typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
     265        typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
    252266        return newnode;
    253267} // DeclarationNode::newEnumConstant
     
    255269DeclarationNode * DeclarationNode::newName( std::string * name ) {
    256270        DeclarationNode * newnode = new DeclarationNode;
    257         newnode->name = assign_strptr( name );
     271        newnode->name = name;
    258272        return newnode;
    259273} // DeclarationNode::newName
     
    262276        DeclarationNode * newnode = new DeclarationNode;
    263277        newnode->type = new TypeData( TypeData::SymbolicInst );
    264         newnode->type->symbolic.name = assign_strptr( name );
     278        newnode->type->symbolic.name = name ? new string( *name ) : nullptr;
    265279        newnode->type->symbolic.isTypedef = false;
    266280        newnode->type->symbolic.actuals = params;
     
    270284DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, std::string * name ) {
    271285        DeclarationNode * newnode = new DeclarationNode;
    272         newnode->name = assign_strptr( name );
    273         newnode->type = new TypeData( TypeData::Variable );
    274 //      newnode->type = nullptr;
     286        newnode->name = name;
     287//      newnode->type = new TypeData( TypeData::Variable );
     288        newnode->type = nullptr;
    275289        newnode->variable.tyClass = tc;
    276         newnode->variable.name = newnode->name;
     290        newnode->variable.name = newnode->name ? new string( *newnode->name ) : nullptr;
    277291        return newnode;
    278292} // DeclarationNode::newTypeParam
    279293
    280 DeclarationNode * DeclarationNode::newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts ) {
     294DeclarationNode * DeclarationNode::newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ) {
    281295        DeclarationNode * newnode = new DeclarationNode;
    282296        newnode->type = new TypeData( TypeData::Aggregate );
     297        newnode->type->aggregate.name = name;
    283298        newnode->type->aggregate.kind = Trait;
    284299        newnode->type->aggregate.params = params;
    285300        newnode->type->aggregate.fields = asserts;
    286         newnode->type->aggregate.name = assign_strptr( name );
    287301        return newnode;
    288302} // DeclarationNode::newTrait
    289303
    290 DeclarationNode * DeclarationNode::newTraitUse( std::string * name, ExpressionNode * params ) {
     304DeclarationNode * DeclarationNode::newTraitUse( const std::string * name, ExpressionNode * params ) {
    291305        DeclarationNode * newnode = new DeclarationNode;
    292306        newnode->type = new TypeData( TypeData::AggregateInst );
    293307        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    294308        newnode->type->aggInst.aggregate->aggregate.kind = Trait;
    295         newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name );
     309        newnode->type->aggInst.aggregate->aggregate.name = name;
    296310        newnode->type->aggInst.params = params;
    297311        return newnode;
     
    300314DeclarationNode * DeclarationNode::newTypeDecl( std::string * name, DeclarationNode * typeParams ) {
    301315        DeclarationNode * newnode = new DeclarationNode;
    302         newnode->name = assign_strptr( name );
     316        newnode->name = name;
    303317        newnode->type = new TypeData( TypeData::Symbolic );
    304318        newnode->type->symbolic.isTypedef = false;
     
    319333        newnode->type->array.dimension = size;
    320334        newnode->type->array.isStatic = isStatic;
    321         if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
     335        if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ConstantExpr * >() ) {
    322336                newnode->type->array.isVarLen = false;
    323337        } else {
     
    330344        DeclarationNode * newnode = new DeclarationNode;
    331345        newnode->type = new TypeData( TypeData::Array );
    332         newnode->type->array.dimension = 0;
     346        newnode->type->array.dimension = nullptr;
    333347        newnode->type->array.isStatic = false;
    334348        newnode->type->array.isVarLen = true;
     
    365379DeclarationNode * DeclarationNode::newAttr( std::string * name, ExpressionNode * expr ) {
    366380        DeclarationNode * newnode = new DeclarationNode;
    367         newnode->type = new TypeData( TypeData::Attr );
    368 //      newnode->type = nullptr;
    369         newnode->attr.name = assign_strptr( name );
     381//      newnode->type = new TypeData( TypeData::Attr );
     382        newnode->type = nullptr;
     383        newnode->attr.name = name;
    370384        newnode->attr.expr = expr;
    371385        return newnode;
     
    374388DeclarationNode * DeclarationNode::newAttr( std::string * name, DeclarationNode * type ) {
    375389        DeclarationNode * newnode = new DeclarationNode;
    376         newnode->type = new TypeData( TypeData::Attr );
    377 //      newnode->type = nullptr;
    378         newnode->attr.name = assign_strptr( name );
     390//      newnode->type = new TypeData( TypeData::Attr );
     391        newnode->type = nullptr;
     392        newnode->attr.name = name;
    379393        newnode->attr.type = type;
    380394        return newnode;
     
    429443                        dst->forall = src->forall;
    430444                } // if
    431                 src->forall = 0;
     445                src->forall = nullptr;
    432446        } // if
    433447        if ( dst->base ) {
     
    435449        } else if ( dst->kind == TypeData::Function ) {
    436450                dst->base = src;
    437                 src = 0;
     451                src = nullptr;
    438452        } else {
    439453                dst->qualifiers |= src->qualifiers;
     
    442456
    443457DeclarationNode * DeclarationNode::addQualifiers( DeclarationNode * q ) {
    444         if ( ! q ) return this;
     458        if ( ! q ) { delete q; return this; }
    445459
    446460        checkStorageClasses( q );
     
    469483                                type->aggregate.params = q->type->forall;
    470484                                // change implicit typedef from TYPEDEFname to TYPEGENname
    471                                 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG );
     485                                typedefTable.changeKind( *type->aggregate.name, TypedefTable::TG );
    472486                        } else {
    473487                                type->forall = q->type->forall;
    474488                        } // if
    475489                } // if
    476                 q->type->forall = 0;
     490                q->type->forall = nullptr;
    477491        } // if
    478492        delete q;
     
    487501                        dst->forall = src->forall;
    488502                } // if
    489                 src->forall = 0;
     503                src->forall = nullptr;
    490504        } // if
    491505        if ( dst->base ) {
     
    496510                        src->qualifiers |= dst->qualifiers;
    497511                        dst = src;
    498                         src = 0;
     512                        src = nullptr;
    499513                        break;
    500514                  case TypeData::Basic:
     
    536550                                } // if
    537551                                dst->base->qualifiers |= src->qualifiers;
    538                                 src = 0;
     552                                src = nullptr;
    539553                                break;
    540554                          default:
     
    544558                                        dst->forall = src->forall;
    545559                                } // if
    546                                 src->forall = 0;
     560                                src->forall = nullptr;
    547561                                dst->base = src;
    548                                 src = 0;
     562                                src = nullptr;
    549563                        } // switch
    550564                } // switch
     
    568582                                        type = o->type;
    569583                                } // if
    570                                 o->type = 0;
     584                                o->type = nullptr;
    571585                        } else {
    572586                                addTypeToType( o->type, type );
     
    588602DeclarationNode * DeclarationNode::addTypedef() {
    589603        TypeData * newtype = new TypeData( TypeData::Symbolic );
    590         newtype->symbolic.params = 0;
     604        newtype->symbolic.params = nullptr;
    591605        newtype->symbolic.isTypedef = true;
    592         newtype->symbolic.name = name;
     606        newtype->symbolic.name = name ? new string( *name ) : nullptr;
    593607        newtype->base = type;
    594608        type = newtype;
     
    597611
    598612DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) {
     613        if ( variable.name ) {
     614                if ( variable.assertions ) {
     615                        variable.assertions->appendList( assertions );
     616                } else {
     617                        variable.assertions = assertions;
     618                } // if
     619                return this;
     620        } // if
     621
    599622        assert( type );
    600623        switch ( type->kind ) {
     
    606629                } // if
    607630                break;
    608           case TypeData::Variable:
    609                 if ( variable.assertions ) {
    610                         variable.assertions->appendList( assertions );
    611                 } else {
    612                         variable.assertions = assertions;
    613                 } // if
    614                 break;
     631          // case TypeData::Variable:
     632          //    if ( variable.assertions ) {
     633          //            variable.assertions->appendList( assertions );
     634          //    } else {
     635          //            variable.assertions = assertions;
     636          //    } // if
     637          //    break;
    615638          default:
    616639                assert( false );
     
    621644
    622645DeclarationNode * DeclarationNode::addName( std::string * newname ) {
    623         name = assign_strptr( newname );
     646        assert( ! name );
     647        name = newname;
    624648        return this;
    625649}
     
    639663        assert( type );
    640664        assert( type->kind == TypeData::Function );
    641         assert( type->function.body == 0 );
     665        assert( ! type->function.body );
    642666        type->function.body = body;
    643667        type->function.hasBody = true;
     
    648672        assert( type );
    649673        assert( type->kind == TypeData::Function );
    650         assert( type->function.oldDeclList == 0 );
     674        assert( ! type->function.oldDeclList );
    651675        type->function.oldDeclList = list;
    652676        return this;
     
    657681                TypeData * prevBase = type;
    658682                TypeData * curBase = type->base;
    659                 while ( curBase != 0 ) {
     683                while ( curBase != nullptr ) {
    660684                        prevBase = curBase;
    661685                        curBase = curBase->base;
     
    671695                assert( p->type->kind == TypeData::Pointer );
    672696                setBase( type, p->type );
    673                 p->type = 0;
     697                p->type = nullptr;
    674698                delete p;
    675699        } // if
     
    681705                assert( a->type->kind == TypeData::Array );
    682706                setBase( type, a->type );
    683                 a->type = 0;
     707                a->type = nullptr;
    684708                delete a;
    685709        } // if
     
    705729                                p->type->base = type;
    706730                        } // switch
    707                         type = 0;
     731                        type = nullptr;
    708732                } // if
    709733                delete this;
     
    741765                                lastArray->base = type;
    742766                        } // switch
    743                         type = 0;
     767                        type = nullptr;
    744768                } // if
    745769                delete this;
     
    770794                return newtype;
    771795        } // if
    772 }
     796} // addIdListToType
    773797
    774798DeclarationNode * DeclarationNode::addIdList( DeclarationNode * ids ) {
     
    778802
    779803DeclarationNode * DeclarationNode::addInitializer( InitializerNode * init ) {
    780         //assert
    781804        initializer = init;
    782805        return this;
    783 }
    784 
    785 DeclarationNode * DeclarationNode::cloneBaseType( string * newName ) {
    786         DeclarationNode * newnode = new DeclarationNode;
    787         TypeData * srcType = type;
    788         while ( srcType->base ) {
    789                 srcType = srcType->base;
    790         } // while
    791         newnode->type = maybeClone( srcType );
    792         if ( newnode->type->kind == TypeData::AggregateInst ) {
    793                 // don't duplicate members
    794                 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) {
    795                         delete newnode->type->aggInst.aggregate->enumeration.constants;
    796                         newnode->type->aggInst.aggregate->enumeration.constants = 0;
    797                 } else {
    798                         assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate );
    799                         delete newnode->type->aggInst.aggregate->aggregate.fields;
    800                         newnode->type->aggInst.aggregate->aggregate.fields = 0;
    801                 } // if
    802         } // if
    803         newnode->type->forall = maybeClone( type->forall );
    804         assert( storageClass == NoStorageClass );
    805         newnode->copyStorageClasses( this );
    806         newnode->name = assign_strptr( newName );
    807         return newnode;
    808 }
    809 
    810 DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
    811         if ( o ) {
    812                 o->copyStorageClasses( this );
    813                 if ( type ) {
    814                         TypeData * srcType = type;
    815                         while ( srcType->base ) {
    816                                 srcType = srcType->base;
    817                         } // while
    818                         TypeData * newType = srcType->clone();
    819                         if ( newType->kind == TypeData::AggregateInst ) {
    820                                 // don't duplicate members
    821                                 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
    822                                         delete newType->aggInst.aggregate->enumeration.constants;
    823                                         newType->aggInst.aggregate->enumeration.constants = 0;
    824                                 } else {
    825                                         assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
    826                                         delete newType->aggInst.aggregate->aggregate.fields;
    827                                         newType->aggInst.aggregate->aggregate.fields = 0;
    828                                 } // if
    829                         } // if
    830                         newType->forall = maybeClone( type->forall );
    831                         if ( ! o->type ) {
    832                                 o->type = newType;
    833                         } else {
    834                                 addTypeToType( newType, o->type );
    835                                 delete newType;
    836                         } // if
    837                 } // if
    838         } // if
    839         return o;
    840806}
    841807
     
    846812        newnode->copyStorageClasses( this );
    847813        assert( newName );
    848         newnode->name = assign_strptr( newName );
    849         return newnode;
    850 }
    851 
    852 DeclarationNode * DeclarationNode::cloneType( DeclarationNode * o ) {
    853         if ( o ) {
    854                 assert( storageClass == NoStorageClass );
    855                 o->copyStorageClasses( this );
    856                 if ( type ) {
    857                         TypeData * newType = type->clone();
    858                         if ( ! o->type ) {
    859                                 o->type = newType;
     814        newnode->name = newName;
     815        return newnode;
     816}
     817
     818DeclarationNode * DeclarationNode::cloneBaseType( DeclarationNode * o ) {
     819        if ( ! o ) return nullptr;
     820
     821        o->copyStorageClasses( this );
     822        if ( type ) {
     823                TypeData * srcType = type;
     824
     825                while ( srcType->base ) {
     826                        srcType = srcType->base;
     827                } // while
     828
     829                TypeData * newType = srcType->clone();
     830                if ( newType->kind == TypeData::AggregateInst ) {
     831                        // don't duplicate members
     832                        if ( newType->aggInst.aggregate->kind == TypeData::Enum ) {
     833                                delete newType->aggInst.aggregate->enumeration.constants;
     834                                newType->aggInst.aggregate->enumeration.constants = nullptr;
    860835                        } else {
    861                                 addTypeToType( newType, o->type );
    862                                 delete newType;
     836                                assert( newType->aggInst.aggregate->kind == TypeData::Aggregate );
     837                                delete newType->aggInst.aggregate->aggregate.fields;
     838                                newType->aggInst.aggregate->aggregate.fields = nullptr;
    863839                        } // if
    864840                } // if
    865         } // if
    866         delete o;
     841
     842                newType->forall = maybeClone( type->forall );
     843                if ( ! o->type ) {
     844                        o->type = newType;
     845                } else {
     846                        addTypeToType( newType, o->type );
     847                        delete newType;
     848                } // if
     849        } // if
    867850        return o;
    868851}
     
    877860                } // if
    878861        } // if
    879         return 0;
     862        return nullptr;
    880863}
    881864
     
    884867        std::back_insert_iterator< std::list< Declaration * > > out( outputList );
    885868        const DeclarationNode * cur = firstNode;
     869
    886870        while ( cur ) {
    887871                try {
     
    894878                                delete extr;
    895879                        } // if
     880
    896881                        Declaration * decl = cur->build();
    897882                        if ( decl ) {
     
    903888                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    904889        } // while
     890
    905891        if ( ! errors.isEmpty() ) {
    906892                throw errors;
    907893        } // if
    908 }
     894} // buildList
    909895
    910896void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > &outputList ) {
     
    920906                                } else if ( StructDecl * agg = dynamic_cast< StructDecl * >( decl ) ) {
    921907                                        StructInstType * inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    922                                         * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
     908                                        * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
    923909                                        delete agg;
    924910                                } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
    925911                                        UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    926                                         * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
     912                                        * out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
    927913                                } // if
    928914                        } // if
     
    935921                throw errors;
    936922        } // if
    937 }
     923} // buildList
    938924
    939925void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > &outputList ) {
     
    941927        std::back_insert_iterator< std::list< Type * > > out( outputList );
    942928        const DeclarationNode * cur = firstNode;
     929
    943930        while ( cur ) {
    944931                try {
     
    949936                cur = dynamic_cast< DeclarationNode * >( cur->get_next() );
    950937        } // while
     938
    951939        if ( ! errors.isEmpty() ) {
    952940                throw errors;
    953941        } // if
    954 }
     942} // buildTypeList
    955943
    956944Declaration * DeclarationNode::build() const {
    957945        if ( ! error.empty() ) throw SemanticError( error + " in declaration of ", this );
     946
     947        if ( variable.name ) {
     948                static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
     949                TypeDecl * ret = new TypeDecl( *variable.name, DeclarationNode::NoStorageClass, nullptr, kindMap[ variable.tyClass ] );
     950                buildList( variable.assertions, ret->get_assertions() );
     951                return ret;
     952        } // if
     953
    958954        if ( type ) {
    959                 if ( type->kind == TypeData::Variable ) {
    960                         static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    961                         TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] );
    962                         buildList( variable.assertions, ret->get_assertions() );
    963                         return ret;
    964                 } else {
    965                         return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
    966                 } // if
    967         } // if
     955                return buildDecl( type, name ? *name : string( "" ), storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension );
     956        } // if
     957
    968958        if ( ! isInline && ! isNoreturn ) {
    969                 return (new ObjectDecl( name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
    970         } // if
     959                assertf( name, "ObjectDecl are assumed to have names\n" );
     960                return (new ObjectDecl( *name, storageClass, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_extension( extension );
     961        } // if
     962
    971963        throw SemanticError( "invalid function specifier ", this );
    972964}
     
    975967        assert( type );
    976968
     969        if ( attr.name ) {
     970                AttrType * ret;
     971                if ( attr.expr ) {
     972                        ret = new AttrType( buildQualifiers( type ), *attr.name, attr.expr->build() );
     973                } else {
     974                        assert( attr.type );
     975                        ret = new AttrType( buildQualifiers( type ), *attr.name, attr.type->buildType() );
     976                } // if
     977                return ret;
     978        } // if
     979
    977980        switch ( type->kind ) {
    978981          case TypeData::Enum:
    979                 return new EnumInstType( buildQualifiers( type ), type->enumeration.name );
     982                return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
    980983          case TypeData::Aggregate: {
    981984                  ReferenceToType * ret;
    982985                  switch ( type->aggregate.kind ) {
    983986                        case DeclarationNode::Struct:
    984                           ret = new StructInstType( buildQualifiers( type ), type->aggregate.name );
     987                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    985988                          break;
    986989                        case DeclarationNode::Union:
    987                           ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name );
     990                          ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    988991                          break;
    989992                        case DeclarationNode::Trait:
    990                           ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name );
     993                          ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    991994                          break;
    992995                        default:
     
    9971000          }
    9981001          case TypeData::Symbolic: {
    999                   TypeInstType * ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false );
     1002                  TypeInstType * ret = new TypeInstType( buildQualifiers( type ), *type->symbolic.name, false );
    10001003                  buildList( type->symbolic.actuals, ret->get_parameters() );
    1001                   return ret;
    1002           }
    1003           case TypeData::Attr: {
    1004                   assert( type->kind == TypeData::Attr );
    1005                   // assert( type->attr );
    1006                   AttrType * ret;
    1007                   if ( attr.expr ) {
    1008                           ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() );
    1009                   } else {
    1010                           assert( attr.type );
    1011                           ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() );
    1012                   } // if
    10131004                  return ret;
    10141005          }
  • src/Parser/ParseNode.h

    r1b77274 r2298f728  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 15:02:38 2016
    13 // Update Count     : 613
     12// Last Modified On : Sat Sep 24 11:12:04 2016
     13// Update Count     : 633
    1414//
    1515
     
    4141  public:
    4242        ParseNode() {};
    43         virtual ~ParseNode() { delete next; };
     43        virtual ~ParseNode() { delete next; delete name; };
    4444        virtual ParseNode * clone() const = 0;
    4545
     
    4949        ParseNode * get_last() {
    5050                ParseNode * current;
    51                 for ( current = this; current->get_next() != 0; current = current->get_next() );
     51                for ( current = this; current->get_next() != nullptr; current = current->get_next() );
    5252                return current;
    5353        }
    5454        ParseNode * set_last( ParseNode * newlast ) {
    55                 if ( newlast != 0 ) get_last()->set_next( newlast );
     55                if ( newlast != nullptr ) get_last()->set_next( newlast );
    5656                return this;
    5757        }
     
    6363
    6464        ParseNode * next = nullptr;
    65         std::string name;
     65        std::string * name = nullptr;
    6666}; // ParseNode
    6767
     
    7070class InitializerNode : public ParseNode {
    7171  public:
    72         InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode * des = 0 );
    73         InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = 0 );
     72        InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode * des = nullptr );
     73        InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr );
    7474        ~InitializerNode();
    7575        virtual InitializerNode * clone() const { assert( false ); return nullptr; }
     
    178178Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node );
    179179Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node );
    180 Expression * build_tuple( ExpressionNode * expr_node = 0 );
     180Expression * build_tuple( ExpressionNode * expr_node = nullptr );
    181181Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
    182182Expression * build_range( ExpressionNode * low, ExpressionNode * high );
     
    214214        static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false );
    215215        static DeclarationNode * newQualifier( Qualifier );
    216         static DeclarationNode * newForall( DeclarationNode *);
     216        static DeclarationNode * newForall( DeclarationNode * );
    217217        static DeclarationNode * newStorageClass( StorageClass );
    218218        static DeclarationNode * newBasicType( BasicType );
     
    221221        static DeclarationNode * newLength( Length lnth );
    222222        static DeclarationNode * newBuiltinType( BuiltinType );
    223         static DeclarationNode * newFromTypedef( std::string *);
     223        static DeclarationNode * newFromTypedef( std::string * );
    224224        static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    225225        static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants );
    226226        static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant );
    227         static DeclarationNode * newName( std::string *);
     227        static DeclarationNode * newName( std::string * );
    228228        static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params );
    229         static DeclarationNode * newTypeParam( TypeClass, std::string *);
    230         static DeclarationNode * newTrait( std::string * name, DeclarationNode * params, DeclarationNode * asserts );
    231         static DeclarationNode * newTraitUse( std::string * name, ExpressionNode * params );
     229        static DeclarationNode * newTypeParam( TypeClass, std::string * );
     230        static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts );
     231        static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params );
    232232        static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams );
    233233        static DeclarationNode * newPointer( DeclarationNode * qualifiers );
     
    244244        DeclarationNode * clone() const;
    245245
    246         DeclarationNode * addQualifiers( DeclarationNode *);
     246        DeclarationNode * addQualifiers( DeclarationNode * );
    247247        void checkQualifiers( const TypeData *, const TypeData * );
    248         void checkStorageClasses( DeclarationNode *q );
    249         DeclarationNode * copyStorageClasses( DeclarationNode *);
    250         DeclarationNode * addType( DeclarationNode *);
     248        void checkStorageClasses( DeclarationNode * );
     249        DeclarationNode * copyStorageClasses( DeclarationNode * );
     250        DeclarationNode * addType( DeclarationNode * );
    251251        DeclarationNode * addTypedef();
    252         DeclarationNode * addAssertions( DeclarationNode *);
    253         DeclarationNode * addName( std::string *);
     252        DeclarationNode * addAssertions( DeclarationNode * );
     253        DeclarationNode * addName( std::string * );
    254254        DeclarationNode * addBitfield( ExpressionNode * size );
    255255        DeclarationNode * addVarArgs();
     
    265265
    266266        DeclarationNode * cloneType( std::string * newName );
    267         DeclarationNode * cloneType( DeclarationNode * existing );
    268         DeclarationNode * cloneType( int ) { return cloneType( ( std::string *)0 ); }
    269         DeclarationNode * cloneBaseType( std::string * newName );
    270267        DeclarationNode * cloneBaseType( DeclarationNode * newdecl );
    271268
     
    290287  public:
    291288        struct Variable_t {
     289                const std::string * name;
    292290                DeclarationNode::TypeClass tyClass;
    293                 std::string name;
    294291                DeclarationNode * assertions;
    295292        };
     
    297294
    298295        struct Attr_t {
    299                 std::string name;
     296                const std::string * name;
    300297                ExpressionNode * expr;
    301298                DeclarationNode * type;
     
    382379Statement * build_finally( StatementNode * stmt );
    383380Statement * build_compound( StatementNode * first );
    384 Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = 0, ExpressionNode * input = 0, ExpressionNode * clobber = 0, LabelNode * gotolabels = 0 );
     381Statement * build_asmstmt( bool voltile, ConstantExpr * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
    385382
    386383//##############################################################################
  • src/Parser/TypeData.cc

    r1b77274 r2298f728  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 15:12:55 2016
    13 // Update Count     : 388
     12// Last Modified On : Sat Sep 24 11:14:26 2016
     13// Update Count     : 415
    1414//
    1515
     
    2424#include "SynTree/Statement.h"
    2525#include "SynTree/Initializer.h"
    26 
    27 TypeData::TypeData( Kind k ) : kind( k ), base( 0 ), forall( 0 ) {
     26using namespace std;
     27
     28TypeData::TypeData( Kind k ) : kind( k ), base( nullptr ), forall( nullptr ) {
    2829        switch ( kind ) {
    2930          case Unknown:
     
    3738          case Array:
    3839                // array = new Array_t;
    39                 array.dimension = 0;
     40                array.dimension = nullptr;
    4041                array.isVarLen = false;
    4142                array.isStatic = false;
     
    4344          case Function:
    4445                // function = new Function_t;
    45                 function.params = 0;
    46                 function.idList = 0;
    47                 function.oldDeclList = 0;
    48                 function.body = 0;
     46                function.params = nullptr;
     47                function.idList = nullptr;
     48                function.oldDeclList = nullptr;
     49                function.body = nullptr;
    4950                function.hasBody = false;
    5051                function.newStyle = false;
     
    5253          case Aggregate:
    5354                // aggregate = new Aggregate_t;
    54                 aggregate.params = 0;
    55                 aggregate.actuals = 0;
    56                 aggregate.fields = 0;
     55                aggregate.name = nullptr;
     56                aggregate.params = nullptr;
     57                aggregate.actuals = nullptr;
     58                aggregate.fields = nullptr;
    5759                break;
    5860          case AggregateInst:
    5961                // aggInst = new AggInst_t;
    60                 aggInst.aggregate = 0;
    61                 aggInst.params = 0;
     62                aggInst.aggregate = nullptr;
     63                aggInst.params = nullptr;
    6264                break;
    6365          case Enum:
    6466                // enumeration = new Enumeration_t;
    65                 enumeration.constants = 0;
     67                enumeration.name = nullptr;
     68                enumeration.constants = nullptr;
    6669                break;
    6770          case Symbolic:
    6871          case SymbolicInst:
    6972                // symbolic = new Symbolic_t;
    70                 symbolic.params = 0;
    71                 symbolic.actuals = 0;
    72                 symbolic.assertions = 0;
    73                 break;
    74           case Variable:
    75                 // variable = new Variable_t;
    76                 // variable.tyClass = DeclarationNode::Type;
    77                 // variable.assertions = 0;
     73                symbolic.name = nullptr;
     74                symbolic.params = nullptr;
     75                symbolic.actuals = nullptr;
     76                symbolic.assertions = nullptr;
    7877                break;
    7978          case Tuple:
     
    8483                // typeexpr = new Typeof_t;
    8584                typeexpr = nullptr;
    86                 break;
    87           case Attr:
    88                 // attr = new Attr_t;
    89                 // attr.expr = nullptr;
    90                 // attr.type = nullptr;
    9185                break;
    9286          case Builtin:
     
    121115                break;
    122116          case Aggregate:
     117                delete aggregate.name;
    123118                delete aggregate.params;
    124119                delete aggregate.actuals;
     
    132127                break;
    133128          case Enum:
     129                delete enumeration.name;
    134130                delete enumeration.constants;
    135131                // delete enumeration;
     
    137133          case Symbolic:
    138134          case SymbolicInst:
     135                delete symbolic.name;
    139136                delete symbolic.params;
    140137                delete symbolic.actuals;
     
    142139                // delete symbolic;
    143140                break;
    144           case Variable:
    145                 // delete variable.assertions;
    146                 // delete variable;
    147                 break;
    148141          case Tuple:
    149142                // delete tuple->members;
     
    153146                // delete typeexpr->expr;
    154147                delete typeexpr;
    155                 break;
    156           case Attr:
    157                 // delete attr.expr;
    158                 // delete attr.type;
    159                 // delete attr;
    160148                break;
    161149          case Builtin:
     
    197185                break;
    198186          case Aggregate:
     187                newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
    199188                newtype->aggregate.params = maybeClone( aggregate.params );
    200189                newtype->aggregate.actuals = maybeClone( aggregate.actuals );
    201190                newtype->aggregate.fields = maybeClone( aggregate.fields );
    202                 newtype->aggregate.name = aggregate.name;
    203191                newtype->aggregate.kind = aggregate.kind;
    204192                newtype->aggregate.body = aggregate.body;
     
    209197                break;
    210198          case Enum:
    211                 newtype->enumeration.name = enumeration.name;
     199                newtype->enumeration.name = enumeration.name ? new string( *enumeration.name ) : nullptr;
    212200                newtype->enumeration.constants = maybeClone( enumeration.constants );
    213201                break;
    214202          case Symbolic:
    215203          case SymbolicInst:
     204                newtype->symbolic.name = symbolic.name ? new string( *symbolic.name ) : nullptr;
    216205                newtype->symbolic.params = maybeClone( symbolic.params );
    217206                newtype->symbolic.actuals = maybeClone( symbolic.actuals );
    218207                newtype->symbolic.assertions = maybeClone( symbolic.assertions );
    219208                newtype->symbolic.isTypedef = symbolic.isTypedef;
    220                 newtype->symbolic.name = symbolic.name;
    221                 break;
    222           case Variable:
    223                 assert( false );
    224                 // newtype->variable.assertions = maybeClone( variable.assertions );
    225                 // newtype->variable.name = variable.name;
    226                 // newtype->variable.tyClass = variable.tyClass;
    227209                break;
    228210          case Tuple:
     
    231213          case Typeof:
    232214                newtype->typeexpr = maybeClone( typeexpr );
    233                 break;
    234           case Attr:
    235                 assert( false );
    236                 // newtype->attr.expr = maybeClone( attr.expr );
    237                 // newtype->attr.type = maybeClone( attr.type );
    238215                break;
    239216          case Builtin:
     
    245222} // TypeData::clone
    246223
    247 void TypeData::print( std::ostream &os, int indent ) const {
    248         using std::endl;
    249         using std::string;
    250 
     224void TypeData::print( ostream &os, int indent ) const {
    251225        for ( int i = 0; i < DeclarationNode::NoQualifier; i += 1 ) {
    252226                if ( qualifiers[i] ) os << DeclarationNode::qualifierName[ i ] << ' ';
     
    326300                break;
    327301          case Aggregate:
    328                 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl;
     302                os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << *aggregate.name << endl;
    329303                if ( aggregate.params ) {
    330304                        os << string( indent + 2, ' ' ) << "with type parameters " << endl;
     
    363337                break;
    364338          case SymbolicInst:
    365                 os << "instance of type " << symbolic.name;
     339                os << "instance of type " << *symbolic.name;
    366340                if ( symbolic.actuals ) {
    367341                        os << " with parameters" << endl;
     
    389363                } // if
    390364                break;
    391           case Variable:
    392                 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable ";
    393                 // if ( variable.assertions ) {
    394                 //      os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;
    395                 //      variable.assertions->printList( os, indent + 4 );
    396                 //      os << string( indent + 2, ' ' );
    397                 // } // if
    398                 break;
    399365          case Tuple:
    400366                os << "tuple ";
     
    410376                } // if
    411377                break;
    412           case Attr:
    413                 // os << "attribute type decl " << attr.name << " applied to ";
    414                 // if ( attr.expr ) {
    415                 //      attr.expr->print( os, indent + 2 );
    416                 // } // if
    417                 // if ( attr.type ) {
    418                 //      attr.type->print( os, indent + 2 );
    419                 // } // if
    420                 break;
    421378          case Builtin:
    422379                os << "gcc builtin type";
     
    428385} // TypeData::print
    429386
    430 void buildForall( const DeclarationNode * firstNode, std::list< TypeDecl* > &outputList ) {
     387void buildForall( const DeclarationNode * firstNode, list< TypeDecl* > &outputList ) {
    431388        buildList( firstNode, outputList );
    432         for ( std::list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
     389        for ( list< TypeDecl* >::iterator i = outputList.begin(); i != outputList.end(); ++i ) {
    433390                if ( (*i)->get_kind() == TypeDecl::Any ) {
    434391                        // add assertion parameters to `type' tyvars in reverse order
    435392                        // add dtor:  void ^?{}(T *)
    436393                        FunctionType * dtorType = new FunctionType( Type::Qualifiers(), false );
    437                         dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    438                         (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, 0, false, false ) );
     394                        dtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) );
     395                        (*i)->get_assertions().push_front( new FunctionDecl( "^?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, dtorType, nullptr, false, false ) );
    439396
    440397                        // add copy ctor:  void ?{}(T *, T)
    441398                        FunctionType * copyCtorType = new FunctionType( Type::Qualifiers(), false );
    442                         copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    443                         copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
    444                         (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, 0, false, false ) );
     399                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) );
     400                        copyCtorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) );
     401                        (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, copyCtorType, nullptr, false, false ) );
    445402
    446403                        // add default ctor:  void ?{}(T *)
    447404                        FunctionType * ctorType = new FunctionType( Type::Qualifiers(), false );
    448                         ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    449                         (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, 0, false, false ) );
     405                        ctorType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) );
     406                        (*i)->get_assertions().push_front( new FunctionDecl( "?{}", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, ctorType, nullptr, false, false ) );
    450407
    451408                        // add assignment operator:  T * ?=?(T *, T)
    452409                        FunctionType * assignType = new FunctionType( Type::Qualifiers(), false );
    453                         assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    454                         assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
    455                         assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
    456                         (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, 0, false, false ) );
     410                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), nullptr ) );
     411                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) );
     412                        assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), nullptr ) );
     413                        (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, nullptr, false, false ) );
    457414                } // if
    458415        } // for
     
    486443          case TypeData::Builtin:
    487444                return new VarArgsType( buildQualifiers( td ) );
    488           case TypeData::Attr:
    489445          case TypeData::Symbolic:
    490446          case TypeData::Enum:
    491447          case TypeData::Aggregate:
    492           case TypeData::Variable:
    493448                assert( false );
    494449        } // switch
    495         return 0;
     450        return nullptr;
    496451} // typebuild
    497452
    498453TypeData * typeextractAggregate( const TypeData * td, bool toplevel ) {
    499         TypeData * ret = 0;
     454        TypeData * ret = nullptr;
    500455
    501456        switch ( td->kind ) {
     
    547502          case DeclarationNode::Bool:
    548503                if ( td->signedness != DeclarationNode::NoSignedness ) {
    549                         throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
     504                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
    550505                } // if
    551506                if ( td->length != DeclarationNode::NoLength ) {
    552                         throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     507                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
    553508                } // if
    554509
     
    563518
    564519                if ( td->length != DeclarationNode::NoLength ) {
    565                         throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     520                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
    566521                } // if
    567522
     
    593548          FloatingPoint: ;
    594549                if ( td->signedness != DeclarationNode::NoSignedness ) {
    595                         throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
     550                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::signednessName[ td->signedness ] + " in type: ", td );
    596551                } // if
    597552                if ( td->length == DeclarationNode::Short || td->length == DeclarationNode::LongLong ) {
    598                         throw SemanticError( std::string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
     553                        throw SemanticError( string( "invalid type specifier " ) + DeclarationNode::lengthName[ td->length ] + " in type: ", td );
    599554                } // if
    600555                if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) {
     
    653608        switch ( td->aggregate.kind ) {
    654609          case DeclarationNode::Struct:
    655                 at = new StructDecl( td->aggregate.name );
     610                at = new StructDecl( *td->aggregate.name );
    656611                buildForall( td->aggregate.params, at->get_parameters() );
    657612                break;
    658613          case DeclarationNode::Union:
    659                 at = new UnionDecl( td->aggregate.name );
     614                at = new UnionDecl( *td->aggregate.name );
    660615                buildForall( td->aggregate.params, at->get_parameters() );
    661616                break;
    662617          case DeclarationNode::Trait:
    663                 at = new TraitDecl( td->aggregate.name );
     618                at = new TraitDecl( *td->aggregate.name );
    664619                buildList( td->aggregate.params, at->get_parameters() );
    665620                break;
     
    679634        ReferenceToType * ret;
    680635        if ( td->aggInst.aggregate->kind == TypeData::Enum ) {
    681                 ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name );
     636                ret = new EnumInstType( buildQualifiers( td ), *td->aggInst.aggregate->enumeration.name );
    682637        } else {
    683638                assert( td->aggInst.aggregate->kind == TypeData::Aggregate );
    684639                switch ( td->aggInst.aggregate->aggregate.kind ) {
    685640                  case DeclarationNode::Struct:
    686                         ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
     641                        assert( td->aggInst.aggregate->aggregate.name );
     642                        ret = new StructInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name );
    687643                        break;
    688644                  case DeclarationNode::Union:
    689                         ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
     645                        ret = new UnionInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name );
    690646                        break;
    691647                  case DeclarationNode::Trait:
    692                         ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name );
     648                        ret = new TraitInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name );
    693649                        break;
    694650                  default:
     
    701657} // buildAggInst
    702658
    703 NamedTypeDecl * buildSymbolic( const TypeData * td, const std::string & name, DeclarationNode::StorageClass sc ) {
     659NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, DeclarationNode::StorageClass sc ) {
    704660        assert( td->kind == TypeData::Symbolic );
    705661        NamedTypeDecl * ret;
     
    715671} // buildSymbolic
    716672
    717 TypeDecl * buildVariable( const TypeData * td ) {
    718         assert( false );
    719         return nullptr;
    720         // assert( td->kind == TypeData::Variable );
    721         // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    722 
    723         // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] );
    724         // buildList( td->variable.assertions, ret->get_assertions() );
    725         // return ret;
    726 } // buildSymbolic
    727 
    728673EnumDecl * buildEnum( const TypeData * td ) {
    729674        assert( td->kind == TypeData::Enum );
    730         EnumDecl * ret = new EnumDecl( td->enumeration.name );
     675        EnumDecl * ret = new EnumDecl( *td->enumeration.name );
    731676        buildList( td->enumeration.constants, ret->get_members() );
    732         std::list< Declaration * >::iterator members = ret->get_members().begin();
     677        list< Declaration * >::iterator members = ret->get_members().begin();
    733678        for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    734679                if ( cur->has_enumeratorValue() ) {
    735680                        ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members);
    736                         member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) );
     681                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), list< Expression * >() ) );
    737682                } // if
    738683        } // for
     
    742687TypeInstType * buildSymbolicInst( const TypeData * td ) {
    743688        assert( td->kind == TypeData::SymbolicInst );
    744         TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false );
     689        TypeInstType * ret = new TypeInstType( buildQualifiers( td ), *td->symbolic.name, false );
    745690        buildList( td->symbolic.actuals, ret->get_parameters() );
    746691        buildForall( td->forall, ret->get_forall() );
     
    763708} // buildTypeof
    764709
    765 Declaration * buildDecl( const TypeData * td, std::string name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) {
     710Declaration * buildDecl( const TypeData * td, const string &name, DeclarationNode::StorageClass sc, Expression * bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Spec linkage, Initializer * init ) {
    766711        if ( td->kind == TypeData::Function ) {
    767712                FunctionDecl * decl;
     
    773718                                decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), body, isInline, isNoreturn );
    774719                        } else {
    775                                 // std::list< Label > ls;
    776                                 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( std::list< Label >() ), isInline, isNoreturn );
     720                                // list< Label > ls;
     721                                decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), new CompoundStmt( list< Label >() ), isInline, isNoreturn );
    777722                        } // if
    778723                } else {
    779                         decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn );
    780                 } // if
    781                 for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
    782                         if ( cur->name != "" ) {
    783                                 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->name );
     724                        decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), nullptr, isInline, isNoreturn );
     725                } // if
     726                for ( DeclarationNode * cur = td->function.idList; cur != nullptr; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {
     727                        if ( cur->name ) {
     728                                decl->get_oldIdents().insert( decl->get_oldIdents().end(), *cur->name );
    784729                        } // if
    785730                } // for
     
    792737        } else if ( td->kind == TypeData::Symbolic ) {
    793738                return buildSymbolic( td, name, sc );
    794         } else if ( td->kind == TypeData::Variable ) {
    795                 assert( false );
    796                 return buildVariable( td );
    797739        } else {
    798                 return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, std::list< Attribute * >(), isInline, isNoreturn );
     740                return new ObjectDecl( name, sc, linkage, bitfieldWidth, typebuild( td ), init, list< Attribute * >(), isInline, isNoreturn );
    799741        } // if
    800         return 0;
     742        return nullptr;
    801743} // buildDecl
    802744
     
    814756                        break;
    815757                  default:
    816                         ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base,  "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) );
     758                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( buildDecl( td->base,  "", DeclarationNode::NoStorageClass, nullptr, false, false, LinkageSpec::Cforall ) ) );
    817759                } // switch
    818760        } else {
    819                 ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
     761                ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    820762        } // if
    821763        return ft;
  • src/Parser/TypeData.h

    r1b77274 r2298f728  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 15:17:31 2016
    13 // Update Count     : 131
     12// Last Modified On : Sat Sep 24 11:10:38 2016
     13// Update Count     : 141
    1414//
    1515
     
    2424struct TypeData {
    2525        enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst,
    26                                 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr };
     26                                Enum, EnumConstant, Symbolic, SymbolicInst, Tuple, Typeof, Builtin };
    2727
    2828        struct Aggregate_t {
    2929                DeclarationNode::Aggregate kind;
    30                 std::string name;
     30                const std::string * name;
    3131                DeclarationNode * params;
    32                 ExpressionNode  * actuals;                                              // holds actual parameters later applied to AggInst
     32                ExpressionNode * actuals;                                               // holds actual parameters later applied to AggInst
    3333                DeclarationNode * fields;
    3434                bool body;
     
    4747
    4848        struct Enumeration_t {
    49                 std::string name;
     49                const std::string * name;
    5050                DeclarationNode * constants;
    5151        };
     
    6161
    6262        struct Symbolic_t {
    63                 std::string name;
     63                const std::string * name;
    6464                bool isTypedef;                                                                 // false => TYPEGENname, true => TYPEDEFname
    6565                DeclarationNode * params;
     
    110110TupleType * buildTuple( const TypeData * );
    111111TypeofType * buildTypeof( const TypeData * );
    112 Declaration * buildDecl( const TypeData *, std::string, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = 0 );
     112Declaration * buildDecl( const TypeData *, const std::string &, DeclarationNode::StorageClass, Expression *, bool isInline, bool isNoreturn, LinkageSpec::Spec, Initializer * init = nullptr );
    113113FunctionType * buildFunction( const TypeData * );
    114114
  • src/Parser/parser.h

    r1b77274 r2298f728  
    262262
    263263/* Line 2068 of yacc.c  */
    264 #line 115 "parser.yy"
     264#line 116 "parser.yy"
    265265
    266266        Token tok;
  • src/Parser/parser.yy

    r1b77274 r2298f728  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Sep 16 18:12:21 2016
    13 // Update Count     : 1978
     12// Last Modified On : Sat Sep 24 11:30:40 2016
     13// Update Count     : 1991
    1414//
    1515
     
    5454#include "TypeData.h"
    5555#include "LinkageSpec.h"
     56using namespace std;
    5657
    5758extern DeclarationNode * parseTree;
     
    5960extern TypedefTable typedefTable;
    6061
    61 std::stack< LinkageSpec::Spec > linkageStack;
    62 
    63 void appendStr( std::string *to, std::string *from ) {
     62stack< LinkageSpec::Spec > linkageStack;
     63
     64void appendStr( string *to, string *from ) {
    6465        // "abc" "def" "ghi" => "abcdefghi", remove new text from quotes and insert before last quote in old string.
    6566        to->insert( to->length() - 1, from->substr( 1, from->length() - 2 ) );
     
    389390                {
    390391                        Token fn;
    391                         fn.str = new std::string( "?{}" ); // location undefined
     392                        fn.str = new string( "?{}" );                           // location undefined
    392393                        $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) );
    393394                }
     
    666667                {
    667668                        Token fn;
    668                         fn.str = new std::string( "^?{}" ); // location undefined
     669                        fn.str = new string( "^?{}" );                          // location undefined
    669670                        $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );
    670671                }
     
    14671468aggregate_name:
    14681469        aggregate_key '{' field_declaration_list '}'
    1469                 { $$ = DeclarationNode::newAggregate( $1, new std::string( "" ), nullptr, $3, true ); }
     1470                { $$ = DeclarationNode::newAggregate( $1, nullptr, nullptr, $3, true ); }
    14701471        | aggregate_key no_attr_identifier_or_type_name
    14711472                {
    14721473                        typedefTable.makeTypedef( *$2 );
    1473                         $$ = DeclarationNode::newAggregate( $1, $2, 0, 0, false );
     1474                        $$ = DeclarationNode::newAggregate( $1, $2, nullptr, nullptr, false );
    14741475                }
    14751476        | aggregate_key no_attr_identifier_or_type_name
     
    14781479                { $$ = DeclarationNode::newAggregate( $1, $2, nullptr, $5, true ); }
    14791480        | aggregate_key '(' type_name_list ')' '{' field_declaration_list '}' // CFA
    1480                 { $$ = DeclarationNode::newAggregate( $1, new std::string( "" ), $3, $6, false ); }
     1481                { $$ = DeclarationNode::newAggregate( $1, nullptr, $3, $6, false ); }
    14811482        | aggregate_key typegen_name                                            // CFA, S/R conflict
    14821483                { $$ = $2; }
     
    15591560enum_name:
    15601561        enum_key '{' enumerator_list comma_opt '}'
    1561                 { $$ = DeclarationNode::newEnum( new std::string( "" ), $3 ); }
     1562                { $$ = DeclarationNode::newEnum( nullptr, $3 ); }
    15621563        | enum_key no_attr_identifier_or_type_name
    15631564                {
     
    25202521abstract_function:
    25212522        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
    2522                 { $$ = DeclarationNode::newFunction( new std::string( "" ), nullptr, $3, nullptr ); }
     2523                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
    25232524        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25242525                { $$ = $2->addParamList( $6 ); }
     
    25892590abstract_parameter_function:
    25902591        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
    2591                 { $$ = DeclarationNode::newFunction( new std::string( "" ), nullptr, $3, nullptr ); }
     2592                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
    25922593        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
    25932594                { $$ = $2->addParamList( $6 ); }
     
    27932794                // empty (void) function return type.
    27942795        '[' ']' type_specifier
    2795                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2796                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    27962797        | '[' ']' multi_array_dimension type_specifier
    2797                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2798                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    27982799        | multi_array_dimension type_specifier
    27992800                { $$ = $2->addNewArray( $1 ); }
    28002801        | '[' ']' new_abstract_ptr
    2801                 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2802                { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    28022803        | '[' ']' multi_array_dimension new_abstract_ptr
    2803                 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }
     2804                { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); }
    28042805        | multi_array_dimension new_abstract_ptr
    28052806                { $$ = $2->addNewArray( $1 ); }
     
    28132814new_abstract_function:                                                                  // CFA
    28142815        '[' ']' '(' new_parameter_type_list_opt ')'
    2815         { $$ = DeclarationNode::newFunction( new std::string( "" ), DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
     2816                { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    28162817        | new_abstract_tuple '(' push new_parameter_type_list_opt pop ')'
    2817                 { $$ = DeclarationNode::newFunction( new std::string( "" ), $1, $4, nullptr ); }
     2818                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28182819        | new_function_return '(' push new_parameter_type_list_opt pop ')'
    2819                 { $$ = DeclarationNode::newFunction( new std::string( "" ), $1, $4, nullptr ); }
     2820                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    28202821        ;
    28212822
     
    28522853
    28532854void yyerror( const char * ) {
    2854         std::cout << "Error ";
     2855        cout << "Error ";
    28552856        if ( yyfilename ) {
    2856                 std::cout << "in file " << yyfilename << " ";
     2857                cout << "in file " << yyfilename << " ";
    28572858        } // if
    2858         std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl;
     2859        cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;
    28592860}
    28602861
Note: See TracChangeset for help on using the changeset viewer.