Changes in / [21bdce2:1596726]
- Location:
- src
- Files:
-
- 5 edited
-
Common/ScopedMap.h (modified) (2 diffs)
-
Parser/DeclarationNode.cc (modified) (3 diffs)
-
Parser/TypedefTable.cc (modified) (2 diffs)
-
Parser/TypedefTable.h (modified) (2 diffs)
-
Parser/parser.yy (modified) (60 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/ScopedMap.h
r21bdce2 r1596726 10 10 // Created On : Wed Dec 2 11:37:00 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 21 15:22:40 201813 // Update Count : 312 // Last Modified On : Fri Jul 21 22:18:24 2017 13 // Update Count : 2 14 14 // 15 15 … … 276 276 } 277 277 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 283 278 Value& operator[] ( const Key &key ) { 284 279 iterator slot = find( key ); -
src/Parser/DeclarationNode.cc
r21bdce2 r1596726 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 21 20:36:45201813 // Update Count : 107 312 // Last Modified On : Wed May 16 09:37:17 2018 13 // Update Count : 1070 14 14 // 15 15 … … 181 181 newnode->type->function.body = body; 182 182 183 // ignore unnamed routine declarations: void p( int (*)(int) ); 184 if ( newnode->name ) { 185 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID ); 186 } // if 187 183 188 if ( ret ) { 184 189 newnode->type->base = ret->type; … … 282 287 newnode->name = name; 283 288 newnode->enumeratorValue.reset( constant ); 289 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID ); 284 290 return newnode; 285 291 } // DeclarationNode::newEnumConstant -
src/Parser/TypedefTable.cc
r21bdce2 r1596726 7 7 // TypedefTable.cc -- 8 8 // 9 // Author : Peter A. Buhr9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 21 20:55:24 201813 // Update Count : 11712 // Last Modified On : Mon Aug 15 18:24:42 2016 13 // Update Count : 25 14 14 // 15 15 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 16 22 23 #include "Parser/ParserTypes.h" // for typedefTable 24 #include "Parser/parser.hh" // for IDENTIFIER 17 25 #include "TypedefTable.h" 18 #include <cassert> // for assert 26 27 using namespace std; 19 28 20 29 #if 0 21 30 #include <iostream> 31 22 32 #define debugPrint( x ) cerr << x 23 33 #else … … 25 35 #endif 26 36 27 using namespace std; 37 TypedefTable::TypedefTable() : currentScope( 0 ) {} 28 38 29 TypedefTable::~TypedefTable() { 30 if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) { 31 // std::cerr << "scope failure " << kindTable.currentScope() << endl; 32 } // if 33 } // TypedefTable::~TypedefTable 39 bool TypedefTable::exists( const string &identifier ) { 40 return table.count( identifier ) > 0; 41 } 34 42 35 bool TypedefTable::exists( const string & identifier ) { 36 return kindTable.find( identifier ) != kindTable.end(); 37 } // TypedefTable::exists 43 int 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 } 38 49 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 50 void 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 } 50 55 51 56 // 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 the53 // 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. 59 void TypedefTable::makeTypedef( const string &name ) { 55 60 if ( ! typedefTable.exists( name ) ) { 56 61 typedefTable.addToEnclosingScope( name, TypedefTable::TD ); 57 62 } // if 58 } // TypedefTable::makeTypedef63 } 59 64 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 65 void 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 67 84 } // if 68 } // TypedefTable::addToEnclosingScope 85 } 86 87 void TypedefTable::addToCurrentScope( const std::string &identifier, kind_t kind ) { 88 addToScope( identifier, kind, currentScope ); 89 } 90 91 void TypedefTable::addToCurrentScope( kind_t kind ) { 92 addToCurrentScope( nextIdentifiers.top(), kind ); 93 } 94 95 void TypedefTable::addToEnclosingScope( const std::string &identifier, kind_t kind ) { 96 assert( currentScope >= 1 ); 97 addToScope( identifier, kind, currentScope - 1 ); 98 } 99 100 void TypedefTable::addToEnclosingScope( kind_t kind ) { 101 addToEnclosingScope( nextIdentifiers.top(), kind ); 102 } 103 104 void TypedefTable::addToEnclosingScope2( const std::string &identifier, kind_t kind ) { 105 assert( currentScope >= 2 ); 106 addToScope( identifier, kind, currentScope - 2 ); 107 } 108 109 void TypedefTable::addToEnclosingScope2( kind_t kind ) { 110 addToEnclosingScope2( nextIdentifiers.top(), kind ); 111 } 112 113 void TypedefTable::setNextIdentifier( const std::string &identifier ) { 114 nextIdentifiers.top() = identifier; 115 } 116 117 void 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 } 69 126 70 127 void 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 } 74 133 75 134 void 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 } 79 154 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 // } 155 void TypedefTable::enterTrait( const std::string &contextName ) { 156 currentTrait = contextName; 157 contextScope = currentScope; 158 } 159 160 void TypedefTable::leaveTrait() { 161 currentTrait = ""; 162 } 163 164 void 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 } 90 174 91 175 // Local Variables: // -
src/Parser/TypedefTable.h
r21bdce2 r1596726 7 7 // TypedefTable.h -- 8 8 // 9 // Author : Peter A. Buhr9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 21 20:28:01 201813 // Update Count : 7612 // Last Modified On : Sat Jul 22 09:33:14 2017 13 // Update Count : 34 14 14 // 15 15 16 16 #pragma once 17 17 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 19 22 20 #include "Common/ScopedMap.h" // for ScopedMap21 23 #include "ParserTypes.h" 22 #include "parser.hh" // for IDENTIFIER, TYPEDEFname, TYPEGENname24 #include "parser.hh" // for IDENTIFIER, TYPEDEFname, TYPEGENname 23 25 24 26 class TypedefTable { … … 26 28 enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname }; 27 29 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 ); 30 54 public: 31 ~TypedefTable();55 TypedefTable(); 32 56 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 ); 38 83 39 84 void enterScope(); 40 85 void leaveScope(); 41 }; // TypedefTable 86 void enterTrait( const std::string &contextName ); 87 void leaveTrait(); 88 89 void print() const; 90 }; 42 91 43 92 // Local Variables: // -
src/Parser/parser.yy
r21bdce2 r1596726 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 21 21:44:01201813 // Update Count : 3 35012 // Last Modified On : Fri May 11 17:51:38 2018 13 // Update Count : 3261 14 14 // 15 15 … … 119 119 // Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding. 120 120 // 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 ) {}124 121 125 122 void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) { 126 if ( declSpec->type->kind == TypeData::Aggregate ) { // ignoreaggregate definition123 if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition 127 124 funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type 128 125 declSpec->type->aggregate.params = nullptr; … … 304 301 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt 305 302 306 %type<decl> field_declaration field_declaration_list _opt field_declarator_optfield_declaring_list303 %type<decl> field_declaration field_declaration_list field_declarator field_declaring_list 307 304 %type<en> field field_list field_name fraction_constants_opt 308 305 … … 364 361 365 362 // initializers 366 %type<in> initializer initializer_list _optinitializer_opt363 %type<in> initializer initializer_list initializer_opt 367 364 368 365 // designators … … 415 412 // actions during the parser update this data structure when the class of identifiers change. 416 413 // 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. 426 427 427 428 push: … … 497 498 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 498 499 | 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; } 502 505 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 503 506 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } … … 516 519 postfix_expression: 517 520 primary_expression 518 | postfix_expression '[' assignment_expression']'521 | postfix_expression '[' push assignment_expression pop ']' 519 522 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a 520 523 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 521 524 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 522 525 // 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 ) ); } 524 527 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call 525 528 { … … 536 539 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 537 540 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 538 | postfix_expression '.' '[' field_list ']'// CFA, tuple field selector539 { $$ = 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 ) ) ); } 540 543 | postfix_expression ARROW no_attr_identifier 541 544 { … … 544 547 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 545 548 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 546 | postfix_expression ARROW '[' field_list ']'// CFA, tuple field selector547 { $$ = 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 ) ) ); } 548 551 | postfix_expression ICR 549 552 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } 550 553 | postfix_expression DECR 551 554 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 552 | '(' type_no_function ')' '{' initializer_list _optcomma_opt '}' // C99, compound-literal555 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal 553 556 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 554 | '(' type_no_function ')' '@' '{' initializer_list _optcomma_opt '}' // CFA, explicit C compound-literal557 | '(' type_no_function ')' '@' '{' initializer_list comma_opt '}' // CFA, explicit C compound-literal 555 558 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 556 559 | '^' primary_expression '{' argument_expression_list '}' // CFA … … 585 588 | FLOATING_DECIMALconstant field 586 589 { $$ = 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 ) ) ); } 589 592 | field_name '.' field 590 593 { $$ = 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 ) ) ); } 593 596 | field_name ARROW field 594 597 { $$ = 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 ) ) ); } 597 600 ; 598 601 … … 804 807 | unary_expression assignment_operator assignment_expression 805 808 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 806 | unary_expression '=' '{' initializer_list _optcomma_opt '}'809 | unary_expression '=' '{' initializer_list comma_opt '}' 807 810 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } 808 811 ; … … 837 840 // '[' push assignment_expression pop ']' 838 841 // { $$ = 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 ) ) ); } 843 846 ; 844 847 … … 1071 1074 | RETURN comma_expression_opt ';' 1072 1075 { $$ = new StatementNode( build_return( $2 ) ); } 1073 | RETURN '{' initializer_list _optcomma_opt '}'1076 | RETURN '{' initializer_list comma_opt '}' 1074 1077 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1075 1078 | THROW assignment_expression_opt ';' // handles rethrow … … 1165 1168 1166 1169 handler_predicate_opt: 1167 // empty1170 //empty 1168 1171 { $$ = nullptr; } 1169 1172 | ';' conditional_expression { $$ = $2; } … … 1184 1187 | type_specifier_nobody declarator 1185 1188 { 1189 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1186 1190 $$ = $2->addType( $1 ); 1187 1191 } … … 1190 1194 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1191 1195 { 1196 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1192 1197 $$ = $1->addName( $2 ); 1193 1198 } … … 1339 1344 cfa_variable_declaration: // CFA 1340 1345 cfa_variable_specifier initializer_opt 1341 { $$ = $1->addInitializer( $2 ); } 1346 { 1347 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1348 $$ = $1->addInitializer( $2 ); 1349 } 1342 1350 | declaration_qualifier_list cfa_variable_specifier initializer_opt 1343 1351 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 1344 1352 // 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 } 1346 1357 | 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 } 1348 1362 ; 1349 1363 … … 1352 1366 // storage-class 1353 1367 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 } 1355 1372 | 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 } 1357 1377 | 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 } 1359 1382 ; 1360 1383 1361 1384 cfa_function_declaration: // CFA 1362 1385 cfa_function_specifier 1363 { $$ = $1; } 1386 { 1387 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1388 $$ = $1; 1389 } 1364 1390 | type_qualifier_list cfa_function_specifier 1365 { $$ = $2->addQualifiers( $1 ); } 1391 { 1392 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1393 $$ = $2->addQualifiers( $1 ); 1394 } 1366 1395 | declaration_qualifier_list cfa_function_specifier 1367 { $$ = $2->addQualifiers( $1 ); } 1396 { 1397 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1398 $$ = $2->addQualifiers( $1 ); 1399 } 1368 1400 | 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 ')' 1371 1406 { 1372 1407 // Append the return type at the start (left-hand-side) to each identifier in the list. 1373 1408 DeclarationNode * ret = new DeclarationNode; 1374 1409 ret->type = maybeClone( $1->type->base ); 1375 $$ = $1->appendList( DeclarationNode::newFunction( $ 3, ret, $5, nullptr ) );1410 $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr ) ); 1376 1411 } 1377 1412 ; … … 1400 1435 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1401 1436 // 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 ')' 1403 1438 // 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 } 1407 1446 ; 1408 1447 1409 1448 cfa_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 ']' 1413 1452 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1414 1453 // ']'. 1415 { $$ = DeclarationNode::newTuple( $ 2->appendList( $4) ); }1454 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1416 1455 ; 1417 1456 … … 1419 1458 TYPEDEF cfa_variable_specifier 1420 1459 { 1421 typedefTable.addToEnclosingScope( *$2->name,TypedefTable::TD );1460 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1422 1461 $$ = $2->addTypedef(); 1423 1462 } 1424 1463 | TYPEDEF cfa_function_specifier 1425 1464 { 1426 typedefTable.addToEnclosingScope( *$2->name,TypedefTable::TD );1465 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1427 1466 $$ = $2->addTypedef(); 1428 1467 } … … 1440 1479 TYPEDEF type_specifier declarator 1441 1480 { 1442 typedefTable.addToEnclosingScope( *$3->name,TypedefTable::TD );1481 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1443 1482 $$ = $3->addType( $2 )->addTypedef(); 1444 1483 } 1445 1484 | typedef_declaration pop ',' push declarator 1446 1485 { 1447 typedefTable.addToEnclosingScope( *$5->name,TypedefTable::TD );1486 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1448 1487 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1449 1488 } 1450 1489 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1451 1490 { 1452 typedefTable.addToEnclosingScope( *$4->name,TypedefTable::TD );1491 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1453 1492 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1454 1493 } 1455 1494 | type_specifier TYPEDEF declarator 1456 1495 { 1457 typedefTable.addToEnclosingScope( *$3->name,TypedefTable::TD );1496 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1458 1497 $$ = $3->addType( $1 )->addTypedef(); 1459 1498 } 1460 1499 | type_specifier TYPEDEF type_qualifier_list declarator 1461 1500 { 1462 typedefTable.addToEnclosingScope( *$4->name,TypedefTable::TD );1501 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1463 1502 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1464 1503 } … … 1469 1508 TYPEDEF no_attr_identifier '=' assignment_expression 1470 1509 { 1471 // $$ = DeclarationNode::newName( 0 ); // unimplemented1472 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;1510 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); 1511 $$ = DeclarationNode::newName( 0 ); // unimplemented 1473 1512 } 1474 1513 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1475 1514 { 1476 // $$ = DeclarationNode::newName( 0 ); // unimplemented1477 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;1515 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); 1516 $$ = DeclarationNode::newName( 0 ); // unimplemented 1478 1517 } 1479 1518 ; … … 1503 1542 c_declaration: 1504 1543 declaration_specifier declaring_list 1505 { $$ = distAttr( $1, $2 ); } 1544 { 1545 $$ = distAttr( $1, $2 ); 1546 } 1506 1547 | typedef_declaration 1507 1548 | typedef_expression // GCC, naming expression type … … 1513 1554 // storage-class 1514 1555 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 } 1516 1560 | 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 } 1518 1565 ; 1519 1566 … … 1807 1854 1808 1855 aggregate_type: // struct, union 1809 aggregate_key attribute_list_opt '{' field_declaration_list _opt'}'1856 aggregate_key attribute_list_opt '{' field_declaration_list '}' 1810 1857 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1811 1858 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name … … 1815 1862 forall = false; // reset 1816 1863 } 1817 '{' field_declaration_list _opt'}'1864 '{' field_declaration_list '}' 1818 1865 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1819 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list _opt'}' // CFA1866 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA 1820 1867 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 1821 1868 | aggregate_type_nobody … … 1862 1909 ; 1863 1910 1864 field_declaration_list _opt:1911 field_declaration_list: 1865 1912 // empty 1866 1913 { $$ = nullptr; } 1867 | field_declaration_list _optfield_declaration1914 | field_declaration_list field_declaration 1868 1915 { $$ = $1 ? $1->appendList( $2 ) : $2; } 1869 1916 ; … … 1898 1945 1899 1946 field_declaring_list: 1900 field_declarator _opt1901 | field_declaring_list ',' attribute_list_opt field_declarator _opt1947 field_declarator 1948 | field_declaring_list ',' attribute_list_opt field_declarator 1902 1949 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1903 1950 ; 1904 1951 1905 field_declarator _opt:1952 field_declarator: 1906 1953 // empty 1907 1954 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name … … 1970 2017 | cfa_abstract_parameter_list 1971 2018 | cfa_parameter_list 1972 | cfa_parameter_list ','cfa_abstract_parameter_list1973 { $$ = $1->appendList( $ 3); }1974 | cfa_abstract_parameter_list ','ELLIPSIS2019 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list 2020 { $$ = $1->appendList( $5 ); } 2021 | cfa_abstract_parameter_list pop ',' push ELLIPSIS 1975 2022 { $$ = $1->addVarArgs(); } 1976 | cfa_parameter_list ','ELLIPSIS2023 | cfa_parameter_list pop ',' push ELLIPSIS 1977 2024 { $$ = $1->addVarArgs(); } 1978 2025 ; … … 1982 2029 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'. 1983 2030 cfa_parameter_declaration 1984 | cfa_abstract_parameter_list ','cfa_parameter_declaration1985 { $$ = $1->appendList( $ 3); }1986 | cfa_parameter_list ','cfa_parameter_declaration1987 { $$ = $1->appendList( $ 3); }1988 | cfa_parameter_list ',' cfa_abstract_parameter_list ','cfa_parameter_declaration1989 { $$ = $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 ); } 1990 2037 ; 1991 2038 1992 2039 cfa_abstract_parameter_list: // CFA, new & old style abstract 1993 2040 cfa_abstract_parameter_declaration 1994 | cfa_abstract_parameter_list ','cfa_abstract_parameter_declaration1995 { $$ = $1->appendList( $ 3); }2041 | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration 2042 { $$ = $1->appendList( $5 ); } 1996 2043 ; 1997 2044 … … 2043 2090 // No SUE declaration in parameter list. 2044 2091 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 } 2046 2096 | 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 } 2048 2101 ; 2049 2102 … … 2103 2156 initializer: 2104 2157 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 2161 initializer_list: 2109 2162 // empty 2110 2163 { $$ = nullptr; } 2111 2164 | initializer 2112 2165 | designation initializer { $$ = $2->set_designators( $1 ); } 2113 | initializer_list _opt ',' initializer{ $$ = (InitializerNode *)( $1->set_last( $3 ) ); }2114 | initializer_list _opt',' designation initializer2166 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2167 | initializer_list ',' designation initializer 2115 2168 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2116 2169 ; … … 2142 2195 '.' no_attr_identifier // C99, field name 2143 2196 { $$ = new ExpressionNode( build_varref( $2 ) ); } 2144 | '[' assignment_expression ']'// C99, single array element2197 | '[' push assignment_expression pop ']' // C99, single array element 2145 2198 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 2146 { $$ = $2; }2147 | '[' subrange ']' // CFA, multiple array elements2148 { $$ = $2; }2149 | '[' constant_expression ELLIPSIS constant_expression ']' // GCC, multiple array elements2150 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $2 ), maybeMoveBuild< Expression >( $4 ) ) ); }2151 | '.' '[' field_list ']' // CFA, tuple field selector2152 2199 { $$ = $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; } 2153 2206 ; 2154 2207 … … 2220 2273 assertion: // CFA 2221 2274 '|' no_attr_identifier_or_type_name '(' type_list ')' 2222 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2275 { 2276 typedefTable.openTrait( *$2 ); 2277 $$ = DeclarationNode::newTraitUse( $2, $4 ); 2278 } 2223 2279 | '|' '{' push trait_declaration_list '}' 2224 2280 { $$ = $4; } 2225 2281 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')' 2226 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." );$$ = nullptr; }2282 { $$ = nullptr; } 2227 2283 ; 2228 2284 … … 2268 2324 trait_specifier: // CFA 2269 2325 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 } 2271 2330 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' 2272 { typedefTable.enterScope(); } 2331 { 2332 typedefTable.enterTrait( *$2 ); 2333 typedefTable.enterScope(); 2334 } 2273 2335 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 } 2275 2341 ; 2276 2342 … … 2288 2354 cfa_trait_declaring_list: // CFA 2289 2355 cfa_variable_specifier 2290 { $$ = $1; } 2356 { 2357 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2358 $$ = $1; 2359 } 2291 2360 | cfa_function_specifier 2292 { $$ = $1; } 2361 { 2362 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2363 $$ = $1; 2364 } 2293 2365 | 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 } 2295 2370 ; 2296 2371 2297 2372 trait_declaring_list: // CFA 2298 2373 type_specifier declarator 2299 { $$ = $2->addType( $1 ); } 2374 { 2375 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2376 $$ = $2->addType( $1 ); 2377 } 2300 2378 | 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 } 2302 2383 ; 2303 2384 … … 2407 2488 | function_declarator compound_statement 2408 2489 { 2490 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2409 2491 typedefTable.leaveScope(); 2410 2492 $$ = $1->addFunctionBody( $2 ); … … 2412 2494 | KR_function_declarator KR_declaration_list_opt compound_statement 2413 2495 { 2496 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2414 2497 typedefTable.leaveScope(); 2415 2498 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); … … 2427 2510 cfa_function_declaration with_clause_opt compound_statement // CFA 2428 2511 { 2512 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2429 2513 typedefTable.leaveScope(); 2430 2514 // Add the function body to the last identifier in the function definition list, i.e., foo3: … … 2436 2520 { 2437 2521 rebindForall( $1, $2 ); 2522 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2438 2523 typedefTable.leaveScope(); 2439 2524 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2440 2525 } 2441 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement2442 {2443 rebindForall( $1, $2 );2444 typedefTable.leaveScope();2445 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 );2446 }2447 2526 // handles default int return type, OBSOLESCENT (see 1) 2448 2527 | type_qualifier_list function_declarator with_clause_opt compound_statement 2449 2528 { 2529 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2450 2530 typedefTable.leaveScope(); 2451 2531 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); … … 2454 2534 | declaration_qualifier_list function_declarator with_clause_opt compound_statement 2455 2535 { 2536 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2456 2537 typedefTable.leaveScope(); 2457 2538 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); … … 2460 2541 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement 2461 2542 { 2543 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2462 2544 typedefTable.leaveScope(); 2463 2545 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); … … 2468 2550 { 2469 2551 rebindForall( $1, $2 ); 2552 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2470 2553 typedefTable.leaveScope(); 2471 2554 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); … … 2474 2557 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2475 2558 { 2559 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2476 2560 typedefTable.leaveScope(); 2477 2561 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); … … 2480 2564 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2481 2565 { 2566 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2482 2567 typedefTable.leaveScope(); 2483 2568 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); … … 2486 2571 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2487 2572 { 2573 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2488 2574 typedefTable.leaveScope(); 2489 2575 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); … … 2598 2684 paren_identifier: 2599 2685 identifier 2600 { $$ = DeclarationNode::newName( $1 ); } 2686 { 2687 typedefTable.setNextIdentifier( *$1 ); 2688 $$ = DeclarationNode::newName( $1 ); 2689 } 2601 2690 | '(' paren_identifier ')' // redundant parenthesis 2602 2691 { $$ = $2; } … … 2685 2774 paren_identifier '(' identifier_list ')' // function_declarator handles empty parameter 2686 2775 { $$ = $1->addIdList( $3 ); } 2687 | '(' KR_function_ptr ')' '(' p arameter_type_list_opt')'2688 { $$ = $2->addParamList( $ 5); }2776 | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')' 2777 { $$ = $2->addParamList( $6 ); } 2689 2778 | '(' KR_function_no_ptr ')' // redundant parenthesis 2690 2779 { $$ = $2; } … … 2731 2820 paren_type: 2732 2821 typedef 2733 { // hide type name by variable name2734 typedefTable.addToEnclosingScope( *$1->name, TypedefTable::ID );2735 }2736 2822 | '(' paren_type ')' 2737 2823 { $$ = $2; } … … 2805 2891 2806 2892 identifier_parameter_function: 2807 paren_identifier '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)2808 { $$ = $1->addParamList( $ 3); }2809 | '(' identifier_parameter_ptr ')' '(' p arameter_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 ); } 2811 2897 | '(' identifier_parameter_function ')' // redundant parenthesis 2812 2898 { $$ = $2; } … … 2836 2922 typedef: 2837 2923 TYPEDEFname 2838 { $$ = DeclarationNode::newName( $1 ); } 2924 { 2925 typedefTable.setNextIdentifier( *$1 ); 2926 $$ = DeclarationNode::newName( $1 ); 2927 } 2839 2928 | TYPEGENname 2840 { $$ = DeclarationNode::newName( $1 ); } 2929 { 2930 typedefTable.setNextIdentifier( *$1 ); 2931 $$ = DeclarationNode::newName( $1 ); 2932 } 2841 2933 ; 2842 2934 … … 2858 2950 2859 2951 type_parameter_function: 2860 typedef '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)2861 { $$ = $1->addParamList( $ 3); }2862 | '(' type_parameter_ptr ')' '(' p arameter_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 ); } 2864 2956 ; 2865 2957 … … 2908 3000 2909 3001 abstract_function: 2910 '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)2911 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $ 2, nullptr ); }2912 | '(' abstract_ptr ')' '(' p arameter_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 ); } 2914 3006 | '(' abstract_function ')' // redundant parenthesis 2915 3007 { $$ = $2; } … … 2926 3018 2927 3019 multi_array_dimension: 2928 '[' assignment_expression']'2929 { $$ = DeclarationNode::newArray( $ 2, 0, false ); }2930 | '[' '*' ']'// C993020 '[' push assignment_expression pop ']' 3021 { $$ = DeclarationNode::newArray( $3, 0, false ); } 3022 | '[' push '*' pop ']' // C99 2931 3023 { $$ = DeclarationNode::newVarArray( 0 ); } 2932 | multi_array_dimension '[' assignment_expression']'2933 { $$ = $1->addArray( DeclarationNode::newArray( $ 3, 0, false ) ); }2934 | multi_array_dimension '[' '*' ']'// C993024 | multi_array_dimension '[' push assignment_expression pop ']' 3025 { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); } 3026 | multi_array_dimension '[' push '*' pop ']' // C99 2935 3027 { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); } 2936 3028 ; … … 2999 3091 3000 3092 abstract_parameter_function: 3001 '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)3002 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $ 2, nullptr ); }3003 | '(' abstract_parameter_ptr ')' '(' p arameter_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 ); } 3005 3097 | '(' abstract_parameter_function ')' // redundant parenthesis 3006 3098 { $$ = $2; } … … 3024 3116 { $$ = DeclarationNode::newArray( 0, 0, false ); } 3025 3117 // multi_array_dimension handles the '[' '*' ']' case 3026 | '[' type_qualifier_list '*' ']'// remaining C993027 { $$ = 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 ); } 3030 3122 // 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 ); } 3037 3129 ; 3038 3130 … … 3078 3170 3079 3171 variable_abstract_function: 3080 '(' variable_abstract_ptr ')' '(' p arameter_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 ); } 3082 3174 | '(' variable_abstract_function ')' // redundant parenthesis 3083 3175 { $$ = $2; } … … 3142 3234 3143 3235 cfa_array_parameter_1st_dimension: 3144 '[' type_qualifier_list '*' ']'// remaining C993145 { $$ = 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 ']' 3149 3241 // declaration_qualifier_list must be used because of shift/reduce conflict with 3150 3242 // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot 3151 3243 // 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 ); } 3155 3247 ; 3156 3248 … … 3221 3313 3222 3314 cfa_abstract_tuple: // CFA 3223 '[' cfa_abstract_parameter_list']'3224 { $$ = DeclarationNode::newTuple( $ 2); }3315 '[' push cfa_abstract_parameter_list pop ']' 3316 { $$ = DeclarationNode::newTuple( $3 ); } 3225 3317 ; 3226 3318 … … 3228 3320 // '[' ']' '(' cfa_parameter_type_list_opt ')' 3229 3321 // { $$ = 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 ); } 3234 3326 ; 3235 3327
Note:
See TracChangeset
for help on using the changeset viewer.