Changeset eba74ba for src/Parser
- Timestamp:
- May 25, 2018, 2:51:06 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- cdc4d43
- Parents:
- 3ef35bd (diff), 58e822a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r3ef35bd reba74ba 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 16 09:37:17201813 // Update Count : 107 012 // Last Modified On : Tue May 22 08:39:29 2018 13 // Update Count : 1074 14 14 // 15 15 … … 32 32 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Type::... 33 33 #include "TypeData.h" // for TypeData, TypeData::Aggregate_t 34 #include "TypedefTable.h" // for TypedefTable , TypedefTable::kind_t...34 #include "TypedefTable.h" // for TypedefTable 35 35 36 36 class Initializer; … … 54 54 55 55 DeclarationNode::DeclarationNode() : 56 builtin( NoBuiltinType ), 56 57 type( nullptr ), 57 58 bitfieldWidth( nullptr ), … … 100 101 newnode->name = name ? new string( *name ) : nullptr; 101 102 103 newnode->builtin = NoBuiltinType; 102 104 newnode->type = maybeClone( type ); 103 105 newnode->storageClasses = storageClasses; … … 178 180 newnode->type->function.body = body; 179 181 180 // ignore unnamed routine declarations: void p( int (*)(int) );181 if ( newnode->name ) {182 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );183 } // if184 185 182 if ( ret ) { 186 183 newnode->type->base = ret->type; … … 284 281 newnode->name = name; 285 282 newnode->enumeratorValue.reset( constant ); 286 typedefTable.addToEnclosingScope( *newnode->name, TypedefTable::ID );287 283 return newnode; 288 284 } // DeclarationNode::newEnumConstant … … 550 546 type->aggregate.params = q->type->forall; // make polymorphic type 551 547 // change implicit typedef from TYPEDEFname to TYPEGENname 552 typedefTable.changeKind( *type->aggregate.name, T ypedefTable::TG);548 typedefTable.changeKind( *type->aggregate.name, TYPEGENname ); 553 549 } // if 554 550 } else { // not polymorphic -
src/Parser/LinkageSpec.h
r3ef35bd reba74ba 27 27 Overrideable = 1 << 2, 28 28 Builtin = 1 << 3, 29 GccBuiltin = 1 << 4, 29 30 30 NoOfSpecs = 1 << 4,31 NoOfSpecs = 1 << 5, 31 32 }; 32 33 … … 38 39 bool is_overridable : 1; 39 40 bool is_builtin : 1; 41 bool is_gcc_builtin : 1; 40 42 }; 41 43 constexpr Spec( unsigned int val ) : val( val ) {} … … 61 63 inline bool isOverridable( Spec spec ) { return spec.is_overridable; } 62 64 inline bool isBuiltin( Spec spec ) { return spec.is_builtin; } 65 inline bool isGccBuiltin( Spec spec ) { return spec.is_gcc_builtin; } 63 66 64 67 // Pre-defined flag combinations: … … 72 75 constexpr Spec const AutoGen = { Mangle | Generate | Overrideable }; 73 76 // gcc internal 74 constexpr Spec const Compiler = { Builtin };77 constexpr Spec const Compiler = { Mangle | Builtin | GccBuiltin }; 75 78 // mangled builtins 76 79 constexpr Spec const BuiltinCFA = { Mangle | Generate | Builtin }; -
src/Parser/TypedefTable.cc
r3ef35bd reba74ba 7 7 // TypedefTable.cc -- 8 8 // 9 // Author : Rodolfo G. Esteves9 // Author : Peter A. Buhr 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 15 18:24:42 201613 // Update Count : 2512 // Last Modified On : Tue May 22 08:40:01 2018 13 // Update Count : 121 14 14 // 15 15 16 #include <ext/alloc_traits.h> // for __alloc_traits<>::value_type17 #include <cassert> // for assert18 #include <list> // for list, _List_iterator, list<>::iterator19 #include <map> // for _Rb_tree_iterator, _Rb_tree_const_it...20 #include <memory> // for allocator_traits<>::value_type21 #include <utility> // for pair22 16 23 #include "Parser/ParserTypes.h" // for typedefTable24 #include "Parser/parser.hh" // for IDENTIFIER25 17 #include "TypedefTable.h" 26 27 using namespace std; 18 #include <cassert> // for assert 28 19 29 20 #if 0 30 21 #include <iostream> 31 32 22 #define debugPrint( x ) cerr << x 33 23 #else … … 35 25 #endif 36 26 37 TypedefTable::TypedefTable() : currentScope( 0 ) {} 27 using namespace std; // string, iostream 38 28 39 bool TypedefTable::exists( const string &identifier ) { 40 return table.count( identifier ) > 0; 41 } 29 TypedefTable::~TypedefTable() { 30 if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) { 31 // std::cerr << "scope failure " << kindTable.currentScope() << endl; 32 } // if 33 } // TypedefTable::~TypedefTable 42 34 43 int TypedefTable::isKind( const string &identifier ) const { 44 tableType::const_iterator id_pos = table.find( identifier ); 35 bool TypedefTable::exists( const string & identifier ) { 36 return kindTable.find( identifier ) != kindTable.end(); 37 } // TypedefTable::exists 38 39 int TypedefTable::isKind( const string & identifier ) const { 40 KindTable::const_iterator posn = kindTable.find( identifier ); 45 41 // 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 } 42 if ( posn == kindTable.end() ) return IDENTIFIER; 43 return posn->second; 44 } // TypedefTable::isKind 49 45 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 } 46 void TypedefTable::changeKind( const string & identifier, int kind ) { 47 KindTable::iterator posn = kindTable.find( identifier ); 48 if ( posn != kindTable.end() ) posn->second = kind; // exists => update 49 } // TypedefTable::changeKind 55 50 56 51 // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by 57 // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed 58 // if thename is explicitly used.59 void TypedefTable::makeTypedef( const string & name ) {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 ) { 60 55 if ( ! typedefTable.exists( name ) ) { 61 typedefTable.addToEnclosingScope( name, T ypedefTable::TD);56 typedefTable.addToEnclosingScope( name, TYPEDEFname ); 62 57 } // if 63 } 58 } // TypedefTable::makeTypedef 64 59 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 84 } // if 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 } 60 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) { 61 assert( kindTable.currentScope() >= 1 ); 62 auto scope = kindTable.currentScope() - 1; 63 debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl ); 64 auto ret = kindTable.insertAt( scope, identifier, kind ); 65 if ( ! ret.second ) ret.first->second = kind; // exists => update 66 } // TypedefTable::addToEnclosingScope 126 67 127 68 void TypedefTable::enterScope() { 128 currentScope += 1; 129 deferListStack.push( deferListType() ); 130 nextIdentifiers.push( "" ); 131 debugPrint( "Entering scope " << currentScope << ", nextIdentifiers size is " << nextIdentifiers.size() << endl ); 132 } 69 kindTable.beginScope(); 70 debugPrint( "Entering scope " << kindTable.currentScope() << endl ); 71 } // TypedefTable::enterScope 133 72 134 73 void 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 } 74 debugPrint( "Leaving scope " << kindTable.currentScope() << endl ); 75 kindTable.endScope(); 76 } // TypedefTable::leaveScope 154 77 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 } 78 // void TypedefTable::print( void ) const { 79 // for ( KindTable::const_iterator i = table.begin(); i != table.end(); i++) { 80 // debugPrint( (*i ).first << ": " ); 81 // list< Entry > declList = (*i).second; 82 // for ( list< Entry >::const_iterator j = declList.begin(); j != declList.end(); j++ ) { 83 // debugPrint( "(" << (*j).scope << " " << (*j).kind << ") " ); 84 // } 85 // debugPrint( endl ); 86 // } // for 87 // } 174 88 175 89 // Local Variables: // -
src/Parser/TypedefTable.h
r3ef35bd reba74ba 7 7 // TypedefTable.h -- 8 8 // 9 // Author : Rodolfo G. Esteves9 // Author : Peter A. Buhr 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:33:14 201713 // Update Count : 3412 // Last Modified On : Tue May 22 08:39:29 2018 13 // Update Count : 77 14 14 // 15 15 16 16 #pragma once 17 17 18 #include <list> // for list 19 #include <map> // for map, map<>::value_compare 20 #include <stack> // for stack 21 #include <string> // for string 18 #include <string> // for string 22 19 20 #include "Common/ScopedMap.h" // for ScopedMap 23 21 #include "ParserTypes.h" 24 #include "parser.hh" 22 #include "parser.hh" // for IDENTIFIER, TYPEDEFname, TYPEGENname 25 23 26 24 class TypedefTable { 25 typedef ScopedMap< std::string, int > KindTable; 26 KindTable kindTable; 27 27 public: 28 enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname }; 29 private: 30 struct Entry { 31 int scope; 32 kind_t kind; 33 }; 28 ~TypedefTable(); 34 29 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 ); 54 public: 55 TypedefTable(); 56 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 ); 30 bool exists( const std::string & identifier ); 31 int isKind( const std::string & identifier ) const; 32 void changeKind( const std::string & identifier, int kind ); 33 void makeTypedef( const std::string & name ); 34 void addToEnclosingScope( const std::string & identifier, int kind ); 83 35 84 36 void enterScope(); 85 37 void leaveScope(); 86 void enterTrait( const std::string &contextName ); 87 void leaveTrait(); 88 89 void print() const; 90 }; 38 }; // TypedefTable 91 39 92 40 // Local Variables: // -
src/Parser/parser.yy
r3ef35bd reba74ba 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri May 11 17:51:38201813 // Update Count : 3 26112 // Last Modified On : Thu May 24 18:11:59 2018 13 // Update Count : 3369 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 ) {} 121 124 122 125 void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) { 123 if ( declSpec->type->kind == TypeData::Aggregate ) { // return isaggregate definition126 if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition 124 127 funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type 125 128 declSpec->type->aggregate.params = nullptr; … … 301 304 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt 302 305 303 %type<decl> field_declaration field_declaration_list field_declaratorfield_declaring_list306 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list 304 307 %type<en> field field_list field_name fraction_constants_opt 305 308 … … 361 364 362 365 // initializers 363 %type<in> initializer initializer_list initializer_opt366 %type<in> initializer initializer_list_opt initializer_opt 364 367 365 368 // designators … … 412 415 // actions during the parser update this data structure when the class of identifiers change. 413 416 // 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. 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. 427 426 428 427 push: … … 498 497 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 499 498 | type_name '.' no_attr_identifier // CFA, nested type 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; } 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; } 505 502 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 506 503 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } … … 519 516 postfix_expression: 520 517 primary_expression 521 | postfix_expression '[' push assignment_expression pop']'518 | postfix_expression '[' assignment_expression ']' 522 519 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a 523 520 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 524 521 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 525 522 // equivalent to the old x[i,j]. 526 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $ 4) ); }523 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 527 524 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call 528 525 { … … 539 536 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 540 537 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 541 | postfix_expression '.' '[' push field_list pop ']'// CFA, tuple field selector542 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $ 5) ) ); }538 | postfix_expression '.' '[' field_list ']' // CFA, tuple field selector 539 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 543 540 | postfix_expression ARROW no_attr_identifier 544 541 { … … 547 544 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 548 545 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 549 | postfix_expression ARROW '[' push field_list pop ']'// CFA, tuple field selector550 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $ 5) ) ); }546 | postfix_expression ARROW '[' field_list ']' // CFA, tuple field selector 547 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 551 548 | postfix_expression ICR 552 549 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } 553 550 | postfix_expression DECR 554 551 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 555 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal552 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 556 553 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 557 | '(' type_no_function ')' '@' '{' initializer_list comma_opt '}' // CFA, explicit C compound-literal554 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 558 555 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 559 556 | '^' primary_expression '{' argument_expression_list '}' // CFA … … 588 585 | FLOATING_DECIMALconstant field 589 586 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 590 | FLOATING_DECIMALconstant '[' push field_list pop']'591 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $ 4) ) ); }587 | FLOATING_DECIMALconstant '[' field_list ']' 588 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 592 589 | field_name '.' field 593 590 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 594 | field_name '.' '[' push field_list pop']'595 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $ 5) ) ); }591 | field_name '.' '[' field_list ']' 592 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 596 593 | field_name ARROW field 597 594 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 598 | field_name ARROW '[' push field_list pop']'599 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $ 5) ) ); }595 | field_name ARROW '[' field_list ']' 596 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 600 597 ; 601 598 … … 807 804 | unary_expression assignment_operator assignment_expression 808 805 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 809 | unary_expression '=' '{' initializer_list comma_opt '}'806 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 810 807 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } 811 808 ; … … 869 866 labeled_statement 870 867 | compound_statement 871 | expression_statement { $$ = $1; }868 | expression_statement 872 869 | selection_statement 873 870 | iteration_statement … … 1074 1071 | RETURN comma_expression_opt ';' 1075 1072 { $$ = new StatementNode( build_return( $2 ) ); } 1076 | RETURN '{' initializer_list comma_opt '}'1073 | RETURN '{' initializer_list_opt comma_opt '}' 1077 1074 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1078 1075 | THROW assignment_expression_opt ';' // handles rethrow … … 1168 1165 1169 1166 handler_predicate_opt: 1170 // empty1167 // empty 1171 1168 { $$ = nullptr; } 1172 1169 | ';' conditional_expression { $$ = $2; } … … 1186 1183 type_specifier_nobody 1187 1184 | type_specifier_nobody declarator 1188 { 1189 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1190 $$ = $2->addType( $1 ); 1191 } 1185 { $$ = $2->addType( $1 ); } 1192 1186 | type_specifier_nobody variable_abstract_declarator 1193 1187 { $$ = $2->addType( $1 ); } 1194 1188 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1195 { 1196 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1197 $$ = $1->addName( $2 ); 1198 } 1189 { $$ = $1->addName( $2 ); } 1199 1190 | cfa_abstract_declarator_tuple // CFA 1200 1191 ; … … 1274 1265 1275 1266 declaration_list_opt: // used at beginning of switch statement 1276 pop 1267 pop // empty 1277 1268 { $$ = nullptr; } 1278 1269 | declaration_list … … 1309 1300 1310 1301 local_label_list: // GCC, local label 1311 no_attr_identifier_or_type_name {}1312 | local_label_list ',' no_attr_identifier_or_type_name {}1302 no_attr_identifier_or_type_name 1303 | local_label_list ',' no_attr_identifier_or_type_name 1313 1304 ; 1314 1305 … … 1344 1335 cfa_variable_declaration: // CFA 1345 1336 cfa_variable_specifier initializer_opt 1346 { 1347 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1348 $$ = $1->addInitializer( $2 ); 1349 } 1337 { $$ = $1->addInitializer( $2 ); } 1350 1338 | declaration_qualifier_list cfa_variable_specifier initializer_opt 1351 1339 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 1352 1340 // them as a type_qualifier cannot appear in that context. 1353 { 1354 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1355 $$ = $2->addQualifiers( $1 )->addInitializer( $3 );; 1356 } 1341 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1357 1342 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1358 { 1359 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); 1360 $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); 1361 } 1343 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1362 1344 ; 1363 1345 … … 1366 1348 // storage-class 1367 1349 cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt 1368 { 1369 typedefTable.setNextIdentifier( *$2 ); 1370 $$ = $1->addName( $2 )->addAsmName( $3 ); 1371 } 1350 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1372 1351 | cfa_abstract_tuple identifier_or_type_name asm_name_opt 1373 { 1374 typedefTable.setNextIdentifier( *$2 ); 1375 $$ = $1->addName( $2 )->addAsmName( $3 ); 1376 } 1352 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1377 1353 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt 1378 { 1379 typedefTable.setNextIdentifier( *$3 ); 1380 $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); 1381 } 1354 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); } 1382 1355 ; 1383 1356 1384 1357 cfa_function_declaration: // CFA 1385 1358 cfa_function_specifier 1386 { 1387 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1388 $$ = $1; 1389 } 1359 { $$ = $1; } 1390 1360 | type_qualifier_list cfa_function_specifier 1391 { 1392 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1393 $$ = $2->addQualifiers( $1 ); 1394 } 1361 { $$ = $2->addQualifiers( $1 ); } 1395 1362 | declaration_qualifier_list cfa_function_specifier 1396 { 1397 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1398 $$ = $2->addQualifiers( $1 ); 1399 } 1363 { $$ = $2->addQualifiers( $1 ); } 1400 1364 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 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 ')' 1365 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1366 | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt ')' 1406 1367 { 1407 1368 // Append the return type at the start (left-hand-side) to each identifier in the list. 1408 1369 DeclarationNode * ret = new DeclarationNode; 1409 1370 ret->type = maybeClone( $1->type->base ); 1410 $$ = $1->appendList( DeclarationNode::newFunction( $ 5, ret, $8, nullptr ) );1371 $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $5, nullptr ) ); 1411 1372 } 1412 1373 ; … … 1437 1398 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1438 1399 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1439 { 1440 $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); 1441 } 1400 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1442 1401 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1443 { 1444 $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); 1445 } 1402 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1446 1403 ; 1447 1404 … … 1450 1407 { $$ = DeclarationNode::newTuple( $3 ); } 1451 1408 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 1452 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1453 // ']'. 1409 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 1454 1410 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1455 1411 ; … … 1458 1414 TYPEDEF cfa_variable_specifier 1459 1415 { 1460 typedefTable.addToEnclosingScope( TypedefTable::TD);1416 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1461 1417 $$ = $2->addTypedef(); 1462 1418 } 1463 1419 | TYPEDEF cfa_function_specifier 1464 1420 { 1465 typedefTable.addToEnclosingScope( TypedefTable::TD);1421 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1466 1422 $$ = $2->addTypedef(); 1467 1423 } 1468 1424 | cfa_typedef_declaration pop ',' push no_attr_identifier 1469 1425 { 1470 typedefTable.addToEnclosingScope( *$5, T ypedefTable::TD);1426 typedefTable.addToEnclosingScope( *$5, TYPEDEFname ); 1471 1427 $$ = $1->appendList( $1->cloneType( $5 ) ); 1472 1428 } … … 1479 1435 TYPEDEF type_specifier declarator 1480 1436 { 1481 typedefTable.addToEnclosingScope( TypedefTable::TD);1437 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1482 1438 $$ = $3->addType( $2 )->addTypedef(); 1483 1439 } 1484 1440 | typedef_declaration pop ',' push declarator 1485 1441 { 1486 typedefTable.addToEnclosingScope( TypedefTable::TD);1442 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname ); 1487 1443 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1488 1444 } 1489 1445 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1490 1446 { 1491 typedefTable.addToEnclosingScope( TypedefTable::TD);1447 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1492 1448 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1493 1449 } 1494 1450 | type_specifier TYPEDEF declarator 1495 1451 { 1496 typedefTable.addToEnclosingScope( TypedefTable::TD);1452 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1497 1453 $$ = $3->addType( $1 )->addTypedef(); 1498 1454 } 1499 1455 | type_specifier TYPEDEF type_qualifier_list declarator 1500 1456 { 1501 typedefTable.addToEnclosingScope( TypedefTable::TD);1457 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1502 1458 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1503 1459 } … … 1508 1464 TYPEDEF no_attr_identifier '=' assignment_expression 1509 1465 { 1510 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );1511 $$ = DeclarationNode::newName( 0 ); // unimplemented1466 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1467 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1512 1468 } 1513 1469 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1514 1470 { 1515 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );1516 $$ = DeclarationNode::newName( 0 ); // unimplemented1471 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1472 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1517 1473 } 1518 1474 ; … … 1530 1486 // declarator asm_name_opt initializer_opt 1531 1487 // { 1532 // typedefTable.addToEnclosingScope( TypedefTable::ID);1488 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1533 1489 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1534 1490 // } 1535 1491 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1536 1492 // { 1537 // typedefTable.addToEnclosingScope( TypedefTable::ID);1493 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1538 1494 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1539 1495 // } … … 1542 1498 c_declaration: 1543 1499 declaration_specifier declaring_list 1544 { 1545 $$ = distAttr( $1, $2 ); 1546 } 1500 { $$ = distAttr( $1, $2 ); } 1547 1501 | typedef_declaration 1548 1502 | typedef_expression // GCC, naming expression type … … 1554 1508 // storage-class 1555 1509 declarator asm_name_opt initializer_opt 1556 { 1557 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1558 $$ = $1->addAsmName( $2 )->addInitializer( $3 ); 1559 } 1510 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 1560 1511 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1561 { 1562 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1563 $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); 1564 } 1512 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 1565 1513 ; 1566 1514 … … 1634 1582 1635 1583 forall: 1636 FORALL '(' 1637 { 1638 typedefTable.enterScope(); 1639 } 1640 type_parameter_list ')' // CFA 1641 { 1642 typedefTable.leaveScope(); 1643 $$ = DeclarationNode::newForall( $4 ); 1644 } 1584 FORALL '(' push type_parameter_list pop ')' // CFA 1585 { $$ = DeclarationNode::newForall( $4 ); } 1645 1586 ; 1646 1587 … … 1854 1795 1855 1796 aggregate_type: // struct, union 1856 aggregate_key attribute_list_opt '{' field_declaration_list '}'1797 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' 1857 1798 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1858 1799 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1859 1800 { 1860 1801 typedefTable.makeTypedef( *$3 ); // create typedef 1861 if ( forall ) typedefTable.changeKind( *$3, T ypedefTable::TG); // possibly update1802 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1862 1803 forall = false; // reset 1863 1804 } 1864 '{' field_declaration_list '}'1805 '{' field_declaration_list_opt '}' 1865 1806 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1866 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA1807 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA 1867 1808 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 1868 1809 | aggregate_type_nobody … … 1873 1814 { 1874 1815 typedefTable.makeTypedef( *$3 ); 1875 if ( forall ) typedefTable.changeKind( *$3, T ypedefTable::TG); // possibly update1816 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1876 1817 forall = false; // reset 1877 1818 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); … … 1909 1850 ; 1910 1851 1911 field_declaration_list :1852 field_declaration_list_opt: 1912 1853 // empty 1913 1854 { $$ = nullptr; } 1914 | field_declaration_list field_declaration1855 | field_declaration_list_opt field_declaration 1915 1856 { $$ = $1 ? $1->appendList( $2 ) : $2; } 1916 1857 ; … … 1945 1886 1946 1887 field_declaring_list: 1947 field_declarator 1948 | field_declaring_list ',' attribute_list_opt field_declarator 1888 field_declarator_opt 1889 | field_declaring_list ',' attribute_list_opt field_declarator_opt 1949 1890 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1950 1891 ; 1951 1892 1952 field_declarator :1893 field_declarator_opt: 1953 1894 // empty 1954 1895 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name … … 2090 2031 // No SUE declaration in parameter list. 2091 2032 declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt 2092 { 2093 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2094 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2095 } 2033 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2096 2034 | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt 2097 { 2098 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2099 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2100 } 2035 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2101 2036 ; 2102 2037 … … 2156 2091 initializer: 2157 2092 assignment_expression { $$ = new InitializerNode( $1 ); } 2158 | '{' initializer_list comma_opt '}'{ $$ = new InitializerNode( $2, true ); }2159 ; 2160 2161 initializer_list :2093 | '{' initializer_list_opt comma_opt '}' { $$ = new InitializerNode( $2, true ); } 2094 ; 2095 2096 initializer_list_opt: 2162 2097 // empty 2163 2098 { $$ = nullptr; } 2164 2099 | initializer 2165 2100 | designation initializer { $$ = $2->set_designators( $1 ); } 2166 | initializer_list ',' initializer{ $$ = (InitializerNode *)( $1->set_last( $3 ) ); }2167 | initializer_list ',' designation initializer2101 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2102 | initializer_list_opt ',' designation initializer 2168 2103 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2169 2104 ; … … 2240 2175 type_parameter: // CFA 2241 2176 type_class no_attr_identifier_or_type_name 2242 { typedefTable.addToEnclosingScope( *$2, T ypedefTable::TD); }2177 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); } 2243 2178 type_initializer_opt assertion_list_opt 2244 2179 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2273 2208 assertion: // CFA 2274 2209 '|' no_attr_identifier_or_type_name '(' type_list ')' 2275 { 2276 typedefTable.openTrait( *$2 ); 2277 $$ = DeclarationNode::newTraitUse( $2, $4 ); 2278 } 2210 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2279 2211 | '|' '{' push trait_declaration_list '}' 2280 2212 { $$ = $4; } 2281 2213 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')' 2282 { $$ = nullptr; }2214 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; } 2283 2215 ; 2284 2216 … … 2312 2244 no_attr_identifier_or_type_name 2313 2245 { 2314 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TD);2246 typedefTable.addToEnclosingScope( *$1, TYPEDEFname ); 2315 2247 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2316 2248 } 2317 2249 | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' 2318 2250 { 2319 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TG);2251 typedefTable.addToEnclosingScope( *$1, TYPEGENname ); 2320 2252 $$ = DeclarationNode::newTypeDecl( $1, $4 ); 2321 2253 } … … 2324 2256 trait_specifier: // CFA 2325 2257 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}' 2326 { 2327 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 2328 $$ = DeclarationNode::newTrait( $2, $5, 0 ); 2329 } 2330 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' 2331 { 2332 typedefTable.enterTrait( *$2 ); 2333 typedefTable.enterScope(); 2334 } 2335 trait_declaration_list '}' 2336 { 2337 typedefTable.leaveTrait(); 2338 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 2339 $$ = DeclarationNode::newTrait( $2, $5, $10 ); 2340 } 2258 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); } 2259 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' 2260 { $$ = DeclarationNode::newTrait( $2, $5, $10 ); } 2341 2261 ; 2342 2262 … … 2354 2274 cfa_trait_declaring_list: // CFA 2355 2275 cfa_variable_specifier 2356 {2357 typedefTable.addToEnclosingScope2( TypedefTable::ID );2358 $$ = $1;2359 }2360 2276 | cfa_function_specifier 2361 {2362 typedefTable.addToEnclosingScope2( TypedefTable::ID );2363 $$ = $1;2364 }2365 2277 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 2366 { 2367 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); 2368 $$ = $1->appendList( $1->cloneType( $5 ) ); 2369 } 2278 { $$ = $1->appendList( $1->cloneType( $5 ) ); } 2370 2279 ; 2371 2280 2372 2281 trait_declaring_list: // CFA 2373 2282 type_specifier declarator 2374 { 2375 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2376 $$ = $2->addType( $1 ); 2377 } 2283 { $$ = $2->addType( $1 ); } 2378 2284 | trait_declaring_list pop ',' push declarator 2379 { 2380 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2381 $$ = $1->appendList( $1->cloneBaseType( $5 ) ); 2382 } 2285 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); } 2383 2286 ; 2384 2287 … … 2430 2333 } 2431 2334 | type_qualifier_list 2432 { 2433 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2434 } 2335 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2435 2336 push '{' external_definition_list '}' // CFA, namespace 2436 2337 { … … 2445 2346 } 2446 2347 | declaration_qualifier_list 2447 { 2448 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2449 } 2348 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2450 2349 push '{' external_definition_list '}' // CFA, namespace 2451 2350 { … … 2487 2386 // declaration must still have a type_specifier. OBSOLESCENT (see 1) 2488 2387 | function_declarator compound_statement 2489 { 2490 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2491 typedefTable.leaveScope(); 2492 $$ = $1->addFunctionBody( $2 ); 2493 } 2388 { $$ = $1->addFunctionBody( $2 ); } 2494 2389 | KR_function_declarator KR_declaration_list_opt compound_statement 2495 { 2496 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2497 typedefTable.leaveScope(); 2498 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); 2499 } 2390 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2500 2391 ; 2501 2392 … … 2510 2401 cfa_function_declaration with_clause_opt compound_statement // CFA 2511 2402 { 2512 typedefTable.addToEnclosingScope( TypedefTable::ID );2513 typedefTable.leaveScope();2514 2403 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2515 2404 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } … … 2520 2409 { 2521 2410 rebindForall( $1, $2 ); 2522 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2523 typedefTable.leaveScope(); 2411 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2412 } 2413 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement 2414 { 2415 rebindForall( $1, $2 ); 2524 2416 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2525 2417 } 2526 2418 // handles default int return type, OBSOLESCENT (see 1) 2527 2419 | type_qualifier_list function_declarator with_clause_opt compound_statement 2528 { 2529 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2530 typedefTable.leaveScope(); 2531 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2532 } 2420 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2533 2421 // handles default int return type, OBSOLESCENT (see 1) 2534 2422 | declaration_qualifier_list function_declarator with_clause_opt compound_statement 2535 { 2536 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2537 typedefTable.leaveScope(); 2538 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2539 } 2423 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2540 2424 // handles default int return type, OBSOLESCENT (see 1) 2541 2425 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement 2542 { 2543 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2544 typedefTable.leaveScope(); 2545 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); 2546 } 2426 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2547 2427 2548 2428 // Old-style K&R function definition, OBSOLESCENT (see 4) … … 2550 2430 { 2551 2431 rebindForall( $1, $2 ); 2552 typedefTable.addToEnclosingScope( TypedefTable::ID );2553 typedefTable.leaveScope();2554 2432 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); 2555 2433 } 2556 2434 // handles default int return type, OBSOLESCENT (see 1) 2557 2435 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2558 { 2559 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2560 typedefTable.leaveScope(); 2561 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2562 } 2436 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2563 2437 // handles default int return type, OBSOLESCENT (see 1) 2564 2438 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2565 { 2566 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2567 typedefTable.leaveScope(); 2568 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2569 } 2439 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2570 2440 // handles default int return type, OBSOLESCENT (see 1) 2571 2441 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2572 { 2573 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2574 typedefTable.leaveScope(); 2575 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); 2576 } 2442 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2577 2443 ; 2578 2444 … … 2684 2550 paren_identifier: 2685 2551 identifier 2686 { 2687 typedefTable.setNextIdentifier( *$1 ); 2688 $$ = DeclarationNode::newName( $1 ); 2689 } 2552 { $$ = DeclarationNode::newName( $1 ); } 2690 2553 | '(' paren_identifier ')' // redundant parenthesis 2691 2554 { $$ = $2; } … … 2820 2683 paren_type: 2821 2684 typedef 2685 // hide type name in enclosing scope by variable name 2686 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); } 2822 2687 | '(' paren_type ')' 2823 2688 { $$ = $2; } … … 2922 2787 typedef: 2923 2788 TYPEDEFname 2924 { 2925 typedefTable.setNextIdentifier( *$1 ); 2926 $$ = DeclarationNode::newName( $1 ); 2927 } 2789 { $$ = DeclarationNode::newName( $1 ); } 2928 2790 | TYPEGENname 2929 { 2930 typedefTable.setNextIdentifier( *$1 ); 2931 $$ = DeclarationNode::newName( $1 ); 2932 } 2791 { $$ = DeclarationNode::newName( $1 ); } 2933 2792 ; 2934 2793
Note: See TracChangeset
for help on using the changeset viewer.