Changeset 138e29e
- Timestamp:
- Feb 14, 2017, 3:53:52 PM (6 years ago)
- Branches:
- aaron-thesis, arm-eh, 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:
- 9bb90a86
- Parents:
- 294647b
- Location:
- src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
r294647b r138e29e 22 22 #include "SemanticError.h" 23 23 24 #include <unistd.h> 25 26 inline const std::string& error_str() { 27 static std::string str = isatty( fileno(stderr) ) ? "\e[31merror:\e[39m " : "error: "; 28 return str; 29 } 30 24 31 SemanticError::SemanticError() { 25 32 } 26 33 27 34 SemanticError::SemanticError( std::string error ) { 28 35 append( error ); 29 36 } 30 37 31 38 void SemanticError::append( SemanticError &other ) { 32 39 errors.splice( errors.end(), other.errors ); 33 40 } 34 41 35 42 void SemanticError::append( const std::string & msg ) { 36 using std::to_string; 37 const std::string loc = location.linenumber >= 0 ? "At \"" + to_string(location) + "\" " : ""; 38 errors.push_back( loc + "Error: " + msg ); 43 errors.emplace_back( error_str() + msg ); 39 44 } 40 45 … … 44 49 45 50 void SemanticError::print( std::ostream &os ) { 46 std::copy( errors.begin(), errors.end(), std::ostream_iterator< std::string >( os, "\n" ) ); 51 using std::to_string; 52 for(auto err : errors) { 53 os << to_string( err.location ) << err.description << '\n'; 54 } 47 55 } 48 56 49 57 void SemanticError::set_location( const CodeLocation& location ) { 50 this->location = location; 51 using std::to_string; 52 const std::string loc = location.linenumber >= 0 ? "At \"" + to_string(location) + "\" " : ""; 53 auto& error = *errors.begin(); 54 error.insert( 0, loc.c_str()); 58 errors.begin()->maybeSet( location ); 55 59 } 56 60 -
src/Common/SemanticError.h
r294647b r138e29e 25 25 #include "utility.h" 26 26 27 struct error { 28 std::string description; 29 CodeLocation location; 30 31 error() = default; 32 error( const std::string& str ) : description( str ) {} 33 34 void maybeSet( const CodeLocation& location ) { 35 if( this->location.linenumber < 0 ) { 36 this->location = location; 37 } 38 } 39 }; 40 27 41 class SemanticError : public std::exception { 28 42 public: … … 41 55 // representation of the obj (T must have a print method) 42 56 private: 43 std::list< std::string > errors; 44 CodeLocation location; 57 std::list< error > errors; 45 58 }; 46 59 -
src/Common/utility.h
r294647b r138e29e 320 320 321 321 inline std::string to_string( const CodeLocation& location ) { 322 return location. filename + ":" + std::to_string(location.linenumber);322 return location.linenumber >= 0 ? location.filename + ":" + std::to_string(location.linenumber) + " " : ""; 323 323 } 324 324 #endif // _UTILITY_H -
src/GenPoly/Box.cc
r294647b r138e29e 236 236 } // if 237 237 } catch( SemanticError &e ) { 238 e.set_location( (*i)->location ); 238 239 errors.append( e ); 239 240 } // try -
src/InitTweak/FixInit.cc
r294647b r138e29e 313 313 translationUnit.splice( i, fixer.staticDtorDecls ); 314 314 } catch( SemanticError &e ) { 315 e.set_location( (*i)->location ); 315 316 errors.append( e ); 316 317 } // try -
src/Parser/DeclarationNode.cc
r294647b r138e29e 988 988 * out++ = cur->buildType(); 989 989 } catch( SemanticError &e ) { 990 e.set_location( cur->location ); 990 991 errors.append( e ); 991 992 } // try -
src/ResolvExpr/Resolver.cc
r294647b r138e29e 86 86 Resolver resolver; 87 87 acceptAll( translationUnit, resolver ); 88 #if 089 resolver.print( cerr );90 for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) {91 (*i)->print( std::cerr );92 (*i)->accept( resolver );93 } // for94 #endif95 88 } 96 89 -
src/SynTree/Mutator.h
r294647b r138e29e 139 139 } // if 140 140 } catch( SemanticError &e ) { 141 e.set_location( (*i)->location ); 141 142 errors.append( e ); 142 143 } // try -
src/SynTree/Type.h
r294647b r138e29e 17 17 #define TYPE_H 18 18 19 #include "BaseSyntaxNode.h" 20 #include "Mutator.h" 19 21 #include "SynTree.h" 20 22 #include "Visitor.h" 21 #include "Mutator.h"22 23 #include "Common/utility.h" 23 24 24 class Type {25 class Type : public BaseSyntaxNode { 25 26 public: 26 27 struct Qualifiers { -
src/SynTree/Visitor.h
r294647b r138e29e 133 133 } 134 134 } catch( SemanticError &e ) { 135 e.set_location( (*i)->location ); 135 136 errors.append( e ); 136 137 } … … 159 160 } // if 160 161 } catch( SemanticError &e ) { 162 e.set_location( (*i)->location ); 161 163 errors.append( e ); 162 164 } // try
Note: See TracChangeset
for help on using the changeset viewer.