- Timestamp:
- Jun 22, 2018, 2:58:30 PM (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, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 203c667, 63238a4
- Parents:
- 6d43cc57
- git-author:
- Peter A. Buhr <pabuhr@…> (06/22/18 13:56:53)
- git-committer:
- Peter A. Buhr <pabuhr@…> (06/22/18 14:58:30)
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TypedefTable.cc
r6d43cc57 r3d56d15b 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 13:17:56201813 // Update Count : 19212 // Last Modified On : Fri Jun 22 06:14:39 2018 13 // Update Count : 206 14 14 // 15 15 … … 78 78 debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl ); 79 79 auto ret = kindTable.insertAt( scope, identifier, kind ); 80 if ( ! ret.second ) ret.first->second = kind; // exists => update 80 //if ( ! ret.second ) ret.first->second = kind; // exists => update 81 assert( ret.first->second == kind ); // exists 81 82 } // TypedefTable::addToScope 82 83 83 84 void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) { 84 assert( kindTable.currentScope() >= 1 );85 auto scope = kindTable.currentScope() - 1 ;86 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl );85 assert( kindTable.currentScope() >= 1 + level ); 86 auto scope = kindTable.currentScope() - 1 - level; 87 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << " level " << level << endl ); 87 88 auto ret = kindTable.insertAt( scope, identifier, kind ); 88 89 if ( ! ret.second ) ret.first->second = kind; // exists => update … … 91 92 void TypedefTable::enterScope() { 92 93 kindTable.beginScope(); 93 debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl ); 94 debugPrint( print() ); 94 debugPrint( cerr << "Entering scope " << kindTable.currentScope() << endl; print() ); 95 95 } // TypedefTable::enterScope 96 96 97 97 void TypedefTable::leaveScope() { 98 debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl ); 99 debugPrint( print() ); 98 debugPrint( cerr << "Leaving scope " << kindTable.currentScope() << endl; print() ); 100 99 kindTable.endScope(); 101 100 } // TypedefTable::leaveScope … … 114 113 --scope; 115 114 debugPrint( cerr << endl << "[" << scope << "]" ); 116 } 115 } // while 117 116 debugPrint( cerr << endl ); 118 } 117 } // TypedefTable::print 119 118 120 119 // Local Variables: // -
src/Parser/TypedefTable.h
r6d43cc57 r3d56d15b 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 12:10:17201813 // Update Count : 8 512 // Last Modified On : Fri Jun 22 05:29:58 2018 13 // Update Count : 86 14 14 // 15 15 … … 25 25 typedef ScopedMap< std::string, int > KindTable; 26 26 KindTable kindTable; 27 unsigned int level = 0; 27 28 public: 28 29 ~TypedefTable(); … … 37 38 void leaveScope(); 38 39 40 void up() { level += 1; } 41 void down() { level -= 1; } 42 39 43 void print( void ) const; 40 44 }; // TypedefTable -
src/Parser/parser.yy
r6d43cc57 r3d56d15b 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 10:07:12201813 // Update Count : 35 2712 // Last Modified On : Fri Jun 22 13:59:11 2018 13 // Update Count : 3586 14 14 // 15 15 … … 136 136 } // build_postfix_name 137 137 138 bool forall = false, xxx = false ;// aggregate have one or more forall qualifiers ?138 bool forall = false, xxx = false, yyy = false; // aggregate have one or more forall qualifiers ? 139 139 140 140 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 304 304 %type<en> enumerator_value_opt 305 305 306 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt 306 %type<decl> external_definition external_definition_list external_definition_list_opt 307 308 %type<decl> exception_declaration 307 309 308 310 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list … … 1821 1823 ; 1822 1824 1825 fred: 1826 // empty 1827 { yyy = false; } 1828 ; 1829 1823 1830 aggregate_type: // struct, union 1824 1831 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' 1825 1832 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1826 | aggregate_key attribute_list_opt no_attr_identifier 1833 | aggregate_key attribute_list_opt no_attr_identifier fred 1827 1834 { 1828 1835 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // create typedef … … 1831 1838 } 1832 1839 '{' field_declaration_list_opt '}' 1833 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $ 6, true )->addQualifiers( $2 ); }1834 | aggregate_key attribute_list_opt type_name 1840 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); } 1841 | aggregate_key attribute_list_opt type_name fred 1835 1842 { 1836 1843 typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // create typedef … … 1839 1846 } 1840 1847 '{' field_declaration_list_opt '}' 1841 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $ 6, true )->addQualifiers( $2 ); }1848 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); } 1842 1849 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA 1843 1850 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } … … 1846 1853 1847 1854 aggregate_type_nobody: // struct, union - {...} 1848 aggregate_key attribute_list_opt no_attr_identifier 1855 aggregate_key attribute_list_opt no_attr_identifier fred 1849 1856 { 1850 1857 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); … … 1853 1860 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1854 1861 } 1855 | aggregate_key attribute_list_opt type_name 1862 | aggregate_key attribute_list_opt type_name fred 1856 1863 { 1857 1864 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is … … 1867 1874 aggregate_key: 1868 1875 STRUCT 1869 { $$ = DeclarationNode::Struct; }1876 { yyy = true; $$ = DeclarationNode::Struct; } 1870 1877 | UNION 1871 { $$ = DeclarationNode::Union; }1878 { yyy = true; $$ = DeclarationNode::Union; } 1872 1879 | EXCEPTION 1873 { $$ = DeclarationNode::Exception; }1880 { yyy = true; $$ = DeclarationNode::Exception; } 1874 1881 | COROUTINE 1875 { $$ = DeclarationNode::Coroutine; }1882 { yyy = true; $$ = DeclarationNode::Coroutine; } 1876 1883 | MONITOR 1877 { $$ = DeclarationNode::Monitor; }1884 { yyy = true; $$ = DeclarationNode::Monitor; } 1878 1885 | THREAD 1879 { $$ = DeclarationNode::Thread; }1886 { yyy = true; $$ = DeclarationNode::Thread; } 1880 1887 ; 1881 1888 … … 2322 2329 2323 2330 translation_unit: 2324 // empty 2325 {} // empty input file 2331 // empty, input file 2326 2332 | external_definition_list 2327 2333 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; } … … 2337 2343 ; 2338 2344 2339 // SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope.2340 // However, external_definition_list creates a new scope around each external_definition, but the pop loses all the2341 // types in the extern "X" and distribution at the end of the block. This version of external_definition_list does2342 2343 // not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of2344 // external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level.2345 external_definition_list_no_pop_push:2346 external_definition2347 | external_definition_list_no_pop_push2348 { forall = xxx; }2349 external_definition2350 { $$ = $1 ? $1->appendList( $3 ) : $3; }2351 ;2352 2353 2345 external_definition_list_opt: 2354 2346 // empty 2355 2347 { $$ = nullptr; } 2356 | external_definition_list_no_pop_push 2348 | external_definition_list 2349 ; 2350 2351 up: 2352 { typedefTable.up(); } 2353 ; 2354 2355 down: 2356 { typedefTable.down(); } 2357 2357 ; 2358 2358 … … 2374 2374 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2375 2375 } 2376 '{' external_definition_list_opt'}'2376 '{' up external_definition_list_opt down '}' 2377 2377 { 2378 2378 linkage = linkageStack.top(); 2379 2379 linkageStack.pop(); 2380 $$ = $ 5;2380 $$ = $6; 2381 2381 } 2382 2382 | type_qualifier_list 2383 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2384 '{' external_definition_list_opt '}' // CFA, namespace 2385 { 2386 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2383 { 2384 if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2385 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2386 } 2387 '{' up external_definition_list_opt down '}' // CFA, namespace 2388 { 2389 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2387 2390 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2388 2391 iter->addQualifiers( $1->clone() ); … … 2391 2394 xxx = false; 2392 2395 delete $1; 2393 $$ = $ 4;2396 $$ = $5; 2394 2397 } 2395 2398 | declaration_qualifier_list 2396 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2397 '{' external_definition_list_opt '}' // CFA, namespace 2398 { 2399 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2399 { 2400 if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2401 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2402 } 2403 '{' up external_definition_list_opt down '}' // CFA, namespace 2404 { 2405 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2400 2406 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2401 2407 iter->addQualifiers( $1->clone() ); … … 2404 2410 xxx = false; 2405 2411 delete $1; 2406 $$ = $ 4;2412 $$ = $5; 2407 2413 } 2408 2414 | declaration_qualifier_list type_qualifier_list 2409 2415 { 2410 // forall must be in the type_qualifier_list2411 if ( $2->type->forall ) xxx = forall = true; // remember generic type2412 } 2413 '{' external_definition_list_opt '}'// CFA, namespace2414 { 2415 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2416 if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2417 if ( ($1->type && $1->type->forall) || $2->type->forall ) xxx = forall = true; // remember generic type 2418 } 2419 '{' up external_definition_list_opt down '}' // CFA, namespace 2420 { 2421 for ( DeclarationNode * iter = $6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2416 2422 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2417 2423 iter->addQualifiers( $1->clone() ); … … 2422 2428 delete $1; 2423 2429 delete $2; 2424 $$ = $ 5;2430 $$ = $6; 2425 2431 } 2426 2432 ;
Note: See TracChangeset
for help on using the changeset viewer.