Changeset 937e51d for src/Parser


Ignore:
Timestamp:
Jun 26, 2015, 4:00:26 PM (11 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
0df292b, e0ff3e6
Parents:
eb50842 (diff), 1869adf (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 pointer to pointer to qualified fix into master

Location:
src/Parser
Files:
4 added
1 deleted
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 21 09:28:54 2015
    13 // Update Count     : 13
     12// Last Modified On : Wed Jun 24 15:29:19 2015
     13// Update Count     : 86
    1414//
    1515
     
    2121
    2222#include "TypeData.h"
     23
     24#include "SynTree/Declaration.h"
    2325#include "SynTree/Expression.h"
    2426
     27#include "Parser.h"
     28#include "TypedefTable.h"
     29extern TypedefTable typedefTable;
    2530
    2631using namespace std;
    2732
    2833// These must remain in the same order as the corresponding DeclarationNode enumerations.
     34const char *DeclarationNode::storageName[] = { "extern", "static", "auto", "register", "inline", "fortran", "_Noreturn", "_Thread_local", "" };
    2935const char *DeclarationNode::qualifierName[] = { "const", "restrict", "volatile", "lvalue", "_Atomic" };
    3036const char *DeclarationNode::basicTypeName[] = { "char", "int", "float", "double", "void", "_Bool", "_Complex", "_Imaginary" };
    31 const char *DeclarationNode::modifierName[] = { "signed", "unsigned", "short", "long" };
    32 const char *DeclarationNode::tyConName[] = { "struct", "union", "context" };
     37const char *DeclarationNode::modifierName[]  = { "signed", "unsigned", "short", "long" };
     38const char *DeclarationNode::aggregateName[] = { "struct", "union", "context" };
    3339const char *DeclarationNode::typeClassName[] = { "type", "dtype", "ftype" };
    3440
     
    6369}
    6470
    65 const char *storageClassName[] = {
    66         // order must correspond with DeclarationNode::StorageClass
    67         "extern",
    68         "static",
    69         "auto",
    70         "register",
    71         "inline",
    72         "fortran",
    73 };
    74 
    7571void DeclarationNode::print( std::ostream &os, int indent ) const {
    76         os << string(indent, ' ' );
     72        os << string( indent, ' ' );
    7773        if ( name == "" ) {
    7874                os << "unnamed: ";
    7975        } else {
    8076                os << name << ": ";
    81         }
     77        } // if
    8278
    8379        if ( linkage != LinkageSpec::Cforall ) {
    8480                os << LinkageSpec::toString( linkage ) << " ";
    85         }
    86 
    87         printEnums( storageClasses.begin(), storageClasses.end(), storageClassName, os );
     81        } // if
     82
     83        printEnums( storageClasses.begin(), storageClasses.end(), DeclarationNode::storageName, os );
    8884        if ( type ) {
    8985                type->print( os, indent );
    9086        } else {
    9187                os << "untyped entity ";
    92         }
     88        } // if
    9389
    9490        if ( bitfieldWidth ) {
    95                 os << endl << string(indent+2,  ' ') << "with bitfield width ";
     91                os << endl << string( indent + 2, ' ' ) << "with bitfield width ";
    9692                bitfieldWidth->printOneLine( os );
    97         }
     93        } // if
    9894
    9995        if ( initializer != 0 ) {
    100                 os << endl << string(indent+2,  ' ') << "with initializer ";
     96                os << endl << string( indent + 2, ' ' ) << "with initializer ";
    10197                initializer->printOneLine( os );
    102         }
     98        } // if
    10399
    104100        os << endl;
     
    109105        if ( hasEllipsis ) {
    110106                os << string( indent, ' ' )  << "and a variable number of other arguments" << endl;
    111         }
     107        } // if
    112108}
    113109
     
    123119        if ( body ) {
    124120                newnode->type->function->hasBody = true;
    125         }
     121        } // if
    126122
    127123        if ( ret ) {
     
    129125                ret->type = 0;
    130126                delete ret;
    131         }
     127        } // if
    132128
    133129        return newnode;
     
    141137}
    142138
    143 DeclarationNode *DeclarationNode::newStorageClass( StorageClass sc ) {
     139DeclarationNode *DeclarationNode::newStorageClass( DeclarationNode::StorageClass sc ) {
    144140        DeclarationNode *newnode = new DeclarationNode;
    145141        newnode->storageClasses.push_back( sc );
     
    161157}
    162158
    163 DeclarationNode *DeclarationNode::newForall( DeclarationNode* forall ) {
     159DeclarationNode *DeclarationNode::newForall( DeclarationNode *forall ) {
    164160        DeclarationNode *newnode = new DeclarationNode;
    165161        newnode->type = new TypeData( TypeData::Unknown );
     
    168164}
    169165
    170 DeclarationNode *DeclarationNode::newFromTypedef( std::string* name ) {
     166DeclarationNode *DeclarationNode::newFromTypedef( std::string *name ) {
    171167        DeclarationNode *newnode = new DeclarationNode;
    172168        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    177173}
    178174
    179 DeclarationNode *DeclarationNode::newAggregate( TyCon kind, std::string* name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ) {
     175DeclarationNode *DeclarationNode::newAggregate( Aggregate kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields ) {
    180176        DeclarationNode *newnode = new DeclarationNode;
    181177        newnode->type = new TypeData( TypeData::Aggregate );
     
    184180        if ( newnode->type->aggregate->name == "" ) {
    185181                newnode->type->aggregate->name = DeclarationNode::anonymous.newName();
    186         }
     182        } // if
     183
     184        // SKULLDUGGERY: generate a typedef for the aggregate name so that the aggregate does not have to be qualified by
     185        // "struct"
     186        typedefTable.addToEnclosingScope( newnode->type->aggregate->name, TypedefTable::TD );
     187        DeclarationNode *typedf = new DeclarationNode;
     188        typedf->name = newnode->type->aggregate->name;
     189        newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );
     190
    187191        newnode->type->aggregate->params = formals;
    188192        newnode->type->aggregate->actuals = actuals;
     
    198202        if ( newnode->type->enumeration->name == "" ) {
    199203                newnode->type->enumeration->name = DeclarationNode::anonymous.newName();
    200         }
     204        } // if
     205
     206        // SKULLDUGGERY: generate a typedef for the enumeration name so that the enumeration does not have to be qualified
     207        // by "enum"
     208        typedefTable.addToEnclosingScope( newnode->type->enumeration->name, TypedefTable::TD );
     209        DeclarationNode *typedf = new DeclarationNode;
     210        typedf->name = newnode->type->enumeration->name;
     211        newnode->appendList( typedf->addType( newnode->clone() )->addTypedef() );
     212
    201213        newnode->type->enumeration->constants = constants;
    202214        return newnode;
    203215}
    204216
    205 DeclarationNode *DeclarationNode::newEnumConstant( std::string* name, ExpressionNode *constant ) {
     217DeclarationNode *DeclarationNode::newEnumConstant( std::string *name, ExpressionNode *constant ) {
    206218        DeclarationNode *newnode = new DeclarationNode;
    207219        newnode->name = assign_strptr( name );
     
    210222}
    211223
    212 DeclarationNode *DeclarationNode::newName( std::string* name ) {
     224DeclarationNode *DeclarationNode::newName( std::string *name ) {
    213225        DeclarationNode *newnode = new DeclarationNode;
    214226        newnode->name = assign_strptr( name );
     
    216228}
    217229
    218 DeclarationNode *DeclarationNode::newFromTypeGen( std::string* name, ExpressionNode *params ) {
     230DeclarationNode *DeclarationNode::newFromTypeGen( std::string *name, ExpressionNode *params ) {
    219231        DeclarationNode *newnode = new DeclarationNode;
    220232        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    225237}
    226238
    227 DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string* name ) {
     239DeclarationNode *DeclarationNode::newTypeParam( TypeClass tc, std::string *name ) {
    228240        DeclarationNode *newnode = new DeclarationNode;
    229241        newnode->name = assign_strptr( name );
     
    331343                        } else {
    332344                                dst->forall = src->forall;
    333                         }
     345                        } // if
    334346                        src->forall = 0;
    335                 }
     347                } // if
    336348                if ( dst->base ) {
    337349                        addQualifiersToType( src, dst->base );
     
    341353                } else {
    342354                        dst->qualifiers.splice( dst->qualifiers.end(), src->qualifiers );
    343                 }
    344         }
     355                } // if
     356        } // if
    345357}
    346358         
     
    351363                        if ( ! type ) {
    352364                                type = new TypeData;
    353                         }
     365                        } // if
    354366                        addQualifiersToType( q->type, type );
    355367                        if ( q->type && q->type->forall ) {
     
    357369                                        type->forall->appendList( q->type->forall );
    358370                                } else {
    359                                         type->forall = q->type->forall;
    360                                 }
     371                                        if ( type->kind == TypeData::Aggregate ) {
     372                                                type->aggregate->params = q->type->forall;
     373                                        } else {
     374                                                type->forall = q->type->forall;
     375                                        } // if
     376                                } // if
    361377                                q->type->forall = 0;
    362                         }
    363                 }
    364         }
     378                        } // if
     379                } // if
     380        } // if
    365381        delete q;
    366382        return this;
     
    379395                        } else {
    380396                                dst->forall = src->forall;
    381                         }
     397                        } // if
    382398                        src->forall = 0;
    383                 }
     399                } // if
    384400                if ( dst->base ) {
    385401                        addTypeToType( src, dst->base );
     
    398414                                        dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers );
    399415                                        dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec );
    400                                 }
     416                                } // if
    401417                                break;
    402418
     
    409425                                        if ( src->kind == TypeData::Aggregate ) {
    410426                                                dst->base->aggInst->params = maybeClone( src->aggregate->actuals );
    411                                         }
     427                                        } // if
    412428                                        dst->base->qualifiers.splice( dst->base->qualifiers.end(), src->qualifiers );
    413429                                        src = 0;
     
    419435                                        } else {
    420436                                                dst->forall = src->forall;
    421                                         }
     437                                        } // if
    422438                                        src->forall = 0;
    423439                                        dst->base = src;
    424440                                        src = 0;
    425                                 }
    426                         }
    427                 }
    428         }
     441                                } // switch
     442                        } // switch
     443                } // if
     444        } // if
    429445}
    430446
     
    439455                                        if ( o->type->kind == TypeData::Aggregate ) {
    440456                                                type->aggInst->params = maybeClone( o->type->aggregate->actuals );
    441                                         }
     457                                        } // if
    442458                                        type->qualifiers.splice( type->qualifiers.end(), o->type->qualifiers );
    443459                                } else {
    444460                                        type = o->type;
    445                                 }
     461                                } // if
    446462                                o->type = 0;
    447463                        } else {
    448464                                addTypeToType( o->type, type );
    449                         }
    450                 }
     465                        } // if
     466                } // if
    451467                if ( o->bitfieldWidth ) {
    452468                        bitfieldWidth = o->bitfieldWidth;
    453                 }
    454         }
     469                } // if
     470        } // if
    455471        delete o;
    456472        return this;
     
    467483}
    468484
    469 DeclarationNode *DeclarationNode::addAssertions( DeclarationNode* assertions ) {
     485DeclarationNode *DeclarationNode::addAssertions( DeclarationNode *assertions ) {
    470486        assert( type );
    471487        switch ( type->kind ) {
     
    475491                } else {
    476492                        type->symbolic->assertions = assertions;
    477                 }
     493                } // if
    478494                break;
    479        
    480495          case TypeData::Variable:
    481496                if ( type->variable->assertions ) {
     
    483498                } else {
    484499                        type->variable->assertions = assertions;
    485                 }
     500                } // if
    486501                break;
    487        
    488502          default:
    489503                assert( false );
    490         }
     504        } // switch
    491505       
    492506        return this;
    493507}
    494508
    495 DeclarationNode *DeclarationNode::addName( std::string* newname ) {
     509DeclarationNode *DeclarationNode::addName( std::string *newname ) {
    496510        name = assign_strptr( newname );
    497511        return this;
     
    526540}
    527541
    528 static void
    529 setBase( TypeData *&type, TypeData *newType ) {
     542static void setBase( TypeData *&type, TypeData *newType ) {
    530543        if ( type ) {
    531544                TypeData *prevBase = type;
     
    534547                        prevBase = curBase;
    535548                        curBase = curBase->base;
    536                 }
     549                } // while
    537550                prevBase->base = newType;
    538551        } else {
    539552                type = newType;
    540         }
     553        } // if
    541554}
    542555
     
    547560                p->type = 0;
    548561                delete p;
    549         }
     562        } // if
    550563        return this;
    551564}
     
    557570                a->type = 0;
    558571                delete a;
    559         }
     572        } // if
    560573        return this;
    561574}
     
    572585                                if ( type->kind == TypeData::Aggregate ) {
    573586                                        p->type->base->aggInst->params = maybeClone( type->aggregate->actuals );
    574                                 }
     587                                } // if
    575588                                p->type->base->qualifiers.splice( p->type->base->qualifiers.end(), type->qualifiers );
    576589                                break;
     
    578591                          default:
    579592                                p->type->base = type;
    580                         }
     593                        } // switch
    581594                        type = 0;
    582                 }
     595                } // if
    583596                delete this;
    584597                return p;
    585598        } else {
    586599                return this;
    587         }
     600        } // if
    588601}
    589602
     
    593606        while ( cur->base ) {
    594607                cur = cur->base;
    595         }
     608        } // while
    596609        return cur;
    597610}
     
    609622                                if ( type->kind == TypeData::Aggregate ) {
    610623                                        lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals );
    611                                 }
     624                                } // if
    612625                                lastArray->base->qualifiers.splice( lastArray->base->qualifiers.end(), type->qualifiers );
    613626                                break;
    614627                          default:
    615628                                lastArray->base = type;
    616                         }
     629                        } // switch
    617630                        type = 0;
    618                 }
     631                } // if
    619632                delete this;
    620633                return a;
    621634        } else {
    622635                return this;
    623         }
     636        } // if
    624637}
    625638
     
    637650                } else {
    638651                        type->function->idList = ids;
    639                 }
     652                } // if
    640653                return type;
    641654        } else {
     
    643656                newtype->function->idList = ids;
    644657                return newtype;
    645         }
     658        } // if
    646659}
    647660       
     
    662675        while ( srcType->base ) {
    663676                srcType = srcType->base;
    664         }
     677        } // while
    665678        newnode->type = maybeClone( srcType );
    666679        if ( newnode->type->kind == TypeData::AggregateInst ) {
     
    673686                        delete newnode->type->aggInst->aggregate->aggregate->members;
    674687                        newnode->type->aggInst->aggregate->aggregate->members = 0;
    675                 }
    676         }
     688                } // if
     689        } // if
    677690        newnode->type->forall = maybeClone( type->forall );
    678691        newnode->storageClasses = storageClasses;
     
    688701                        while ( srcType->base ) {
    689702                                srcType = srcType->base;
    690                         }
     703                        } // while
    691704                        TypeData *newType = srcType->clone();
    692705                        if ( newType->kind == TypeData::AggregateInst ) {
     
    699712                                        delete newType->aggInst->aggregate->aggregate->members;
    700713                                        newType->aggInst->aggregate->aggregate->members = 0;
    701                                 }
    702                         }
     714                                } // if
     715                        } // if
    703716                        newType->forall = maybeClone( type->forall );
    704717                        if ( ! o->type ) {
     
    707720                                addTypeToType( newType, o->type );
    708721                                delete newType;
    709                         }
    710                 }
    711         }
     722                        } // if
     723                } // if
     724        } // if
    712725        return o;
    713726}
     
    731744                                addTypeToType( newType, o->type );
    732745                                delete newType;
    733                         }
    734                 }
    735         }
     746                        } // if
     747                } // if
     748        } // if
    736749        return o;
    737750}
     
    740753        if ( node != 0 ) {
    741754                set_link( node );
    742         }
     755        } // if
    743756        return this;
    744757}
     
    756769}
    757770
    758 void buildList( const DeclarationNode *firstNode, std::list< Declaration* > &outputList ) {
     771void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ) {
    759772        SemanticError errors;
    760         std::back_insert_iterator< std::list< Declaration* > > out( outputList );
     773        std::back_insert_iterator< std::list< Declaration *> > out( outputList );
    761774        const DeclarationNode *cur = firstNode;
    762775        while ( cur ) {
     
    776789                        errors.append( e );
    777790                } // try
    778                 cur = dynamic_cast< DeclarationNode* >( cur->get_link() );
     791                cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
    779792        } // while
    780793        if ( ! errors.isEmpty() ) {
     
    783796}
    784797
    785 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType* > &outputList ) {
     798void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ) {
    786799        SemanticError errors;
    787         std::back_insert_iterator< std::list< DeclarationWithType* > > out( outputList );
     800        std::back_insert_iterator< std::list< DeclarationWithType *> > out( outputList );
    788801        const DeclarationNode *cur = firstNode;
    789802        while ( cur ) {
     
    799812                        Declaration *decl = cur->build();
    800813                        if ( decl ) {
    801                                 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) {
     814                                if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType *>( decl ) ) {
    802815                                        *out++ = dwt;
    803                                 } else if ( StructDecl *agg = dynamic_cast< StructDecl* >( decl ) ) {
     816                                } else if ( StructDecl *agg = dynamic_cast< StructDecl *>( decl ) ) {
    804817                                        StructInstType *inst = new StructInstType( Type::Qualifiers(), agg->get_name() );
    805                                         *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );
     818                                        *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
    806819                                        delete agg;
    807                                 } else if ( UnionDecl *agg = dynamic_cast< UnionDecl* >( decl ) ) {
     820                                } else if ( UnionDecl *agg = dynamic_cast< UnionDecl *>( decl ) ) {
    808821                                        UnionInstType *inst = new UnionInstType( Type::Qualifiers(), agg->get_name() );
    809                                         *out++ = new ObjectDecl( "", Declaration::NoStorageClass, linkage, 0, inst, 0 );
     822                                        *out++ = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, 0, inst, 0 );
    810823                                } // if
    811824                        } // if
     
    813826                        errors.append( e );
    814827                } // try
    815                 cur = dynamic_cast< DeclarationNode* >( cur->get_link() );
     828                cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
    816829        } // while
    817830        if ( ! errors.isEmpty() ) {
     
    820833}
    821834
    822 void buildTypeList( const DeclarationNode *firstNode, std::list< Type* > &outputList ) {
     835void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList ) {
    823836        SemanticError errors;
    824         std::back_insert_iterator< std::list< Type* > > out( outputList );
     837        std::back_insert_iterator< std::list< Type *> > out( outputList );
    825838        const DeclarationNode *cur = firstNode;
    826839        while ( cur ) {
     
    830843                        errors.append( e );
    831844                } // try
    832                 cur = dynamic_cast< DeclarationNode* >( cur->get_link() );
     845                cur = dynamic_cast< DeclarationNode *>( cur->get_link() );
    833846        } // while
    834847        if ( ! errors.isEmpty() ) {
     
    839852Declaration *DeclarationNode::build() const {
    840853        if ( type ) {
    841                 Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildInline(), linkage, maybeBuild< Initializer >(initializer) );
     854                Declaration *newDecl = type->buildDecl( name, buildStorageClass(), maybeBuild< Expression >( bitfieldWidth ), buildFuncSpecifier( Inline ), buildFuncSpecifier( Noreturn ), linkage, maybeBuild< Initializer >(initializer) );
    842855                return newDecl;
    843856        } // if
    844         if ( ! buildInline() ) {
     857        if ( ! buildFuncSpecifier( Inline ) && ! buildFuncSpecifier( Noreturn ) ) {
    845858                return new ObjectDecl( name, buildStorageClass(), linkage, maybeBuild< Expression >( bitfieldWidth ), 0, maybeBuild< Initializer >( initializer ) );
    846859        } // if
    847         throw SemanticError( "invalid inline specification in declaration of ", this );
     860        throw SemanticError( "invalid function specifier in declaration of ", this );
    848861}
    849862
     
    882895}
    883896
    884 Declaration::StorageClass DeclarationNode::buildStorageClass() const {
    885         static const Declaration::StorageClass scMap[] = { 
    886                 Declaration::Extern,
    887                 Declaration::Static,
    888                 Declaration::Auto,
    889                 Declaration::Register,
    890                 Declaration::Inline,
    891                 Declaration::Fortran
    892         }; 
    893  
    894         Declaration::StorageClass ret = Declaration::NoStorageClass;
    895         for ( std::list< StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
    896                 assert( unsigned( *i ) < sizeof( scMap ) / sizeof( scMap[0] ) );
    897           if ( *i == Inline ) continue;
    898           if ( ret != Declaration::NoStorageClass ) {
     897DeclarationNode::StorageClass DeclarationNode::buildStorageClass() const {
     898        DeclarationNode::StorageClass ret = DeclarationNode::NoStorageClass;
     899        for ( std::list< DeclarationNode::StorageClass >::const_iterator i = storageClasses.begin(); i != storageClasses.end(); ++i ) {
     900          if ( *i == DeclarationNode::Inline || *i == DeclarationNode::Noreturn ) continue; // ignore function specifiers
     901          if ( ret != DeclarationNode::NoStorageClass ) {       // already have a valid storage class ?
    899902                        throw SemanticError( "invalid combination of storage classes in declaration of ", this );
    900                 }
    901                 ret = scMap[ *i ];
    902         }
     903                } // if
     904                ret = *i;
     905        } // for
    903906        return ret;
    904907}
    905908
    906 bool DeclarationNode::buildInline() const {
    907         std::list< StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), Inline );
    908   if ( first == storageClasses.end() ) return false;
    909         std::list< StorageClass >::const_iterator next = std::find( ++first, storageClasses.end(), Inline );
    910   if ( next == storageClasses.end() ) return true;
    911         throw SemanticError( "duplicate inline specification in declaration of ", this );
     909bool DeclarationNode::buildFuncSpecifier( DeclarationNode::StorageClass key ) const {
     910        std::list< DeclarationNode::StorageClass >::const_iterator first = std::find( storageClasses.begin(), storageClasses.end(), key );
     911  if ( first == storageClasses.end() ) return false;    // not found
     912        first = std::find( ++first, storageClasses.end(), key ); // found
     913  if ( first == storageClasses.end() ) return true;             // not found again
     914        throw SemanticError( "duplicate function specifier in declaration of ", this );
    912915}
    913916
  • src/Parser/ExpressionNode.cc

    reb50842 r937e51d  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:17:07 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 13:19:35 2015
    13 // Update Count     : 2
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jun 24 16:20:00 2015
     13// Update Count     : 158
    1414//
    1515
     
    1717#include <cctype>
    1818#include <algorithm>
     19#include <sstream>
     20#include <cstdio>
     21#include <climits>
    1922
    2023#include "ParseNode.h"
    21 #include "SynTree/Type.h"
    2224#include "SynTree/Constant.h"
    2325#include "SynTree/Expression.h"
    24 #include "SynTree/Declaration.h"
    2526#include "UnimplementedError.h"
    2627#include "parseutility.h"
     
    3132ExpressionNode::ExpressionNode() : ParseNode(), argName( 0 ) {}
    3233
    33 ExpressionNode::ExpressionNode( string *name_) : ParseNode( *name_ ), argName( 0 ) {
    34         delete name_;
    35 }
     34ExpressionNode::ExpressionNode( const string *name_ ) : ParseNode( name_ ), argName( 0 ) {}
    3635
    3736ExpressionNode::ExpressionNode( const ExpressionNode &other ) : ParseNode( other.name ) {
     
    4342}
    4443
    45 ExpressionNode * ExpressionNode::set_asArgName( std::string *aName ) {
     44ExpressionNode * ExpressionNode::set_asArgName( const std::string *aName ) {
    4645        argName = new VarRefNode( aName );
    4746        return this;
     
    5554void ExpressionNode::printDesignation( std::ostream &os, int indent ) const {
    5655        if ( argName ) {
    57                 os << string(' ', indent ) << "(designated by:  ";
     56                os << string( indent, ' ' ) << "(designated by:  ";
    5857                argName->printOneLine( os, indent );
    5958                os << ")" << std::endl;
     
    6160}
    6261
     62//##############################################################################
     63
    6364NullExprNode::NullExprNode() {}
    6465
     
    8586}
    8687
    87 //  enum ConstantNode::Type =  { Integer, Float, Character, String, Range }
    88 
    89 ConstantNode::ConstantNode( void ) : ExpressionNode(), sign( true ), longs(0), size(0) {}
    90 
    91 ConstantNode::ConstantNode( string *name_) : ExpressionNode( name_), sign( true ), longs(0), size(0) {}
    92 
    93 ConstantNode::ConstantNode( Type t, string *inVal ) : type( t ), sign( true ), longs(0), size(0) {
    94         if ( inVal ) {
    95                 value = *inVal;
    96                 delete inVal;
    97         } else {
    98                 value = "";
    99         } // if
    100 
    101         classify( value );
    102 }
    103 
    104 ConstantNode::ConstantNode( const ConstantNode &other ) : ExpressionNode( other ), type( other.type ), value( other.value ), sign( other.sign ),
    105                                                                                                                   base( other.base ), longs( other.longs ), size( other.size ) {
    106 }
    107 
    108 // for some reason, std::tolower doesn't work as an argument to std::transform in g++ 3.1
    109 inline char tolower_hack( char c ) {
    110         return std::tolower( c );
    111 }
    112 
    113 void ConstantNode::classify( std::string &str ) {
     88//##############################################################################
     89
     90static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
     91static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }
     92static inline bool checkF( char c ) { return c == 'f' || c == 'F'; }
     93static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
     94
     95// Difficult to separate extra parts of constants during lexing because actions are not allow in the middle of patterns:
     96//
     97//              prefix action constant action suffix
     98//
     99// Alternatively, breaking a pattern using BEGIN does not work if the following pattern can be empty:
     100//
     101//              constant BEGIN CONT ...
     102//              <CONT>(...)? BEGIN 0 ... // possible empty suffix
     103//
     104// because the CONT rule is NOT triggered if the pattern is empty. Hence, constants are reparsed here to determine their
     105// type.
     106
     107ConstantNode::ConstantNode( Type t, string *inVal ) : type( t ), value( *inVal ) {
     108        // lexing divides constants into 4 kinds
     109        switch ( type ) {
     110          case Integer:
     111                {
     112                        static const BasicType::Kind kind[2][3] = {
     113                                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
     114                                { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
     115                        };
     116                        size_t last = value.length() - 1;                       // last character of constant
     117                        unsigned long long v;                                           // converted integral value
     118                        bool dec = true, Unsigned = false;                      // decimal, unsigned constant
     119                        int size;                                                                       // 0 => int, 1 => long, 2 => long long
     120
     121                        if ( value[0] == '0' ) {                                        // octal constant ?
     122                                dec = false;
     123                                if ( last != 0 && checkX( value[1] ) ) { // hex constant ?
     124                                        sscanf( (char *)value.c_str(), "%llx", &v );
     125                                        //printf( "%llx %llu\n", v, v );
     126                                } else {
     127                                        sscanf( (char *)value.c_str(), "%llo", &v );
     128                                        //printf( "%llo %llu\n", v, v );
     129                                } // if
     130                        } else {                                                                        // decimal constant ?
     131                                sscanf( (char *)value.c_str(), "%llu", &v );
     132                                //printf( "%llu %llu\n", v, v );
     133                        } // if
     134
     135                        if ( v <= INT_MAX ) {                                           // signed int
     136                                size = 0;
     137                        } else if ( v <= UINT_MAX && ! dec ) {          // unsigned int
     138                                size = 0;
     139                                Unsigned = true;                                                // unsigned
     140                        } else if ( v <= LONG_MAX ) {                           // signed long int
     141                                size = 1;
     142                        } else if ( v <= ULONG_MAX && ( ! dec || LONG_MAX == LLONG_MAX ) ) { // signed long int
     143                                size = 1;
     144                                Unsigned = true;                                                // unsigned long int
     145                        } else if ( v <= LLONG_MAX ) {                          // signed long long int
     146                                size = 2;
     147                        } else {                                                                        // unsigned long long int
     148                                size = 2;
     149                                Unsigned = true;                                                // unsigned long long int
     150                        } // if
     151
     152                        if ( checkU( value[last] ) ) {                          // suffix 'u' ?
     153                                Unsigned = true;
     154                                if ( last > 0 && checkL( value[ last - 1 ] ) ) { // suffix 'l' ?
     155                                        size = 1;
     156                                        if ( last > 1 && checkL( value[ last - 2 ] ) ) { // suffix 'll' ?
     157                                                size = 2;
     158                                        } // if
     159                                } // if
     160                        } else if ( checkL( value[ last ] ) ) {         // suffix 'l' ?
     161                                size = 1;
     162                                if ( last > 0 && checkL( value[ last - 1 ] ) ) { // suffix 'll' ?
     163                                        size = 2;
     164                                        if ( last > 1 && checkU( value[ last - 2 ] ) ) { // suffix 'u' ?
     165                                                Unsigned = true;
     166                                        } // if
     167                                } else {
     168                                        if ( last > 0 && checkU( value[ last - 1 ] ) ) { // suffix 'u' ?
     169                                                Unsigned = true;
     170                                        } // if
     171                                } // if
     172                        } // if
     173                        btype = kind[Unsigned][size];                           // lookup constant type
     174                        break;
     175                }
     176          case Float:
     177                {
     178                        size_t len = value.length() - 1;
     179
     180                        btype = BasicType::Double;                                      // default
     181                        if ( checkF( value[len] ) ) {                           // float ?
     182                                btype = BasicType::Float;
     183                        } // if
     184                        if ( checkL( value[len] ) ) {                           // long double ?
     185                                btype = BasicType::LongDouble;
     186                        } // if
     187                        break;
     188                }
     189          case Character:
     190                btype = BasicType::Char;                                                // default
     191                if ( string( "LUu" ).find( value[0] ) != string::npos ) {
     192                        // ???
     193                } // if
     194                break;
     195          case String:
     196                // array of char
     197                if ( string( "LUu" ).find( value[0] ) != string::npos ) {
     198                        if ( value[0] == 'u' && value[1] == '8' ) {
     199                                // ???
     200                        } else {
     201                                // ???
     202                        } // if
     203                } // if
     204                break;
     205        } // switch
     206} // ConstantNode::ConstantNode
     207
     208ConstantNode *ConstantNode::appendstr( const std::string *newValue ) {
     209        assert( newValue != 0 );
     210        assert( type == String );
     211
     212        // "abc" "def" "ghi" => "abcdefghi", so remove new text from quotes and insert before last quote in old string.
     213        value.insert( value.length() - 1, newValue->substr( 1, newValue->length() - 2 ) );
     214       
     215        delete newValue;                                                                        // allocated by lexer
     216        return this;
     217}
     218
     219void ConstantNode::printOneLine( std::ostream &os, int indent ) const {
     220        os << string( indent, ' ' );
     221        printDesignation( os );
     222
    114223        switch ( type ) {
    115224          case Integer:
    116225          case Float:
    117                 {
    118                         std::string sfx("");
    119                         char c;
    120                         int i = str.length() - 1;
    121 
    122                         while ( i >= 0 && ! isxdigit( c = str.at( i--)) )
    123                                 sfx += c;
    124 
    125                         value = str.substr( 0, i + 2 );
    126 
    127                         // get rid of underscores
    128                         value.erase( remove( value.begin(), value.end(), '_'), value.end());
    129 
    130                         std::transform( sfx.begin(), sfx.end(), sfx.begin(), tolower_hack );
    131 
    132                         if ( sfx.find("ll") != string::npos ) {
    133                                 longs = 2;
    134                         } else if ( sfx.find("l") != string::npos ) {
    135                                 longs = 1;
    136                         } // if
    137 
    138                         assert(( longs >= 0) && ( longs <= 2));
    139 
    140                         if ( sfx.find("u") != string::npos )
    141                                 sign = false;
    142 
    143                         break;
    144                 }
    145           case Character:
    146                 {
    147                         // remove underscores from hex and oct escapes
    148                         if ( str.substr(1,2) == "\\x")
    149                                 value.erase( remove( value.begin(), value.end(), '_'), value.end());
    150 
    151                         break;
    152                 }
    153           default:
    154                 // shouldn't be here
    155                 ;
    156         }
    157 }
    158 
    159 ConstantNode::Type ConstantNode::get_type( void ) const {
    160         return type;
    161 }
    162 
    163 ConstantNode *ConstantNode::append( std::string *newValue ) {
    164         if ( newValue ) {
    165                 if ( type == String ) {
    166                         std::string temp = *newValue;
    167                         value.resize( value.size() - 1 );
    168                         value += newValue->substr(1, newValue->size());
    169                 } else
    170                         value += *newValue;
    171 
    172                 delete newValue;
    173         } // if
    174         return this;
    175 }
    176 
    177 void ConstantNode::printOneLine( std::ostream &os, int indent ) const {
    178         os << string( indent, ' ');
    179         printDesignation( os );
    180 
    181         switch ( type ) {
    182                 /* integers */
    183           case Integer:
    184226                os << value ;
    185227                break;
    186           case Float:
    187                 os << value ;
    188                 break;
    189 
    190228          case Character:
    191229                os << "'" << value << "'";
    192230                break;
    193 
    194231          case String:
    195232                os << '"' << value << '"';
    196233                break;
    197         }
     234        } // switch
    198235
    199236        os << ' ';
     
    206243
    207244Expression *ConstantNode::build() const {
    208         ::Type::Qualifiers q;
    209         BasicType *bt;
    210 
    211         switch ( get_type()) {
    212           case Integer:
    213                 /* Cfr. standard 6.4.4.1 */
    214                 //bt.set_kind( BasicType::SignedInt );
    215                 bt = new BasicType( q, BasicType::SignedInt );
    216                 break;
    217           case Float:
    218                 bt = new BasicType( q, BasicType::Float );
    219                 break;
    220           case Character:
    221                 bt = new BasicType( q, BasicType::Char );
    222                 break;
     245        ::Type::Qualifiers q;                                                           // no qualifiers on constants
     246
     247        switch ( get_type() ) {
    223248          case String:
    224                 // string should probably be a primitive type
    225                 ArrayType *at;
    226                 std::string value = get_value();
    227                 at = new ArrayType( q, new BasicType( q, BasicType::Char ),
    228                                                         new ConstantExpr( Constant( new BasicType( q, BasicType::SignedInt ),
    229                                                                                                                 toString( value.size() - 1 ) ) ),  // account for '\0'
    230                                                         false, false );
    231                 return new ConstantExpr( Constant( at, value ), maybeBuild< Expression >( get_argName() ) );
     249                {
     250                        // string should probably be a primitive type
     251                        ArrayType *at = new ArrayType( q, new BasicType( q, BasicType::Char ),
     252                                                                                   new ConstantExpr(
     253                                                                                           Constant( new BasicType( q, BasicType::UnsignedInt ),
     254                                                                                                                 toString( value.size()+1-2 ) ) ),  // +1 for '\0' and -2 for '"'
     255                                                                                   false, false );
     256                        return new ConstantExpr( Constant( at, value ), maybeBuild< Expression >( get_argName() ) );
     257                }
     258          default:
     259                return new ConstantExpr( Constant( new BasicType( q, btype ), get_value() ), maybeBuild< Expression >( get_argName() ) );
    232260        }
    233         return new ConstantExpr(  Constant( bt, get_value()),  maybeBuild< Expression >( get_argName() ) );
    234 }
     261}
     262
     263//##############################################################################
    235264
    236265VarRefNode::VarRefNode() : isLabel( false ) {}
    237266
    238 VarRefNode::VarRefNode( string *name_, bool labelp ) : ExpressionNode( name_), isLabel( labelp ) {}
     267VarRefNode::VarRefNode( const string *name_, bool labelp ) : ExpressionNode( name_ ), isLabel( labelp ) {}
    239268
    240269VarRefNode::VarRefNode( const VarRefNode &other ) : ExpressionNode( other ), isLabel( other.isLabel ) {
     
    252281void VarRefNode::print( std::ostream &os, int indent ) const {
    253282        printDesignation( os );
    254         os << '\r' << string( indent, ' ') << "Referencing: ";
     283        os << string( indent, ' ' ) << "Referencing: ";
    255284        os << "Variable: " << get_name();
    256285        os << endl;
    257286}
    258287
     288//##############################################################################
     289
    259290OperatorNode::OperatorNode( Type t ) : type( t ) {}
    260291
     
    275306void OperatorNode::print( std::ostream &os, int indent ) const{
    276307        printDesignation( os );
    277         os << '\r' << string( indent, ' ') << "Operator: " << OpName[type] << endl;
     308        os << string( indent, ' ' ) << "Operator: " << OpName[type] << endl;
    278309        return;
    279310}
    280311
    281 std::string OperatorNode::get_typename( void ) const{
    282         return string( OpName[ type ]);
     312const char *OperatorNode::get_typename( void ) const{
     313        return OpName[ type ];
    283314}
    284315
     
    288319        "Cond",   "NCond",
    289320        // diadic
    290         "SizeOf",      "AlignOf", "Attr", "CompLit", "Plus",    "Minus",   "Mul",     "Div",     "Mod",      "Or",
     321        "SizeOf",     "AlignOf", "Attr", "CompLit", "Plus",    "Minus",   "Mul",     "Div",     "Mod",      "Or",
    291322        "And",       "BitOr",   "BitAnd",  "Xor",     "Cast",    "LShift",  "RShift",  "LThan",   "GThan",
    292323        "LEThan",    "GEThan", "Eq",      "Neq",     "Assign",  "MulAssn", "DivAssn", "ModAssn", "PlusAssn",
     
    297328};
    298329
     330//##############################################################################
     331
    299332CompositeExprNode::CompositeExprNode( void ) : ExpressionNode(), function( 0 ), arguments( 0 ) {
    300333}
    301334
    302 CompositeExprNode::CompositeExprNode( string *name_) : ExpressionNode( name_), function( 0 ), arguments( 0 ) {
     335CompositeExprNode::CompositeExprNode( const string *name_ ) : ExpressionNode( name_ ), function( 0 ), arguments( 0 ) {
    303336}
    304337
     
    331364// the names that users use to define operator functions
    332365static const char *opFuncName[] = {
    333         "",  "", "",
    334         "",   "",
    335         // diadic
    336         "",   "", "", "", "?+?",    "?-?",   "?*?",     "?/?",     "?%?",     "",      "",
    337         "?|?",  "?&?",  "?^?",     "",    "?<<?",  "?>>?",  "?<?",   "?>?",    "?<=?",
    338         "?>=?", "?==?",      "?!=?",     "?=?",  "?*=?", "?/=?", "?%=?", "?+=?", "?-=?",
    339         "?<<=?", "?>>=?",  "?&=?", "?^=?",  "?|=?",  "?[?]",   "","","Range",
    340         // monadic
    341         "+?", "-?", "", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "LabAddress"
     366        "",             "",             "",
     367        "",             "",
     368        //diadic
     369        "",             "",             "",             "",             "?+?",          "?-?",  "?*?",  "?/?",  "?%?",  "",              "",
     370        "?|?",          "?&?",          "?^?",  "",             "?<<?", "?>>?", "?<?",  "?>?",  "?<=?",
     371        "?>=?",         "?==?",         "?!=?", "?=?",  "?*=?", "?/=?", "?%=?", "?+=?", "?-=?",
     372        "?<<=?",        "?>>=?",        "?&=?", "?^=?", "?|=?", "?[?]", "",             "",             "Range",
     373        //monadic
     374        "+?",           "-?",           "",             "*?",   "!?",   "~?",   "++?",  "?++",  "--?",  "?--",  "&&"
    342375};
    343376
     
    350383        buildList( get_args(), args );
    351384
    352         if ( ! ( op = dynamic_cast<OperatorNode *>( function )) ) {
    353                 // a function as opposed to an operator
     385        if ( ! ( op = dynamic_cast<OperatorNode *>( function ) ) ) { // function as opposed to operator
    354386                return new UntypedExpr( function->build(), args, maybeBuild< Expression >( get_argName() ));
    355         } else {
    356                 switch ( op->get_type()) {
    357                   case OperatorNode::Incr:
    358                   case OperatorNode::Decr:
    359                   case OperatorNode::IncrPost:
    360                   case OperatorNode::DecrPost:
    361                   case OperatorNode::Assign:
    362                   case OperatorNode::MulAssn:
    363                   case OperatorNode::DivAssn:
    364                   case OperatorNode::ModAssn:
    365                   case OperatorNode::PlusAssn:
    366                   case OperatorNode::MinusAssn:
    367                   case OperatorNode::LSAssn:
    368                   case OperatorNode::RSAssn:
    369                   case OperatorNode::AndAssn:
    370                   case OperatorNode::ERAssn:
    371                   case OperatorNode::OrAssn:
    372                         // the rewrite rules for these expressions specify that the first argument has its address taken
    373                         assert( ! args.empty() );
    374                         args.front() = new AddressExpr( args.front() );
    375                         break;
    376                   default:
    377                         /* do nothing */
    378                         ;
    379                 }
    380 
    381                 switch ( op->get_type() ) {
    382                   case OperatorNode::Incr:
    383                   case OperatorNode::Decr:
    384                   case OperatorNode::IncrPost:
    385                   case OperatorNode::DecrPost:
    386                   case OperatorNode::Assign:
    387                   case OperatorNode::MulAssn:
    388                   case OperatorNode::DivAssn:
    389                   case OperatorNode::ModAssn:
    390                   case OperatorNode::PlusAssn:
    391                   case OperatorNode::MinusAssn:
    392                   case OperatorNode::LSAssn:
    393                   case OperatorNode::RSAssn:
    394                   case OperatorNode::AndAssn:
    395                   case OperatorNode::ERAssn:
    396                   case OperatorNode::OrAssn:
    397                   case OperatorNode::Plus:
    398                   case OperatorNode::Minus:
    399                   case OperatorNode::Mul:
    400                   case OperatorNode::Div:
    401                   case OperatorNode::Mod:
    402                   case OperatorNode::BitOr:
    403                   case OperatorNode::BitAnd:
    404                   case OperatorNode::Xor:
    405                   case OperatorNode::LShift:
    406                   case OperatorNode::RShift:
    407                   case OperatorNode::LThan:
    408                   case OperatorNode::GThan:
    409                   case OperatorNode::LEThan:
    410                   case OperatorNode::GEThan:
    411                   case OperatorNode::Eq:
    412                   case OperatorNode::Neq:
    413                   case OperatorNode::Index:
    414                   case OperatorNode::Range:
    415                   case OperatorNode::UnPlus:
    416                   case OperatorNode::UnMinus:
    417                   case OperatorNode::PointTo:
    418                   case OperatorNode::Neg:
    419                   case OperatorNode::BitNeg:
    420                   case OperatorNode::LabelAddress:
    421                         return new UntypedExpr( new NameExpr( opFuncName[ op->get_type() ] ), args );
    422                   case OperatorNode::AddressOf:
    423                         assert( args.size() == 1 );
    424                         assert( args.front() );
    425 
    426                         return new AddressExpr( args.front() );
    427                   case OperatorNode::Cast:
    428                         {
    429                                 TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args());
    430                                 assert( arg );
    431 
    432                                 DeclarationNode *decl_node = arg->get_decl();
    433                                 ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link());
    434 
    435                                 Type *targetType = decl_node->buildType();
    436                                 if ( dynamic_cast< VoidType* >( targetType ) ) {
    437                                         delete targetType;
    438                                         return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );
    439                                 } else {
    440                                         return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
    441                                 } // if
    442                         }
    443                   case OperatorNode::FieldSel:
    444                         {
    445                                 assert( args.size() == 2 );
    446 
    447                                 NameExpr *member = dynamic_cast<NameExpr *>( args.back());
    448                                 // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back());
    449 
    450                                 if ( member != 0 ) {
    451                                         UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front());
    452                                         delete member;
    453                                         return ret;
    454                                         /* else if ( memberTup != 0 )
    455                                            {
    456                                            UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front());
    457                                            delete member;
    458                                            return ret;
    459                                            } */
    460                                 } else
    461                                         assert( false );
    462                         }
    463                   case OperatorNode::PFieldSel:
    464                         {
    465                                 assert( args.size() == 2 );
    466 
    467                                 NameExpr *member = dynamic_cast<NameExpr *>( args.back());  // modify for Tuples   xxx
    468                                 assert( member != 0 );
    469 
    470                                 UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    471                                 deref->get_args().push_back( args.front() );
    472 
    473                                 UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
     387        } // if
     388
     389        switch ( op->get_type()) {
     390          case OperatorNode::Incr:
     391          case OperatorNode::Decr:
     392          case OperatorNode::IncrPost:
     393          case OperatorNode::DecrPost:
     394          case OperatorNode::Assign:
     395          case OperatorNode::MulAssn:
     396          case OperatorNode::DivAssn:
     397          case OperatorNode::ModAssn:
     398          case OperatorNode::PlusAssn:
     399          case OperatorNode::MinusAssn:
     400          case OperatorNode::LSAssn:
     401          case OperatorNode::RSAssn:
     402          case OperatorNode::AndAssn:
     403          case OperatorNode::ERAssn:
     404          case OperatorNode::OrAssn:
     405                // the rewrite rules for these expressions specify that the first argument has its address taken
     406                assert( ! args.empty() );
     407                args.front() = new AddressExpr( args.front() );
     408                break;
     409          default:
     410                /* do nothing */
     411                ;
     412        }
     413
     414        switch ( op->get_type() ) {
     415          case OperatorNode::Incr:
     416          case OperatorNode::Decr:
     417          case OperatorNode::IncrPost:
     418          case OperatorNode::DecrPost:
     419          case OperatorNode::Assign:
     420          case OperatorNode::MulAssn:
     421          case OperatorNode::DivAssn:
     422          case OperatorNode::ModAssn:
     423          case OperatorNode::PlusAssn:
     424          case OperatorNode::MinusAssn:
     425          case OperatorNode::LSAssn:
     426          case OperatorNode::RSAssn:
     427          case OperatorNode::AndAssn:
     428          case OperatorNode::ERAssn:
     429          case OperatorNode::OrAssn:
     430          case OperatorNode::Plus:
     431          case OperatorNode::Minus:
     432          case OperatorNode::Mul:
     433          case OperatorNode::Div:
     434          case OperatorNode::Mod:
     435          case OperatorNode::BitOr:
     436          case OperatorNode::BitAnd:
     437          case OperatorNode::Xor:
     438          case OperatorNode::LShift:
     439          case OperatorNode::RShift:
     440          case OperatorNode::LThan:
     441          case OperatorNode::GThan:
     442          case OperatorNode::LEThan:
     443          case OperatorNode::GEThan:
     444          case OperatorNode::Eq:
     445          case OperatorNode::Neq:
     446          case OperatorNode::Index:
     447          case OperatorNode::Range:
     448          case OperatorNode::UnPlus:
     449          case OperatorNode::UnMinus:
     450          case OperatorNode::PointTo:
     451          case OperatorNode::Neg:
     452          case OperatorNode::BitNeg:
     453          case OperatorNode::LabelAddress:
     454                return new UntypedExpr( new NameExpr( opFuncName[ op->get_type() ] ), args );
     455          case OperatorNode::AddressOf:
     456                assert( args.size() == 1 );
     457                assert( args.front() );
     458
     459                return new AddressExpr( args.front() );
     460          case OperatorNode::Cast:
     461                {
     462                        TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args());
     463                        assert( arg );
     464
     465                        DeclarationNode *decl_node = arg->get_decl();
     466                        ExpressionNode *expr_node = dynamic_cast<ExpressionNode *>( arg->get_link());
     467
     468                        Type *targetType = decl_node->buildType();
     469                        if ( dynamic_cast< VoidType* >( targetType ) ) {
     470                                delete targetType;
     471                                return new CastExpr( expr_node->build(), maybeBuild< Expression >( get_argName() ) );
     472                        } else {
     473                                return new CastExpr( expr_node->build(),targetType, maybeBuild< Expression >( get_argName() ) );
     474                        } // if
     475                }
     476          case OperatorNode::FieldSel:
     477                {
     478                        assert( args.size() == 2 );
     479
     480                        NameExpr *member = dynamic_cast<NameExpr *>( args.back());
     481                        // TupleExpr *memberTup = dynamic_cast<TupleExpr *>( args.back());
     482
     483                        if ( member != 0 ) {
     484                                UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), args.front());
    474485                                delete member;
    475486                                return ret;
     487                                /* else if ( memberTup != 0 )
     488                                   {
     489                                   UntypedMemberExpr *ret = new UntypedMemberExpr( memberTup->get_name(), args.front());
     490                                   delete member;
     491                                   return ret;
     492                                   } */
     493                        } else
     494                                assert( false );
     495                }
     496          case OperatorNode::PFieldSel:
     497                {
     498                        assert( args.size() == 2 );
     499
     500                        NameExpr *member = dynamic_cast<NameExpr *>( args.back());  // modify for Tuples   xxx
     501                        assert( member != 0 );
     502
     503                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     504                        deref->get_args().push_back( args.front() );
     505
     506                        UntypedMemberExpr *ret = new UntypedMemberExpr( member->get_name(), deref );
     507                        delete member;
     508                        return ret;
     509                }
     510          case OperatorNode::AlignOf:
     511          case OperatorNode::SizeOf:
     512                {
     513///     bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
     514
     515                        if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
     516                                return new SizeofExpr( arg->get_decl()->buildType());
     517                        } else {
     518                                return new SizeofExpr( args.front());
     519                        } // if
     520                }
     521          case OperatorNode::Attr:
     522                {
     523                        VarRefNode *var = dynamic_cast<VarRefNode *>( get_args());
     524                        assert( var );
     525                        if ( ! get_args()->get_link() ) {
     526                                return new AttrExpr( var->build(), ( Expression*)0);
     527                        } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {
     528                                return new AttrExpr( var->build(), arg->get_decl()->buildType());
     529                        } else {
     530                                return new AttrExpr( var->build(), args.back());
     531                        } // if
     532                }
     533          case OperatorNode::CompLit:
     534                throw UnimplementedError( "C99 compound literals" );
     535                // the short-circuited operators
     536          case OperatorNode::Or:
     537          case OperatorNode::And:
     538                assert( args.size() == 2);
     539                return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) );
     540          case OperatorNode::Cond:
     541                {
     542                        assert( args.size() == 3);
     543                        std::list< Expression* >::const_iterator i = args.begin();
     544                        Expression *arg1 = notZeroExpr( *i++ );
     545                        Expression *arg2 = *i++;
     546                        Expression *arg3 = *i++;
     547                        return new ConditionalExpr( arg1, arg2, arg3 );
     548                }
     549          case OperatorNode::NCond:
     550                throw UnimplementedError( "GNU 2-argument conditional expression" );
     551          case OperatorNode::Comma:
     552                {
     553                        assert( args.size() == 2);
     554                        std::list< Expression* >::const_iterator i = args.begin();
     555                        Expression *ret = *i++;
     556                        while ( i != args.end() ) {
     557                                ret = new CommaExpr( ret, *i++ );
    476558                        }
    477                   case OperatorNode::AlignOf:
    478                   case OperatorNode::SizeOf:
    479                         {
    480 ///     bool isSizeOf = ( op->get_type() == OperatorNode::SizeOf );
    481 
    482                                 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {
    483                                         return new SizeofExpr( arg->get_decl()->buildType());
    484                                 } else {
    485                                         return new SizeofExpr( args.front());
    486                                 } // if
    487                         }
    488                   case OperatorNode::Attr:
    489                         {
    490                                 VarRefNode *var = dynamic_cast<VarRefNode *>( get_args());
    491                                 assert( var );
    492                                 if ( ! get_args()->get_link() ) {
    493                                         return new AttrExpr( var->build(), ( Expression*)0);
    494                                 } else if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()->get_link()) ) {
    495                                         return new AttrExpr( var->build(), arg->get_decl()->buildType());
    496                                 } else {
    497                                         return new AttrExpr( var->build(), args.back());
    498                                 } // if
    499                         }
    500                   case OperatorNode::CompLit:
    501                         throw UnimplementedError( "C99 compound literals" );
    502                         // the short-circuited operators
    503                   case OperatorNode::Or:
    504                   case OperatorNode::And:
    505                         assert( args.size() == 2);
    506                         return new LogicalExpr( notZeroExpr( args.front() ), notZeroExpr( args.back() ), ( op->get_type() == OperatorNode::And ) );
    507                   case OperatorNode::Cond:
    508                         {
    509                                 assert( args.size() == 3);
    510                                 std::list< Expression* >::const_iterator i = args.begin();
    511                                 Expression *arg1 = notZeroExpr( *i++ );
    512                                 Expression *arg2 = *i++;
    513                                 Expression *arg3 = *i++;
    514                                 return new ConditionalExpr( arg1, arg2, arg3 );
    515                         }
    516                   case OperatorNode::NCond:
    517                         throw UnimplementedError( "GNU 2-argument conditional expression" );
    518                   case OperatorNode::Comma:
    519                         {
    520                                 assert( args.size() == 2);
    521                                 std::list< Expression* >::const_iterator i = args.begin();
    522                                 Expression *ret = *i++;
    523                                 while ( i != args.end() ) {
    524                                         ret = new CommaExpr( ret, *i++ );
    525                                 }
    526                                 return ret;
    527                         }
    528                         // Tuples
    529                   case OperatorNode::TupleC:
    530                         {
    531                                 TupleExpr *ret = new TupleExpr();
    532                                 std::copy( args.begin(), args.end(), back_inserter( ret->get_exprs() ) );
    533                                 return ret;
    534                         }
    535                   default:
    536                         // shouldn't happen
    537                         return 0;
    538                 }
    539         }
     559                        return ret;
     560                }
     561                // Tuples
     562          case OperatorNode::TupleC:
     563                {
     564                        TupleExpr *ret = new TupleExpr();
     565                        std::copy( args.begin(), args.end(), back_inserter( ret->get_exprs() ) );
     566                        return ret;
     567                }
     568          default:
     569                // shouldn't happen
     570                return 0;
     571        } // switch
    540572}
    541573
     
    552584void CompositeExprNode::print( std::ostream &os, int indent ) const {
    553585        printDesignation( os );
    554         os << '\r' << string( indent, ' ') << "Application of: " << endl;
     586        os << string( indent, ' ' ) << "Application of: " << endl;
    555587        function->print( os, indent + ParseNode::indent_by );
    556588
    557         os << '\r' << string( indent, ' ') ;
     589        os << string( indent, ' ' ) ;
    558590        if ( arguments ) {
    559591                os << "... on arguments: " << endl;
     
    586618}
    587619
     620//##############################################################################
     621
    588622CommaExprNode::CommaExprNode(): CompositeExprNode( new OperatorNode( OperatorNode::Comma )) {}
    589623
     
    603637}
    604638
     639//##############################################################################
     640
    605641ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {}
    606642
     
    614650void ValofExprNode::print( std::ostream &os, int indent ) const {
    615651        printDesignation( os );
    616         os << string( indent, ' ') << "Valof Expression:" << std::endl;
     652        os << string( indent, ' ' ) << "Valof Expression:" << std::endl;
    617653        get_body()->print( os, indent + 4);
    618654}
     
    625661        return new UntypedValofExpr ( get_body()->build(), maybeBuild< Expression >( get_argName() ) );
    626662}
     663
     664//##############################################################################
    627665
    628666ForCtlExprNode::ForCtlExprNode( ParseNode *init_, ExpressionNode *cond, ExpressionNode *incr ) throw ( SemanticError ) : condition( cond ), change( incr ) {
     
    633671                ExpressionNode *exp;
    634672
    635                 if (( decl = dynamic_cast<DeclarationNode *>( init_)) != 0)
     673                if (( decl = dynamic_cast<DeclarationNode *>(init_) ) != 0)
    636674                        init = new StatementNode( decl );
    637675                else if (( exp = dynamic_cast<ExpressionNode *>( init_)) != 0)
     
    659697
    660698void ForCtlExprNode::print( std::ostream &os, int indent ) const{
    661         os << string( indent,' ') << "For Control Expression -- : " << endl;
    662 
    663         os << "\r" << string( indent + 2,' ') << "initialization: ";
    664         if ( init != 0)
    665                 init->print( os, indent + 4);
    666 
    667         os << "\n\r" << string( indent + 2,' ') << "condition: ";
    668         if ( condition != 0)
    669                 condition->print( os, indent + 4);
    670         os << "\n\r" << string( indent + 2,' ') << "increment: ";
    671         if ( change != 0)
    672                 change->print( os, indent + 4);
     699        os << string( indent,' ' ) << "For Control Expression -- :" << endl;
     700
     701        os << string( indent + 2, ' ' ) << "initialization:" << endl;
     702        if ( init != 0 )
     703                init->printList( os, indent + 4 );
     704
     705        os << string( indent + 2, ' ' ) << "condition: " << endl;
     706        if ( condition != 0 )
     707                condition->print( os, indent + 4 );
     708        os << string( indent + 2, ' ' ) << "increment: " << endl;
     709        if ( change != 0 )
     710                change->print( os, indent + 4 );
    673711}
    674712
     
    677715}
    678716
    679 TypeValueNode::TypeValueNode( DeclarationNode *decl )
    680         : decl( decl ) {
    681 }
    682 
    683 TypeValueNode::TypeValueNode( const TypeValueNode &other )
    684         : ExpressionNode( other ), decl( maybeClone( other.decl ) ) {
     717//##############################################################################
     718
     719TypeValueNode::TypeValueNode( DeclarationNode *decl ) : decl( decl ) {
     720}
     721
     722TypeValueNode::TypeValueNode( const TypeValueNode &other ) : ExpressionNode( other ), decl( maybeClone( other.decl ) ) {
    685723}
    686724
     
    700738
    701739ExpressionNode *flattenCommas( ExpressionNode *list ) {
    702         if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) )
    703                 {
    704                         OperatorNode *op;
    705                         if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) )
    706                                 {
    707                                         if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
    708                                                 composite->add_arg( next );
    709                                         return flattenCommas( composite->get_args() );
    710                                 }
    711                 }
     740        if ( CompositeExprNode *composite = dynamic_cast< CompositeExprNode * >( list ) ) {
     741                OperatorNode *op;
     742                if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::Comma ) ) {
     743                        if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
     744                                composite->add_arg( next );
     745                        return flattenCommas( composite->get_args() );
     746                } // if
     747        } // if
    712748
    713749        if ( ExpressionNode *next = dynamic_cast< ExpressionNode * >( list->get_link() ) )
     
    722758                if ( ( op = dynamic_cast< OperatorNode * >( composite->get_function() )) && ( op->get_type() == OperatorNode::TupleC ) )
    723759                        return composite->get_args();
    724         }
     760        } // if
    725761        return tuple;
    726762}
  • src/Parser/InitializerNode.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 13:20:24 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 13:21:40 2015
    13 // Update Count     : 2
     12// Last Modified On : Sat Jun  6 15:49:42 2015
     13// Update Count     : 3
    1414//
    1515
     
    4848
    4949void InitializerNode::print( std::ostream &os, int indent ) const {
    50         os << std::string(indent, ' ') << "Initializer expression" << std::endl;
     50        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
    5151}
    5252
  • src/Parser/ParseNode.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 13:26:29 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 16:48:30 2015
    13 // Update Count     : 3
     12// Last Modified On : Sat Jun  6 20:17:58 2015
     13// Update Count     : 23
    1414//
    1515
     
    2020int ParseNode::indent_by = 4;
    2121
    22 ParseNode::ParseNode( void ) : next( 0 ) {};
    23 ParseNode::ParseNode( string _name ) : name( _name ), next( 0 ) {}
     22ParseNode::ParseNode() : name( 0 ), next( 0 ) {};
     23ParseNode::ParseNode( const string *name_ ) : name( name_ ), next( 0 ) {}
    2424
    25 ParseNode *ParseNode::set_name( string _name ) {
    26         name = _name;
    27         return this;
    28 }
    29 
    30 ParseNode *ParseNode::set_name( string *_name ) {
    31         name = *_name; // deep copy
    32         delete _name;
    33 
    34         return this;
    35 }
    36 
    37 ParseNode::~ParseNode( void ) {
     25ParseNode::~ParseNode() {
    3826        delete next;
    3927};
    4028
    41 string ParseNode::get_name( void ) {
    42         return name;
    43 }
    44 
    45 ParseNode *ParseNode::get_link( void ) const {
     29ParseNode *ParseNode::get_link() const {
    4630        return next;
    4731}
    4832
    49 ParseNode *ParseNode::get_last(void) {
     33ParseNode *ParseNode::get_last() {
    5034        ParseNode *current = this;
    5135
     
    5640}
    5741
    58 ParseNode *ParseNode::set_link(ParseNode *_next) {
     42ParseNode *ParseNode::set_link( ParseNode *next_ ) {
    5943        ParseNode *follow;
    6044
    61         if ( _next == 0 ) return this;
     45        if ( next_ == 0 ) return this;
    6246
    6347        for ( follow = this; follow->next != 0; follow = follow->next );
    64         follow->next = _next;
     48        follow->next = next_;
    6549
    6650        return this;
    6751}
    6852
    69 const string ParseNode::get_name(void) const {
    70         return name;
    71 }
    72 
    73 void ParseNode::print(std::ostream &os, int indent) const {}
     53void ParseNode::print( std::ostream &os, int indent ) const {}
    7454
    7555
     
    7858
    7959        if ( next ) {
    80         next->printList( os, indent );
    81         }
     60                next->printList( os, indent );
     61        } // if
    8262}
    8363
  • src/Parser/ParseNode.h

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 13:30:24 2015
    13 // Update Count     : 3
     12// Last Modified On : Wed Jun 24 14:09:51 2015
     13// Update Count     : 81
    1414//
    1515
     
    2222
    2323#include "utility.h"
    24 #include "SynTree/Declaration.h"
     24#include "Parser/LinkageSpec.h"
     25#include "SynTree/Type.h"
     26//#include "SynTree/Declaration.h"
    2527#include "UniqueName.h"
    2628
     
    3638class ParseNode {
    3739  public:
    38         ParseNode( void );
    39         ParseNode ( std::string );
    40         virtual ~ParseNode( void );
    41 
    42         ParseNode *set_name ( std::string ) ;
    43         ParseNode *set_name ( std::string * ) ;
    44 
    45         std::string get_name( void );
    46 
    47         ParseNode *get_link( void ) const;
    48         ParseNode *get_last( void );
     40        ParseNode();
     41        ParseNode( const std::string * );
     42        virtual ~ParseNode();
     43
     44        ParseNode *get_link() const;
     45        ParseNode *get_last();
    4946        ParseNode *set_link( ParseNode * );
    5047        void set_next( ParseNode *newlink ) { next = newlink; }
     
    5249        virtual ParseNode *clone() const { return 0; };
    5350
    54         const std::string get_name( void ) const;
     51        const std::string &get_name() const { return *name; }
    5552        virtual void print( std::ostream &, int indent = 0 ) const;
    5653        virtual void printList( std::ostream &, int indent = 0 ) const;
     
    5855        ParseNode &operator,( ParseNode &);
    5956  protected:
    60         std::string name;
     57        const std::string *name;
    6158        ParseNode *next;
    6259        static int indent_by;
     
    6865  public:
    6966        ExpressionNode();
    70         ExpressionNode( std::string * );
     67        ExpressionNode( const std::string * );
    7168        ExpressionNode( const ExpressionNode &other );
    7269        virtual ~ExpressionNode() {} // cannot delete asArgName because it might be referenced elsewhere
     
    7774
    7875        ExpressionNode *get_argName() const { return argName; }
    79         ExpressionNode *set_asArgName( std::string *aName );
     76        ExpressionNode *set_asArgName( const std::string *aName );
    8077        ExpressionNode *set_asArgName( ExpressionNode *aDesignator );
    8178
     
    105102class ConstantNode : public ExpressionNode {
    106103  public:
    107         enum Type {
    108                 Integer, Float, Character, String /* , Range, EnumConstant  */
    109         };
    110 
    111         ConstantNode( void );
    112         ConstantNode( std::string * );
     104        enum Type { Integer, Float, Character, String };
     105
    113106        ConstantNode( Type, std::string * );
    114         ConstantNode( const ConstantNode &other );
    115107
    116108        virtual ConstantNode *clone() const { return new ConstantNode( *this ); }
    117 
    118         Type get_type( void ) const ;
     109        Type get_type( void ) const { return type; }
    119110        virtual void print( std::ostream &, int indent = 0) const;
    120111        virtual void printOneLine( std::ostream &, int indent = 0) const;
    121112
    122         std::string get_value() const { return value; }
    123         ConstantNode *append( std::string *newValue );
     113        const std::string &get_value() const { return value; }
     114        ConstantNode *appendstr( const std::string *newValue );
    124115
    125116        Expression *build() const;
    126117  private:
    127         void classify( std::string &);
    128118        Type type;
    129         std::string value;
    130         bool sign;
    131         short base;
    132         int longs, size;
     119        BasicType::Kind btype;
     120        std::string &value;
    133121};
    134122
     
    136124  public:
    137125        VarRefNode();
    138         VarRefNode( std::string *, bool isLabel = false );
     126        VarRefNode( const std::string *, bool isLabel = false );
    139127        VarRefNode( const VarRefNode &other );
    140128
     
    143131        virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
    144132
    145         virtual void print( std::ostream &, int indent = 0) const;
    146         virtual void printOneLine( std::ostream &, int indent = 0) const;
     133        virtual void print( std::ostream &, int indent = 0 ) const;
     134        virtual void printOneLine( std::ostream &, int indent = 0 ) const;
    147135  private:
    148136        bool isLabel;
     
    183171        virtual OperatorNode *clone() const { return new OperatorNode( *this ); }
    184172
    185         Type get_type( void ) const;
    186         std::string get_typename( void ) const;
     173        Type get_type() const;
     174        const char *get_typename() const;
    187175
    188176        virtual void print( std::ostream &, int indent = 0) const;
     
    198186class CompositeExprNode : public ExpressionNode {
    199187  public:
    200         CompositeExprNode( void );
    201         CompositeExprNode( std::string * );
     188        CompositeExprNode();
     189        CompositeExprNode( const std::string * );
    202190        CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 );
    203191        CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 );
     
    278266  public:
    279267        enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic, Attribute };
    280         enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran };
     268        enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, };
    281269        enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
    282         enum Modifier { Signed, Unsigned, Short, Long };
    283         enum TyCon { Struct, Union, Context };
     270        enum Modifier  { Signed, Unsigned, Short, Long };
     271        enum Aggregate { Struct, Union, Context };
    284272        enum TypeClass { Type, Dtype, Ftype };
    285273
     274        static const char *storageName[]; 
    286275        static const char *qualifierName[];
    287276        static const char *basicTypeName[];
    288277        static const char *modifierName[];
    289         static const char *tyConName[];
     278        static const char *aggregateName[];
    290279        static const char *typeClassName[];
    291280
     
    298287        static DeclarationNode *newForall( DeclarationNode *);
    299288        static DeclarationNode *newFromTypedef( std::string *);
    300         static DeclarationNode *newAggregate( TyCon kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields );
     289        static DeclarationNode *newAggregate( Aggregate kind, std::string *name, DeclarationNode *formals, ExpressionNode *actuals, DeclarationNode *fields );
    301290        static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
    302291        static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
    303292        static DeclarationNode *newName( std::string *);
    304         static DeclarationNode *newFromTypeGen( std::string*, ExpressionNode *params );
     293        static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params );
    305294        static DeclarationNode *newTypeParam( TypeClass, std::string *);
    306295        static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
     
    313302        static DeclarationNode *newTuple( DeclarationNode *members );
    314303        static DeclarationNode *newTypeof( ExpressionNode *expr );
    315         static DeclarationNode *newAttr( std::string*, ExpressionNode *expr );
    316         static DeclarationNode *newAttr( std::string*, DeclarationNode *type );
     304        static DeclarationNode *newAttr( std::string *, ExpressionNode *expr );
     305        static DeclarationNode *newAttr( std::string *, DeclarationNode *type );
    317306
    318307        DeclarationNode *addQualifiers( DeclarationNode *);
     
    340329        DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
    341330
    342         DeclarationNode *appendList( DeclarationNode  *);
     331        DeclarationNode *appendList( DeclarationNode * );
    343332
    344333        DeclarationNode *clone() const;
     
    350339
    351340        bool get_hasEllipsis() const;
    352         std::string get_name() const { return name; }
     341        const std::string &get_name() const { return name; }
    353342        LinkageSpec::Type get_linkage() const { return linkage; }
    354343        DeclarationNode *extractAggregate() const;
     
    357346        ~DeclarationNode();
    358347  private:
    359         Declaration::StorageClass buildStorageClass() const;
    360         bool buildInline() const;
     348        StorageClass buildStorageClass() const;
     349        bool buildFuncSpecifier( StorageClass key ) const;
    361350
    362351        TypeData *type;
     
    380369        };
    381370
    382         StatementNode( void );
    383         StatementNode( std::string );
     371        StatementNode();
     372        StatementNode( const std::string * );
    384373        StatementNode( Type, ExpressionNode *e = 0, StatementNode *s = 0 );
    385374        StatementNode( Type, std::string *target );
     
    387376
    388377
    389         ~StatementNode( void );
    390 
    391         static StatementNode  *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
     378        ~StatementNode();
     379
     380        static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
    392381
    393382        void set_control( ExpressionNode * );
     
    396385        ExpressionNode *get_control() const ;
    397386        StatementNode *get_block() const;
    398         StatementNode::Type get_type( void ) const;
    399 
    400         StatementNode *add_label( std::string * );
     387        StatementNode::Type get_type() const;
     388
     389        StatementNode *add_label( const std::string * );
    401390        std::list<std::string> *get_labels() const;
    402391
     
    429418class CompoundStmtNode : public StatementNode {
    430419  public:
    431         CompoundStmtNode( void );
    432         CompoundStmtNode( std::string * );
     420        CompoundStmtNode();
     421        CompoundStmtNode( const std::string * );
    433422        CompoundStmtNode( StatementNode * );
    434423        ~CompoundStmtNode();
     
    499488
    500489// in DeclarationNode.cc
    501 void buildList( const DeclarationNode *firstNode, std::list< Declaration *> &outputList );
     490void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
    502491void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
    503 void buildTypeList( const DeclarationNode *firstNode, std::list< Type *> &outputList );
     492void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
    504493
    505494// in ExpressionNode.cc
  • src/Parser/Parser.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 14:54:28 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 14:55:59 2015
    13 // Update Count     : 2
     12// Last Modified On : Sun May 31 23:45:19 2015
     13// Update Count     : 4
    1414//
    1515
     
    1717#include "TypedefTable.h"
    1818#include "lex.h"
    19 #include "cfa.tab.h"
     19#include "parser.h"
    2020
    2121// global variables in cfa.y
  • src/Parser/StatementNode.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:10:45 2015
    13 // Update Count     : 7
     12// Last Modified On : Sat Jun  6 23:25:41 2015
     13// Update Count     : 19
    1414//
    1515
     
    3636StatementNode::StatementNode() : ParseNode(), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    3737
    38 StatementNode::StatementNode( string name_) : ParseNode( name_), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
     38StatementNode::StatementNode( const string *name_ ) : ParseNode( name_ ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), decl( 0 ), isCatchRest ( false ) {}
    3939
    4040StatementNode::StatementNode( DeclarationNode *decl ) : type( Decl ), control( 0 ), block( 0 ), labels( 0 ), target( 0 ), isCatchRest ( false ) {
     
    4949                                next->set_next( new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) ) );
    5050                                decl->set_next( 0 );
    51                         }
     51                        } // if
    5252                } else {
    5353                        if ( decl->get_link() ) {
    5454                                next = new StatementNode( dynamic_cast< DeclarationNode* >( decl->get_link() ) );
    5555                                decl->set_next( 0 );
    56                         }
     56                        } // if
    5757                        this->decl = decl;
    58                 }
    59         }
     58                } // if
     59        } // if
    6060}
    6161
     
    6767
    6868StatementNode::StatementNode( Type t, string *_target ) :
    69                 type( t ), control( 0 ), block( 0 ),   labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {}
     69                type( t ), control( 0 ), block( 0 ), labels( 0 ), target(_target ), decl( 0 ), isCatchRest ( false ) {}
    7070
    7171StatementNode::~StatementNode() {
     
    9898        } else {
    9999                newnode->target = 0;
    100         }
     100        } // if
    101101        newnode->decl = maybeClone( decl );
    102102        return newnode;
     
    125125}
    126126
    127 StatementNode *StatementNode::add_label( std::string *l ) {
     127StatementNode *StatementNode::add_label( const std::string *l ) {
    128128        if ( l != 0 ) {
    129129                if ( labels == 0 )
     
    132132                labels->push_front(*l );
    133133                delete l;
    134         }
     134        } // if
    135135        return this;
    136136}
     
    151151                else
    152152                        block->set_link( stmt );
    153         }
     153        } // if
    154154        return this;
    155155}
     
    165165                        else
    166166                                block->set_link( stmt );
    167         }
     167        } // if
    168168        return this;
    169169}
    170170
    171171void StatementNode::print( std::ostream &os, int indent ) const {
    172         if ( labels != 0 )
     172        if ( labels != 0 ) {
    173173                if ( ! labels->empty()) {
    174174                        std::list<std::string>::const_iterator i;
    175175
    176                         os << '\r' << string( indent, ' ');
     176                        os << string( indent, ' ' );
    177177                        for ( i = labels->begin(); i != labels->end(); i++ )
    178178                                os << *i << ":";
    179179                        os << endl;
    180                 }
     180                } // if
     181        } // if
    181182
    182183        switch ( type ) {
     
    193194                break;
    194195          default:
    195                 os << '\r' << string( indent, ' ') << StatementNode::StType[type] << endl;
     196                os << string( indent, ' ' ) << StatementNode::StType[type] << endl;
    196197                if ( type == Catch ) {
    197198                        if ( decl ) {
    198                                 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
     199                                os << string( indent + ParseNode::indent_by, ' ' ) << "Declaration: " << endl;
    199200                                decl->print( os, indent + 2*ParseNode::indent_by );
    200201                        } else if ( isCatchRest ) {
    201                                 os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
     202                                os << string( indent + ParseNode::indent_by, ' ' ) << "Catches the rest " << endl;
    202203                        } else {
    203204                                ; // should never reach here
    204                         }
    205                 }
     205                        } // if
     206                } // if
    206207                if ( control ) {
    207                         os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;
     208                        os << string( indent + ParseNode::indent_by, ' ' ) << "Expression: " << endl;
    208209                        control->printList( os, indent + 2*ParseNode::indent_by );
    209                 }
     210                } // if
    210211                if ( block ) {
    211                         os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
     212                        os << string( indent + ParseNode::indent_by, ' ' ) << "Branches of execution: " << endl;
    212213                        block->printList( os, indent + 2*ParseNode::indent_by ); 
    213                 }
     214                } // if
    214215                if ( target ) {
    215                         os << '\r' << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
    216                 }
     216                        os << string( indent + ParseNode::indent_by, ' ' ) << "Target: " << get_target() << endl;
     217                } // if
    217218                break;
    218         }
     219        } // switch
    219220}
    220221
     
    227228                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    228229                copy( labels->begin(), labels->end(), lab_it );
    229         }
     230        } // if
    230231
    231232        // try {
     
    254255                                elseb = branches.front();
    255256                                branches.pop_front();
    256                         }
     257                        } // if
    257258                        return new IfStmt( labs, notZeroExpr( get_control()->build() ), thenb, elseb );
    258259                }
     
    299300                                assert( get_control() != 0 );
    300301                                return new BranchStmt( labs, get_control()->build(), BranchStmt::Goto );
    301                         }
     302                        } // if
    302303
    303304                        return new BranchStmt( labs, get_target(), BranchStmt::Goto );
     
    322323                        if ( ( finallyBlock = dynamic_cast<FinallyStmt *>( branches.back())) ) {
    323324                                branches.pop_back();
    324                         }
     325                        } // if
    325326                        return new TryStmt( labs, tryBlock, branches, finallyBlock );
    326327                }
     
    342343                // shouldn't be here
    343344                return 0;
    344         }
    345 }
    346 
    347 CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {
    348 }
    349 
    350 CompoundStmtNode::CompoundStmtNode( string *name_) : StatementNode(*name_), first( 0 ), last( 0 ) {
    351 }
    352 
    353 CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ): first( stmt ) {
     345        } // switch
     346}
     347
     348CompoundStmtNode::CompoundStmtNode() : first( 0 ), last( 0 ) {}
     349
     350CompoundStmtNode::CompoundStmtNode( const string *name_ ) : StatementNode( name_ ), first( 0 ), last( 0 ) {}
     351
     352CompoundStmtNode::CompoundStmtNode( StatementNode *stmt ) : first( stmt ) {
    354353        if ( first ) {
    355354                last = ( StatementNode *)( stmt->get_last());
    356355        } else {
    357356                last = 0;
    358         }
     357        } // if
    359358}
    360359
     
    367366                last->set_link( stmt );
    368367                last = ( StatementNode *)( stmt->get_link());
    369         }
     368        } // if
    370369}
    371370
     
    373372        if ( first ) {
    374373                first->printList( os, indent+2 );
    375         }
     374        } // if
    376375}
    377376
     
    383382                std::back_insert_iterator< std::list<Label> > lab_it( labs );
    384383                copy( labels->begin(), labels->end(), lab_it );
    385         }
     384        } // if
    386385
    387386        CompoundStmt *cs = new CompoundStmt( labs );
     
    391390
    392391void NullStmtNode::print( ostream &os, int indent ) const {
    393         os << "\r" << string( indent, ' ') << "Null Statement:" << endl;
     392        os << string( indent, ' ' ) << "Null Statement:" << endl;
    394393}
    395394
  • src/Parser/TypeData.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:17:56 2015
    13 // Update Count     : 4
     12// Last Modified On : Thu Jun 18 22:06:23 2015
     13// Update Count     : 21
    1414//
    1515
     
    8989                attr->type = 0;
    9090                break;
    91         }
     91        } // switch
    9292}
    9393
     
    155155                delete attr;
    156156                break;
    157         }
     157        } // switch
    158158}
    159159
     
    225225                newtype->attr->type = maybeClone( attr->type );
    226226                break;
    227         }
     227        } // switch
    228228        return newtype;
    229229}
     
    238238                os << "forall " << endl;
    239239                forall->printList( os, indent+4 );
    240         }
     240        } // if
    241241
    242242        switch ( kind ) {
     
    249249                        os << "to ";
    250250                        base->print( os, indent );
    251                 }
     251                } // if
    252252                break;
    253253          case EnumConstant:
     
    261261                if ( array->isStatic ) {
    262262                        os << "static ";
    263                 }
     263                } // if
    264264                if ( array->dimension ) {
    265265                        os << "array of ";
     
    269269                } else {
    270270                        os << "open array of ";
    271                 }
     271                } // if
    272272                if ( base ) {
    273273                        base->print( os, indent );
    274                 }
     274                } // if
    275275                break;
    276276          case Function:
     
    281281                } else {
    282282                        os << string( indent+2, ' ' ) << "with no parameters " << endl;
    283                 }
     283                } // if
    284284                if ( function->idList ) {
    285285                        os << string( indent+2, ' ' ) << "with old-style identifier list " << endl;
    286286                        function->idList->printList( os, indent+4 );
    287                 }
     287                } // if
    288288                if ( function->oldDeclList ) {
    289289                        os << string( indent+2, ' ' ) << "with old-style declaration list " << endl;
    290290                        function->oldDeclList->printList( os, indent+4 );
    291                 }
     291                } // if
    292292                os << string( indent+2, ' ' ) << "returning ";
    293293                if ( base ) {
     
    295295                } else {
    296296                        os << "nothing ";
    297                 }
     297                } // if
    298298                os << endl;
    299299                if ( function->hasBody ) {
    300300                        os << string( indent+2, ' ' ) << "with body " << endl;
    301                 }
     301                } // if
    302302                if ( function->body ) {
    303303                        function->body->printList( os, indent+2 );
    304                 }
     304                } // if
    305305                break;
    306306          case Aggregate:
    307                 os << DeclarationNode::tyConName[ aggregate->kind ] << ' ' << aggregate->name << endl;
     307                os << DeclarationNode::aggregateName[ aggregate->kind ] << ' ' << aggregate->name << endl;
    308308                if ( aggregate->params ) {
    309309                        os << string( indent+2, ' ' ) << "with type parameters " << endl;
    310310                        aggregate->params->printList( os, indent+4 );
    311                 }
     311                } // if
    312312                if ( aggregate->actuals ) {
    313313                        os << string( indent+2, ' ' ) << "instantiated with actual parameters " << endl;
    314314                        aggregate->actuals->printList( os, indent+4 );
    315                 }
     315                } // if
    316316                if ( aggregate->members ) {
    317317                        os << string( indent+2, ' ' ) << "with members " << endl;
     
    319319///     } else {
    320320///       os << string( indent+2, ' ' ) << "with no members " << endl;
    321                 }
     321                } // if
    322322                break;
    323323          case AggregateInst:
     
    327327                } else {
    328328                        os << "instance of an unspecified aggregate ";
    329                 }
     329                } // if
    330330                if ( aggInst->params ) {
    331331                        os << string( indent+2, ' ' ) << "with parameters " << endl;
    332332                        aggInst->params->printList( os, indent+2 );
    333                 }
     333                } // if
    334334                break;
    335335          case Enum:
     
    338338                        os << "with constants" << endl;
    339339                        enumeration->constants->printList( os, indent+2 );
    340                 }
     340                } // if
    341341                break;
    342342          case SymbolicInst:
     
    345345                        os << " with parameters" << endl;
    346346                        symbolic->actuals->printList( os, indent + 2 );
    347                 }
     347                } // if
    348348                break;
    349349          case Symbolic:
     
    352352                } else {
    353353                        os << "type definition ";
    354                 }
     354                } // if
    355355                if ( symbolic->params ) {
    356356                        os << endl << string( indent+2, ' ' ) << "with parameters" << endl;
    357357                        symbolic->params->printList( os, indent + 2 );
    358                 }
     358                } // if
    359359                if ( symbolic->assertions ) {
    360360                        os << endl << string( indent+2, ' ' ) << "with assertions" << endl;
    361361                        symbolic->assertions->printList( os, indent + 4 );
    362362                        os << string( indent+2, ' ' );
    363                 }
     363                } // if
    364364                if ( base ) {
    365365                        os << "for ";
    366366                        base->print( os, indent + 2 );
    367                 }
     367                } // if
    368368                break;
    369369          case Variable:
     
    373373                        variable->assertions->printList( os, indent + 4 );
    374374                        os << string( indent+2, ' ' );
    375                 }
     375                } // if
    376376                break;
    377377          case Tuple:
     
    380380                        os << "with members " << endl;
    381381                        tuple->members->printList( os, indent + 2 );
    382                 }
     382                } // if
    383383                break;
    384384          case Typeof:
     
    386386                if ( typeexpr->expr ) {
    387387                        typeexpr->expr->print( os, indent + 2 );
    388                 }
     388                } // if
    389389                break;
    390390          case Attr:
     
    392392                if ( attr->expr ) {
    393393                        attr->expr->print( os, indent + 2 );
    394                 }
     394                } // if
    395395                if ( attr->type ) {
    396396                        attr->type->print( os, indent + 2 );
    397                 }
    398                 break;
    399         }
     397                } // if
     398                break;
     399        } // switch
    400400}
    401401
     
    408408                        ret = clone();
    409409                        ret->qualifiers.clear();
    410                 }
     410                } // if
    411411                break;
    412412          case Enum:
     
    414414                        ret = clone();
    415415                        ret->qualifiers.clear();
    416                 }
     416                } // if
    417417                break;
    418418          case AggregateInst:
    419419                if ( aggInst->aggregate ) {
    420420                        ret = aggInst->aggregate->extractAggregate( false );
    421                 }
     421                } // if
    422422                break;
    423423          default:
    424424                if ( base ) {
    425425                        ret = base->extractAggregate( false );
    426                 }
    427         }
     426                } // if
     427        } // switch
    428428        return ret;
    429429}
     
    434434                if ( (*i)->get_kind() == TypeDecl::Any ) {
    435435                        FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    436                         assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ) ), 0 ) );
    437                         assignType->get_parameters().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
    438                         assignType->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
    439                         (*i)->get_assertions().push_front( new FunctionDecl( "?=?", Declaration::NoStorageClass, LinkageSpec::Cforall, assignType, 0, false ) );
    440                 }
    441         }
    442 }
    443 
    444 Declaration *TypeData::buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init ) const {
     436                        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 ) );
     437                        assignType->get_parameters().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
     438                        assignType->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new TypeInstType( Type::Qualifiers(), (*i)->get_name(), *i ), 0 ) );
     439                        (*i)->get_assertions().push_front( new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, assignType, 0, false, false ) );
     440                } // if
     441        } // for
     442}
     443
     444Declaration *TypeData::buildDecl( std::string name, DeclarationNode::StorageClass sc, Expression *bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Type linkage, Initializer *init ) const {
    445445        if ( kind == TypeData::Function ) {
    446446                FunctionDecl *decl;
     
    450450                                CompoundStmt *body = dynamic_cast< CompoundStmt* >( stmt );
    451451                                assert( body );
    452                                 decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline );
     452                                decl = new FunctionDecl( name, sc, linkage, buildFunction(), body, isInline, isNoreturn );
    453453                        } else {
    454454                                // std::list<Label> ls;
    455                                 decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list<Label>() ), isInline );
    456                         }
     455                                decl = new FunctionDecl( name, sc, linkage, buildFunction(), new CompoundStmt( std::list<Label>() ), isInline, isNoreturn );
     456                        } // if
    457457                } else {
    458                         decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline );
    459                 }
     458                        decl = new FunctionDecl( name, sc, linkage, buildFunction(), 0, isInline, isNoreturn );
     459                } // if
    460460                for ( DeclarationNode *cur = function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_link() ) ) {
    461461                        if ( cur->get_name() != "" ) {
    462462                                decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() );
    463                         }
    464                 }
     463                        } // if
     464                } // for
    465465                buildList( function->oldDeclList, decl->get_oldDecls() );
    466466                return decl;
     
    474474                return buildVariable();
    475475        } else {
    476                 if ( isInline ) {
    477                         throw SemanticError( "invalid inline specification in declaration of ", this );
     476                if ( isInline || isNoreturn ) {
     477                        throw SemanticError( "invalid inline or _Noreturn specification in declaration of ", this );
    478478                } else {
    479479                        return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init );
    480                 }
    481         }
     480                } // if
     481        } // if
    482482        return 0;
    483483}
     
    514514          case Variable:
    515515                assert( false );
    516         }
     516        } // switch
    517517
    518518        return 0;
     
    541541                        q.isAttribute = true;
    542542                        break;
    543                 }
    544         }
     543                } // switch
     544        } // for
    545545        return q;
    546546}
     
    563563                                } else {
    564564                                        return new VoidType( buildQualifiers() );
    565                                 }
     565                                } // if
    566566                        } else {
    567567                                ret = kindMap[ *i ];
    568                         }
     568                        } // if
    569569                } else {
    570570                        switch ( *i ) {
     
    582582                                          default:
    583583                                                throw SemanticError( "invalid type specifier \"float\" in type: ", this );
    584                                         }
    585                                 }
     584                                        } // switch
     585                                } // if
    586586                                break;
    587587                          case DeclarationNode::Double:
     
    595595                                          default:
    596596                                                throw SemanticError( "invalid type specifier \"double\" in type: ", this );
    597                                         }
    598                                 }
     597                                        } // switch
     598                                } // if
    599599                                break;
    600        
    601600                          case DeclarationNode::Complex:
    602601                                switch ( ret ) {
     
    609608                                  default:
    610609                                        throw SemanticError( "invalid type specifier \"_Complex\" in type: ", this );
    611                                 }
     610                                } // switch
    612611                                break;
    613612                          case DeclarationNode::Imaginary:
     
    621620                                  default:
    622621                                        throw SemanticError( "invalid type specifier \"_Imaginary\" in type: ", this );
    623                                 }
     622                                } // switch
    624623                                break;
    625624                          default:
    626625                                throw SemanticError( std::string( "invalid type specifier \"" ) + DeclarationNode::basicTypeName[ *i ] + "\" in type: ", this );
    627                         }
    628                 }
     626                        } // switch
     627                } // if
    629628                if ( *i == DeclarationNode::Double ) {
    630629                        sawDouble = true;
    631                 }
    632         }
     630                } // if
     631        } // for
    633632
    634633        for ( std::list< DeclarationNode::Modifier >::const_iterator i = basic->modifiers.begin(); i != basic->modifiers.end(); ++i ) {
     
    663662                                  default:
    664663                                        throw SemanticError( "invalid type modifier \"long\" in type: ", this );
    665                                 }
    666                         }
     664                                } // switch
     665                        } // if
    667666                        break;
    668667                  case DeclarationNode::Short:
     
    680679                                  default:
    681680                                        throw SemanticError( "invalid type modifier \"short\" in type: ", this );
    682                                 }
    683                         }
     681                                } // switch
     682                        } // if
    684683                        break;
    685684                  case DeclarationNode::Signed:
     
    691690                        } else {
    692691                                switch ( ret ) {
    693                                   case BasicType::LongLongSignedInt:    // PAB
     692                                  case BasicType::LongLongSignedInt:
    694693                                        ret = BasicType::LongLongUnsignedInt;
    695694                                        break;
     
    705704                                  default:
    706705                                        throw SemanticError( "invalid type modifer \"signed\" in type: ", this );
    707                                 }
    708                         }
     706                                } // switch
     707                        } // if
    709708                        break;
    710709                  case DeclarationNode::Unsigned:
     
    716715                        } else {
    717716                                switch ( ret ) {
    718                                   case BasicType::LongLongSignedInt:    // PAB
     717                                  case BasicType::LongLongSignedInt:
    719718                                        ret = BasicType::LongLongUnsignedInt;
    720719                                        break;
     
    733732                                  default:
    734733                                        throw SemanticError( "invalid type modifer \"unsigned\" in type: ", this );
    735                                 }
    736                         }
    737                         break;
    738                 }
     734                                } // switch
     735                        } // if
     736                        break;
     737                } // switch
    739738
    740739                if ( *i == DeclarationNode::Signed ) {
    741740                        sawSigned = true;
    742                 }
    743         }
     741                } // if
     742        } // for
    744743
    745744        BasicType *bt;
     
    748747        } else {
    749748                bt = new BasicType( buildQualifiers(), ret );
    750         }
     749        } // if
    751750        buildForall( forall, bt->get_forall() );
    752751        return bt;
     
    760759        } else {
    761760                pt = new PointerType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
    762         }
     761        } // if
    763762        buildForall( forall, pt->get_forall() );
    764763        return pt;
     
    773772                at = new ArrayType( buildQualifiers(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ),
    774773                                                        maybeBuild< Expression >( array->dimension ), array->isVarLen, array->isStatic );
    775         }
     774        } // if
    776775        buildForall( forall, at->get_forall() );
    777776        return at;
     
    791790                        break;
    792791                  default:
    793                         ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", Declaration::NoStorageClass, 0, false, LinkageSpec::Cforall ) ) );
    794                 }
     792                        ft->get_returnVals().push_back( dynamic_cast< DeclarationWithType* >( base->buildDecl( "", DeclarationNode::NoStorageClass, 0, false, false, LinkageSpec::Cforall ) ) );
     793                } // switch
    795794        } else {
    796                 ft->get_returnVals().push_back( new ObjectDecl( "", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
    797         }
     795                ft->get_returnVals().push_back( new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 0 ) );
     796        } // if
    798797        return ft;
    799798}
     
    806805                at = new StructDecl( aggregate->name );
    807806                break;
    808        
    809807          case DeclarationNode::Union:
    810808                at = new UnionDecl( aggregate->name );
    811809                break;
    812        
    813810          case DeclarationNode::Context:
    814811                at = new ContextDecl( aggregate->name );
    815812                break;
    816        
    817813          default:
    818814                assert( false );
    819         }
     815        } // switch
    820816        buildList( aggregate->params, at->get_parameters() );
    821817        buildList( aggregate->members, at->get_members() );
     
    838834ReferenceToType *TypeData::buildAggInst() const {
    839835        assert( kind == AggregateInst );
    840         std::string name;
    841836
    842837        ReferenceToType *ret;
     
    857852                  default:
    858853                        assert( false );
    859                 }
    860         }
     854                } // switch
     855        } // if
    861856        buildList( aggInst->params, ret->get_parameters() );
    862857        buildForall( forall, ret->get_forall() );
     
    864859}
    865860
    866 NamedTypeDecl *TypeData::buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const {
     861NamedTypeDecl *TypeData::buildSymbolic( const std::string &name, DeclarationNode::StorageClass sc ) const {
    867862        assert( kind == Symbolic );
    868863        NamedTypeDecl *ret;
     
    871866        } else {
    872867                ret = new TypeDecl( name, sc, maybeBuild< Type >( base ), TypeDecl::Any );
    873         }
     868        } // if
    874869        buildList( symbolic->params, ret->get_parameters() );
    875870        buildList( symbolic->assertions, ret->get_assertions() );
     
    881876        static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype };
    882877
    883         TypeDecl *ret = new TypeDecl( variable->name, Declaration::NoStorageClass, 0, kindMap[ variable->tyClass ] );
     878        TypeDecl *ret = new TypeDecl( variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ variable->tyClass ] );
    884879        buildList( variable->assertions, ret->get_assertions() );
    885        
    886880        return ret;
    887881}
     
    891885        EnumDecl *ret = new EnumDecl( enumeration->name );
    892886        buildList( enumeration->constants, ret->get_members() );
    893 
    894887        return ret;
    895888}
     
    900893        buildList( symbolic->actuals, ret->get_parameters() );
    901894        buildForall( forall, ret->get_forall() );
    902 
    903895        return ret;
    904896}
     
    909901        buildTypeList( tuple->members, ret->get_types() );
    910902        buildForall( forall, ret->get_forall() );
    911 
    912903        return ret;
    913904}
     
    918909        assert( typeexpr->expr );
    919910        TypeofType *ret = new TypeofType( buildQualifiers(), typeexpr->expr->build() );
    920 
    921911        return ret;
    922912}
     
    931921                assert( attr->type );
    932922                ret = new AttrType( buildQualifiers(), attr->name, attr->type->buildType() );
    933         }
    934 
     923        } // if
    935924        return ret;
    936925}
  • src/Parser/TypeData.h

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:20:00 2015
    13 // Update Count     : 2
     12// Last Modified On : Thu Jun 18 21:03:18 2015
     13// Update Count     : 7
    1414//
    1515
     
    4444
    4545        struct Aggregate_t {
    46                 DeclarationNode::TyCon kind;
     46                DeclarationNode::Aggregate kind;
    4747                std::string name;
    4848                DeclarationNode *params;
     
    120120        TypeData *extractAggregate( bool toplevel = true ) const;
    121121        // helper function for DeclNodeImpl::build
    122         Declaration * buildDecl( std::string name, Declaration::StorageClass sc, Expression *bitfieldWidth, bool isInline, LinkageSpec::Type linkage, Initializer *init = 0 ) const;
     122        Declaration * buildDecl( std::string name, DeclarationNode::StorageClass sc, Expression *bitfieldWidth, bool isInline, bool isNoreturn, LinkageSpec::Type linkage, Initializer *init = 0 ) const;
    123123        // helper functions for build()
    124124        Type::Qualifiers buildQualifiers() const;
    125         Type *buildBasicType() const;
     125        Type * buildBasicType() const;
    126126        PointerType * buildPointer() const;
    127127        ArrayType * buildArray() const;
    128128        AggregateDecl * buildAggregate() const;
    129129        ReferenceToType * buildAggInst() const;
    130         NamedTypeDecl * buildSymbolic( const std::string &name, Declaration::StorageClass sc ) const;
     130        NamedTypeDecl * buildSymbolic( const std::string &name, DeclarationNode::StorageClass sc ) const;
    131131        TypeDecl* buildVariable() const;
    132132        EnumDecl* buildEnum() const;
  • src/Parser/TypedefTable.cc

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:24:03 2015
    13 // Update Count     : 2
     12// Last Modified On : Sun Jun 21 11:46:15 2015
     13// Update Count     : 7
    1414//
    1515
     
    2929TypedefTable::TypedefTable() : currentScope( 0 ) {}
    3030
    31 bool TypedefTable::isKind( string identifier, kind_t kind ) const {
     31bool TypedefTable::isKind( const string &identifier, kind_t kind ) const {
    3232        tableType::const_iterator id_pos = table.find( identifier );
    33         if ( id_pos == table.end()) {
     33        if ( id_pos == table.end() ) {
    3434                return true;
    3535        } else {
    3636                return (*((*id_pos ).second.begin())).kind == kind;
    37         }
     37        } // if
    3838}
    3939
    40 bool TypedefTable::isIdentifier( string identifier ) const {
     40bool TypedefTable::isIdentifier( const string &identifier ) const {
    4141        return isKind( identifier, ID );
    4242}
    4343
    44 bool TypedefTable::isTypedef( string identifier ) const {
     44bool TypedefTable::isTypedef( const string &identifier ) const {
    4545        return isKind( identifier, TD );
    4646}
    4747
    48 bool TypedefTable::isTypegen( string identifier ) const {
     48bool TypedefTable::isTypegen( const string &identifier ) const {
    4949        return isKind( identifier, TG );
    5050}
     
    6666                        while ( listPos != (*curPos ).second.end() && listPos->scope > scope ) {
    6767                                listPos++;
    68                         }
     68                        } // while
    6969                        (*curPos ).second.insert( listPos, newEntry );
    70                 }
    71         }
     70                } // if
     71        } // if
    7272}
    7373
     
    102102}
    103103
    104 void TypedefTable::openContext( std::string contextName ) {
     104void TypedefTable::openContext( const std::string &contextName ) {
    105105        map< string, deferListType >::iterator i = contexts.find( contextName );
    106106        if ( i != contexts.end() ) {
     
    108108                for ( deferListType::iterator i = entries.begin(); i != entries.end(); i++) {
    109109                        addToEnclosingScope( i->identifier, i->kind );
    110                 }
    111         }
     110                } // for
     111        } // if
    112112}
    113113
    114 void TypedefTable::enterScope( void ) {
     114void TypedefTable::enterScope() {
    115115        currentScope += 1;
    116116        deferListStack.push( deferListType() );
     
    119119}
    120120
    121 void TypedefTable::leaveScope( void ) {
     121void TypedefTable::leaveScope() {
    122122        debugPrint( "Leaving scope " << currentScope << endl );
    123123        for ( tableType::iterator i = table.begin(); i != table.end(); ) {
     
    129129                        table.erase( i++ );
    130130                } else ++i;
    131         }
     131        } // for
    132132        currentScope -= 1;
    133133        for ( deferListType::iterator i = deferListStack.top().begin(); i != deferListStack.top().end(); i++) {
    134134                addToCurrentScope( i->identifier, i->kind );
    135         }
     135        } // for
    136136        deferListStack.pop();
    137137        debugPrint( "nextIdentifiers size is " << nextIdentifiers.size() << " top is " << nextIdentifiers.top() << endl );
     
    139139}
    140140
    141 void TypedefTable::enterContext( std::string contextName ) {
     141void TypedefTable::enterContext( const std::string &contextName ) {
    142142        currentContext = contextName;
    143143        contextScope = currentScope;
    144144}
    145145
    146 void TypedefTable::leaveContext( void ) {
     146void TypedefTable::leaveContext() {
    147147        currentContext = "";
    148148}
     
    156156                }
    157157                debugPrint( endl );
    158         }
     158        } // for
    159159}
    160160
  • src/Parser/TypedefTable.h

    reb50842 r937e51d  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 15:25:59 2015
    13 // Update Count     : 3
     12// Last Modified On : Thu Jun 18 21:03:17 2015
     13// Update Count     : 7
    1414//
    1515
     
    4949        std::stack< std::string > nextIdentifiers;
    5050
    51         bool isKind( std::string identifier, kind_t kind ) const;
     51        bool isKind( const std::string &identifier, kind_t kind ) const;
    5252        void addToScope( const std::string &identifier, kind_t kind, int scope );
    5353  public:
    5454        TypedefTable();
    5555
    56         bool isIdentifier( std::string identifier ) const;
    57         bool isTypedef( std::string identifier ) const;
    58         bool isTypegen( std::string identifier ) const;
     56        bool isIdentifier( const std::string &identifier ) const;
     57        bool isTypedef( const std::string &identifier ) const;
     58        bool isTypegen( const std::string &identifier ) const;
    5959       
    60         // "addToCurrentScope" adds the identifier/type pair to the current scope This does less than you think it does,
     60        // "addToCurrentScope" adds the identifier/type pair to the current scope. This does less than you think it does,
    6161        // since each declaration is within its own scope.  Mostly useful for type parameters.
    6262        void addToCurrentScope( const std::string &identifier, kind_t kind );
     
    7777       
    7878        // dump the definitions from a pre-defined context into the current scope
    79         void openContext( std::string contextName );
     79        void openContext( const std::string &contextName );
    8080       
    8181        void enterScope();
    8282        void leaveScope();
    83         void enterContext( std::string contextName );
     83        void enterContext( const std::string &contextName );
    8484        void leaveContext();
    8585
  • src/Parser/lex.h

    reb50842 r937e51d  
    1010// Created On       : Sat Sep 22 08:58:10 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 12:18:48 2015
    13 // Update Count     : 334
     12// Last Modified On : Mon Jun  8 20:28:48 2015
     13// Update Count     : 341
    1414//
    1515
     
    1818
    1919int yylex();
    20 void yyerror(char *);
     20void yyerror( const char * );
    2121
    2222// External declarations for information sharing between lexer and scanner
     
    3535class Token {
    3636  public:
    37     std::string *str;
     37    std::string *str;                                                                   // must be pointer as used in union
    3838    Location loc;
    3939
     
    4444
    4545// Local Variables: //
    46 // fill-column: 110 //
    4746// tab-width: 4 //
    4847// mode: c++ //
  • src/Parser/lex.ll

    reb50842 r937e51d  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Tue May 19 15:41:54 2015
    13  * Update Count     : 331
     12 * Last Modified On : Fri Jun 19 11:10:14 2015
     13 * Update Count     : 392
    1414 */
    1515
    1616%option yylineno
     17%option nounput
    1718
    1819%{
    19 // This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive
    20 // have been performed and removed from the source. The only exceptions are preprocessor directives passed to
    21 // the compiler (e.g., line-number directives) and C/C++ style comments, which are ignored.
     20// This lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been
     21// performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g.,
     22// line-number directives) and C/C++ style comments, which are ignored.
    2223
    2324//**************************** Includes and Defines ****************************
     
    2728#include "lex.h"
    2829#include "ParseNode.h"
    29 #include "cfa.tab.h"                                                                    // YACC generated definitions based on C++ grammar
     30#include "parser.h"                                                                             // YACC generated definitions based on C++ grammar
    3031
    3132char *yyfilename;
    3233std::string *strtext;                                                                   // accumulate parts of character and string constant value
    3334
     35#define RETURN_LOCN(x)          yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x )
     36#define RETURN_VAL(x)           yylval.tok.str = new std::string( yytext ); RETURN_LOCN( x )
     37#define RETURN_CHAR(x)          yylval.tok.str = NULL; RETURN_LOCN( x )
     38#define RETURN_STR(x)           yylval.tok.str = strtext; RETURN_LOCN( x )
     39
    3440#define WHITE_RETURN(x)                                                                 // do nothing
    35 #define NEWLINE_RETURN()        WHITE_RETURN('\n')
    36 #define RETURN_VAL(x)           yylval.tok.str = new std::string(yytext); \
    37                                         yylval.tok.loc.file = yyfilename; \
    38                                         yylval.tok.loc.line = yylineno; \
    39                                         return(x)
    40 #define RETURN_STR(x)           yylval.tok.str = strtext; \
    41                                         yylval.tok.loc.file = yyfilename; \
    42                                         yylval.tok.loc.line = yylineno; \
    43                                         return(x)
    44 
    45 #define KEYWORD_RETURN(x)       RETURN_VAL(x)                           // keyword
    46 #define IDENTIFIER_RETURN()     RETURN_VAL((typedefTable.isIdentifier(yytext) ? IDENTIFIER : typedefTable.isTypedef(yytext) ? TYPEDEFname : TYPEGENname))
    47 //#define ATTRIBUTE_RETURN()    RETURN_VAL((typedefTable.isIdentifier(yytext) ? ATTR_IDENTIFIER : typedefTable.isTypedef(yytext) ? ATTR_TYPEDEFname : ATTR_TYPEGENname))
    48 #define ATTRIBUTE_RETURN()      RETURN_VAL(ATTR_IDENTIFIER)
    49 
    50 #define ASCIIOP_RETURN()        RETURN_VAL((int)yytext[0])      // single character operator
    51 #define NAMEDOP_RETURN(x)       RETURN_VAL(x)                           // multichar operator, with a name
    52 
    53 #define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL(x) // numeric constant
     41#define NEWLINE_RETURN()        WHITE_RETURN( '\n' )
     42#define ASCIIOP_RETURN()        RETURN_CHAR( (int)yytext[0] ) // single character operator
     43#define NAMEDOP_RETURN(x)       RETURN_VAL( x )                         // multichar operator, with a name
     44#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
     45#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
     46#define IDENTIFIER_RETURN()     RETURN_VAL( (typedefTable.isIdentifier( yytext ) ? IDENTIFIER : typedefTable.isTypedef( yytext ) ? TYPEDEFname : TYPEGENname ) )
     47#define ATTRIBUTE_RETURN()      RETURN_VAL( ATTR_IDENTIFIER )
    5448
    5549void rm_underscore() {
     
    114108hex_escape "\\""x""_"?{hex_digits}
    115109escape_seq {simple_escape}|{octal_escape}|{hex_escape}|{universal_char}
     110cwide_prefix "L"|"U"|"u"
     111swide_prefix {cwide_prefix}|"u8"
    116112
    117113                                // display/white-space characters
     
    165161^{h_white}*"#"[^\n]*"\n" ;
    166162
    167                                 /* ignore C style comments */
     163                                /* ignore C style comments (ALSO HANDLED BY CPP) */
    168164"/*"                    { BEGIN COMMENT; }
    169 <COMMENT>.|\n           ;
    170 <COMMENT>"*/"           { BEGIN 0; }
    171 
    172                                 /* ignore C++ style comments */
    173 "//"[^\n]*"\n"          ;
     165<COMMENT>.|\n   ;
     166<COMMENT>"*/"   { BEGIN 0; }
     167
     168                                /* ignore C++ style comments (ALSO HANDLED BY CPP) */
     169"//"[^\n]*"\n"  ;
    174170
    175171                                /* ignore whitespace */
     
    275271"0"                             { NUMERIC_RETURN(ZERO); }                               // CFA
    276272"1"                             { NUMERIC_RETURN(ONE); }                                // CFA
    277 {decimal_constant}      { NUMERIC_RETURN(INTEGERconstant); }
    278 {octal_constant}        { NUMERIC_RETURN(INTEGERconstant); }
    279 {hex_constant}          { NUMERIC_RETURN(INTEGERconstant); }
     273{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
     274{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
     275{hex_constant}  { NUMERIC_RETURN(INTEGERconstant); }
    280276{floating_constant}     { NUMERIC_RETURN(FLOATINGconstant); }
    281277{hex_floating_constant} { NUMERIC_RETURN(FLOATINGconstant); }
    282278
    283279                                /* character constant, allows empty value */
    284 "L"?"_"?[']             { BEGIN QUOTE; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
     280({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
    285281<QUOTE>[^'\\\n]* { *strtext += std::string( yytext ); }
    286282<QUOTE>['\n]    { BEGIN 0; *strtext += std::string( yytext); RETURN_STR(CHARACTERconstant); }
     
    288284
    289285                                /* string constant */
    290 "L"?"_"?["]             { BEGIN STRING; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
     286({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new std::string; *strtext += std::string( yytext ); }
    291287<STRING>[^"\\\n]* { *strtext += std::string( yytext ); }
    292 <STRING>["\n]   { BEGIN 0; *strtext += std::string( yytext); RETURN_STR(STRINGliteral); }
     288<STRING>["\n]   { BEGIN 0; *strtext += std::string( yytext ); RETURN_STR(STRINGliteral); }
    293289                                /* " stop highlighting */
    294290
     291                                /* common character/string constant */
    295292<QUOTE,STRING>{escape_seq} { rm_underscore(); *strtext += std::string( yytext ); }
    296 <QUOTE,STRING>[\\]      { *strtext += std::string( yytext ); } // unknown escape character
     293<QUOTE,STRING>"\\"{h_white}*"\n" {}                                             // continuation (ALSO HANDLED BY CPP)
     294<QUOTE,STRING>"\\" { *strtext += std::string( yytext ); } // unknown escape character
    297295
    298296                                /* punctuation */
     
    355353                                /* CFA, operator identifier */
    356354{op_unary}"?"   { IDENTIFIER_RETURN(); }                                // unary
    357 "?"({op_unary_pre_post}|"()"|"[?]") { IDENTIFIER_RETURN(); }
     355"?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); }
    358356"?"{op_binary_over}"?"  { IDENTIFIER_RETURN(); }                // binary
    359357        /*
     
    400398
    401399// Local Variables: //
    402 // fill-column: 110 //
     400// mode: c++ //
    403401// tab-width: 4 //
    404 // mode: c++ //
    405402// compile-command: "make install" //
    406403// End: //
  • src/Parser/module.mk

    reb50842 r937e51d  
    88## module.mk --
    99##
    10 ## Author           : Richard C. Bilson
     10## Author           : Peter A. Buhr
    1111## Created On       : Sat May 16 15:29:09 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Thu May 21 21:17:07 2015
    14 ## Update Count     : 2
     13## Last Modified On : Mon Jun  8 20:23:47 2015
     14## Update Count     : 87
    1515###############################################################################
    1616
    17 YACC=bison
    18 YFLAGS=-d --debug -v
    19 LEX=flex
    20 LFLAGS=
     17BUILT_SOURCES = Parser/parser.h
    2118
    22 SRC += Parser/cfa.y \
    23        Parser/lex.l \
     19AM_YFLAGS = -d -t -v
     20cfa_cpp_LDADD = ${LEXLIB}       # yywrap
     21MAINTAINERCLEANFILES = Parser/parser.output
     22
     23SRC += Parser/parser.yy \
     24       Parser/lex.ll \
    2425       Parser/TypedefTable.cc \
    2526       Parser/ParseNode.cc \
     
    3233       Parser/parseutility.cc \
    3334       Parser/Parser.cc
    34 
    35 EXTRA_OUTPUT += Parser/cfa.tab.cc \
    36                 Parser/cfa.tab.h \
    37                 Parser/lex.yy.cc \
    38                 Parser/cfa.output
    39 
    40 LIBS += -lfl
    41 
    42 Parser/Parser.cc: Parser/cfa.tab.h
    43 
    44 Parser/cfa.tab.cc: Parser/cfa.y
    45         $(YACC) $(YFLAGS) $< --file-prefix=Parser/cfa
    46         -mv Parser/cfa.tab.c Parser/cfa.tab.cc
    47 
    48 Parser/cfa.tab.h: Parser/cfa.tab.cc
    49 
    50 Parser/lex.yy.cc: Parser/lex.l Parser/cfa.tab.h Parser/TypedefTable.h
    51         $(LEX) $(LFLAGS) -o$@ $<
    52 
    53 Parser/lex.yy.o: Parser/lex.yy.cc Parser/ParseNode.h
    54         $(CXX) $(CXXFLAGS) -Wno-unused -c -o $@ $<
Note: See TracChangeset for help on using the changeset viewer.