Changes in / [95487027:a43c561]
- Location:
- src
- Files:
-
- 6 edited
-
Common/SemanticError.cc (modified) (2 diffs)
-
Parser/DeclarationNode.cc (modified) (2 diffs)
-
Parser/TypedefTable.cc (modified) (5 diffs)
-
Parser/TypedefTable.h (modified) (2 diffs)
-
Parser/lex.ll (modified) (2 diffs)
-
Parser/parser.yy (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
r95487027 ra43c561 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 08:05:26201813 // Update Count : 1012 // Last Modified On : Wed May 16 15:01:20 2018 13 // Update Count : 9 14 14 // 15 15 … … 97 97 void SemanticError( CodeLocation location, std::string error ) { 98 98 SemanticErrorThrow = true; 99 throw SemanticErrorException( location, error);99 throw SemanticErrorException(location, error); 100 100 } 101 101 -
src/Parser/DeclarationNode.cc
r95487027 ra43c561 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 12:08:55201813 // Update Count : 107 912 // Last Modified On : Wed Jun 6 15:57:50 2018 13 // Update Count : 1076 14 14 // 15 15 … … 545 545 type->aggregate.params->appendList( q->type->forall ); // augment forall qualifier 546 546 } else { // not polymorphic 547 type->aggregate.params = q->type->forall; // set forall qualifier 547 type->aggregate.params = q->type->forall; // make polymorphic type 548 // change implicit typedef from TYPEDEFname to TYPEGENname 549 typedefTable.changeKind( *type->aggregate.name, TYPEGENname ); 548 550 } // if 549 551 } else { // not polymorphic -
src/Parser/TypedefTable.cc
r95487027 ra43c561 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 : 1 9212 // Last Modified On : Fri Jun 1 16:54:18 2018 13 // Update Count : 155 14 14 // 15 15 … … 17 17 #include "TypedefTable.h" 18 18 #include <cassert> // for assert 19 #include <iostream>20 19 21 20 #if 0 21 #include <iostream> 22 22 #define debugPrint( code ) code 23 23 #else … … 27 27 using namespace std; // string, iostream 28 28 29 debugPrint(30 static const char *kindName( int kind ) {31 switch ( kind ) {32 case IDENTIFIER: return "identifier";33 case TYPEDEFname: return "typedef";34 case TYPEGENname: return "typegen";35 default:36 cerr << "Error: cfa-cpp internal error, invalid kind of identifier" << endl;37 abort();38 } // switch39 } // kindName40 )41 42 29 TypedefTable::~TypedefTable() { 43 30 if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) { 44 cerr << "Error: cfa-cpp internal error, scope failure " << kindTable.currentScope() << endl; 45 abort(); 31 std::cerr << "scope failure " << kindTable.currentScope() << endl; 46 32 } // if 47 33 } // TypedefTable::~TypedefTable … … 58 44 } // TypedefTable::isKind 59 45 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 50 60 51 // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by 61 52 // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if the 62 53 // name is explicitly used. 63 void TypedefTable::makeTypedef( const string & name, int kind ) { 64 // Check for existence is necessary to handle: 65 // struct Fred {}; 66 // void Fred(); 67 // void fred() { 68 // struct Fred act; // do not add as type in this scope 69 // Fred(); 70 // } 54 void TypedefTable::makeTypedef( const string & name ) { 71 55 if ( ! typedefTable.exists( name ) ) { 72 typedefTable.addToEnclosingScope( name, kind, "MTD" );56 typedefTable.addToEnclosingScope( name, TYPEDEFname, "MTD" ); 73 57 } // if 74 58 } // TypedefTable::makeTypedef 75 59 76 void TypedefTable::addToScope( const st ring & identifier, int kind, const char * locn __attribute__((unused)) ) {60 void TypedefTable::addToScope( const std::string & identifier, int kind, const char * locn __attribute__((unused)) ) { 77 61 auto scope = kindTable.currentScope(); 78 debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind )<< " scope " << scope << endl );62 debugPrint( cerr << "Adding at " << locn << " " << identifier << " as kind " << kind << " scope " << scope << endl ); 79 63 auto ret = kindTable.insertAt( scope, identifier, kind ); 80 64 if ( ! ret.second ) ret.first->second = kind; // exists => update 81 65 } // TypedefTable::addToScope 82 66 83 void TypedefTable::addToEnclosingScope( const st ring & identifier, int kind, const char * locn __attribute__((unused)) ) {67 void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind, const char * locn __attribute__((unused)) ) { 84 68 assert( kindTable.currentScope() >= 1 ); 85 69 auto scope = kindTable.currentScope() - 1; 86 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind )<< " scope " << scope << endl );70 debugPrint( cerr << "Adding+1 at " << locn << " " << identifier << " as kind " << kind << " scope " << scope << endl ); 87 71 auto ret = kindTable.insertAt( scope, identifier, kind ); 88 72 if ( ! ret.second ) ret.first->second = kind; // exists => update … … 109 93 debugPrint( cerr << endl << "[" << scope << "]" ); 110 94 } // while 111 debugPrint( cerr << " " << (*i).first << ":" << kindName( (*i).second ));95 debugPrint( cerr << " " << (*i).first << ":" << (*i).second ); 112 96 } // for 113 97 while ( scope > 0 ) { -
src/Parser/TypedefTable.h
r95487027 ra43c561 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:17 201813 // Update Count : 8 512 // Last Modified On : Thu May 31 23:23:47 2018 13 // Update Count : 83 14 14 // 15 15 … … 30 30 bool exists( const std::string & identifier ); 31 31 int isKind( const std::string & identifier ) const; 32 void makeTypedef( const std::string & name, int kind = TYPEDEFname ); 32 void changeKind( const std::string & identifier, int kind ); 33 void makeTypedef( const std::string & name ); 33 34 void addToScope( const std::string & identifier, int kind, const char * ); 34 35 void addToEnclosingScope( const std::string & identifier, int kind, const char * ); -
src/Parser/lex.ll
r95487027 ra43c561 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Thu Jun 7 08:27:40201813 * Update Count : 67 912 * Last Modified On : Wed Jun 6 17:31:09 2018 13 * Update Count : 677 14 14 */ 15 15 … … 452 452 453 453 %% 454 455 454 // ----end of lexer---- 456 455 457 456 void yyerror( const char * errmsg ) { 458 SemanticErrorThrow = true;459 457 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 460 458 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; -
src/Parser/parser.yy
r95487027 ra43c561 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 : 352 712 // Last Modified On : Wed Jun 6 14:53:38 2018 13 // Update Count : 3522 14 14 // 15 15 … … 1826 1826 | aggregate_key attribute_list_opt no_attr_identifier 1827 1827 { 1828 typedefTable.makeTypedef( *$3 , forall ? TYPEGENname : TYPEDEFname );// create typedef1829 //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update1828 typedefTable.makeTypedef( *$3 ); // create typedef 1829 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1830 1830 forall = false; // reset 1831 1831 } … … 1834 1834 | aggregate_key attribute_list_opt type_name 1835 1835 { 1836 typedefTable.makeTypedef( *$3->type->symbolic.name , forall ? TYPEGENname : TYPEDEFname); // create typedef1837 //if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update1836 typedefTable.makeTypedef( *$3->type->symbolic.name ); // create typedef 1837 if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update 1838 1838 forall = false; // reset 1839 1839 } … … 1848 1848 aggregate_key attribute_list_opt no_attr_identifier 1849 1849 { 1850 typedefTable.makeTypedef( *$3 , forall ? TYPEGENname : TYPEDEFname);1851 //if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update1850 typedefTable.makeTypedef( *$3 ); 1851 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update 1852 1852 forall = false; // reset 1853 1853 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); … … 3264 3264 3265 3265 %% 3266 3267 3266 // ----end of grammar---- 3268 3267
Note:
See TracChangeset
for help on using the changeset viewer.