Changeset 294647b for src/Common
- Timestamp:
- Feb 14, 2017, 2:54:51 PM (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:
- 138e29e
- Parents:
- eafb094
- Location:
- src/Common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
reafb094 r294647b 34 34 35 35 void SemanticError::append( const std::string & msg ) { 36 errors.push_back( std::string( "Error: ") + 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 ); 37 39 } 38 40 … … 45 47 } 46 48 49 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()); 55 } 56 47 57 // Local Variables: // 48 58 // tab-width: 4 // -
src/Common/SemanticError.h
reafb094 r294647b 23 23 #include <iostream> 24 24 25 #include "utility.h" 26 25 27 class SemanticError : public std::exception { 26 28 public: … … 35 37 void print( std::ostream &os ); 36 38 39 void set_location( const CodeLocation& location ); 37 40 // constructs an exception using the given message and the printed 38 41 // representation of the obj (T must have a print method) 39 42 private: 40 43 std::list< std::string > errors; 44 CodeLocation location; 41 45 }; 42 46 -
src/Common/utility.h
reafb094 r294647b 25 25 #include <sstream> 26 26 #include <string> 27 27 28 #include <cassert> 28 29 29 template< typename T > 30 30 static inline T * maybeClone( const T *orig ) { … … 303 303 return group_iterate_t<Args...>(args...); 304 304 } 305 306 struct CodeLocation { 307 int linenumber; 308 std::string filename; 309 310 CodeLocation() 311 : linenumber( -1 ) 312 , filename("") 313 {} 314 315 CodeLocation( const char* filename, int lineno ) 316 : linenumber( lineno ) 317 , filename(filename ? filename : "") 318 {} 319 }; 320 321 inline std::string to_string( const CodeLocation& location ) { 322 return location.filename + ":" + std::to_string(location.linenumber); 323 } 305 324 #endif // _UTILITY_H 306 325
Note: See TracChangeset
for help on using the changeset viewer.