Changes in / [a43c561:95487027]
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
ra43c561 r95487027 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 16 15:01:20201813 // Update Count : 912 // Last Modified On : Thu Jun 7 08:05:26 2018 13 // Update Count : 10 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
ra43c561 r95487027 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 6 15:57:50201813 // Update Count : 107 612 // Last Modified On : Thu Jun 7 12:08:55 2018 13 // Update Count : 1079 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; // make polymorphic type 548 // change implicit typedef from TYPEDEFname to TYPEGENname 549 typedefTable.changeKind( *type->aggregate.name, TYPEGENname ); 547 type->aggregate.params = q->type->forall; // set forall qualifier 550 548 } // if 551 549 } else { // not polymorphic -
src/Parser/TypedefTable.cc
ra43c561 r95487027 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 1 16:54:18201813 // Update Count : 1 5512 // Last Modified On : Thu Jun 7 13:17:56 2018 13 // Update Count : 192 14 14 // 15 15 … … 17 17 #include "TypedefTable.h" 18 18 #include <cassert> // for assert 19 #include <iostream> 19 20 20 21 #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 } // switch 39 } // kindName 40 ) 41 29 42 TypedefTable::~TypedefTable() { 30 43 if ( ! SemanticErrorThrow && kindTable.currentScope() != 0 ) { 31 std::cerr << "scope failure " << kindTable.currentScope() << endl; 44 cerr << "Error: cfa-cpp internal error, scope failure " << kindTable.currentScope() << endl; 45 abort(); 32 46 } // if 33 47 } // TypedefTable::~TypedefTable … … 44 58 } // TypedefTable::isKind 45 59 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 => update49 } // TypedefTable::changeKind50 51 60 // SKULLDUGGERY: Generate a typedef for the aggregate name so the aggregate does not have to be qualified by 52 61 // "struct". Only generate the typedef, if the name is not in use. The typedef is implicitly (silently) removed if the 53 62 // name is explicitly used. 54 void TypedefTable::makeTypedef( const string & name ) { 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 // } 55 71 if ( ! typedefTable.exists( name ) ) { 56 typedefTable.addToEnclosingScope( name, TYPEDEFname, "MTD" );72 typedefTable.addToEnclosingScope( name, kind, "MTD" ); 57 73 } // if 58 74 } // TypedefTable::makeTypedef 59 75 60 void TypedefTable::addToScope( const st d::string & identifier, int kind, const char * locn __attribute__((unused)) ) {76 void TypedefTable::addToScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) { 61 77 auto scope = kindTable.currentScope(); 62 debugPrint( cerr << "Adding at " << locn << " " << identifier << " as kind " << kind<< " scope " << scope << endl );78 debugPrint( cerr << "Adding current at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl ); 63 79 auto ret = kindTable.insertAt( scope, identifier, kind ); 64 80 if ( ! ret.second ) ret.first->second = kind; // exists => update 65 81 } // TypedefTable::addToScope 66 82 67 void TypedefTable::addToEnclosingScope( const st d::string & identifier, int kind, const char * locn __attribute__((unused)) ) {83 void TypedefTable::addToEnclosingScope( const string & identifier, int kind, const char * locn __attribute__((unused)) ) { 68 84 assert( kindTable.currentScope() >= 1 ); 69 85 auto scope = kindTable.currentScope() - 1; 70 debugPrint( cerr << "Adding +1 at " << locn << " " << identifier << " as kind " << kind<< " scope " << scope << endl );86 debugPrint( cerr << "Adding enclosing at " << locn << " " << identifier << " as " << kindName( kind ) << " scope " << scope << endl ); 71 87 auto ret = kindTable.insertAt( scope, identifier, kind ); 72 88 if ( ! ret.second ) ret.first->second = kind; // exists => update … … 93 109 debugPrint( cerr << endl << "[" << scope << "]" ); 94 110 } // while 95 debugPrint( cerr << " " << (*i).first << ":" << (*i).second);111 debugPrint( cerr << " " << (*i).first << ":" << kindName( (*i).second ) ); 96 112 } // for 97 113 while ( scope > 0 ) { -
src/Parser/TypedefTable.h
ra43c561 r95487027 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 31 23:23:47 201813 // Update Count : 8 312 // Last Modified On : Thu Jun 7 12:10:17 2018 13 // Update Count : 85 14 14 // 15 15 … … 30 30 bool exists( const std::string & identifier ); 31 31 int isKind( const std::string & identifier ) const; 32 void changeKind( const std::string & identifier, int kind ); 33 void makeTypedef( const std::string & name ); 32 void makeTypedef( const std::string & name, int kind = TYPEDEFname ); 34 33 void addToScope( const std::string & identifier, int kind, const char * ); 35 34 void addToEnclosingScope( const std::string & identifier, int kind, const char * ); -
src/Parser/lex.ll
ra43c561 r95487027 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Wed Jun 6 17:31:09201813 * Update Count : 67 712 * Last Modified On : Thu Jun 7 08:27:40 2018 13 * Update Count : 679 14 14 */ 15 15 … … 452 452 453 453 %% 454 454 455 // ----end of lexer---- 455 456 456 457 void yyerror( const char * errmsg ) { 458 SemanticErrorThrow = true; 457 459 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 458 460 << ": " << ErrorHelpers::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; -
src/Parser/parser.yy
ra43c561 r95487027 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 6 14:53:38201813 // Update Count : 352 212 // Last Modified On : Thu Jun 7 10:07:12 2018 13 // Update Count : 3527 14 14 // 15 15 … … 1826 1826 | aggregate_key attribute_list_opt no_attr_identifier 1827 1827 { 1828 typedefTable.makeTypedef( *$3 );// create typedef1829 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update1828 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); // 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 ); // create typedef1837 if ( forall ) typedefTable.changeKind( *$3->type->symbolic.name, TYPEGENname ); // possibly update1836 typedefTable.makeTypedef( *$3->type->symbolic.name, forall ? TYPEGENname : TYPEDEFname ); // 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 );1851 if ( forall ) typedefTable.changeKind( *$3, TYPEGENname ); // possibly update1850 typedefTable.makeTypedef( *$3, forall ? TYPEGENname : TYPEDEFname ); 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 3266 3267 // ----end of grammar---- 3267 3268
Note: See TracChangeset
for help on using the changeset viewer.