Changes in / [21bdce2:1596726]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Common/ScopedMap.h

    r21bdce2 r1596726  
    1010// Created On       : Wed Dec 2 11:37:00 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 21 15:22:40 2018
    13 // Update Count     : 3
     12// Last Modified On : Fri Jul 21 22:18:24 2017
     13// Update Count     : 2
    1414//
    1515
     
    276276        }
    277277
    278         template< typename value_t >
    279         std::pair< iterator, bool > insertAt( size_type scope, const Key& key, value_t&& value ) {
    280                 return insertAt( scope, std::make_pair( key, std::forward<value_t>( value ) ) );
    281         }
    282 
    283278        Value& operator[] ( const Key &key ) {
    284279                iterator slot = find( key );
  • src/Parser/DeclarationNode.cc

    r21bdce2 r1596726  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 21 20:36:45 2018
    13 // Update Count     : 1073
     12// Last Modified On : Wed May 16 09:37:17 2018
     13// Update Count     : 1070
    1414//
    1515
     
    181181        newnode->type->function.body = body;
    182182
     183        // ignore unnamed routine declarations: void p( int (*)(int) );
     184        if ( newnode->name ) {
     185                typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
     186        } // if
     187
    183188        if ( ret ) {
    184189                newnode->type->base = ret->type;
     
    282287        newnode->name = name;
    283288        newnode->enumeratorValue.reset( constant );
     289        typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );
    284290        return newnode;
    285291} // DeclarationNode::newEnumConstant
  • src/Parser/TypedefTable.cc

    r21bdce2 r1596726  
    77// TypedefTable.cc --
    88//
    9 // Author           : Peter A. Buhr
     9// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:20:13 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 21 20:55:24 2018
    13 // Update Count     : 117
     12// Last Modified On : Mon Aug 15 18:24:42 2016
     13// Update Count     : 25
    1414//
    1515
     16#include <ext/alloc_traits.h>    // for __alloc_traits<>::value_type
     17#include <cassert>               // for assert
     18#include <list>                  // for list, _List_iterator, list<>::iterator
     19#include <map>                   // for _Rb_tree_iterator, _Rb_tree_const_it...
     20#include <memory>                // for allocator_traits<>::value_type
     21#include <utility>               // for pair
    1622
     23#include "Parser/ParserTypes.h"  // for typedefTable
     24#include "Parser/parser.hh"      // for IDENTIFIER
    1725#include "TypedefTable.h"
    18 #include <cassert>               // for assert
     26
     27using namespace std;
    1928
    2029#if 0
    2130#include <iostream>
     31
    2232#define debugPrint( x ) cerr << x
    2333#else
     
    2535#endif
    2636
    27 using namespace std;
     37TypedefTable::TypedefTable() : currentScope( 0 ) {}
    2838
    29 TypedefTable::~TypedefTable() {
    30         if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) {
    31                 // std::cerr << "scope failure " << kindTable.currentScope() << endl;
    32         } // if
    33 } // TypedefTable::~TypedefTable
     39bool TypedefTable::exists( const string &identifier ) {
     40        return table.count( identifier ) > 0;
     41}
    3442
    35 bool TypedefTable::exists( const string & identifier ) {
    36         return kindTable.find( identifier ) != kindTable.end();
    37 } // TypedefTable::exists
     43int TypedefTable::isKind( const string &identifier ) const {
     44        tableType::const_iterator id_pos = table.find( identifier );
     45        // Name lookup defaults to identifier, and then the identifier's kind is set by the parser.
     46        if ( id_pos == table.end() ) return IDENTIFIER;
     47        return id_pos->second.begin()->kind;
     48}
    3849
    39 int TypedefTable::isKind( const string & identifier ) const {
    40         // Name lookup defaults to identifier, and then the identifier's kind is set by the parser.
    41         KindTable::const_iterator posn = kindTable.find( identifier );
    42         if ( posn == kindTable.end() ) return IDENTIFIER;
    43         return posn->second;
    44 } // TypedefTable::isKind
    45 
    46 void TypedefTable::changeKind( const string & identifier, kind_t kind ) {
    47         KindTable::iterator posn = kindTable.find( identifier );
    48         if ( posn != kindTable.end() ) posn->second = kind;
    49 } // TypedefTable::changeKind
     50void TypedefTable::changeKind( const string &identifier, kind_t kind ) {
     51        tableType::iterator id_pos = table.find( identifier );
     52        if ( id_pos == table.end() ) return;
     53        id_pos->second.begin()->kind = kind;
     54}
    5055
    5156// SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by
    52 // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if the
    53 // name is explicitly used.
    54 void TypedefTable::makeTypedef( const string & name ) {
     57// "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed
     58// if the name is explicitly used.
     59void TypedefTable::makeTypedef( const string &name ) {
    5560        if ( ! typedefTable.exists( name ) ) {
    5661                typedefTable.addToEnclosingScope( name, TypedefTable::TD );
    5762        } // if
    58 } // TypedefTable::makeTypedef
     63}
    5964
    60 void TypedefTable::addToEnclosingScope( const std::string & identifier, kind_t kind ) {
    61         assert( kindTable.currentScope() >= 1 );
    62         auto scope = kindTable.currentScope() - 1;
    63         debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl );
    64         auto ret = kindTable.insertAt( scope, identifier, kind );
    65         if ( ! ret.second ) { // already an element there
    66                 ret.first->second = kind; // update existing element with new kind
     65void TypedefTable::addToScope( const std::string &identifier, kind_t kind, int scope ) {
     66        if ( currentTrait != "" && scope == contextScope ) {
     67                DeferredEntry entry = { identifier, kind };
     68                contexts[currentTrait].push_back( entry );
     69        } else {
     70                debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << " from scope " << currentScope << endl );
     71                Entry newEntry = { scope, kind };
     72                tableType::iterator curPos = table.find( identifier );
     73                if ( curPos == table.end()) {
     74                        list< Entry > newList;
     75                        newList.push_front( newEntry );
     76                        table[identifier] = newList;
     77                } else {
     78                        list< Entry >::iterator listPos = (*curPos ).second.begin();
     79                        while ( listPos != (*curPos ).second.end() && listPos->scope > scope ) {
     80                                listPos++;
     81                        } // while
     82                        (*curPos ).second.insert( listPos, newEntry );
     83                } // if
    6784        } // if
    68 } // TypedefTable::addToEnclosingScope
     85}
     86
     87void TypedefTable::addToCurrentScope( const std::string &identifier, kind_t kind ) {
     88        addToScope( identifier, kind, currentScope );
     89}
     90
     91void TypedefTable::addToCurrentScope( kind_t kind ) {
     92        addToCurrentScope( nextIdentifiers.top(), kind );
     93}
     94
     95void TypedefTable::addToEnclosingScope( const std::string &identifier, kind_t kind ) {
     96        assert( currentScope >= 1 );
     97        addToScope( identifier, kind, currentScope - 1 );
     98}
     99
     100void TypedefTable::addToEnclosingScope( kind_t kind ) {
     101        addToEnclosingScope( nextIdentifiers.top(), kind );
     102}
     103
     104void TypedefTable::addToEnclosingScope2( const std::string &identifier, kind_t kind ) {
     105        assert( currentScope >= 2 );
     106        addToScope( identifier, kind, currentScope - 2 );
     107}
     108
     109void TypedefTable::addToEnclosingScope2( kind_t kind ) {
     110        addToEnclosingScope2( nextIdentifiers.top(), kind );
     111}
     112
     113void TypedefTable::setNextIdentifier( const std::string &identifier ) {
     114        nextIdentifiers.top() = identifier;
     115}
     116
     117void TypedefTable::openTrait( const std::string &contextName ) {
     118        map< string, deferListType >::iterator i = contexts.find( contextName );
     119        if ( i != contexts.end() ) {
     120                deferListType &entries = i->second;
     121                for ( deferListType::iterator i = entries.begin(); i != entries.end(); i++) {
     122                        addToEnclosingScope( i->identifier, i->kind );
     123                } // for
     124        } // if
     125}
    69126
    70127void TypedefTable::enterScope() {
    71         kindTable.beginScope();
    72         debugPrint( "Entering scope " << kindTable.currentScope() << endl );
    73 } // TypedefTable::enterScope
     128        currentScope += 1;
     129        deferListStack.push( deferListType() );
     130        nextIdentifiers.push( "" );
     131        debugPrint( "Entering scope " << currentScope << ", nextIdentifiers size is " << nextIdentifiers.size() << endl );
     132}
    74133
    75134void TypedefTable::leaveScope() {
    76         debugPrint( "Leaving scope " << kindTable.currentScope() << endl );
    77         kindTable.endScope();
    78 } // TypedefTable::leaveScope
     135        debugPrint( "Leaving scope " << currentScope << endl );
     136        for ( tableType::iterator i = table.begin(); i != table.end(); ) {
     137                list< Entry > &declList = (*i).second;
     138                while ( ! declList.empty() && declList.front().scope == currentScope ) {
     139                        declList.pop_front();
     140                }
     141                if ( declList.empty() ) {                                               // standard idom for erasing during traversal
     142                        table.erase( i++ );
     143                } else
     144                        ++i;
     145        } // for
     146        currentScope -= 1;
     147        for ( deferListType::iterator i = deferListStack.top().begin(); i != deferListStack.top().end(); i++ ) {
     148                addToCurrentScope( i->identifier, i->kind );
     149        } // for
     150        deferListStack.pop();
     151        debugPrint( "nextIdentifiers size is " << nextIdentifiers.size() << " top is " << nextIdentifiers.top() << endl );
     152        nextIdentifiers.pop();
     153}
    79154
    80 // void TypedefTable::print( void ) const {
    81 //      for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) {
    82 //              debugPrint( (*i ).first << ": " );
    83 //              list< Entry > declList = (*i).second;
    84 //              for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
    85 //                      debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
    86 //              }
    87 //              debugPrint( endl );
    88 //      } // for
    89 // }
     155void TypedefTable::enterTrait( const std::string &contextName ) {
     156        currentTrait = contextName;
     157        contextScope = currentScope;
     158}
     159
     160void TypedefTable::leaveTrait() {
     161        currentTrait = "";
     162}
     163
     164void TypedefTable::print( void ) const {
     165        for ( tableType::const_iterator i = table.begin(); i != table.end(); i++) {
     166                debugPrint( (*i ).first << ": " );
     167                list< Entry > declList = (*i).second;
     168                for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) {
     169                        debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " );
     170                }
     171                debugPrint( endl );
     172        } // for
     173}
    90174
    91175// Local Variables: //
  • src/Parser/TypedefTable.h

    r21bdce2 r1596726  
    77// TypedefTable.h --
    88//
    9 // Author           : Peter A. Buhr
     9// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:24:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 21 20:28:01 2018
    13 // Update Count     : 76
     12// Last Modified On : Sat Jul 22 09:33:14 2017
     13// Update Count     : 34
    1414//
    1515
    1616#pragma once
    1717
    18 #include <string>                                                                               // for string
     18#include <list>       // for list
     19#include <map>        // for map, map<>::value_compare
     20#include <stack>      // for stack
     21#include <string>     // for string
    1922
    20 #include "Common/ScopedMap.h"                                                   // for ScopedMap
    2123#include "ParserTypes.h"
    22 #include "parser.hh"                                                                    // for IDENTIFIER, TYPEDEFname, TYPEGENname
     24#include "parser.hh"  // for IDENTIFIER, TYPEDEFname, TYPEGENname
    2325
    2426class TypedefTable {
     
    2628        enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname };
    2729  private:
    28         typedef ScopedMap< std::string, kind_t > KindTable;
    29         KindTable kindTable;   
     30        struct Entry {
     31                int scope;
     32                kind_t kind;
     33        };
     34
     35        struct DeferredEntry {
     36                std::string identifier;
     37                kind_t kind;
     38        };
     39
     40        typedef std::map< std::string, std::list< Entry > > tableType;
     41        tableType table;
     42
     43        int currentScope;
     44        std::string currentTrait;
     45        int contextScope;
     46
     47        typedef std::list< DeferredEntry > deferListType;
     48        std::stack< deferListType > deferListStack;
     49        std::map< std::string, deferListType > contexts;
     50
     51        std::stack< std::string > nextIdentifiers;
     52
     53        void addToScope( const std::string &identifier, kind_t kind, int scope );
    3054  public:
    31         ~TypedefTable();
     55        TypedefTable();
    3256
    33         bool exists( const std::string & identifier );
    34         int isKind( const std::string & identifier ) const;
    35         void changeKind( const std::string & identifier, kind_t kind );
    36         void makeTypedef( const std::string & name );
    37         void addToEnclosingScope( const std::string & identifier, kind_t kind );
     57        bool exists( const std::string &identifier );
     58        int isKind( const std::string &identifier ) const;
     59        void changeKind( const std::string &identifier, kind_t kind );
     60
     61        void makeTypedef( const std::string &name );
     62
     63        // "addToCurrentScope" adds the identifier/type pair to the current scope. This does less than you think it does,
     64        // since each declaration is within its own scope.  Mostly useful for type parameters.
     65        void addToCurrentScope( const std::string &identifier, kind_t kind );
     66        void addToCurrentScope( kind_t kind );                  // use nextIdentifiers.top()
     67
     68        // "addToEnclosingScope" adds the identifier/type pair to the scope that encloses the current one.  This is the
     69        // right way to handle type and typedef names
     70        void addToEnclosingScope( const std::string &identifier, kind_t kind );
     71        void addToEnclosingScope( kind_t kind );                // use nextIdentifiers.top()
     72
     73        // "addToEnclosingScope2" adds the identifier/type pair to the scope that encloses the scope enclosing the the
     74        // current one.  This is the right way to handle assertion names
     75        void addToEnclosingScope2( const std::string &identifier, kind_t kind );
     76        void addToEnclosingScope2( kind_t kind );               // use nextIdentifiers.top()
     77
     78        // set the next identifier to be used by an "add" operation without an identifier parameter within the current scope
     79        void setNextIdentifier( const std::string &identifier );
     80
     81        // dump the definitions from a pre-defined context into the current scope
     82        void openTrait( const std::string &contextName );
    3883
    3984        void enterScope();
    4085        void leaveScope();
    41 }; // TypedefTable
     86        void enterTrait( const std::string &contextName );
     87        void leaveTrait();
     88
     89        void print() const;
     90};
    4291
    4392// Local Variables: //
  • src/Parser/parser.yy

    r21bdce2 r1596726  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 21 21:44:01 2018
    13 // Update Count     : 3350
     12// Last Modified On : Fri May 11 17:51:38 2018
     13// Update Count     : 3261
    1414//
    1515
     
    119119// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
    120120//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
    121 // Currently, the forall is associated with the routine, and the generic type has to be separately defined:
    122 //   forall( otype T ) struct S { int T; };
    123 //   forall( otype W ) bar( W ) {}
    124121
    125122void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
    126         if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition
     123        if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
    127124                funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
    128125                declSpec->type->aggregate.params = nullptr;
     
    304301%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
    305302
    306 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
     303%type<decl> field_declaration field_declaration_list field_declarator field_declaring_list
    307304%type<en> field field_list field_name fraction_constants_opt
    308305
     
    364361
    365362// initializers
    366 %type<in>  initializer initializer_list_opt initializer_opt
     363%type<in>  initializer initializer_list initializer_opt
    367364
    368365// designators
     
    415412// actions during the parser update this data structure when the class of identifiers change.
    416413//
    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.
     414// Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a
     415// local scope; it must revert to its original class at the end of the block.  Since type names can be local to a
     416// particular declaration, each declaration is itself a scope.  This requires distinguishing between type names that are
     417// local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in
     418// "typedef" or "otype" declarations).
     419//
     420// The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of
     421// scopes.  Every push must have a matching pop, although it is regrettable the matching pairs do not always occur
     422// within the same rule.  These non-terminals may appear in more contexts than strictly necessary from a semantic point
     423// of view.  Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have
     424// enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra
     425// rules is to open a new scope unconditionally.  As the grammar evolves, it may be neccesary to add or move around
     426// "push" and "pop" nonterminals to resolve conflicts of this sort.
    426427
    427428push:
     
    497498                { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }
    498499        | type_name '.' no_attr_identifier                                      // CFA, nested type
    499                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
    500         | type_name '.' '[' field_list ']'                                      // CFA, nested type / tuple field selector
    501                 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; }
     500                { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; }
     501//              { $$ = nullptr; }
     502        | type_name '.' '[' push field_list pop ']'                     // CFA, nested type / tuple field selector
     503                { SemanticError( yylloc, "Qualified names are currently unimplemented." ); $$ = nullptr; }
     504//              { $$ = nullptr; }
    502505        | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11
    503506                { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; }
     
    516519postfix_expression:
    517520        primary_expression
    518         | postfix_expression '[' assignment_expression ']'
     521        | postfix_expression '[' push assignment_expression pop ']'
    519522                // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a
    520523                // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be
    521524                // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is
    522525                // equivalent to the old x[i,j].
    523                 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }
     526                { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); }
    524527        | postfix_expression '{' argument_expression_list '}' // CFA, constructor call
    525528                {
     
    536539        | postfix_expression FLOATING_FRACTIONconstant          // CFA, tuple index
    537540                { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); }
    538         | postfix_expression '.' '[' field_list ']'                     // CFA, tuple field selector
    539                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     541        | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector
     542                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    540543        | postfix_expression ARROW no_attr_identifier
    541544                {
     
    544547        | postfix_expression ARROW INTEGERconstant                      // CFA, tuple index
    545548                { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); }
    546         | postfix_expression ARROW '[' field_list ']'           // CFA, tuple field selector
    547                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     549        | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector
     550                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    548551        | postfix_expression ICR
    549552                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); }
    550553        | postfix_expression DECR
    551554                { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); }
    552         | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal
     555        | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal
    553556                { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }
    554         | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal
     557        | '(' type_no_function ')' '@' '{' initializer_list comma_opt '}' // CFA, explicit C compound-literal
    555558                { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }
    556559        | '^' primary_expression '{' argument_expression_list '}' // CFA
     
    585588        | FLOATING_DECIMALconstant field
    586589                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }
    587         | FLOATING_DECIMALconstant '[' field_list ']'
    588                 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); }
     590        | FLOATING_DECIMALconstant '[' push field_list pop ']'
     591                { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); }
    589592        | field_name '.' field
    590593                { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    591         | field_name '.' '[' field_list ']'
    592                 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
     594        | field_name '.' '[' push field_list pop ']'
     595                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); }
    593596        | field_name ARROW field
    594597                { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }
    595         | field_name ARROW '[' field_list ']'
    596                 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }
     598        | field_name ARROW '[' push field_list pop ']'
     599                { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }
    597600        ;
    598601
     
    804807        | unary_expression assignment_operator assignment_expression
    805808                { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); }
    806         | unary_expression '=' '{' initializer_list_opt comma_opt '}'
     809        | unary_expression '=' '{' initializer_list comma_opt '}'
    807810                { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }
    808811        ;
     
    837840//      '[' push assignment_expression pop ']'
    838841//              { $$ = new ExpressionNode( build_tuple( $3 ) ); }
    839         '[' ',' tuple_expression_list ']'
    840                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }
    841         | '[' assignment_expression ',' tuple_expression_list ']'
    842                 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$2->set_last( $4 ) ) ); }
     842        '[' push ',' tuple_expression_list pop ']'
     843                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); }
     844        | '[' push assignment_expression ',' tuple_expression_list pop ']'
     845                { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); }
    843846        ;
    844847
     
    10711074        | RETURN comma_expression_opt ';'
    10721075                { $$ = new StatementNode( build_return( $2 ) ); }
    1073         | RETURN '{' initializer_list_opt comma_opt '}'
     1076        | RETURN '{' initializer_list comma_opt '}'
    10741077                { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }
    10751078        | THROW assignment_expression_opt ';'                           // handles rethrow
     
    11651168
    11661169handler_predicate_opt:
    1167         // empty
     1170        //empty
    11681171                { $$ = nullptr; }
    11691172        | ';' conditional_expression                            { $$ = $2; }
     
    11841187        | type_specifier_nobody declarator
    11851188                {
     1189                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11861190                        $$ = $2->addType( $1 );
    11871191                }
     
    11901194        | cfa_abstract_declarator_tuple no_attr_identifier      // CFA
    11911195                {
     1196                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    11921197                        $$ = $1->addName( $2 );
    11931198                }
     
    13391344cfa_variable_declaration:                                                               // CFA
    13401345        cfa_variable_specifier initializer_opt
    1341                 { $$ = $1->addInitializer( $2 ); }
     1346                {
     1347                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1348                        $$ = $1->addInitializer( $2 );
     1349                }
    13421350        | declaration_qualifier_list cfa_variable_specifier initializer_opt
    13431351                // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude
    13441352                // them as a type_qualifier cannot appear in that context.
    1345                 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); }
     1353                {
     1354                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1355                        $$ = $2->addQualifiers( $1 )->addInitializer( $3 );;
     1356                }
    13461357        | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt
    1347                 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }
     1358                {
     1359                        typedefTable.addToEnclosingScope( *$5, TypedefTable::ID );
     1360                        $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) );
     1361                }
    13481362        ;
    13491363
     
    13521366                // storage-class
    13531367        cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt
    1354                 { $$ = $1->addName( $2 )->addAsmName( $3 ); }
     1368                {
     1369                        typedefTable.setNextIdentifier( *$2 );
     1370                        $$ = $1->addName( $2 )->addAsmName( $3 );
     1371                }
    13551372        | cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1356                 { $$ = $1->addName( $2 )->addAsmName( $3 ); }
     1373                {
     1374                        typedefTable.setNextIdentifier( *$2 );
     1375                        $$ = $1->addName( $2 )->addAsmName( $3 );
     1376                }
    13571377        | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt
    1358                 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); }
     1378                {
     1379                        typedefTable.setNextIdentifier( *$3 );
     1380                        $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 );
     1381                }
    13591382        ;
    13601383
    13611384cfa_function_declaration:                                                               // CFA
    13621385        cfa_function_specifier
    1363                 { $$ = $1; }
     1386                {
     1387                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1388                        $$ = $1;
     1389                }
    13641390        | type_qualifier_list cfa_function_specifier
    1365                 { $$ = $2->addQualifiers( $1 ); }
     1391                {
     1392                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1393                        $$ = $2->addQualifiers( $1 );
     1394                }
    13661395        | declaration_qualifier_list cfa_function_specifier
    1367                 { $$ = $2->addQualifiers( $1 ); }
     1396                {
     1397                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1398                        $$ = $2->addQualifiers( $1 );
     1399                }
    13681400        | declaration_qualifier_list type_qualifier_list cfa_function_specifier
    1369                 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); }
    1370         | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1401                {
     1402                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1403                        $$ = $3->addQualifiers( $1 )->addQualifiers( $2 );
     1404                }
     1405        | cfa_function_declaration pop ',' push identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    13711406                {
    13721407                        // Append the return type at the start (left-hand-side) to each identifier in the list.
    13731408                        DeclarationNode * ret = new DeclarationNode;
    13741409                        ret->type = maybeClone( $1->type->base );
    1375                         $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) );
     1410                        $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr ) );
    13761411                }
    13771412        ;
     
    14001435                // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be
    14011436                // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name.
    1402         cfa_abstract_tuple identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
     1437        cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
    14031438                // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator).
    1404                 { $$ = DeclarationNode::newFunction( $2, $1, $4, 0 ); }
    1405         | cfa_function_return identifier_or_type_name '(' cfa_parameter_type_list_opt ')'
    1406                 { $$ = DeclarationNode::newFunction( $2, $1, $4, 0 ); }
     1439                {
     1440                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0 );
     1441                }
     1442        | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')'
     1443                {
     1444                        $$ = DeclarationNode::newFunction( $2, $1, $5, 0 );
     1445                }
    14071446        ;
    14081447
    14091448cfa_function_return:                                                                    // CFA
    1410         '[' cfa_parameter_list ']'
    1411                 { $$ = DeclarationNode::newTuple( $2 ); }
    1412         | '[' cfa_parameter_list ',' cfa_abstract_parameter_list ']'
     1449        '[' push cfa_parameter_list pop ']'
     1450                { $$ = DeclarationNode::newTuple( $3 ); }
     1451        | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']'
    14131452                // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the
    14141453                // ']'.
    1415                 { $$ = DeclarationNode::newTuple( $2->appendList( $4 ) ); }
     1454                { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); }
    14161455        ;
    14171456
     
    14191458        TYPEDEF cfa_variable_specifier
    14201459                {
    1421                         typedefTable.addToEnclosingScope( *$2->name, TypedefTable::TD );
     1460                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14221461                        $$ = $2->addTypedef();
    14231462                }
    14241463        | TYPEDEF cfa_function_specifier
    14251464                {
    1426                         typedefTable.addToEnclosingScope( *$2->name, TypedefTable::TD );
     1465                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14271466                        $$ = $2->addTypedef();
    14281467                }
     
    14401479        TYPEDEF type_specifier declarator
    14411480                {
    1442                         typedefTable.addToEnclosingScope( *$3->name, TypedefTable::TD );
     1481                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14431482                        $$ = $3->addType( $2 )->addTypedef();
    14441483                }
    14451484        | typedef_declaration pop ',' push declarator
    14461485                {
    1447                         typedefTable.addToEnclosingScope( *$5->name, TypedefTable::TD );
     1486                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14481487                        $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
    14491488                }
    14501489        | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
    14511490                {
    1452                         typedefTable.addToEnclosingScope( *$4->name, TypedefTable::TD );
     1491                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14531492                        $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
    14541493                }
    14551494        | type_specifier TYPEDEF declarator
    14561495                {
    1457                         typedefTable.addToEnclosingScope( *$3->name, TypedefTable::TD );
     1496                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14581497                        $$ = $3->addType( $1 )->addTypedef();
    14591498                }
    14601499        | type_specifier TYPEDEF type_qualifier_list declarator
    14611500                {
    1462                         typedefTable.addToEnclosingScope( *$4->name, TypedefTable::TD );
     1501                        typedefTable.addToEnclosingScope( TypedefTable::TD );
    14631502                        $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
    14641503                }
     
    14691508        TYPEDEF no_attr_identifier '=' assignment_expression
    14701509                {
    1471                         // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    1472                         SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1510                        typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );
     1511                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    14731512                }
    14741513        | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression
    14751514                {
    1476                         // $$ = DeclarationNode::newName( 0 );                  // unimplemented
    1477                         SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;
     1515                        typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );
     1516                        $$ = DeclarationNode::newName( 0 );                     // unimplemented
    14781517                }
    14791518        ;
     
    15031542c_declaration:
    15041543        declaration_specifier declaring_list
    1505                 { $$ = distAttr( $1, $2 ); }
     1544                {
     1545                        $$ = distAttr( $1, $2 );
     1546                }
    15061547        | typedef_declaration
    15071548        | typedef_expression                                                            // GCC, naming expression type
     
    15131554                // storage-class
    15141555        declarator asm_name_opt initializer_opt
    1515                 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); }
     1556                {
     1557                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1558                        $$ = $1->addAsmName( $2 )->addInitializer( $3 );
     1559                }
    15161560        | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt
    1517                 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }
     1561                {
     1562                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     1563                        $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) );
     1564                }
    15181565        ;
    15191566
     
    18071854
    18081855aggregate_type:                                                                                 // struct, union
    1809         aggregate_key attribute_list_opt '{' field_declaration_list_opt '}'
     1856        aggregate_key attribute_list_opt '{' field_declaration_list '}'
    18101857                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }
    18111858        | aggregate_key attribute_list_opt no_attr_identifier_or_type_name
     
    18151862                        forall = false;                                                         // reset
    18161863                }
    1817           '{' field_declaration_list_opt '}'
     1864          '{' field_declaration_list '}'
    18181865                { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); }
    1819         | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA
     1866        | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA
    18201867                { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); }
    18211868        | aggregate_type_nobody
     
    18621909        ;
    18631910
    1864 field_declaration_list_opt:
     1911field_declaration_list:
    18651912        // empty
    18661913                { $$ = nullptr; }
    1867         | field_declaration_list_opt field_declaration
     1914        | field_declaration_list field_declaration
    18681915                { $$ = $1 ? $1->appendList( $2 ) : $2; }
    18691916        ;
     
    18981945
    18991946field_declaring_list:
    1900         field_declarator_opt
    1901         | field_declaring_list ',' attribute_list_opt field_declarator_opt
     1947        field_declarator
     1948        | field_declaring_list ',' attribute_list_opt field_declarator
    19021949                { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }
    19031950        ;
    19041951
    1905 field_declarator_opt:
     1952field_declarator:
    19061953        // empty
    19071954                { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name
     
    19702017        | cfa_abstract_parameter_list
    19712018        | cfa_parameter_list
    1972         | cfa_parameter_list ',' cfa_abstract_parameter_list
    1973                 { $$ = $1->appendList( $3 ); }
    1974         | cfa_abstract_parameter_list ',' ELLIPSIS
     2019        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list
     2020                { $$ = $1->appendList( $5 ); }
     2021        | cfa_abstract_parameter_list pop ',' push ELLIPSIS
    19752022                { $$ = $1->addVarArgs(); }
    1976         | cfa_parameter_list ',' ELLIPSIS
     2023        | cfa_parameter_list pop ',' push ELLIPSIS
    19772024                { $$ = $1->addVarArgs(); }
    19782025        ;
     
    19822029                // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'.
    19832030        cfa_parameter_declaration
    1984         | cfa_abstract_parameter_list ',' cfa_parameter_declaration
    1985                 { $$ = $1->appendList( $3 ); }
    1986         | cfa_parameter_list ',' cfa_parameter_declaration
    1987                 { $$ = $1->appendList( $3 ); }
    1988         | cfa_parameter_list ',' cfa_abstract_parameter_list ',' cfa_parameter_declaration
    1989                 { $$ = $1->appendList( $3 )->appendList( $5 ); }
     2031        | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
     2032                { $$ = $1->appendList( $5 ); }
     2033        | cfa_parameter_list pop ',' push cfa_parameter_declaration
     2034                { $$ = $1->appendList( $5 ); }
     2035        | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration
     2036                { $$ = $1->appendList( $5 )->appendList( $9 ); }
    19902037        ;
    19912038
    19922039cfa_abstract_parameter_list:                                                    // CFA, new & old style abstract
    19932040        cfa_abstract_parameter_declaration
    1994         | cfa_abstract_parameter_list ',' cfa_abstract_parameter_declaration
    1995                 { $$ = $1->appendList( $3 ); }
     2041        | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration
     2042                { $$ = $1->appendList( $5 ); }
    19962043        ;
    19972044
     
    20432090                // No SUE declaration in parameter list.
    20442091        declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt
    2045                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2092                {
     2093                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2094                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
     2095                }
    20462096        | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt
    2047                 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }
     2097                {
     2098                        typedefTable.addToEnclosingScope( TypedefTable::ID );
     2099                        $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr );
     2100                }
    20482101        ;
    20492102
     
    21032156initializer:
    21042157        assignment_expression                                           { $$ = new InitializerNode( $1 ); }
    2105         | '{' initializer_list_opt comma_opt '}'        { $$ = new InitializerNode( $2, true ); }
    2106         ;
    2107 
    2108 initializer_list_opt:
     2158        | '{' initializer_list comma_opt '}'            { $$ = new InitializerNode( $2, true ); }
     2159        ;
     2160
     2161initializer_list:
    21092162        // empty
    21102163                { $$ = nullptr; }
    21112164        | initializer
    21122165        | designation initializer                                       { $$ = $2->set_designators( $1 ); }
    2113         | initializer_list_opt ',' initializer          { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
    2114         | initializer_list_opt ',' designation initializer
     2166        | initializer_list ',' initializer                      { $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
     2167        | initializer_list ',' designation initializer
    21152168                { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); }
    21162169        ;
     
    21422195        '.' no_attr_identifier                                                          // C99, field name
    21432196                { $$ = new ExpressionNode( build_varref( $2 ) ); }
    2144         | '[' assignment_expression ']'                                         // C99, single array element
     2197        | '[' push assignment_expression pop ']'                        // C99, single array element
    21452198                // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
    2146                 { $$ = $2; }
    2147         | '[' subrange ']'                                                                      // CFA, multiple array elements
    2148                 { $$ = $2; }
    2149         | '[' constant_expression ELLIPSIS constant_expression ']' // GCC, multiple array elements
    2150                 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $2 ), maybeMoveBuild< Expression >( $4 ) ) ); }
    2151         | '.' '[' field_list ']'                                                        // CFA, tuple field selector
    21522199                { $$ = $3; }
     2200        | '[' push subrange pop ']'                                                     // CFA, multiple array elements
     2201                { $$ = $3; }
     2202        | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements
     2203                { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); }
     2204        | '.' '[' push field_list pop ']'                                       // CFA, tuple field selector
     2205                { $$ = $4; }
    21532206        ;
    21542207
     
    22202273assertion:                                                                                              // CFA
    22212274        '|' no_attr_identifier_or_type_name '(' type_list ')'
    2222                 { $$ = DeclarationNode::newTraitUse( $2, $4 ); }
     2275                {
     2276                        typedefTable.openTrait( *$2 );
     2277                        $$ = DeclarationNode::newTraitUse( $2, $4 );
     2278                }
    22232279        | '|' '{' push trait_declaration_list '}'
    22242280                { $$ = $4; }
    22252281        | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')'
    2226                 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }
     2282                { $$ = nullptr; }
    22272283        ;
    22282284
     
    22682324trait_specifier:                                                                                // CFA
    22692325        TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}'
    2270                 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); }
     2326                {
     2327                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
     2328                        $$ = DeclarationNode::newTrait( $2, $5, 0 );
     2329                }
    22712330        | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{'
    2272                 { typedefTable.enterScope(); }
     2331                {
     2332                        typedefTable.enterTrait( *$2 );
     2333                        typedefTable.enterScope();
     2334                }
    22732335          trait_declaration_list '}'
    2274                 { $$ = DeclarationNode::newTrait( $2, $5, $10 ); }
     2336                {
     2337                        typedefTable.leaveTrait();
     2338                        typedefTable.addToEnclosingScope( *$2, TypedefTable::ID );
     2339                        $$ = DeclarationNode::newTrait( $2, $5, $10 );
     2340                }
    22752341        ;
    22762342
     
    22882354cfa_trait_declaring_list:                                                               // CFA
    22892355        cfa_variable_specifier
    2290                 { $$ = $1; }
     2356                {
     2357                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2358                        $$ = $1;
     2359                }
    22912360        | cfa_function_specifier
    2292                 { $$ = $1; }
     2361                {
     2362                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2363                        $$ = $1;
     2364                }
    22932365        | cfa_trait_declaring_list pop ',' push identifier_or_type_name
    2294                 { $$ = $1->appendList( $1->cloneType( $5 ) ); }
     2366                {
     2367                        typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID );
     2368                        $$ = $1->appendList( $1->cloneType( $5 ) );
     2369                }
    22952370        ;
    22962371
    22972372trait_declaring_list:                                                                   // CFA
    22982373        type_specifier declarator
    2299                 { $$ = $2->addType( $1 ); }
     2374                {
     2375                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2376                        $$ = $2->addType( $1 );
     2377                }
    23002378        | trait_declaring_list pop ',' push declarator
    2301                 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); }
     2379                {
     2380                        typedefTable.addToEnclosingScope2( TypedefTable::ID );
     2381                        $$ = $1->appendList( $1->cloneBaseType( $5 ) );
     2382                }
    23022383        ;
    23032384
     
    24072488        | function_declarator compound_statement
    24082489                {
     2490                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24092491                        typedefTable.leaveScope();
    24102492                        $$ = $1->addFunctionBody( $2 );
     
    24122494        | KR_function_declarator KR_declaration_list_opt compound_statement
    24132495                {
     2496                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24142497                        typedefTable.leaveScope();
    24152498                        $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
     
    24272510        cfa_function_declaration with_clause_opt compound_statement     // CFA
    24282511                {
     2512                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24292513                        typedefTable.leaveScope();
    24302514                        // Add the function body to the last identifier in the function definition list, i.e., foo3:
     
    24362520                {
    24372521                        rebindForall( $1, $2 );
     2522                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24382523                        typedefTable.leaveScope();
    24392524                        $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    24402525                }
    2441         | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement
    2442                 {
    2443                         rebindForall( $1, $2 );
    2444                         typedefTable.leaveScope();
    2445                         $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );
    2446                 }
    24472526                // handles default int return type, OBSOLESCENT (see 1)
    24482527        | type_qualifier_list function_declarator with_clause_opt compound_statement
    24492528                {
     2529                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24502530                        typedefTable.leaveScope();
    24512531                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
     
    24542534        | declaration_qualifier_list function_declarator with_clause_opt compound_statement
    24552535                {
     2536                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24562537                        typedefTable.leaveScope();
    24572538                        $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 );
     
    24602541        | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement
    24612542                {
     2543                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24622544                        typedefTable.leaveScope();
    24632545                        $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 );
     
    24682550                {
    24692551                        rebindForall( $1, $2 );
     2552                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24702553                        typedefTable.leaveScope();
    24712554                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 );
     
    24742557        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24752558                {
     2559                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24762560                        typedefTable.leaveScope();
    24772561                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
     
    24802564        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24812565                {
     2566                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24822567                        typedefTable.leaveScope();
    24832568                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 );
     
    24862571        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    24872572                {
     2573                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    24882574                        typedefTable.leaveScope();
    24892575                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 );
     
    25982684paren_identifier:
    25992685        identifier
    2600                 { $$ = DeclarationNode::newName( $1 ); }
     2686                {
     2687                        typedefTable.setNextIdentifier( *$1 );
     2688                        $$ = DeclarationNode::newName( $1 );
     2689                }
    26012690        | '(' paren_identifier ')'                                                      // redundant parenthesis
    26022691                { $$ = $2; }
     
    26852774        paren_identifier '(' identifier_list ')'                        // function_declarator handles empty parameter
    26862775                { $$ = $1->addIdList( $3 ); }
    2687         | '(' KR_function_ptr ')' '(' parameter_type_list_opt ')'
    2688                 { $$ = $2->addParamList( $5 ); }
     2776        | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')'
     2777                { $$ = $2->addParamList( $6 ); }
    26892778        | '(' KR_function_no_ptr ')'                                            // redundant parenthesis
    26902779                { $$ = $2; }
     
    27312820paren_type:
    27322821        typedef
    2733                 { // hide type name by variable name
    2734                         typedefTable.addToEnclosingScope( *$1->name, TypedefTable::ID );
    2735                 }
    27362822        | '(' paren_type ')'
    27372823                { $$ = $2; }
     
    28052891
    28062892identifier_parameter_function:
    2807         paren_identifier '(' parameter_type_list_opt ')'        // empty parameter list OBSOLESCENT (see 3)
    2808                 { $$ = $1->addParamList( $3 ); }
    2809         | '(' identifier_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    2810                 { $$ = $2->addParamList( $5 ); }
     2893        paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2894                { $$ = $1->addParamList( $4 ); }
     2895        | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2896                { $$ = $2->addParamList( $6 ); }
    28112897        | '(' identifier_parameter_function ')'                         // redundant parenthesis
    28122898                { $$ = $2; }
     
    28362922typedef:
    28372923        TYPEDEFname
    2838                 { $$ = DeclarationNode::newName( $1 ); }
     2924                {
     2925                        typedefTable.setNextIdentifier( *$1 );
     2926                        $$ = DeclarationNode::newName( $1 );
     2927                }
    28392928        | TYPEGENname
    2840                 { $$ = DeclarationNode::newName( $1 ); }
     2929                {
     2930                        typedefTable.setNextIdentifier( *$1 );
     2931                        $$ = DeclarationNode::newName( $1 );
     2932                }
    28412933        ;
    28422934
     
    28582950
    28592951type_parameter_function:
    2860         typedef '(' parameter_type_list_opt ')'                         // empty parameter list OBSOLESCENT (see 3)
    2861                 { $$ = $1->addParamList( $3 ); }
    2862         | '(' type_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    2863                 { $$ = $2->addParamList( $5 ); }
     2952        typedef '(' push parameter_type_list_opt pop ')'        // empty parameter list OBSOLESCENT (see 3)
     2953                { $$ = $1->addParamList( $4 ); }
     2954        | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     2955                { $$ = $2->addParamList( $6 ); }
    28642956        ;
    28652957
     
    29083000
    29093001abstract_function:
    2910         '(' parameter_type_list_opt ')'                                         // empty parameter list OBSOLESCENT (see 3)
    2911                 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    2912         | '(' abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    2913                 { $$ = $2->addParamList( $5 ); }
     3002        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
     3003                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
     3004        | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3005                { $$ = $2->addParamList( $6 ); }
    29143006        | '(' abstract_function ')'                                                     // redundant parenthesis
    29153007                { $$ = $2; }
     
    29263018
    29273019multi_array_dimension:
    2928         '[' assignment_expression ']'
    2929                 { $$ = DeclarationNode::newArray( $2, 0, false ); }
    2930         | '[' '*' ']'                                                                           // C99
     3020        '[' push assignment_expression pop ']'
     3021                { $$ = DeclarationNode::newArray( $3, 0, false ); }
     3022        | '[' push '*' pop ']'                                                          // C99
    29313023                { $$ = DeclarationNode::newVarArray( 0 ); }
    2932         | multi_array_dimension '[' assignment_expression ']'
    2933                 { $$ = $1->addArray( DeclarationNode::newArray( $3, 0, false ) ); }
    2934         | multi_array_dimension '[' '*' ']'                                     // C99
     3024        | multi_array_dimension '[' push assignment_expression pop ']'
     3025                { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
     3026        | multi_array_dimension '[' push '*' pop ']'            // C99
    29353027                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
    29363028        ;
     
    29993091
    30003092abstract_parameter_function:
    3001         '(' parameter_type_list_opt ')'                                         // empty parameter list OBSOLESCENT (see 3)
    3002                 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); }
    3003         | '(' abstract_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    3004                 { $$ = $2->addParamList( $5 ); }
     3093        '(' push parameter_type_list_opt pop ')'                        // empty parameter list OBSOLESCENT (see 3)
     3094                { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); }
     3095        | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3096                { $$ = $2->addParamList( $6 ); }
    30053097        | '(' abstract_parameter_function ')'                           // redundant parenthesis
    30063098                { $$ = $2; }
     
    30243116                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    30253117        // multi_array_dimension handles the '[' '*' ']' case
    3026         | '[' type_qualifier_list '*' ']'                                       // remaining C99
    3027                 { $$ = DeclarationNode::newVarArray( $2 ); }
    3028         | '[' type_qualifier_list ']'
    3029                 { $$ = DeclarationNode::newArray( 0, $2, false ); }
     3118        | '[' push type_qualifier_list '*' pop ']'                      // remaining C99
     3119                { $$ = DeclarationNode::newVarArray( $3 ); }
     3120        | '[' push type_qualifier_list pop ']'
     3121                { $$ = DeclarationNode::newArray( 0, $3, false ); }
    30303122        // multi_array_dimension handles the '[' assignment_expression ']' case
    3031         | '[' type_qualifier_list assignment_expression ']'
    3032                 { $$ = DeclarationNode::newArray( $3, $2, false ); }
    3033         | '[' STATIC type_qualifier_list_opt assignment_expression ']'
    3034                 { $$ = DeclarationNode::newArray( $4, $3, true ); }
    3035         | '[' type_qualifier_list STATIC assignment_expression ']'
    3036                 { $$ = DeclarationNode::newArray( $4, $2, true ); }
     3123        | '[' push type_qualifier_list assignment_expression pop ']'
     3124                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     3125        | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']'
     3126                { $$ = DeclarationNode::newArray( $5, $4, true ); }
     3127        | '[' push type_qualifier_list STATIC assignment_expression pop ']'
     3128                { $$ = DeclarationNode::newArray( $5, $3, true ); }
    30373129        ;
    30383130
     
    30783170
    30793171variable_abstract_function:
    3080         '(' variable_abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)
    3081                 { $$ = $2->addParamList( $5 ); }
     3172        '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)
     3173                { $$ = $2->addParamList( $6 ); }
    30823174        | '(' variable_abstract_function ')'                            // redundant parenthesis
    30833175                { $$ = $2; }
     
    31423234
    31433235cfa_array_parameter_1st_dimension:
    3144         '[' type_qualifier_list '*' ']'                                         // remaining C99
    3145                 { $$ = DeclarationNode::newVarArray( $2 ); }
    3146         | '[' type_qualifier_list assignment_expression ']'
    3147                 { $$ = DeclarationNode::newArray( $3, $2, false ); }
    3148         | '[' declaration_qualifier_list assignment_expression ']'
     3236        '[' push type_qualifier_list '*' pop ']'                        // remaining C99
     3237                { $$ = DeclarationNode::newVarArray( $3 ); }
     3238        | '[' push type_qualifier_list assignment_expression pop ']'
     3239                { $$ = DeclarationNode::newArray( $4, $3, false ); }
     3240        | '[' push declaration_qualifier_list assignment_expression pop ']'
    31493241                // declaration_qualifier_list must be used because of shift/reduce conflict with
    31503242                // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot
    31513243                // appear in this context.
    3152                 { $$ = DeclarationNode::newArray( $3, $2, true ); }
    3153         | '[' declaration_qualifier_list type_qualifier_list assignment_expression ']'
    3154                 { $$ = DeclarationNode::newArray( $4, $3->addQualifiers( $3 ), true ); }
     3244                { $$ = DeclarationNode::newArray( $4, $3, true ); }
     3245        | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']'
     3246                { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); }
    31553247        ;
    31563248
     
    32213313
    32223314cfa_abstract_tuple:                                                                             // CFA
    3223         '[' cfa_abstract_parameter_list ']'
    3224                 { $$ = DeclarationNode::newTuple( $2 ); }
     3315        '[' push cfa_abstract_parameter_list pop ']'
     3316                { $$ = DeclarationNode::newTuple( $3 ); }
    32253317        ;
    32263318
     
    32283320//      '[' ']' '(' cfa_parameter_type_list_opt ')'
    32293321//              { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }
    3230         cfa_abstract_tuple '(' cfa_parameter_type_list_opt ')'
    3231                 { $$ = DeclarationNode::newFunction( nullptr, $1, $3, nullptr ); }
    3232         | cfa_function_return '(' cfa_parameter_type_list_opt ')'
    3233                 { $$ = DeclarationNode::newFunction( nullptr, $1, $3, nullptr ); }
     3322        cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')'
     3323                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
     3324        | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')'
     3325                { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); }
    32343326        ;
    32353327
Note: See TracChangeset for help on using the changeset viewer.