Changeset 2f0a0678
- Timestamp:
- May 22, 2018, 9:26:14 AM (7 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:
- 3d2ae8d, cac8a6e
- Parents:
- 21bdce2
- Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r21bdce2 r2f0a0678 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 : 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; … … 547 547 type->aggregate.params = q->type->forall; // make polymorphic type 548 548 // change implicit typedef from TYPEDEFname to TYPEGENname 549 typedefTable.changeKind( *type->aggregate.name, T ypedefTable::TG);549 typedefTable.changeKind( *type->aggregate.name, TYPEGENname ); 550 550 } // if 551 551 } else { // not polymorphic -
src/Parser/TypedefTable.cc
r21bdce2 r2f0a0678 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:24201813 // Update Count : 1 1712 // Last Modified On : Tue May 22 08:40:01 2018 13 // Update Count : 121 14 14 // 15 15 16 16 17 17 #include "TypedefTable.h" 18 #include <cassert> 18 #include <cassert> // for assert 19 19 20 20 #if 0 … … 25 25 #endif 26 26 27 using namespace std; 27 using namespace std; // string, iostream 28 28 29 29 TypedefTable::~TypedefTable() { … … 38 38 39 39 int TypedefTable::isKind( const string & identifier ) const { 40 KindTable::const_iterator posn = kindTable.find( identifier ); 40 41 // 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 42 if ( posn == kindTable.end() ) return IDENTIFIER; 43 43 return posn->second; 44 44 } // TypedefTable::isKind 45 45 46 void TypedefTable::changeKind( const string & identifier, kind_t kind ) {46 void TypedefTable::changeKind( const string & identifier, int kind ) { 47 47 KindTable::iterator posn = kindTable.find( identifier ); 48 if ( posn != kindTable.end() ) posn->second = kind; 48 if ( posn != kindTable.end() ) posn->second = kind; // exists => update 49 49 } // TypedefTable::changeKind 50 50 … … 54 54 void TypedefTable::makeTypedef( const string & name ) { 55 55 if ( ! typedefTable.exists( name ) ) { 56 typedefTable.addToEnclosingScope( name, T ypedefTable::TD);56 typedefTable.addToEnclosingScope( name, TYPEDEFname ); 57 57 } // if 58 58 } // TypedefTable::makeTypedef 59 59 60 void TypedefTable::addToEnclosingScope( const std::string & identifier, kind_t kind ) {60 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind ) { 61 61 assert( kindTable.currentScope() >= 1 ); 62 62 auto scope = kindTable.currentScope() - 1; 63 63 debugPrint( "Adding " << identifier << " as kind " << kind << " scope " << scope << endl ); 64 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 67 } // if 65 if ( ! ret.second ) ret.first->second = kind; // exists => update 68 66 } // TypedefTable::addToEnclosingScope 69 67 -
src/Parser/TypedefTable.h
r21bdce2 r2f0a0678 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:01201813 // Update Count : 7 612 // Last Modified On : Tue May 22 08:39:29 2018 13 // Update Count : 77 14 14 // 15 15 … … 23 23 24 24 class TypedefTable { 25 public: 26 enum kind_t { ID = IDENTIFIER, TD = TYPEDEFname, TG = TYPEGENname }; 27 private: 28 typedef ScopedMap< std::string, kind_t > KindTable; 25 typedef ScopedMap< std::string, int > KindTable; 29 26 KindTable kindTable; 30 27 public: … … 33 30 bool exists( const std::string & identifier ); 34 31 int isKind( const std::string & identifier ) const; 35 void changeKind( const std::string & identifier, kind_t kind );32 void changeKind( const std::string & identifier, int kind ); 36 33 void makeTypedef( const std::string & name ); 37 void addToEnclosingScope( const std::string & identifier, kind_t kind );34 void addToEnclosingScope( const std::string & identifier, int kind ); 38 35 39 36 void enterScope(); -
src/Parser/parser.yy
r21bdce2 r2f0a0678 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 : 335 012 // Last Modified On : Tue May 22 08:41:57 2018 13 // Update Count : 3353 14 14 // 15 15 … … 1419 1419 TYPEDEF cfa_variable_specifier 1420 1420 { 1421 typedefTable.addToEnclosingScope( *$2->name, T ypedefTable::TD);1421 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1422 1422 $$ = $2->addTypedef(); 1423 1423 } 1424 1424 | TYPEDEF cfa_function_specifier 1425 1425 { 1426 typedefTable.addToEnclosingScope( *$2->name, T ypedefTable::TD);1426 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname ); 1427 1427 $$ = $2->addTypedef(); 1428 1428 } 1429 1429 | cfa_typedef_declaration pop ',' push no_attr_identifier 1430 1430 { 1431 typedefTable.addToEnclosingScope( *$5, T ypedefTable::TD);1431 typedefTable.addToEnclosingScope( *$5, TYPEDEFname ); 1432 1432 $$ = $1->appendList( $1->cloneType( $5 ) ); 1433 1433 } … … 1440 1440 TYPEDEF type_specifier declarator 1441 1441 { 1442 typedefTable.addToEnclosingScope( *$3->name, T ypedefTable::TD);1442 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1443 1443 $$ = $3->addType( $2 )->addTypedef(); 1444 1444 } 1445 1445 | typedef_declaration pop ',' push declarator 1446 1446 { 1447 typedefTable.addToEnclosingScope( *$5->name, T ypedefTable::TD);1447 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname ); 1448 1448 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1449 1449 } 1450 1450 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1451 1451 { 1452 typedefTable.addToEnclosingScope( *$4->name, T ypedefTable::TD);1452 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1453 1453 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1454 1454 } 1455 1455 | type_specifier TYPEDEF declarator 1456 1456 { 1457 typedefTable.addToEnclosingScope( *$3->name, T ypedefTable::TD);1457 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname ); 1458 1458 $$ = $3->addType( $1 )->addTypedef(); 1459 1459 } 1460 1460 | type_specifier TYPEDEF type_qualifier_list declarator 1461 1461 { 1462 typedefTable.addToEnclosingScope( *$4->name, T ypedefTable::TD);1462 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname ); 1463 1463 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1464 1464 } … … 1491 1491 // declarator asm_name_opt initializer_opt 1492 1492 // { 1493 // typedefTable.addToEnclosingScope( TypedefTable::ID);1493 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1494 1494 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1495 1495 // } 1496 1496 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1497 1497 // { 1498 // typedefTable.addToEnclosingScope( TypedefTable::ID);1498 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1499 1499 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1500 1500 // } … … 1812 1812 { 1813 1813 typedefTable.makeTypedef( *$3 ); // create typedef 1814 if ( forall ) typedefTable.changeKind( *$3, T ypedefTable::TG); // possibly update1814 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1815 1815 forall = false; // reset 1816 1816 } … … 1826 1826 { 1827 1827 typedefTable.makeTypedef( *$3 ); 1828 if ( forall ) typedefTable.changeKind( *$3, T ypedefTable::TG); // possibly update1828 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1829 1829 forall = false; // reset 1830 1830 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); … … 2187 2187 type_parameter: // CFA 2188 2188 type_class no_attr_identifier_or_type_name 2189 { typedefTable.addToEnclosingScope( *$2, T ypedefTable::TD); }2189 { typedefTable.addToEnclosingScope( *$2, TYPEDEFname ); } 2190 2190 type_initializer_opt assertion_list_opt 2191 2191 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2256 2256 no_attr_identifier_or_type_name 2257 2257 { 2258 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TD);2258 typedefTable.addToEnclosingScope( *$1, TYPEDEFname ); 2259 2259 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2260 2260 } 2261 2261 | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' 2262 2262 { 2263 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TG);2263 typedefTable.addToEnclosingScope( *$1, TYPEGENname ); 2264 2264 $$ = DeclarationNode::newTypeDecl( $1, $4 ); 2265 2265 } … … 2731 2731 paren_type: 2732 2732 typedef 2733 { // hide type name by variable name 2734 typedefTable.addToEnclosingScope( *$1->name, TypedefTable::ID ); 2735 } 2733 // hide type name in enclosing scope by variable name 2734 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); } 2736 2735 | '(' paren_type ')' 2737 2736 { $$ = $2; }
Note: See TracChangeset
for help on using the changeset viewer.