Changeset 97f65d5 for src/Common
- Timestamp:
- Feb 15, 2017, 8:13:49 AM (9 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, stuck-waitfor-destruct, with_gc
- Children:
- e6512c8
- Parents:
- aa9ee19 (diff), 3149e7e (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:
-
- 5 edited
-
ScopedMap.h (modified) (1 diff)
-
SemanticError.cc (modified) (2 diffs)
-
SemanticError.h (modified) (2 diffs)
-
VectorMap.h (modified) (4 diffs)
-
utility.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/ScopedMap.h
raa9ee19 r97f65d5 230 230 } 231 231 232 /// Finds the given key in the provided scope; returns end() for none such 233 iterator findAt( size_type scope, const Key& key ) { 234 typename Scope::iterator val = scopes[scope].find( key ); 235 if ( val != scopes[scope].end() ) return iterator( scopes, val, scope ); 236 return end(); 237 } 238 const_iterator findAt( size_type scope, const Key& key ) const { 239 return const_iterator( const_cast< ScopedMap< Key, Value >* >(this)->findAt( scope, key ) ); 240 } 241 232 242 /// Finds the given key in the outermost scope inside the given scope where it occurs 233 243 iterator findNext( const_iterator &it, const Key &key ) { -
src/Common/SemanticError.cc
raa9ee19 r97f65d5 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 append( error );35 append( error ); 29 36 } 30 37 31 38 void SemanticError::append( SemanticError &other ) { 32 errors.splice( errors.end(), other.errors );39 errors.splice( errors.end(), other.errors ); 33 40 } 34 41 35 42 void SemanticError::append( const std::string & msg ) { 36 errors.push_back( std::string( "Error: ") + msg );43 errors.emplace_back( error_str() + msg ); 37 44 } 38 45 … … 42 49 43 50 void SemanticError::print( std::ostream &os ) { 44 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 } 55 } 56 57 void SemanticError::set_location( const CodeLocation& location ) { 58 errors.begin()->maybeSet( location ); 45 59 } 46 60 -
src/Common/SemanticError.h
raa9ee19 r97f65d5 23 23 #include <iostream> 24 24 25 #include "utility.h" 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 25 41 class SemanticError : public std::exception { 26 42 public: … … 35 51 void print( std::ostream &os ); 36 52 53 void set_location( const CodeLocation& location ); 37 54 // constructs an exception using the given message and the printed 38 55 // representation of the obj (T must have a print method) 39 56 private: 40 std::list< std::string> errors;57 std::list< error > errors; 41 58 }; 42 59 -
src/Common/VectorMap.h
raa9ee19 r97f65d5 38 38 typedef const const_value_type* const_pointer; 39 39 40 class iterator : public std::iterator< std:: bidirectional_iterator_tag,40 class iterator : public std::iterator< std::random_access_iterator_tag, 41 41 value_type, 42 difference_type,43 pointer,44 reference > {42 difference_type, 43 pointer, 44 reference > { 45 45 friend class VectorMap; 46 46 friend class const_iterator; … … 74 74 iterator operator-- (int) { iterator tmp = *this; --(*this); return tmp; } 75 75 76 iterator& operator+= (difference_type i) { 77 // SHENANIGANS: same reasons as operator++ 78 new(&data) value_type{ (data.first + i), *(&data.second + i) }; 79 return *this; 80 } 81 82 iterator operator+ (difference_type i) const { iterator tmp = *this; return tmp += i; } 83 84 iterator& operator-= (difference_type i) { 85 // SHENANIGANS: same reasons as operator++ 86 new(&data) value_type{ (data.first - i), *(&data.second - i) }; 87 return *this; 88 } 89 90 iterator operator- (difference_type i) const { iterator tmp = *this; return tmp -= i; } 91 92 difference_type operator- (const iterator& o) const { return data.first - o.data.first; } 93 94 value_type operator[] (difference_type i) const { 95 // SHENANIGANS: same reasons as operator++ 96 return value_type{ (data.first + i), *(&data.second + i) }; 97 } 98 76 99 bool operator== (const iterator& o) const { 77 100 return data.first == o.data.first && &data.second == &o.data.second; 78 101 } 102 79 103 bool operator!= (const iterator& that) const { return !(*this == that); } 104 105 bool operator< (const iterator& o) const { return data.first < o.data.first; } 106 107 bool operator> (const iterator& o) const { return data.first > o.data.first; } 108 109 bool operator<= (const iterator& o) const { return data.first <= o.data.first; } 110 111 bool operator>= (const iterator& o) const { return data.first >= o.data.first; } 80 112 }; 81 113 … … 118 150 const_iterator operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; } 119 151 152 const_iterator& operator+= (difference_type i) { 153 // SHENANIGANS: same reasons as iterator::operator++ 154 new(&data) const_value_type{ (data.first + i), *(&data.second + i) }; 155 return *this; 156 } 157 158 const_iterator operator+ (difference_type i) const { 159 const_iterator tmp = *this; return tmp += i; 160 } 161 162 const_iterator& operator-= (difference_type i) { 163 // SHENANIGANS: same reasons as iterator::operator++ 164 new(&data) const_value_type{ (data.first - i), *(&data.second - i) }; 165 return *this; 166 } 167 168 const_iterator operator- (difference_type i) const { 169 const_iterator tmp = *this; return tmp -= i; 170 } 171 172 difference_type operator- (const const_iterator& o) const { 173 return data.first - o.data.first; 174 } 175 176 const_value_type operator[] (difference_type i) const { 177 // SHENANIGANS: same reasons as iterator::operator++ 178 return const_value_type{ (data.first + i), *(&data.second + i) }; 179 } 180 120 181 bool operator== (const const_iterator& o) const { 121 182 return data.first == o.data.first && &data.second == &o.data.second; 122 183 } 184 123 185 bool operator!= (const const_iterator& that) const { return !(*this == that); } 186 187 bool operator< (const const_iterator& o) const { return data.first < o.data.first; } 188 189 bool operator> (const const_iterator& o) const { return data.first > o.data.first; } 190 191 bool operator<= (const const_iterator& o) const { return data.first <= o.data.first; } 192 193 bool operator>= (const const_iterator& o) const { return data.first >= o.data.first; } 124 194 }; 125 195 … … 163 233 }; 164 234 235 template<typename T> 236 typename VectorMap<T>::iterator operator+ (typename VectorMap<T>::difference_type i, 237 const typename VectorMap<T>::iterator& it) { 238 return it + i; 239 } 240 241 template<typename T> 242 typename VectorMap<T>::const_iterator operator+ (typename VectorMap<T>::difference_type i, 243 const typename VectorMap<T>::const_iterator& it) { 244 return it + i; 245 } 246 165 247 #endif // _VECTORMAP_H 166 248 -
src/Common/utility.h
raa9ee19 r97f65d5 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.linenumber >= 0 ? 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.