Changeset 01aeade for translator/Common
- Timestamp:
- May 19, 2015, 7:57:09 AM (11 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- a08ba92
- Parents:
- 51587aa
- Location:
- translator/Common
- Files:
-
- 7 edited
-
CompilerError.h (modified) (2 diffs)
-
SemanticError.cc (modified) (2 diffs)
-
SemanticError.h (modified) (2 diffs)
-
UnimplementedError.h (modified) (1 diff)
-
UniqueName.cc (modified) (2 diffs)
-
UniqueName.h (modified) (2 diffs)
-
utility.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/Common/CompilerError.h
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // CompilerError.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:20:37 2015 13 // Update Count : 2 14 14 // 15 15 16 #ifndef COMPILER_ERROR_H 16 17 #define COMPILER_ERROR_H … … 19 20 //#include "../config.h" 20 21 21 class CompilerError : public std::exception 22 { 23 public: 24 CompilerError(); 25 CompilerError( std::string what ) : what( what ) {} 26 ~CompilerError() throw () {} 22 class CompilerError : public std::exception { 23 public: 24 CompilerError(); 25 CompilerError( std::string what ) : what( what ) {} 26 ~CompilerError() throw () {} 27 27 28 std::string get_what() const { return what; } 29 void set_what( std::string newValue ) { what = newValue; } 30 31 private: 32 std::string what; 28 std::string get_what() const { return what; } 29 void set_what( std::string newValue ) { what = newValue; } 30 private: 31 std::string what; 33 32 }; 34 33 35 #endif / * COMPILER_ERROR_H */34 #endif // COMPILER_ERROR_H 36 35 37 /*38 Local Variables:39 mode: c++40 End:41 */42 36 // Local Variables: // 43 37 // tab-width: 4 // -
translator/Common/SemanticError.cc
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // SemanticError.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:21:25 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: SemanticError.cc,v 1.1 2002/04/27 19:57:10 rcbilson Exp $19 *20 */21 15 22 16 #include <iostream> … … 28 22 #include "SemanticError.h" 29 23 30 SemanticError::SemanticError() 31 { 24 SemanticError::SemanticError() { 32 25 } 33 26 34 SemanticError::SemanticError( std::string error ) 35 { 36 errors.push_back( std::string( "Error: " ) + error ); 27 SemanticError::SemanticError( std::string error ) { 28 errors.push_back( std::string( "Error: " ) + error ); 37 29 } 38 30 39 void 40 SemanticError::append( SemanticError &other ) 41 { 42 errors.splice( errors.end(), other.errors ); 31 void SemanticError::append( SemanticError &other ) { 32 errors.splice( errors.end(), other.errors ); 43 33 } 44 34 45 bool 46 SemanticError::isEmpty() const 47 { 48 return errors.empty(); 35 bool SemanticError::isEmpty() const { 36 return errors.empty(); 49 37 } 50 38 51 void 52 SemanticError::print( std::ostream &os ) 53 { 54 std::copy( errors.begin(), errors.end(), std::ostream_iterator< std::string >( os, "\n" ) ); 39 void SemanticError::print( std::ostream &os ) { 40 std::copy( errors.begin(), errors.end(), std::ostream_iterator< std::string >( os, "\n" ) ); 55 41 } 42 56 43 // Local Variables: // 57 44 // tab-width: 4 // -
translator/Common/SemanticError.h
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // SemanticError.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:22:23 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: SemanticError.h,v 1.1 2002/04/27 19:57:10 rcbilson Exp $19 *20 */21 15 22 16 #ifndef SEMANTICERROR_H … … 29 23 #include <iostream> 30 24 31 class SemanticError : public std::exception 32 { 33 public: 34 SemanticError(); 35 SemanticError( std::string error ); 36 template< typename T > SemanticError( const std::string &error, const T *obj ); 37 ~SemanticError() throw() {} 25 class SemanticError : public std::exception { 26 public: 27 SemanticError(); 28 SemanticError( std::string error ); 29 template< typename T > SemanticError( const std::string &error, const T *obj ); 30 ~SemanticError() throw() {} 38 31 39 void append( SemanticError &other );40 bool isEmpty() const;41 void print( std::ostream &os );32 void append( SemanticError &other ); 33 bool isEmpty() const; 34 void print( std::ostream &os ); 42 35 43 // constructs an exception using the given message and the printed 44 // representation of the obj (T must have a print method) 45 46 private: 47 std::list< std::string > errors; 36 // constructs an exception using the given message and the printed 37 // representation of the obj (T must have a print method) 38 private: 39 std::list< std::string > errors; 48 40 }; 49 41 50 42 template< typename T > 51 SemanticError::SemanticError( const std::string &error, const T *obj ) 52 { 53 std::ostrstream os; 54 os << "Error: " << error; 55 obj->print( os ); 56 errors.push_back( std::string( os.str(), os.pcount() ) ); 43 SemanticError::SemanticError( const std::string &error, const T *obj ) { 44 std::ostrstream os; 45 os << "Error: " << error; 46 obj->print( os ); 47 errors.push_back( std::string( os.str(), os.pcount() ) ); 57 48 } 58 49 59 #endif /* SEMANTICERROR_H */ 50 #endif // SEMANTICERROR_H 51 60 52 // Local Variables: // 61 53 // tab-width: 4 // -
translator/Common/UnimplementedError.h
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // UnimplementedError.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:23:08 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: UnimplementedError.h,v 1.1 2002/09/02 20:31:53 rcbilson Exp $19 *20 */21 15 22 #ifndef COMMON_UNIMPLEMENTEDERROR_H23 #define COMMON_UNIMPLEMENTEDERROR_H16 #ifndef _UNIMPLEMENTEDERROR_H 17 #define _UNIMPLEMENTEDERROR_H 24 18 25 19 #include <string> 26 20 27 class UnimplementedError : public std::exception 28 { 29 public: 30 UnimplementedError(); 31 UnimplementedError( std::string what ) : what( what ) {} 32 ~UnimplementedError() throw () {} 21 class UnimplementedError : public std::exception { 22 public: 23 UnimplementedError(); 24 UnimplementedError( std::string what ) : what( what ) {} 25 ~UnimplementedError() throw () {} 33 26 34 std::string get_what() const { return what; } 35 void set_what( std::string newValue ) { what = newValue; } 36 37 private: 38 std::string what; 27 std::string get_what() const { return what; } 28 void set_what( std::string newValue ) { what = newValue; } 29 private: 30 std::string what; 39 31 }; 40 32 41 #endif /* #ifndef COMMON_UNIMPLEMENTEDERROR_H */ 33 #endif // _UNIMPLEMENTEDERROR_H 34 42 35 // Local Variables: // 43 36 // tab-width: 4 // -
translator/Common/UniqueName.cc
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc --7 // UniqueName.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:23:41 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: UniqueName.cc,v 1.1 2002/04/30 03:30:14 rcbilson Exp $19 *20 */21 15 22 16 #include <string> … … 25 19 #include "UniqueName.h" 26 20 27 UniqueName::UniqueName( const std::string &base ) 28 : base( base ), count( 0 ) 29 { 21 UniqueName::UniqueName( const std::string &base ) : base( base ), count( 0 ) { 30 22 } 31 23 32 std::string 33 UniqueName::newName( const std::string &additional ) 34 { 35 std::ostrstream os; 36 os << base << additional << count++; 37 return std::string( os.str(), os.pcount() ); 24 std::string UniqueName::newName( const std::string &additional ) { 25 std::ostrstream os; 26 os << base << additional << count++; 27 return std::string( os.str(), os.pcount() ); 38 28 } 39 29 -
translator/Common/UniqueName.h
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // UniqueName.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:24:20 2015 13 // Update Count : 1 14 14 // 15 /*16 * This file is part of the Cforall project17 *18 * $Id: UniqueName.h,v 1.1 2002/04/30 03:30:14 rcbilson Exp $19 *20 */21 15 22 16 #ifndef UNIQUENAME_H … … 25 19 #include <string> 26 20 27 class UniqueName 28 { 29 public: 30 UniqueName( const std::string &base = "" ); 31 32 std::string newName( const std::string &additional = "" ); 33 34 private: 35 std::string base; 36 int count; 21 class UniqueName { 22 public: 23 UniqueName( const std::string &base = "" ); 24 std::string newName( const std::string &additional = "" ); 25 private: 26 std::string base; 27 int count; 37 28 }; 38 29 39 #endif /* #ifndef UNIQUENAME_H */ 30 #endif // UNIQUENAME_H 31 40 32 // Local Variables: // 41 33 // tab-width: 4 // -
translator/Common/utility.h
r51587aa r01aeade 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // XXX.cc--7 // utility.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 0 14 // 15 /* 16 * This file is part of the Cforall project 17 * 18 * Some useful template utility functions 19 * 20 * $Id: utility.h,v 1.17 2003/11/26 18:05:21 rgesteve Exp $ 21 * 22 */ 23 24 #ifndef COMMON_UTILITY_H 25 #define COMMON_UTILITY_H 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 07:27:38 2015 13 // Update Count : 2 14 // 15 16 #ifndef _UTILITY_H 17 #define _UTILITY_H 26 18 27 19 #include <iostream> … … 33 25 34 26 template< typename T > 35 static inline T* 36 maybeClone( const T *orig ) 37 { 38 if ( orig ) { 39 return orig->clone(); 40 } else { 41 return 0; 42 } 27 static inline T * maybeClone( const T *orig ) { 28 if ( orig ) { 29 return orig->clone(); 30 } else { 31 return 0; 32 } // if 43 33 } 44 34 45 35 template< typename T, typename U > 46 static inline T* 47 maybeBuild( const U *orig ) 48 { 49 if ( orig ) { 50 return orig->build(); 51 } else { 52 return 0; 53 } 36 static inline T * maybeBuild( const U *orig ) { 37 if ( orig ) { 38 return orig->build(); 39 } else { 40 return 0; 41 } // if 54 42 } 55 43 56 44 template< typename Input_iterator > 57 void 58 printEnums( Input_iterator begin, Input_iterator end, const char * const *name_array, std::ostream &os ) 59 { 60 for ( Input_iterator i = begin; i != end; ++i ) { 61 os << name_array[ *i ] << ' '; 62 } 45 void printEnums( Input_iterator begin, Input_iterator end, const char * const *name_array, std::ostream &os ) { 46 for ( Input_iterator i = begin; i != end; ++i ) { 47 os << name_array[ *i ] << ' '; 48 } // for 63 49 } 64 50 65 51 template< typename Container > 66 void 67 deleteAll( Container &container ) 68 { 69 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 70 delete *i; 71 } 52 void deleteAll( Container &container ) { 53 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 54 delete *i; 55 } // for 72 56 } 73 57 74 58 template< typename Container > 75 void 76 printAll( const Container &container, std::ostream &os, int indent = 0 ) 77 { 78 for ( typename Container::const_iterator i = container.begin(); i != container.end(); ++i ) { 79 if ( *i ) { 80 os << std::string(indent, ' '); 81 (*i)->print( os, indent + 2 ); 82 os << std::endl; 83 } 84 } 59 void printAll( const Container &container, std::ostream &os, int indent = 0 ) { 60 for ( typename Container::const_iterator i = container.begin(); i != container.end(); ++i ) { 61 if ( *i ) { 62 os << std::string(indent, ' '); 63 (*i)->print( os, indent + 2 ); 64 os << std::endl; 65 } // if 66 } // for 85 67 } 86 68 87 69 template< typename SrcContainer, typename DestContainer > 88 void 89 cloneAll( const SrcContainer &src, DestContainer &dest ) 90 { 91 typename SrcContainer::const_iterator in = src.begin(); 92 std::back_insert_iterator< DestContainer > out( dest ); 93 while ( in != src.end() ) { 94 *out++ = (*in++)->clone(); 95 } 70 void cloneAll( const SrcContainer &src, DestContainer &dest ) { 71 typename SrcContainer::const_iterator in = src.begin(); 72 std::back_insert_iterator< DestContainer > out( dest ); 73 while ( in != src.end() ) { 74 *out++ = (*in++)->clone(); 75 } // while 96 76 } 97 77 98 78 template< typename Container > 99 void 100 assertAll( const Container &container ) 101 { 102 int count = 0; 103 for ( typename Container::const_iterator i = container.begin(); i != container.end(); ++i ) { 104 if ( !(*i) ) { 105 std::cerr << count << " is null" << std::endl; 106 } 107 } 108 } 109 110 static inline std::string 111 assign_strptr( std::string *str ) 112 { 113 if ( str == 0 ) { 114 return ""; 115 } else { 116 std::string tmp; 117 tmp = *str; 118 delete str; 119 return tmp; 120 } 79 void assertAll( const Container &container ) { 80 int count = 0; 81 for ( typename Container::const_iterator i = container.begin(); i != container.end(); ++i ) { 82 if ( !(*i) ) { 83 std::cerr << count << " is null" << std::endl; 84 } // if 85 } // for 86 } 87 88 static inline std::string assign_strptr( std::string *str ) { 89 if ( str == 0 ) { 90 return ""; 91 } else { 92 std::string tmp; 93 tmp = *str; 94 delete str; 95 return tmp; 96 } // if 121 97 } 122 98 123 99 template< class T, typename ResultType, ResultType (T::* memfunc)() > 124 ResultType dispatch( T *pT){125 return (pT->*memfunc)();100 ResultType dispatch( T *pT ) { 101 return (pT->*memfunc)(); 126 102 } 127 103 128 104 template < typename T > 129 std::list<T> tail( std::list<T> l ) 130 { 131 if (! l.empty()){ 132 std::list<T> ret(++(l.begin()), l.end()); 133 return ret; 134 } 105 std::list<T> tail( std::list<T> l ) { 106 if ( ! l.empty() ) { 107 std::list<T> ret(++(l.begin()), l.end()); 108 return ret; 109 } // if 135 110 } 136 111 137 112 template < typename T > 138 113 std::list<T> flatten( std::list < std::list<T> > l) { 139 typedef std::list <T> Ts;140 141 Ts ret;142 143 switch ( l.size() ){144 case 0:145 return ret;146 case 1:147 return l.front();148 default:149 ret = flatten(tail(l));150 ret.insert(ret.begin(), l.front().begin(), l.front().end());151 return ret;152 } 114 typedef std::list <T> Ts; 115 116 Ts ret; 117 118 switch ( l.size() ){ 119 case 0: 120 return ret; 121 case 1: 122 return l.front(); 123 default: 124 ret = flatten(tail(l)); 125 ret.insert(ret.begin(), l.front().begin(), l.front().end()); 126 return ret; 127 } // switch 153 128 } 154 129 155 130 template < typename T > 156 131 std::string toString ( T value ) { 157 std::ostrstream os;132 std::ostrstream os; 158 133 159 os << value; // << std::ends;160 os.freeze( false );161 162 return std::string(os.str(), os.pcount());134 os << value; // << std::ends; 135 os.freeze( false ); 136 137 return std::string(os.str(), os.pcount()); 163 138 } 164 139 165 140 template< class Constructed, typename Arg > 166 141 Constructed *ctor( Arg arg ) { 167 Constructed *c = new Constructed( arg );168 return c;142 Constructed *c = new Constructed( arg ); 143 return c; 169 144 } 170 145 171 146 template< class Constructed, typename Arg > 172 147 Constructed ctor_noptr( Arg arg ) { 173 return Constructed( arg );148 return Constructed( arg ); 174 149 } 175 150 176 151 template< typename T > 177 152 void replace( std::list< T > &org, typename std::list< T >::iterator pos, std::list< T > &with ) { 178 // TIter should secretly be a typename std::list< T >::iterator179 // ( g++ 3.2 issues a 'is implicitly a typename' warning if I make this explicit )180 typename std::list< T >::iterator next = pos; advance( next, 1 );181 182 //if ( next != org.end() ) {153 // TIter should secretly be a typename std::list< T >::iterator 154 // ( g++ 3.2 issues a 'is implicitly a typename' warning if I make this explicit ) 155 typename std::list< T >::iterator next = pos; advance( next, 1 ); 156 157 //if ( next != org.end() ) { 183 158 org.erase( pos ); 184 159 org.splice( next, with ); 185 160 //} 186 161 187 return;162 return; 188 163 } 189 164 190 165 template< typename T1, typename T2 > 191 166 T2 *cast_ptr( T1 *from ) { 192 return dynamic_cast< T2 * >( from );167 return dynamic_cast< T2 * >( from ); 193 168 } 194 169 195 170 template< class Exception, typename Arg > 196 171 void inline assert_throw( bool pred, Arg arg ) { 197 if (pred) throw Exception( arg );172 if (pred) throw Exception( arg ); 198 173 } 199 174 200 175 template< typename T > 201 176 struct is_null_pointer { 202 bool operator()( const T *ptr ){ return ( ptr == 0 ); }177 bool operator()( const T *ptr ){ return ( ptr == 0 ); } 203 178 }; 204 179 205 180 template< class InputIterator, class OutputIterator, class Predicate > 206 void filter(InputIterator begin, InputIterator end, OutputIterator out, Predicate pred) 207 { 208 while ( begin++ != end ) 209 if ( pred(*begin) ) *out++ = *begin; 210 211 return; 181 void filter(InputIterator begin, InputIterator end, OutputIterator out, Predicate pred) { 182 while ( begin++ != end ) 183 if ( pred(*begin) ) *out++ = *begin; 184 185 return; 212 186 } 213 187 214 188 template< class InputIterator1, class InputIterator2, class OutputIterator > 215 189 void zip( InputIterator1 b1, InputIterator1 e1, InputIterator2 b2, InputIterator2 e2, OutputIterator out ) { 216 while ( b1 != e1 && b2 != e2 )217 *out++ = std::pair<typename InputIterator1::value_type, typename InputIterator2::value_type>(*b1++, *b2++);190 while ( b1 != e1 && b2 != e2 ) 191 *out++ = std::pair<typename InputIterator1::value_type, typename InputIterator2::value_type>(*b1++, *b2++); 218 192 } 219 193 220 194 template< class InputIterator1, class InputIterator2, class OutputIterator, class BinFunction > 221 195 void zipWith( InputIterator1 b1, InputIterator1 e1, InputIterator2 b2, InputIterator2 e2, OutputIterator out, BinFunction func ) { 222 while ( b1 != e1 && b2 != e2 ) 223 *out++ = func(*b1++, *b2++); 224 } 225 226 #endif /* #ifndef COMMON_UTILITY_H */ 227 228 /* 229 Local Variables: 230 mode: c++ 231 End: 232 */ 196 while ( b1 != e1 && b2 != e2 ) 197 *out++ = func(*b1++, *b2++); 198 } 199 200 #endif // _UTILITY_H 201 233 202 // Local Variables: // 234 203 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.