Changeset 9ed4f94
- Timestamp:
- Aug 30, 2017, 8:08:01 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, resolv-new, with_gc
- Children:
- e5fccf4
- Parents:
- fc1ef62
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
rfc1ef62 r9ed4f94 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:21:25 201513 // Update Count : 112 // Last Modified On : Tue Aug 29 18:17:35 2017 13 // Update Count : 3 14 14 // 15 15 16 #include <cstdio> 17 #include <unistd.h> 18 #include <iostream> 19 #include <list> 20 #include <string> 16 #include <cstdio> // for fileno, stderr 17 #include <unistd.h> // for isatty 18 #include <iostream> // for basic_ostream, operator<<, ostream 19 #include <list> // for list, _List_iterator 20 #include <string> // for string, operator<<, operator+, to_string 21 21 22 #include "Common/utility.h" 22 #include "Common/utility.h" // for to_string, CodeLocation (ptr only) 23 23 #include "SemanticError.h" 24 25 inline const std::string& error_str() {26 static std::string str = isatty( fileno(stderr) ) ? "\e[31merror:\e[39m " : "error: ";27 return str;28 }29 24 30 25 SemanticError::SemanticError() { … … 49 44 void SemanticError::print( std::ostream &os ) { 50 45 using std::to_string; 51 for( auto err : errors) {52 os << to_string( err.location ) << err.description << '\n';46 for( auto err : errors ) { 47 os << to_string( err.location ) << err.description << std::endl; 53 48 } 54 49 } -
src/Common/SemanticError.h
rfc1ef62 r9ed4f94 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : T hr Aug 17 14:01:00201713 // Update Count : 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Aug 29 22:03:36 2017 13 // Update Count : 17 14 14 // 15 15 16 16 #pragma once 17 17 18 #include <exception> // for exception 19 #include <iostream> // for ostream 20 #include <list> // for list 21 #include <string> // for string 18 #include <exception> // for exception 19 #include <iostream> // for ostream 20 #include <list> // for list 21 #include <string> // for string 22 #include <unistd.h> // for isatty 22 23 23 #include "CodeLocation.h" 24 #include "CodeLocation.h" // for CodeLocation, toString 24 25 25 26 struct error { … … 28 29 29 30 error() = default; 30 error( const std::string & str ) : description( str ) {}31 error( const std::string & str ) : description( str ) {} 31 32 32 void maybeSet( const CodeLocation & location ) {33 void maybeSet( const CodeLocation & location ) { 33 34 if( this->location.linenumber < 0 ) { 34 35 this->location = location; … … 41 42 SemanticError(); 42 43 SemanticError( std::string error ); 43 template< typename T > SemanticError( const std::string & error, const T *obj );44 template< typename T > SemanticError( const std::string & error, const T * obj ); 44 45 ~SemanticError() throw() {} 45 46 46 void append( SemanticError &other ); 47 static inline const std::string & error_str() { 48 static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: "; 49 return str; 50 } 51 52 void append( SemanticError & other ); 47 53 void append( const std::string & ); 48 54 bool isEmpty() const; 49 void print( std::ostream & os );55 void print( std::ostream & os ); 50 56 51 void set_location( const CodeLocation & location );52 // constructs an exception using the given message and the printed 53 // representation of the obj (T must have a printmethod)57 void set_location( const CodeLocation & location ); 58 // constructs an exception using the given message and the printed representation of the obj (T must have a print 59 // method) 54 60 private: 55 61 std::list< error > errors; … … 57 63 58 64 template< typename T > 59 SemanticError::SemanticError( const std::string & error, const T *obj ) {65 SemanticError::SemanticError( const std::string & error, const T * obj ) { 60 66 append( toString( error, obj ) ); 61 67 } -
src/Parser/lex.ll
rfc1ef62 r9ed4f94 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Tue Aug 22 22:43:39201713 * Update Count : 5 5812 * Last Modified On : Wed Aug 30 07:53:24 2017 13 * Update Count : 583 14 14 */ 15 15 … … 19 19 20 20 %{ 21 // Th islexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been21 // The lexer assumes the program has been preprocessed by cpp. Hence, all user level preprocessor directive have been 22 22 // performed and removed from the source. The only exceptions are preprocessor directives passed to the compiler (e.g., 23 23 // line-number directives) and C/C++ style comments, which are ignored. … … 25 25 //**************************** Includes and Defines **************************** 26 26 27 unsigned int column = 0; // position of the end of the last token parsed 28 #define YY_USER_ACTION column += yyleng; // trigger before each matching rule's action 29 27 30 #include <string> 28 31 #include <cstdio> // FILENAME_MAX 32 using namespace std; 29 33 30 34 #include "ParseNode.h" … … 32 36 33 37 char *yyfilename; 34 st d::string *strtext;// accumulate parts of character and string constant value38 string *strtext; // accumulate parts of character and string constant value 35 39 36 40 #define RETURN_LOCN(x) yylval.tok.loc.file = yyfilename; yylval.tok.loc.line = yylineno; return( x ) 37 #define RETURN_VAL(x) yylval.tok.str = new st d::string( yytext ); RETURN_LOCN( x )41 #define RETURN_VAL(x) yylval.tok.str = new string( yytext ); RETURN_LOCN( x ) 38 42 #define RETURN_CHAR(x) yylval.tok.str = nullptr; RETURN_LOCN( x ) 39 43 #define RETURN_STR(x) yylval.tok.str = strtext; RETURN_LOCN( x ) 40 44 41 45 #define WHITE_RETURN(x) // do nothing 42 #define NEWLINE_RETURN() WHITE_RETURN( '\n' )46 #define NEWLINE_RETURN() column = 0; WHITE_RETURN( '\n' ) 43 47 #define ASCIIOP_RETURN() RETURN_CHAR( (int)yytext[0] ) // single character operator 44 48 #define NAMEDOP_RETURN(x) RETURN_CHAR( x ) // multichar operator, with a name … … 154 158 memcpy( &filename, begin_string + 1, length ); // copy file name from yytext 155 159 filename[ length ] = '\0'; // terminate string with sentinel 156 // std::cout << "file " << filename << " line " << lineno << std::endl;160 //cout << "file " << filename << " line " << lineno << endl; 157 161 yylineno = lineno; 158 162 yyfilename = filename; … … 302 306 303 307 /* character constant, allows empty value */ 304 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }308 ({cwide_prefix}[_]?)?['] { BEGIN QUOTE; rm_underscore(); strtext = new string( yytext, yyleng ); } 305 309 <QUOTE>[^'\\\n]* { strtext->append( yytext, yyleng ); } 306 310 <QUOTE>['\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(CHARACTERconstant); } … … 308 312 309 313 /* string constant */ 310 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new st d::string( yytext, yyleng ); }314 ({swide_prefix}[_]?)?["] { BEGIN STRING; rm_underscore(); strtext = new string( yytext, yyleng ); } 311 315 <STRING>[^"\\\n]* { strtext->append( yytext, yyleng ); } 312 316 <STRING>["\n] { BEGIN 0; strtext->append( yytext, yyleng ); RETURN_STR(STRINGliteral); } … … 422 426 } 423 427 424 /* unknown character s*/425 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }428 /* unknown character */ 429 . { yyerror( "unknown character" ); } 426 430 427 431 %% 432 // ----end of lexer---- 433 434 void yyerror( const char * errmsg ) { 435 cout << (yyfilename ? yyfilename : "*unknown file*") << ':' << yylineno << ':' << column - yyleng + 1 436 << ':' << SemanticError::error_str() << errmsg << " at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << '"' << endl; 437 } 428 438 429 439 // Local Variables: // -
src/Parser/parser.yy
rfc1ef62 r9ed4f94 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 28 13:24:10201713 // Update Count : 27 2012 // Last Modified On : Wed Aug 30 07:04:19 2017 13 // Update Count : 2740 14 14 // 15 15 … … 48 48 #include <cstdio> 49 49 #include <stack> 50 using namespace std; 51 50 52 #include "ParseNode.h" 51 53 #include "TypedefTable.h" 52 54 #include "TypeData.h" 53 55 #include "LinkageSpec.h" 54 using namespace std; 56 #include "Common/SemanticError.h" // error_str 55 57 56 58 extern DeclarationNode * parseTree; … … 3133 3135 // ----end of grammar---- 3134 3136 3135 extern char *yytext;3136 3137 void yyerror( const char * ) {3138 if ( yyfilename ) {3139 cout << yyfilename << ":";3140 } // if3141 cout << yylineno << ":1 syntax error at token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << endl;3142 }3143 3144 3137 // Local Variables: // 3145 3138 // mode: c++ //
Note: See TracChangeset
for help on using the changeset viewer.