Changeset b3f252a for src/Common
- Timestamp:
- Sep 7, 2017, 10:36:35 AM (8 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:
- e0886db
- Parents:
- 871cdb4 (diff), 416cc86 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/Common
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/CodeLocation.h
r871cdb4 rb3f252a 9 9 // Author : Andrew Beach 10 10 // Created On : Thr Aug 17 11:23:00 2017 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 17 14:07:00201713 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 28 12:46:01 2017 13 // Update Count : 2 14 14 // 15 15 … … 66 66 67 67 inline std::string to_string( const CodeLocation& location ) { 68 return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : ""; 68 // Column number ":1" allows IDEs to parse the error message and position the cursor in the source text. 69 return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + ":1 " : ""; 69 70 } 70 71 -
src/Common/SemanticError.cc
r871cdb4 rb3f252a 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
r871cdb4 rb3f252a 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/Common/utility.h
r871cdb4 rb3f252a 174 174 } 175 175 176 template <typename E, typename UnaryPredicate, template< typename, typename...> class Container, typename... Args > 177 void filter( Container< E *, Args... > & container, UnaryPredicate pred, bool doDelete ) { 178 auto i = begin( container ); 179 while ( i != end( container ) ) { 180 auto it = next( i ); 181 if ( pred( *i ) ) { 182 if ( doDelete ) { 183 delete *i; 184 } // if 185 container.erase( i ); 186 } // if 187 i = it; 188 } // while 189 } 190 176 191 template< typename... Args > 177 192 auto zip(Args&&... args) -> decltype(zipWith(std::forward<Args>(args)..., std::make_pair)) { … … 207 222 std::cerr << "Warning: "; 208 223 warn_single( params... ); 224 } 225 226 /// determines if `pref` is a prefix of `str` 227 static inline bool isPrefix( const std::string & str, const std::string & pref ) { 228 if ( pref.size() > str.size() ) return false; 229 auto its = std::mismatch( pref.begin(), pref.end(), str.begin() ); 230 return its.first == pref.end(); 209 231 } 210 232
Note:
See TracChangeset
for help on using the changeset viewer.