Changeset 28f3a19 for src/Parser


Ignore:
Timestamp:
Jun 27, 2018, 3:28:41 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
b21c77a
Parents:
0182bfa (diff), 63238a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into with_gc

Location:
src/Parser
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 22 08:39:29 2018
    13 // Update Count     : 1074
     12// Last Modified On : Thu Jun  7 12:08:55 2018
     13// Update Count     : 1079
    1414//
    1515
     
    173173}
    174174
    175 DeclarationNode * DeclarationNode::newFunction( string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
     175DeclarationNode * DeclarationNode::newFunction( const string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ) {
    176176        DeclarationNode * newnode = new DeclarationNode;
    177177        newnode->name = name;
     
    244244} // DeclarationNode::newForall
    245245
    246 DeclarationNode * DeclarationNode::newFromTypedef( string * name ) {
     246DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) {
    247247        DeclarationNode * newnode = new DeclarationNode;
    248248        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    267267} // DeclarationNode::newAggregate
    268268
    269 DeclarationNode * DeclarationNode::newEnum( string * name, DeclarationNode * constants, bool body ) {
     269DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {
    270270        assert( name );
    271271        DeclarationNode * newnode = new DeclarationNode;
     
    277277} // DeclarationNode::newEnum
    278278
    279 DeclarationNode * DeclarationNode::newEnumConstant( string * name, ExpressionNode * constant ) {
     279DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) {
    280280        DeclarationNode * newnode = new DeclarationNode;
    281281        newnode->name = name;
     
    284284} // DeclarationNode::newEnumConstant
    285285
    286 DeclarationNode * DeclarationNode::newName( string * name ) {
     286DeclarationNode * DeclarationNode::newName( const string * name ) {
    287287        DeclarationNode * newnode = new DeclarationNode;
    288288        newnode->name = name;
     
    290290} // DeclarationNode::newName
    291291
    292 DeclarationNode * DeclarationNode::newFromTypeGen( string * name, ExpressionNode * params ) {
     292DeclarationNode * DeclarationNode::newFromTypeGen( const string * name, ExpressionNode * params ) {
    293293        DeclarationNode * newnode = new DeclarationNode;
    294294        newnode->type = new TypeData( TypeData::SymbolicInst );
     
    299299} // DeclarationNode::newFromTypeGen
    300300
    301 DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, string * name ) {
     301DeclarationNode * DeclarationNode::newTypeParam( TypeClass tc, const string * name ) {
    302302        DeclarationNode * newnode = new DeclarationNode;
    303303        newnode->type = nullptr;
     
    330330} // DeclarationNode::newTraitUse
    331331
    332 DeclarationNode * DeclarationNode::newTypeDecl( string * name, DeclarationNode * typeParams ) {
     332DeclarationNode * DeclarationNode::newTypeDecl( const string * name, DeclarationNode * typeParams ) {
    333333        DeclarationNode * newnode = new DeclarationNode;
    334334        newnode->name = name;
     
    405405} // DeclarationNode::newBuiltinType
    406406
    407 DeclarationNode * DeclarationNode::newAttr( string * name, ExpressionNode * expr ) {
     407DeclarationNode * DeclarationNode::newAttr( const string * name, ExpressionNode * expr ) {
    408408        DeclarationNode * newnode = new DeclarationNode;
    409409        newnode->type = nullptr;
     
    414414}
    415415
    416 DeclarationNode * DeclarationNode::newAttr( string * name, DeclarationNode * type ) {
     416DeclarationNode * DeclarationNode::newAttr( const string * name, DeclarationNode * type ) {
    417417        DeclarationNode * newnode = new DeclarationNode;
    418418        newnode->type = nullptr;
     
    423423}
    424424
    425 DeclarationNode * DeclarationNode::newAttribute( string * name, ExpressionNode * expr ) {
     425DeclarationNode * DeclarationNode::newAttribute( const string * name, ExpressionNode * expr ) {
    426426        DeclarationNode * newnode = new DeclarationNode;
    427427        newnode->type = nullptr;
     
    544544                                        type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier
    545545                                } else {                                                                // not polymorphic
    546                                         type->aggregate.params = q->type->forall; // make polymorphic type
    547                                         // change implicit typedef from TYPEDEFname to TYPEGENname
    548                                         typedefTable.changeKind( *type->aggregate.name, TYPEGENname );
     546                                        type->aggregate.params = q->type->forall; // set forall qualifier
    549547                                } // if
    550548                        } else {                                                                        // not polymorphic
     
    10651063                        SemanticError( this, "invalid function specifier for " );
    10661064                } // if
    1067                 return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
     1065                bool isDelete = initializer && initializer->get_isDelete();
     1066                Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild< Initializer >(initializer), attributes )->set_extension( extension );
     1067                if ( isDelete ) {
     1068                        DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl );
     1069                        dwt->isDeleted = true;
     1070                }
     1071                return decl;
    10681072        } // if
    10691073
  • src/Parser/ExpressionNode.cc

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 22 11:57:39 2018
    13 // Update Count     : 801
     12// Last Modified On : Mon Jun  4 21:24:45 2018
     13// Update Count     : 802
    1414//
    1515
     
    314314
    315315Expression * build_constantStr( string & str ) {
     316        assert( str.length() > 0 );
    316317        string units;                                                                           // units
    317318        sepString( str, units, '"' );                                           // separate constant from units
  • src/Parser/InitializerNode.cc

    r0182bfa r28f3a19  
    2727
    2828InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des )
    29                 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
     29                : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ), isDelete( false ) {
    3030        if ( aggrp )
    3131                kids = dynamic_cast< InitializerNode * >( get_next() );
     
    3636
    3737InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des )
    38                 : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
     38                : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ), isDelete( false ) {
    3939        if ( init )
    4040                set_last( init );
     
    4646                set_next( nullptr );
    4747} // InitializerNode::InitializerNode
     48
     49InitializerNode::InitializerNode( bool isDelete ) : expr( nullptr ), aggregate( false ), designator( nullptr ), kids( nullptr ), maybeConstructed( false ), isDelete( isDelete ) {}
    4850
    4951InitializerNode::~InitializerNode() {
     
    8486
    8587Initializer * InitializerNode::build() const {
     88        assertf( ! isDelete, "Should not build delete stmt InitializerNode" );
    8689        if ( aggregate ) {
    8790                // steal designators from children
  • src/Parser/ParseNode.h

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 30 09:19:17 2018
    13 // Update Count     : 831
     12// Last Modified On : Wed Jun  6 16:17:18 2018
     13// Update Count     : 843
    1414//
    1515
     
    7777
    7878        ParseNode * next = nullptr;
    79         std::string * name = nullptr;
     79        const std::string * name = nullptr;
    8080        CodeLocation location = yylloc;
    8181}; // ParseNode
     
    8787        InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode * des = nullptr );
    8888        InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr );
     89        InitializerNode( bool isDelete );
    8990        ~InitializerNode();
    9091        virtual InitializerNode * clone() const { assert( false ); return nullptr; }
     
    9798        InitializerNode * set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
    9899        bool get_maybeConstructed() const { return maybeConstructed; }
     100
     101        bool get_isDelete() const { return isDelete; }
    99102
    100103        InitializerNode * next_init() const { return kids; }
     
    110113        InitializerNode * kids;
    111114        bool maybeConstructed;
     115        bool isDelete;
    112116}; // InitializerNode
    113117
     
    167171};
    168172
    169 Expression * build_constantInteger( std::string &str );
    170 Expression * build_constantFloat( std::string &str );
    171 Expression * build_constantChar( std::string &str );
    172 Expression * build_constantStr( std::string &str );
     173Expression * build_constantInteger( std::string & str ); // these 4 routines modify the string
     174Expression * build_constantFloat( std::string & str );
     175Expression * build_constantChar( std::string & str );
     176Expression * build_constantStr( std::string & str );
    173177Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str );
    174178Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str );
     
    226230        static DeclarationNode * newBuiltinType( BuiltinType );
    227231        static DeclarationNode * newForall( DeclarationNode * );
    228         static DeclarationNode * newFromTypedef( std::string * );
    229         static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
     232        static DeclarationNode * newFromTypedef( const std::string * );
     233        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    230234        static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    231         static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants, bool body );
    232         static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant );
    233         static DeclarationNode * newName( std::string * );
    234         static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params );
    235         static DeclarationNode * newTypeParam( TypeClass, std::string * );
     235        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
     236        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
     237        static DeclarationNode * newName( const std::string * );
     238        static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params );
     239        static DeclarationNode * newTypeParam( TypeClass, const std::string * );
    236240        static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts );
    237241        static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params );
    238         static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams );
     242        static DeclarationNode * newTypeDecl( const std::string * name, DeclarationNode * typeParams );
    239243        static DeclarationNode * newPointer( DeclarationNode * qualifiers, OperKinds kind );
    240244        static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic );
     
    243247        static DeclarationNode * newTuple( DeclarationNode * members );
    244248        static DeclarationNode * newTypeof( ExpressionNode * expr );
    245         static DeclarationNode * newAttr( std::string *, ExpressionNode * expr ); // @ attributes
    246         static DeclarationNode * newAttr( std::string *, DeclarationNode * type ); // @ attributes
    247         static DeclarationNode * newAttribute( std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
     249        static DeclarationNode * newAttr( const std::string *, ExpressionNode * expr ); // @ attributes
     250        static DeclarationNode * newAttr( const std::string *, DeclarationNode * type ); // @ attributes
     251        static DeclarationNode * newAttribute( const std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
    248252        static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
    249253        static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message );
     
    399403};
    400404
     405Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init );
    401406Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt );
    402407Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
    403408Statement * build_case( ExpressionNode * ctl );
    404409Statement * build_default();
    405 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false );
     410Statement * build_while( IfCtl * ctl, StatementNode * stmt );
     411Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt );
    406412Statement * build_for( ForCtl * forctl, StatementNode * stmt );
    407413Statement * build_branch( BranchStmt::Type kind );
  • src/Parser/StatementNode.cc

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 30 09:21:16 2018
    13 // Update Count     : 354
     12// Last Modified On : Tue Jun  5 08:58:34 2018
     13// Update Count     : 362
    1414//
    1515
     
    6969        caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts );
    7070        return this;
    71 }
     71} // StatementNode::append_last_case
    7272
    7373Statement * build_expr( ExpressionNode * ctl ) {
    7474        Expression * e = maybeMoveBuild< Expression >( ctl );
    7575
    76         if ( e )
    77                 return new ExprStmt( e );
    78         else
    79                 return new NullStmt();
    80 }
    81 
    82 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
    83         Statement * thenb, * elseb = 0;
    84         std::list< Statement * > branches;
    85         buildMoveList< Statement, StatementNode >( then_stmt, branches );
    86         assert( branches.size() == 1 );
    87         thenb = branches.front();
    88 
    89         if ( else_stmt ) {
    90                 std::list< Statement * > branches;
    91                 buildMoveList< Statement, StatementNode >( else_stmt, branches );
    92                 assert( branches.size() == 1 );
    93                 elseb = branches.front();
    94         } // if
    95 
    96         std::list< Statement * > init;
     76        if ( e ) return new ExprStmt( e );
     77        else return new NullStmt();
     78} // build_expr
     79
     80Expression * build_if_control( IfCtl * ctl, std::list< Statement * > & init ) {
    9781        if ( ctl->init != 0 ) {
    9882                buildMoveList( ctl->init, init );
     
    10286        if ( ctl->condition ) {
    10387                // compare the provided condition against 0
    104                 cond =  notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
     88                cond = notZeroExpr( maybeMoveBuild< Expression >(ctl->condition) );
    10589        } else {
    10690                for ( Statement * stmt : init ) {
     
    11397        }
    11498        delete ctl;
     99        return cond;
     100} // build_if_control
     101
     102Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ) {
     103        Statement * thenb, * elseb = nullptr;
     104        std::list< Statement * > branches;
     105        buildMoveList< Statement, StatementNode >( then_stmt, branches );
     106        assert( branches.size() == 1 );
     107        thenb = branches.front();
     108
     109        if ( else_stmt ) {
     110                std::list< Statement * > branches;
     111                buildMoveList< Statement, StatementNode >( else_stmt, branches );
     112                assert( branches.size() == 1 );
     113                elseb = branches.front();
     114        } // if
     115
     116        std::list< Statement * > init;
     117        Expression * cond = build_if_control( ctl, init );
    115118        return new IfStmt( cond, thenb, elseb, init );
    116 }
     119} // build_if
    117120
    118121Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ) {
     
    130133        // branches.size() == 0 for switch (...) {}, i.e., no declaration or statements
    131134        return new SwitchStmt( maybeMoveBuild< Expression >(ctl), branches );
    132 }
     135} // build_switch
     136
    133137Statement * build_case( ExpressionNode * ctl ) {
    134138        std::list< Statement * > branches;
    135139        return new CaseStmt( maybeMoveBuild< Expression >(ctl), branches );
    136 }
     140} // build_case
     141
    137142Statement * build_default() {
    138143        std::list< Statement * > branches;
    139144        return new CaseStmt( nullptr, branches, true );
    140 }
    141 
    142 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind ) {
    143         std::list< Statement * > branches;
    144         buildMoveList< Statement, StatementNode >( stmt, branches );
    145         assert( branches.size() == 1 );
    146         return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), kind );
    147 }
     145} // build_default
     146
     147Statement * build_while( IfCtl * ctl, StatementNode * stmt ) {
     148        std::list< Statement * > branches;
     149        buildMoveList< Statement, StatementNode >( stmt, branches );
     150        assert( branches.size() == 1 );
     151
     152        std::list< Statement * > init;
     153        Expression * cond = build_if_control( ctl, init );
     154        return new WhileStmt( cond, branches.front(), init, false );
     155} // build_while
     156
     157Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ) {
     158        std::list< Statement * > branches;
     159        buildMoveList< Statement, StatementNode >( stmt, branches );
     160        assert( branches.size() == 1 );
     161
     162        std::list< Statement * > init;
     163        return new WhileStmt( notZeroExpr( maybeMoveBuild< Expression >(ctl) ), branches.front(), init, true );
     164} // build_do_while
    148165
    149166Statement * build_for( ForCtl * forctl, StatementNode * stmt ) {
     
    167184        delete forctl;
    168185        return new ForStmt( init, cond, incr, branches.front() );
    169 }
     186} // build_for
    170187
    171188Statement * build_branch( BranchStmt::Type kind ) {
    172189        Statement * ret = new BranchStmt( "", kind );
    173190        return ret;
    174 }
     191} // build_branch
     192
    175193Statement * build_branch( std::string * identifier, BranchStmt::Type kind ) {
    176194        Statement * ret = new BranchStmt( * identifier, kind );
    177195        delete identifier;                                                                      // allocated by lexer
    178196        return ret;
    179 }
     197} // build_branch
     198
    180199Statement * build_computedgoto( ExpressionNode * ctl ) {
    181200        return new BranchStmt( maybeMoveBuild< Expression >(ctl), BranchStmt::Goto );
    182 }
     201} // build_computedgoto
    183202
    184203Statement * build_return( ExpressionNode * ctl ) {
     
    186205        buildMoveList( ctl, exps );
    187206        return new ReturnStmt( exps.size() > 0 ? exps.back() : nullptr );
    188 }
     207} // build_return
    189208
    190209Statement * build_throw( ExpressionNode * ctl ) {
     
    193212        assertf( exps.size() < 2, "This means we are leaking memory");
    194213        return new ThrowStmt( ThrowStmt::Terminate, !exps.empty() ? exps.back() : nullptr );
    195 }
     214} // build_throw
    196215
    197216Statement * build_resume( ExpressionNode * ctl ) {
     
    200219        assertf( exps.size() < 2, "This means we are leaking memory");
    201220        return new ThrowStmt( ThrowStmt::Resume, !exps.empty() ? exps.back() : nullptr );
    202 }
     221} // build_resume
    203222
    204223Statement * build_resume_at( ExpressionNode * ctl, ExpressionNode * target ) {
     
    206225        (void)target;
    207226        assertf( false, "resume at (non-local throw) is not yet supported," );
    208 }
     227} // build_resume_at
    209228
    210229Statement * build_try( StatementNode * try_stmt, StatementNode * catch_stmt, StatementNode * finally_stmt ) {
     
    214233        FinallyStmt * finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    215234        return new TryStmt( tryBlock, branches, finallyBlock );
    216 }
     235} // build_try
     236
    217237Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body ) {
    218238        std::list< Statement * > branches;
     
    220240        assert( branches.size() == 1 );
    221241        return new CatchStmt( kind, maybeMoveBuild< Declaration >(decl), maybeMoveBuild< Expression >(cond), branches.front() );
    222 }
     242} // build_catch
     243
    223244Statement * build_finally( StatementNode * stmt ) {
    224245        std::list< Statement * > branches;
     
    226247        assert( branches.size() == 1 );
    227248        return new FinallyStmt( dynamic_cast< CompoundStmt * >( branches.front() ) );
    228 }
     249} // build_finally
    229250
    230251WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) {
     
    247268
    248269        return node;
    249 }
     270} // build_waitfor
    250271
    251272WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when, WaitForStmt * node ) {
     
    266287
    267288        return node;
    268 }
     289} // build_waitfor
    269290
    270291WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when ) {
     
    275296                node->timeout.statement = maybeMoveBuild<Statement >( stmt    );
    276297                node->timeout.condition = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    277         }
    278         else {
     298        } else {
    279299                node->orelse.statement  = maybeMoveBuild<Statement >( stmt );
    280300                node->orelse.condition  = notZeroExpr( maybeMoveBuild<Expression>( when ) );
    281         }
     301        } // if
    282302
    283303        return node;
    284 }
     304} // build_waitfor_timeout
    285305
    286306WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when,  StatementNode * else_stmt, ExpressionNode * else_when ) {
     
    295315
    296316        return node;
    297 }
     317} // build_waitfor_timeout
    298318
    299319WithStmt * build_with( ExpressionNode * exprs, StatementNode * stmt ) {
     
    302322        Statement * s = maybeMoveBuild<Statement>( stmt );
    303323        return new WithStmt( e, s );
    304 }
     324} // build_with
    305325
    306326Statement * build_compound( StatementNode * first ) {
     
    308328        buildMoveList( first, cs->get_kids() );
    309329        return cs;
    310 }
     330} // build_compound
    311331
    312332Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) {
     
    318338        buildMoveList( clobber, clob );
    319339        return new AsmStmt( voltile, instruction, out, in, clob, gotolabels ? gotolabels->labels : noLabels );
    320 }
     340} // build_asm
    321341
    322342Statement * build_directive( string * directive ) {
    323343        return new DirectiveStmt( *directive );
    324 }
     344} // build_directive
    325345
    326346// Local Variables: //
  • src/Parser/TypeData.cc

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 26 13:46:07 2018
    13 // Update Count     : 603
     12// Last Modified On : Wed Jun  6 17:40:33 2018
     13// Update Count     : 604
    1414//
    1515
     
    6565          case Aggregate:
    6666                // aggregate = new Aggregate_t;
     67                aggregate.kind = DeclarationNode::NoAggregate;
    6768                aggregate.name = nullptr;
    6869                aggregate.params = nullptr;
     
    7071                aggregate.fields = nullptr;
    7172                aggregate.body = false;
     73                aggregate.tagged = false;
     74                aggregate.parent = nullptr;
    7275                break;
    7376          case AggregateInst:
     
    198201                break;
    199202          case Aggregate:
     203                newtype->aggregate.kind = aggregate.kind;
    200204                newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
    201205                newtype->aggregate.params = maybeClone( aggregate.params );
    202206                newtype->aggregate.actuals = maybeClone( aggregate.actuals );
    203207                newtype->aggregate.fields = maybeClone( aggregate.fields );
    204                 newtype->aggregate.kind = aggregate.kind;
    205208                newtype->aggregate.body = aggregate.body;
    206209                newtype->aggregate.tagged = aggregate.tagged;
     
    575578
    576579          case DeclarationNode::Int128:
    577                 ret = td->signedness == 1 ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
     580                ret = td->signedness == DeclarationNode::Unsigned ? BasicType::UnsignedInt128 : BasicType::SignedInt128;
    578581                if ( td->length != DeclarationNode::NoLength ) {
    579582                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
     
    599602                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    600603                } // if
    601                 if ( td->basictype == DeclarationNode::Float && td->length == DeclarationNode::Long ) {
     604                if ( td->basictype != DeclarationNode::Double && td->length == DeclarationNode::Long ) {
    602605                        genTSError( DeclarationNode::lengthNames[ td->length ], td->basictype );
    603606                } // if
     
    605608                        const_cast<TypeData *>(td)->basictype = DeclarationNode::LongDouble;
    606609                } // if
     610
     611                if ( td->basictype == DeclarationNode::Float80 || td->basictype == DeclarationNode::Float128 ) {
     612                        // if ( td->complextype != DeclarationNode::NoComplexType ) {
     613                        //      genTSError( DeclarationNode::complexTypeNames[ td->complextype ], td->basictype );
     614                        // }
     615                        if ( td->basictype == DeclarationNode::Float80 ) ret = BasicType::Float80;
     616                        else ret = BasicType::Float128;
     617                        break;
     618                }
    607619
    608620                ret = floattype[ td->complextype ][ td->basictype - DeclarationNode::Float ];
  • src/Parser/TypedefTable.cc

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 22 08:40:01 2018
    13 // Update Count     : 121
     12// Last Modified On : Fri Jun 22 06:14:39 2018
     13// Update Count     : 206
    1414//
    1515
     
    1717#include "TypedefTable.h"
    1818#include <cassert>                                                                              // for assert
     19#include <iostream>
    1920
    2021#if 0
    21 #include <iostream>
    22 #define debugPrint( x ) cerr << x
     22#define debugPrint( code ) code
    2323#else
    24 #define debugPrint( x )
     24#define debugPrint( code )
    2525#endif
    2626
    2727using namespace std;                                                                    // string, iostream
    2828
     29debugPrint(
     30static const char *kindName( int kind ) {
     31        switch ( kind ) {
     32          case IDENTIFIER: return "identifier";
     33          case TYPEDEFname: return "typedef";
     34          case TYPEGENname: return "typegen";
     35          default:
     36                cerr << "Error: cfa-cpp internal error, invalid kind of identifier" << endl;
     37                abort();
     38        } // switch
     39} // kindName
     40)
     41
    2942TypedefTable::~TypedefTable() {
    3043        if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) {
    31                 // std::cerr << "scope failure " << kindTable.currentScope() << endl;
     44                cerr << "Error: cfa-cpp internal error, scope failure " << kindTable.currentScope() << endl;
     45                abort();
    3246        } // if
    3347} // TypedefTable::~TypedefTable
     
    4458} // TypedefTable::isKind
    4559
    46 void TypedefTable::changeKind( const string & identifier, int kind ) {
    47         KindTable::iterator posn = kindTable.find( identifier );
    48         if ( posn != kindTable.end() ) posn->second = kind;     // exists => update
    49 } // TypedefTable::changeKind
    50 
    5160// SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
    5261// "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if the
    5362// name is explicitly used.
    54 void TypedefTable::makeTypedef( const string & name ) {
     63void TypedefTable::makeTypedef( const string & name, int kind ) {
     64//    Check for existence is necessary to handle:
     65//        struct Fred {};
     66//        void Fred();
     67//        void fred() {
     68//           struct Fred act; // do not add as type in this scope
     69//           Fred();
     70//        }
    5571        if ( ! typedefTable.exists( name ) ) {
    56                 typedefTable.addToEnclosingScope( name, TYPEDEFname );
     72                typedefTable.addToEnclosingScope( name, kind, "MTD" );
    5773        } // if
    5874} // TypedefTable::makeTypedef
    5975
    60 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) {
    61         assert( kindTable.currentScope() >= 1 );
    62         auto scope = kindTable.currentScope() - 1;
    63         debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl );
     76void TypedefTable::addToScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) {
     77        auto scope = kindTable.currentScope();
     78        debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );
     79        auto ret = kindTable.insertAt( scope, identifier, kind );
     80        //if ( ! ret.second ) ret.first->second = kind;         // exists => update
     81        assert( ret.first->second == kind );                            // exists
     82} // TypedefTable::addToScope
     83
     84void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) {
     85        assert( kindTable.currentScope() >= 1 + level );
     86        auto scope = kindTable.currentScope() - 1 - level;
     87        debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << endl );
    6488        auto ret = kindTable.insertAt( scope, identifier, kind );
    6589        if ( ! ret.second ) ret.first->second = kind;           // exists => update
     
    6892void TypedefTable::enterScope() {
    6993        kindTable.beginScope();
    70         debugPrint( "Entering scope " << kindTable.currentScope() << endl );
     94        debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() );
    7195} // TypedefTable::enterScope
    7296
    7397void TypedefTable::leaveScope() {
    74         debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
     98        debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl; print() );
    7599        kindTable.endScope();
    76100} // TypedefTable::leaveScope
    77101
    78 // void TypedefTable::print( void ) const {
    79 //      for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) {
    80 //              debugPrint( (*i ).first << ": " );
    81 //              list< Entry > declList = (*i).second;
    82 //              for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
    83 //                      debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
    84 //              }
    85 //              debugPrint( endl );
    86 //      } // for
    87 // }
     102void TypedefTable::print( void ) const {
     103        KindTable::size_type scope = kindTable.currentScope();
     104        debugPrint( cerr << "[" << scope << "]" );
     105        for ( KindTable::const_iterator i = kindTable.begin(); i != kindTable.end(); i++ ) {
     106                while ( i.get_level() != scope ) {
     107                        --scope;
     108                        debugPrint( cerr << endl << "[" << scope << "]" );
     109                } // while
     110                debugPrint( cerr << " " << (*i).first << ":" << kindName( (*i).second ) );
     111        } // for
     112        while ( scope > 0 ) {
     113                --scope;
     114                debugPrint( cerr << endl << "[" << scope << "]" );
     115        } // while
     116        debugPrint( cerr << endl );
     117} // TypedefTable::print
    88118
    89119// Local Variables: //
  • src/Parser/TypedefTable.h

    r0182bfa r28f3a19  
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 22 08:39:29 2018
    13 // Update Count     : 77
     12// Last Modified On : Fri Jun 22 05:29:58 2018
     13// Update Count     : 86
    1414//
    1515
     
    2525        typedef ScopedMap< std::string, int > KindTable;
    2626        KindTable kindTable;   
     27        unsigned int level = 0;
    2728  public:
    2829        ~TypedefTable();
     
    3031        bool exists( const std::string & identifier );
    3132        int isKind( const std::string & identifier ) const;
    32         void changeKind( const std::string & identifier, int kind );
    33         void makeTypedef( const std::string & name );
    34         void addToEnclosingScope( const std::string & identifier, int kind );
     33        void makeTypedef( const std::string & name, int kind = TYPEDEFname );
     34        void addToScope( const std::string & identifier, int kind, const char * );
     35        void addToEnclosingScope( const std::string & identifier, int kind, const char * );
    3536
    3637        void enterScope();
    3738        void leaveScope();
     39
     40        void up() { level += 1; }
     41        void down() { level -= 1; }
     42
     43        void print( void ) const;
    3844}; // TypedefTable
    3945
  • src/Parser/lex.ll

    r0182bfa r28f3a19  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Thu May  3 13:42:40 2018
    13  * Update Count     : 676
     12 * Last Modified On : Wed Jun 20 09:08:28 2018
     13 * Update Count     : 682
    1414 */
    1515
     
    2525//**************************** Includes and Defines ****************************
    2626
     27// trigger before each matching rule's action
     28#define YY_USER_ACTION \
     29        yylloc.first_line = yylineno; \
     30        yylloc.first_column = column; \
     31        column += yyleng; \
     32        yylloc.last_column = column; \
     33        yylloc.last_line = yylineno; \
     34        yylloc.filename = yyfilename ? yyfilename : "";
    2735unsigned int column = 0;                                                                // position of the end of the last token parsed
    28 #define YY_USER_ACTION yylloc.first_line = yylineno; yylloc.first_column = column; column += yyleng; yylloc.last_column = column; yylloc.last_line = yylineno; yylloc.filename = yyfilename ? yyfilename : "";                          // trigger before each matching rule's action
    2936
    3037#include <string>
     
    4956#define NUMERIC_RETURN(x)       rm_underscore(); RETURN_VAL( x ) // numeric constant
    5057#define KEYWORD_RETURN(x)       RETURN_CHAR( x )                        // keyword
    51 #define QKEYWORD_RETURN(x)      typedefTable.isKind( yytext ); RETURN_VAL(x); // quasi-keyword
     58#define QKEYWORD_RETURN(x)      RETURN_VAL(x);                          // quasi-keyword
    5259#define IDENTIFIER_RETURN()     RETURN_VAL( typedefTable.isKind( yytext ) )
    5360#define ATTRIBUTE_RETURN()      RETURN_VAL( ATTR_IDENTIFIER )
     
    232239finally                 { KEYWORD_RETURN(FINALLY); }                    // CFA
    233240float                   { KEYWORD_RETURN(FLOAT); }
     241_Float32                { KEYWORD_RETURN(FLOAT); }                              // GCC
     242_Float32x               { KEYWORD_RETURN(FLOAT); }                              // GCC
     243_Float64                { KEYWORD_RETURN(DOUBLE); }                             // GCC
     244_Float64x               { KEYWORD_RETURN(DOUBLE); }                             // GCC
    234245__float80               { KEYWORD_RETURN(FLOAT80); }                    // GCC
    235246float80                 { KEYWORD_RETURN(FLOAT80); }                    // GCC
     247_Float128               { KEYWORD_RETURN(FLOAT128); }                   // GCC
     248_Float128x              { KEYWORD_RETURN(FLOAT128); }                   // GCC
    236249__float128              { KEYWORD_RETURN(FLOAT128); }                   // GCC
    237250float128                { KEYWORD_RETURN(FLOAT128); }                   // GCC
     
    446459
    447460%%
     461
    448462// ----end of lexer----
    449463
    450464void yyerror( const char * errmsg ) {
     465        SemanticErrorThrow = true;
    451466        cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1
    452467                 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl;
  • src/Parser/parser.yy

    r0182bfa r28f3a19  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 24 18:11:59 2018
    13 // Update Count     : 3369
     12// Last Modified On : Fri Jun 22 13:59:11 2018
     13// Update Count     : 3586
    1414//
    1515
     
    136136} // build_postfix_name
    137137
    138 bool forall = false, xxx = false;                                               // aggregate have one or more forall qualifiers ?
     138bool forall = false, xxx = false, yyy = false;                  // aggregate have one or more forall qualifiers ?
    139139
    140140// https://www.gnu.org/software/bison/manual/bison.html#Location-Type
     
    175175        bool flag;
    176176        CatchStmt::Kind catch_kind;
     177        GenericExpr * genexpr;
    177178}
    178179
     
    259260%type<flag> asm_volatile_opt
    260261%type<en> handler_predicate_opt
     262%type<genexpr> generic_association generic_assoc_list
    261263
    262264// statements
    263265%type<sn> statement                                             labeled_statement                       compound_statement
    264266%type<sn> statement_decl                                statement_decl_list                     statement_list_nodecl
    265 %type<sn> selection_statement
     267%type<sn> selection_statement                   if_statement
    266268%type<sn> switch_clause_list_opt                switch_clause_list
    267269%type<en> case_value
     
    302304%type<en> enumerator_value_opt
    303305
    304 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
     306%type<decl> external_definition external_definition_list external_definition_list_opt
     307
     308%type<decl> exception_declaration
    305309
    306310%type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     
    324328%type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr
    325329
    326 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list_opt
     330%type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt
    327331
    328332%type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier
     
    330334%type<decl> c_declaration static_assert
    331335%type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array
    332 %type<decl> KR_declaration_list KR_declaration_list_opt
     336%type<decl> KR_parameter_list KR_parameter_list_opt
    333337
    334338%type<decl> parameter_declaration parameter_list parameter_type_list_opt
     
    402406//************************* Namespace Management ********************************
    403407
    404 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols
    405 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical.  While it is possible to write a purely
    406 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs.
    407 // Hence, this grammar uses the ANSI style.
    408 //
    409 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those
    410 // introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types.  This latter
    411 // type name creates a third class of identifiers that must be distinguished by the scanner.
    412 //
    413 // Since the scanner cannot distinguish among the different classes of identifiers without some context information, it
    414 // accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read.  Semantic
    415 // actions during the parser update this data structure when the class of identifiers change.
    416 //
    417 // Because the Cforall language is block-scoped, an identifier can change its class in a local scope; it must revert to
    418 // its original class at the end of the block.  Since type names can be local to a particular declaration, each
    419 // declaration is itself a scope.  This requires distinguishing between type names that are local to the current
    420 // declaration scope and those that persist past the end of the declaration (i.e., names defined in "typedef" or "otype"
    421 // declarations).
    422 //
    423 // The non-terminals "push" and "pop" denote the opening and closing of scopes.  Every push must have a matching pop,
    424 // although it is regrettable the matching pairs do not always occur within the same rule.  These non-terminals may
    425 // appear in more contexts than strictly necessary from a semantic point of view.
     408// The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",
     409// which are lexically identical.
     410//
     411//   typedef int foo; // identifier foo must now be scanned as TYPEDEFname
     412//   foo f;           // to allow it to appear in this context
     413//
     414// While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship
     415// between syntactic and semantic constructs.  Cforall compounds this problem by introducing type names local to the
     416// scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type
     417// generators" -- parameterized types.  This latter type name creates a third class of identifiers, "TYPEGENname", which
     418// must be distinguished by the lexical scanner.
     419//
     420// Since the scanner cannot distinguish among the different classes of identifiers without some context information,
     421// there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named
     422// scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For
     423// each context that introduces a name scope, a new level is created in the type table and that level is popped on
     424// exiting the scope.  Since type names can be local to a particular declaration, each declaration is itself a scope.
     425// This requires distinguishing between type names that are local to the current declaration scope and those that
     426// persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).
     427//
     428// The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in
     429// the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push
     430// around the list separator.
     431//
     432//  int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) );
     433//      push               pop   push                   pop
    426434
    427435push:
     
    497505                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    498506        | type_name '.' no_attr_identifier                                      // CFA, nested type
    499                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     507                // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     508                { $$ = nullptr; }
    500509        | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    501                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     510                // { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     511                { $$ = nullptr; }
    502512        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    503                 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
     513                {
     514                        // add the missing control expression to the GenericExpr and return it
     515                        $5->control = maybeMoveBuild<Expression>( $3 );
     516                        $$ = new ExpressionNode( $5 );
     517                }
    504518        ;
    505519
    506520generic_assoc_list:                                                                             // C11
    507         | generic_association
     521        generic_association
    508522        | generic_assoc_list ',' generic_association
     523                {
     524                        // steal the association node from the singleton and delete the wrapper
     525                        $1->associations.splice($1->associations.end(), $3->associations);
     526                        delete $3;
     527                        $$ = $1;
     528                }
    509529        ;
    510530
    511531generic_association:                                                                    // C11
    512532        type_no_function ':' assignment_expression
     533                {
     534                        // create a GenericExpr wrapper with one association pair
     535                        $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );
     536                }
    513537        | DEFAULT ':' assignment_expression
     538                { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }
    514539        ;
    515540
     
    623648                // semantics checks, e.g., ++3, 3--, *3, &&3
    624649        | constant
    625                 { $$ = $1; }
    626650        | string_literal
    627651                { $$ = new ExpressionNode( $1 ); }
     
    835859//      '[' ']'
    836860//              { $$ = new ExpressionNode( build_tuple() ); }
    837 //      '[' push assignment_expression pop ']'
     861//      | '[' push assignment_expression pop ']'
    838862//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    839         '[' push ',' tuple_expression_list pop ']'
    840                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
    841         | '[' push assignment_expression ',' tuple_expression_list pop ']'
    842                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
     863        '[' ',' tuple_expression_list ']'
     864                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
     865        | '[' push assignment_expression pop ',' tuple_expression_list ']'
     866                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); }
    843867        ;
    844868
     
    892916        '{' '}'
    893917                { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }
    894         | '{'
    895                 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also
    896                 // requires its own scope.
    897           push push
     918        | '{' push
    898919          local_label_declaration_opt                                           // GCC, local labels
    899920          statement_decl_list                                                           // C99, intermix declarations and statements
    900921          pop '}'
    901                 { $$ = new StatementNode( build_compound( $5 ) ); }
     922                { $$ = new StatementNode( build_compound( $4 ) ); }
    902923        ;
    903924
    904925statement_decl_list:                                                                    // C99
    905926        statement_decl
    906         | statement_decl_list push statement_decl
    907                 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } }
     927        | statement_decl_list statement_decl
     928                { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } }
    908929        ;
    909930
     
    923944                        $$ = new StatementNode( $2 );
    924945                }
    925         | statement pop
     946        | statement
    926947        ;
    927948
     
    938959
    939960selection_statement:
    940         IF '(' push if_control_expression ')' statement         %prec THEN
    941                 // explicitly deal with the shift/reduce conflict on if/else
    942                 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
    943         | IF '(' push if_control_expression ')' statement ELSE statement
    944                 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
     961                        // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving
     962                        // the inherent S/R conflict with THEN/ELSE.
     963        push if_statement pop
     964                { $$ = $2; }
    945965        | SWITCH '(' comma_expression ')' case_clause
    946966                { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }
    947         | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     967        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    948968                {
    949969                        StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );
     
    957977        | CHOOSE '(' comma_expression ')' case_clause           // CFA
    958978                { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }
    959         | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     979        | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA
    960980                {
    961981                        StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );
     
    964984        ;
    965985
     986if_statement:
     987        IF '(' if_control_expression ')' statement                      %prec THEN
     988                // explicitly deal with the shift/reduce conflict on if/else
     989                { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
     990        | IF '(' if_control_expression ')' statement ELSE statement
     991                { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
     992        ;
     993
    966994if_control_expression:
    967         comma_expression pop
     995        comma_expression
    968996                { $$ = new IfCtl( nullptr, $1 ); }
    969         | c_declaration pop                                                                     // no semi-colon
     997        | c_declaration                                                                         // no semi-colon
    970998                { $$ = new IfCtl( $1, nullptr ); }
    971         | cfa_declaration pop                                                           // no semi-colon
     999        | cfa_declaration                                                                       // no semi-colon
    9721000                { $$ = new IfCtl( $1, nullptr ); }
    9731001        | declaration comma_expression                                          // semi-colon separated
     
    10261054
    10271055iteration_statement:
    1028         WHILE '(' comma_expression ')' statement
    1029                 { $$ = new StatementNode( build_while( $3, $5 ) ); }
     1056        WHILE '(' push if_control_expression ')' statement pop
     1057                { $$ = new StatementNode( build_while( $4, $6 ) ); }
    10301058        | DO statement WHILE '(' comma_expression ')' ';'
    1031                 { $$ = new StatementNode( build_while( $5, $2, true ) ); }
    1032         | FOR '(' push for_control_expression ')' statement
     1059                { $$ = new StatementNode( build_do_while( $5, $2 ) ); }
     1060        | FOR '(' push for_control_expression ')' statement pop
    10331061                { $$ = new StatementNode( build_for( $4, $6 ) ); }
    10341062        ;
    10351063
    10361064for_control_expression:
    1037         comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    1038                 { $$ = new ForCtl( $1, $4, $6 ); }
     1065        comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt
     1066                { $$ = new ForCtl( $1, $3, $5 ); }
    10391067        | declaration comma_expression_opt ';' comma_expression_opt // C99
    10401068                { $$ = new ForCtl( $1, $2, $4 ); }
     
    11581186
    11591187handler_clause:
    1160         handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1161                 { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
    1162         | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    1163                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
     1188        handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1189                { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); }
     1190        | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     1191                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); }
    11641192        ;
    11651193
     
    12651293
    12661294declaration_list_opt:                                                                   // used at beginning of switch statement
    1267         pop     // empty
     1295        // empty
    12681296                { $$ = nullptr; }
    12691297        | declaration_list
     
    12721300declaration_list:
    12731301        declaration
    1274         | declaration_list push declaration
    1275                 { $$ = $1->appendList( $3 ); }
    1276         ;
    1277 
    1278 KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
     1302        | declaration_list declaration
     1303                { $$ = $1->appendList( $2 ); }
     1304        ;
     1305
     1306KR_parameter_list_opt:                                                                  // used to declare parameter types in K&R style functions
    12791307        // empty
    12801308                { $$ = nullptr; }
    1281         | KR_declaration_list
    1282         ;
    1283 
    1284 KR_declaration_list:
     1309        | KR_parameter_list
     1310        ;
     1311
     1312KR_parameter_list:
    12851313        push c_declaration pop ';'
    12861314                { $$ = $2; }
    1287         | KR_declaration_list push c_declaration pop ';'
     1315        | KR_parameter_list push c_declaration pop ';'
    12881316                { $$ = $1->appendList( $3 ); }
    12891317        ;
     
    13051333
    13061334declaration:                                                                                    // old & new style declarations
    1307         c_declaration pop ';'
    1308         | cfa_declaration pop ';'                                                       // CFA
    1309         | static_assert
     1335        c_declaration ';'
     1336        | cfa_declaration ';'                                                           // CFA
     1337        | static_assert                                                                         // C11
    13101338        ;
    13111339
     
    13131341        STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11
    13141342                { $$ = DeclarationNode::newStaticAssert( $3, $5 ); }
     1343        | STATICASSERT '(' constant_expression ')' ';'          // CFA
     1344                { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); }
    13151345
    13161346// C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function
     
    13571387cfa_function_declaration:                                                               // CFA
    13581388        cfa_function_specifier
    1359                 { $$ = $1; }
    13601389        | type_qualifier_list cfa_function_specifier
    13611390                { $$ = $2->addQualifiers( $1 ); }
     
    13641393        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    13651394                { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1366         | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1395        | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13671396                {
    13681397                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    13691398                        DeclarationNode * ret = new DeclarationNode;
    13701399                        ret->type = maybeClone( $1->type->base );
    1371                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) );
     1400                        $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );
    13721401                }
    13731402        ;
    13741403
    13751404cfa_function_specifier:                                                                 // CFA
    1376 //      '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict
     1405//      '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict
    13771406//              {
    13781407//                      $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );
    13791408//              }
    1380 //      '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')'
     1409//      '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13811410//              {
    13821411//                      typedefTable.setNextIdentifier( *$5 );
    13831412//                      $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );
    13841413//              }
    1385 //      | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')'
     1414//      | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13861415//              {
    13871416//                      typedefTable.setNextIdentifier( *$5 );
     
    13911420                // identifier_or_type_name must be broken apart because of the sequence:
    13921421                //
    1393                 //   '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1422                //   '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    13941423                //   '[' ']' type_specifier
    13951424                //
    13961425                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    13971426                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1398         cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1427        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    13991428                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    14001429                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    1401         | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1430        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')'
    14021431                { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); }
    14031432        ;
     
    14141443        TYPEDEF cfa_variable_specifier
    14151444                {
    1416                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1445                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1" );
    14171446                        $$ = $2->addTypedef();
    14181447                }
    14191448        | TYPEDEF cfa_function_specifier
    14201449                {
    1421                         typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );
     1450                        typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2" );
    14221451                        $$ = $2->addTypedef();
    14231452                }
    14241453        | cfa_typedef_declaration pop ',' push no_attr_identifier
    14251454                {
    1426                         typedefTable.addToEnclosingScope( *$5, TYPEDEFname );
     1455                        typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
    14271456                        $$ = $1->appendList( $1->cloneType( $5 ) );
    14281457                }
     
    14351464        TYPEDEF type_specifier declarator
    14361465                {
    1437                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1466                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
    14381467                        $$ = $3->addType( $2 )->addTypedef();
    14391468                }
    14401469        | typedef_declaration pop ',' push declarator
    14411470                {
    1442                         typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );
     1471                        typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5" );
    14431472                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14441473                }
    14451474        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14461475                {
    1447                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1476                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
    14481477                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14491478                }
    14501479        | type_specifier TYPEDEF declarator
    14511480                {
    1452                         typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );
     1481                        typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
    14531482                        $$ = $3->addType( $1 )->addTypedef();
    14541483                }
    14551484        | type_specifier TYPEDEF type_qualifier_list declarator
    14561485                {
    1457                         typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );
     1486                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
    14581487                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14591488                }
     
    15821611
    15831612forall:
    1584         FORALL '(' push type_parameter_list pop ')'                                     // CFA
    1585                 { $$ = DeclarationNode::newForall( $4 ); }
     1613        FORALL '(' type_parameter_list ')'                                      // CFA
     1614                { $$ = DeclarationNode::newForall( $3 ); }
    15861615        ;
    15871616
     
    17651794                { $$ = DeclarationNode::newFromTypedef( $1 ); }
    17661795        | '.' TYPEDEFname
    1767                 { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME
     1796                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    17681797        | type_name '.' TYPEDEFname
    1769                 { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME
     1798                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    17701799        | typegen_name
    17711800        | '.' typegen_name
    1772                 { $$ = $2; }                                                                    // FIX ME
     1801                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    17731802        | type_name '.' typegen_name
    1774                 { $$ = $3; }                                                                    // FIX ME
     1803                { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    17751804        ;
    17761805
     
    17941823        ;
    17951824
     1825fred:
     1826        // empty
     1827                { yyy = false; }
     1828        ;
     1829
    17961830aggregate_type:                                                                                 // struct, union
    17971831        aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
    17981832                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    1799         | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
    1800                 {
    1801                         typedefTable.makeTypedef( *$3 );                        // create typedef
    1802                         if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1833        | aggregate_key attribute_list_opt no_attr_identifier fred
     1834                {
     1835                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1836                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18031837                        forall = false;                                                         // reset
    18041838                }
    18051839          '{' field_declaration_list_opt '}'
    1806                 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
     1840                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }
     1841        | aggregate_key attribute_list_opt type_name fred
     1842                {
     1843                        typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef
     1844                        //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update
     1845                        forall = false;                                                         // reset
     1846                }
     1847          '{' field_declaration_list_opt '}'
     1848                { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); }
    18071849        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
    18081850                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
     
    18111853
    18121854aggregate_type_nobody:                                                                  // struct, union - {...}
    1813         aggregate_key attribute_list_opt no_attr_identifier
    1814                 {
    1815                         typedefTable.makeTypedef( *$3 );
    1816                         if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
     1855        aggregate_key attribute_list_opt no_attr_identifier fred
     1856                {
     1857                        typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );
     1858                        //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update
    18171859                        forall = false;                                                         // reset
    18181860                        $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    18191861                }
    1820         | aggregate_key attribute_list_opt TYPEDEFname
    1821                 {
    1822                         typedefTable.makeTypedef( *$3 );
    1823                         $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 );
    1824                 }
    1825         | aggregate_key attribute_list_opt typegen_name         // CFA
     1862        | aggregate_key attribute_list_opt type_name fred
    18261863                {
    18271864                        // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
     
    18371874aggregate_key:
    18381875        STRUCT
    1839                 { $$ = DeclarationNode::Struct; }
     1876                { yyy = true; $$ = DeclarationNode::Struct; }
    18401877        | UNION
    1841                 { $$ = DeclarationNode::Union; }
     1878                { yyy = true; $$ = DeclarationNode::Union; }
    18421879        | EXCEPTION
    1843                 { $$ = DeclarationNode::Exception; }
     1880                { yyy = true; $$ = DeclarationNode::Exception; }
    18441881        | COROUTINE
    1845                 { $$ = DeclarationNode::Coroutine; }
     1882                { yyy = true; $$ = DeclarationNode::Coroutine; }
    18461883        | MONITOR
    1847                 { $$ = DeclarationNode::Monitor; }
     1884                { yyy = true; $$ = DeclarationNode::Monitor; }
    18481885        | THREAD
    1849                 { $$ = DeclarationNode::Thread; }
     1886                { yyy = true; $$ = DeclarationNode::Thread; }
    18501887        ;
    18511888
     
    18581895
    18591896field_declaration:
    1860         cfa_field_declaring_list ';'                                            // CFA, new style field declaration
     1897        type_specifier field_declaring_list ';'
     1898                { $$ = distAttr( $1, $2 ); }
     1899        | EXTENSION type_specifier field_declaring_list ';'     // GCC
     1900                { distExt( $3 ); $$ = distAttr( $2, $3 ); }             // mark all fields in list
     1901        | typedef_declaration ';'                                                       // CFA
     1902                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
     1903        | cfa_field_declaring_list ';'                                          // CFA, new style field declaration
    18611904        | EXTENSION cfa_field_declaring_list ';'                        // GCC
    1862                 {
    1863                         distExt( $2 );                                                          // mark all fields in list
    1864                         $$ = $2;
    1865                 }
    1866         | type_specifier field_declaring_list ';'
    1867                 {
    1868                         $$ = distAttr( $1, $2 ); }
    1869         | EXTENSION type_specifier field_declaring_list ';'     // GCC
    1870                 {
    1871                         distExt( $3 );                                                          // mark all fields in list
    1872                         $$ = distAttr( $2, $3 );
    1873                 }
    1874         | static_assert
     1905                { distExt( $2 ); $$ = $2; }                                             // mark all fields in list
     1906        | cfa_typedef_declaration ';'                                           // CFA
     1907                { SemanticError( yylloc, "Typedef in aggregate is currently unimplemented." ); $$ = nullptr; }
     1908        | static_assert                                                                         // C11
    18751909        ;
    18761910
     
    19111945                { $$ = nullptr; }
    19121946        | bit_subrange_size
    1913                 { $$ = $1; }
    19141947        ;
    19151948
     
    19221955        ENUM attribute_list_opt '{' enumerator_list comma_opt '}'
    19231956                { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }
    1924         | ENUM attribute_list_opt no_attr_identifier_or_type_name
     1957        | ENUM attribute_list_opt no_attr_identifier
    19251958                { typedefTable.makeTypedef( *$3 ); }
    19261959          '{' enumerator_list comma_opt '}'
    19271960                { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }
     1961        | ENUM attribute_list_opt type_name
     1962          '{' enumerator_list comma_opt '}'
     1963                { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }
    19281964        | enum_type_nobody
    19291965        ;
    19301966
    19311967enum_type_nobody:                                                                               // enum - {...}
    1932         ENUM attribute_list_opt no_attr_identifier_or_type_name
     1968        ENUM attribute_list_opt no_attr_identifier
    19331969                {
    19341970                        typedefTable.makeTypedef( *$3 );
    19351971                        $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 );
     1972                }
     1973        | ENUM attribute_list_opt type_name
     1974                {
     1975                        typedefTable.makeTypedef( *$3->type->symbolic.name );
     1976                        $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 );
    19361977                }
    19371978        ;
     
    19511992        ;
    19521993
    1953 cfa_parameter_type_list_opt:                                                    // CFA, abstract + real
     1994cfa_parameter_ellipsis_list_opt:                                                        // CFA, abstract + real
    19541995        // empty
    19551996                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
     
    20842125                { $$ = $2; }
    20852126        | '=' VOID
    2086                 { $$ = nullptr; }
     2127                { $$ = new InitializerNode( true ); }
    20872128        | ATassign initializer
    20882129                { $$ = $2->set_maybeConstructed( false ); }
     
    21612202type_parameter_list:                                                                    // CFA
    21622203        type_parameter
    2163                 { $$ = $1; }
    21642204        | type_parameter_list ',' type_parameter
    21652205                { $$ = $1->appendList( $3 ); }
     
    21752215type_parameter:                                                                                 // CFA
    21762216        type_class no_attr_identifier_or_type_name
    2177                 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); }
     2217                { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
    21782218          type_initializer_opt assertion_list_opt
    21792219                { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
     
    22092249        '|' no_attr_identifier_or_type_name '(' type_list ')'
    22102250                { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
    2211         | '|' '{' push trait_declaration_list '}'
     2251        | '|' '{' push trait_declaration_list pop '}'
    22122252                { $$ = $4; }
    2213         | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    2214                 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2253        // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'
     2254        //      { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
    22152255        ;
    22162256
     
    22442284        no_attr_identifier_or_type_name
    22452285                {
    2246                         typedefTable.addToEnclosingScope( *$1, TYPEDEFname );
     2286                        typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
    22472287                        $$ = DeclarationNode::newTypeDecl( $1, 0 );
    22482288                }
    2249         | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')'
    2250                 {
    2251                         typedefTable.addToEnclosingScope( *$1, TYPEGENname );
    2252                         $$ = DeclarationNode::newTypeDecl( $1, $4 );
     2289        | no_attr_identifier_or_type_name '(' type_parameter_list ')'
     2290                {
     2291                        typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
     2292                        $$ = DeclarationNode::newTypeDecl( $1, $3 );
    22532293                }
    22542294        ;
    22552295
    22562296trait_specifier:                                                                                // CFA
    2257         TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    2258                 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
    2259         | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}'
    2260                 { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
     2297        TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}'
     2298                { $$ = DeclarationNode::newTrait( $2, $4, 0 ); }
     2299        | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}'
     2300                { $$ = DeclarationNode::newTrait( $2, $4, $8 ); }
    22612301        ;
    22622302
    22632303trait_declaration_list:                                                                 // CFA
    22642304        trait_declaration
    2265         | trait_declaration_list push trait_declaration
    2266                 { $$ = $1->appendList( $3 ); }
     2305        | trait_declaration_list pop push trait_declaration
     2306                { $$ = $1->appendList( $4 ); }
    22672307        ;
    22682308
    22692309trait_declaration:                                                                              // CFA
    2270         cfa_trait_declaring_list pop ';'
    2271         | trait_declaring_list pop ';'
     2310        cfa_trait_declaring_list ';'
     2311        | trait_declaring_list ';'
    22722312        ;
    22732313
     
    22892329
    22902330translation_unit:
    2291         // empty
    2292                 {}                                                                                              // empty input file
     2331        // empty, input file
    22932332        | external_definition_list
    22942333                { parseTree = parseTree ? parseTree->appendList( $1 ) : $1;     }
     
    22962335
    22972336external_definition_list:
    2298         external_definition
     2337        push external_definition pop
     2338                { $$ = $2; }
    22992339        | external_definition_list
    23002340                { forall = xxx; }
    2301           push external_definition
     2341          push external_definition pop
    23022342                { $$ = $1 ? $1->appendList( $4 ) : $4; }
    23032343        ;
     
    23092349        ;
    23102350
     2351up:
     2352                { typedefTable.up(); }
     2353        ;
     2354
     2355down:
     2356                { typedefTable.down(); }
     2357        ;
     2358
    23112359external_definition:
    23122360        declaration
    23132361        | external_function_definition
     2362        | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
     2363                {
     2364                        distExt( $2 );                                                          // mark all fields in list
     2365                        $$ = $2;
     2366                }
    23142367        | ASM '(' string_literal ')' ';'                                        // GCC, global assembler statement
    23152368                {
     
    23212374                        linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
    23222375                }
    2323           '{' external_definition_list_opt '}'
     2376          '{' up external_definition_list_opt down '}'
    23242377                {
    23252378                        linkage = linkageStack.top();
    23262379                        linkageStack.pop();
    2327                         $$ = $5;
    2328                 }
    2329         | EXTENSION external_definition                                         // GCC, multiple __extension__ allowed, meaning unknown
    2330                 {
    2331                         distExt( $2 );                                                          // mark all fields in list
    2332                         $$ = $2;
     2380                        $$ = $6;
    23332381                }
    23342382        | type_qualifier_list
    2335                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2336           push '{' external_definition_list '}'                         // CFA, namespace
     2383                {
     2384                        if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2385                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2386                }
     2387          '{' up external_definition_list_opt down '}'          // CFA, namespace
    23372388                {
    23382389                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     
    23462397                }
    23472398        | declaration_qualifier_list
    2348                 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type
    2349           push '{' external_definition_list '}'                         // CFA, namespace
     2399                {
     2400                        if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2401                        if ( $1->type->forall ) xxx = forall = true; // remember generic type
     2402                }
     2403          '{' up external_definition_list_opt down '}'          // CFA, namespace
    23502404                {
    23512405                        for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     
    23602414        | declaration_qualifier_list type_qualifier_list
    23612415                {
    2362                         // forall must be in the type_qualifier_list
    2363                         if ( $2->type->forall ) xxx = forall = true; // remember generic type
    2364                 }
    2365           push '{' external_definition_list '}'                         // CFA, namespace
     2416                        if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }
     2417                        if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type
     2418                }
     2419          '{' up external_definition_list_opt down '}'          // CFA, namespace
    23662420                {
    23672421                        for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
     
    23872441        | function_declarator compound_statement
    23882442                { $$ = $1->addFunctionBody( $2 ); }
    2389         | KR_function_declarator KR_declaration_list_opt compound_statement
     2443        | KR_function_declarator KR_parameter_list_opt compound_statement
    23902444                { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); }
    23912445        ;
     
    24272481
    24282482                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2429         | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2483        | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24302484                {
    24312485                        rebindForall( $1, $2 );
     
    24332487                }
    24342488                // handles default int return type, OBSOLESCENT (see 1)
    2435         | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2489        | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24362490                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24372491                // handles default int return type, OBSOLESCENT (see 1)
    2438         | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2492        | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24392493                { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); }
    24402494                // handles default int return type, OBSOLESCENT (see 1)
    2441         | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2495        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement
    24422496                { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); }
    24432497        ;
     
    26842738        typedef
    26852739                // hide type name in enclosing scope by variable name
    2686                 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }
     2740                { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); }
    26872741        | '(' paren_type ')'
    26882742                { $$ = $2; }
     
    29743028        '[' ']'
    29753029                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    2976         // multi_array_dimension handles the '[' '*' ']' case
     3030                // multi_array_dimension handles the '[' '*' ']' case
    29773031        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
    29783032                { $$ = DeclarationNode::newVarArray( $3 ); }
    29793033        | '[' push type_qualifier_list pop ']'
    29803034                { $$ = DeclarationNode::newArray( 0, $3, false ); }
    2981         // multi_array_dimension handles the '[' assignment_expression ']' case
     3035                // multi_array_dimension handles the '[' assignment_expression ']' case
    29823036        | '[' push type_qualifier_list assignment_expression pop ']'
    29833037                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     
    31153169//
    31163170//              cfa_abstract_tuple identifier_or_type_name
    3117 //              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     3171//              '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')'
    31183172//
    31193173// since a function return type can be syntactically identical to a tuple type:
     
    31743228        '[' push cfa_abstract_parameter_list pop ']'
    31753229                { $$ = DeclarationNode::newTuple( $3 ); }
     3230        | '[' push type_specifier_nobody ELLIPSIS pop ']'
     3231                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
     3232        | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'
     3233                { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }
    31763234        ;
    31773235
    31783236cfa_abstract_function:                                                                  // CFA
    3179 //      '[' ']' '(' cfa_parameter_type_list_opt ')'
     3237//      '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'
    31803238//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    3181         cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
     3239        cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'
    31823240                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    3183         | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
     3241        | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')'
    31843242                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    31853243        ;
     
    32123270
    32133271%%
     3272
    32143273// ----end of grammar----
    32153274
Note: See TracChangeset for help on using the changeset viewer.