Changeset fc20514
- Timestamp:
- Jul 11, 2018, 11:53:09 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 777ed2b
- Parents:
- 132d276
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TypedefTable.cc
r132d276 rfc20514 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 22 06:14:39201813 // Update Count : 2 0612 // Last Modified On : Wed Jul 11 11:47:47 2018 13 // Update Count : 255 14 14 // 15 15 … … 77 77 auto scope = kindTable.currentScope(); 78 78 debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl ); 79 auto ret = kindTable.insertAt( scope, identifier, kind ); 80 //if ( ! ret.second ) ret.first->second = kind; // exists => update 81 assert( ret.first->second == kind ); // exists 79 kindTable.insertAt( scope, identifier, kind ); 82 80 } // TypedefTable::addToScope 83 81 84 82 void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) { 85 a ssert( kindTable.currentScope() >= 1 + level );86 auto scope = kindTable.currentScope() - 1 -level;87 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << endl );83 auto scope = kindTable.currentScope() - 1 - kindTable.getNote( kindTable.currentScope() - 1 ).level; 84 // auto scope = level - kindTable.getNote( kindTable.currentScope() - 1 ).level; 85 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << " note " << kindTable.getNote( kindTable.currentScope() - 1 ).level << endl ); 88 86 auto ret = kindTable.insertAt( scope, identifier, kind ); 89 if ( ! ret.second ) ret.first->second = kind; 87 if ( ! ret.second ) ret.first->second = kind; // exists => update 90 88 } // TypedefTable::addToEnclosingScope 91 89 92 90 void TypedefTable::enterScope() { 93 kindTable.beginScope( 0);94 debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() );91 kindTable.beginScope( (Note){ 0, false } ); 92 debugPrint( cerr << "Entering scope " << kindTable.currentScope() << " level " << level << endl; print() ); 95 93 } // TypedefTable::enterScope 96 94 … … 100 98 } // TypedefTable::leaveScope 101 99 100 void TypedefTable::up( bool forall ) { 101 level += 1; 102 kindTable.getNote( kindTable.currentScope() ) = (Note){ level, forall | getEnclForall() }; 103 debugPrint( cerr << "Up " << " level " << level << " note " << kindTable.getNote( level ).level << ", " << kindTable.getNote( level ).forall << endl; ); 104 } // TypedefTable::up 105 106 void TypedefTable::down() { 107 level -= 1; 108 debugPrint( cerr << "Down " << " level " << level << " note " << kindTable.getNote( level ).level << endl; ); 109 } // TypedefTable::down 110 102 111 void TypedefTable::print( void ) const { 103 112 KindTable::size_type scope = kindTable.currentScope(); 104 debugPrint( cerr << "[" << scope << "] " );113 debugPrint( cerr << "[" << scope << "] " << kindTable.getNote( scope ).level << ", " << kindTable.getNote( scope ).forall << ":" ); 105 114 for ( KindTable::const_iterator i = kindTable.begin(); i != kindTable.end(); i++ ) { 106 115 while ( i.get_level() != scope ) { 107 116 --scope; 108 debugPrint( cerr << endl << "[" << scope << "] " );117 debugPrint( cerr << endl << "[" << scope << "] " << kindTable.getNote( scope ).level << ", " << kindTable.getNote( scope ).forall << ":" ); 109 118 } // while 110 119 debugPrint( cerr << " " << (*i).first << ":" << kindName( (*i).second ) ); … … 112 121 while ( scope > 0 ) { 113 122 --scope; 114 debugPrint( cerr << endl << "[" << scope << "] " );123 debugPrint( cerr << endl << "[" << scope << "] " << kindTable.getNote( scope ).level << ", " << kindTable.getNote( scope ).forall << ":" ); 115 124 } // while 116 125 debugPrint( cerr << endl ); -
src/Parser/TypedefTable.h
r132d276 rfc20514 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 22 05:29:58201813 // Update Count : 8612 // Last Modified On : Tue Jul 10 18:32:23 2018 13 // Update Count : 112 14 14 // 15 15 … … 23 23 24 24 class TypedefTable { 25 typedef ScopedMap< std::string, int, int > KindTable; 25 struct Note { size_t level; bool forall; }; 26 typedef ScopedMap< std::string, int, Note > KindTable; 26 27 KindTable kindTable; 27 unsigned int level ;28 unsigned int level = 0; 28 29 public: 29 TypedefTable() : kindTable{0}, level{0} {}30 30 ~TypedefTable(); 31 31 … … 35 35 void addToScope( const std::string & identifier, int kind, const char * ); 36 36 void addToEnclosingScope( const std::string & identifier, int kind, const char * ); 37 bool getEnclForall() { return kindTable.getNote( kindTable.currentScope() - 1 ).forall; } 37 38 38 39 void enterScope(); 39 40 void leaveScope(); 40 41 41 void up( ) { level += 1; }42 void down() { level -= 1; }42 void up( bool ); 43 void down(); 43 44 44 45 void print( void ) const; -
src/Parser/parser.yy
r132d276 rfc20514 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 6 08:02:38201813 // Update Count : 37 1612 // Last Modified On : Wed Jul 11 11:20:51 2018 13 // Update Count : 3738 14 14 // 15 15 … … 166 166 } // build_postfix_name 167 167 168 bool forall = false, xxx = false, yyy = false;// aggregate have one or more forall qualifiers ?168 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? 169 169 170 170 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 422 422 // Foo ( *fp )( int ); 423 423 // `---' matches start of TYPEGENname '(' 424 // Must be:424 // must be: 425 425 // Foo( int ) ( *fp )( int ); 426 // The same problem occurs here: 427 // forall( otype T ) struct Foo { T v; } ( *fp )( int ); 428 // must be: 429 // forall( otype T ) struct Foo { T v; } ( int ) ( *fp )( int ); 426 430 427 431 // Order of these lines matters (low-to-high precedence). … … 1856 1860 1857 1861 aggregate_type: // struct, union 1858 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' type_parameters_opt 1859 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $6, $4, true )->addQualifiers( $2 ); } 1862 aggregate_key attribute_list_opt 1863 { forall = false; } // reset 1864 '{' field_declaration_list_opt '}' type_parameters_opt 1865 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $7, $5, true )->addQualifiers( $2 ); } 1860 1866 | aggregate_key attribute_list_opt no_attr_identifier fred 1861 1867 { 1862 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef1868 typedefTable.makeTypedef( *$3, forall | typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 1863 1869 forall = false; // reset 1864 1870 } … … 1867 1873 | aggregate_key attribute_list_opt type_name fred 1868 1874 { 1869 typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef1875 typedefTable.makeTypedef( *$3->type->symbolic.name, forall | typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 1870 1876 forall = false; // reset 1871 1877 } … … 1885 1891 aggregate_key attribute_list_opt no_attr_identifier fred 1886 1892 { 1887 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname );1893 typedefTable.makeTypedef( *$3, forall | typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); 1888 1894 forall = false; // reset 1889 1895 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); … … 1891 1897 | aggregate_key attribute_list_opt type_name fred 1892 1898 { 1899 forall = false; // reset 1893 1900 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is 1894 1901 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and … … 2366 2373 push external_definition pop 2367 2374 { $$ = $2; } 2368 | external_definition_list 2369 { forall = xxx; } 2370 push external_definition pop 2371 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2375 | external_definition_list push external_definition pop 2376 { $$ = $1 ? $1->appendList( $3 ) : $3; } 2372 2377 ; 2373 2378 … … 2379 2384 2380 2385 up: 2381 { typedefTable.up( ); }2386 { typedefTable.up( forall ); forall = false; } 2382 2387 ; 2383 2388 … … 2412 2417 { 2413 2418 if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2414 if ( $1->type->forall ) xxx = forall = true;// remember generic type2419 if ( $1->type->forall ) forall = true; // remember generic type 2415 2420 } 2416 2421 '{' up external_definition_list_opt down '}' // CFA, namespace 2417 2422 { 2418 2423 distQual( $5, $1 ); 2419 xxx= false;2424 forall = false; 2420 2425 $$ = $5; 2421 2426 } … … 2423 2428 { 2424 2429 if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2425 if ( $1->type && $1->type->forall ) xxx =forall = true; // remember generic type2430 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 2426 2431 } 2427 2432 '{' up external_definition_list_opt down '}' // CFA, namespace 2428 2433 { 2429 2434 distQual( $5, $1 ); 2430 xxx= false;2435 forall = false; 2431 2436 $$ = $5; 2432 2437 } … … 2434 2439 { 2435 2440 if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2436 if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx =forall = true; // remember generic type2441 if ( ($1->type && $1->type->forall) || $2->type->forall ) forall = true; // remember generic type 2437 2442 } 2438 2443 '{' up external_definition_list_opt down '}' // CFA, namespace 2439 2444 { 2440 2445 distQual( $6, $1->addQualifiers( $2 ) ); 2441 xxx= false;2446 forall = false; 2442 2447 $$ = $6; 2443 2448 }
Note: See TracChangeset
for help on using the changeset viewer.