Changeset 97f65d5 for src/Common


Ignore:
Timestamp:
Feb 15, 2017, 8:13:49 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Location:
src/Common
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Common/ScopedMap.h

    raa9ee19 r97f65d5  
    230230        }
    231231
     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
    232242        /// Finds the given key in the outermost scope inside the given scope where it occurs
    233243        iterator findNext( const_iterator &it, const Key &key ) {
  • src/Common/SemanticError.cc

    raa9ee19 r97f65d5  
    2222#include "SemanticError.h"
    2323
     24#include <unistd.h>
     25
     26inline const std::string& error_str() {
     27        static std::string str = isatty( fileno(stderr) ) ? "\e[31merror:\e[39m " : "error: ";
     28        return str;
     29}
     30
    2431SemanticError::SemanticError() {
    2532}
    2633
    2734SemanticError::SemanticError( std::string error ) {
    28   append( error );
     35        append( error );
    2936}
    3037
    3138void SemanticError::append( SemanticError &other ) {
    32   errors.splice( errors.end(), other.errors );
     39        errors.splice( errors.end(), other.errors );
    3340}
    3441
    3542void SemanticError::append( const std::string & msg ) {
    36   errors.push_back( std::string( "Error: ") + msg );
     43        errors.emplace_back( error_str() + msg );
    3744}
    3845
     
    4249
    4350void 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
     57void SemanticError::set_location( const CodeLocation& location ) {
     58        errors.begin()->maybeSet( location );
    4559}
    4660
  • src/Common/SemanticError.h

    raa9ee19 r97f65d5  
    2323#include <iostream>
    2424
     25#include "utility.h"
     26
     27struct 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
    2541class SemanticError : public std::exception {
    2642  public:
     
    3551        void print( std::ostream &os );
    3652
     53        void set_location( const CodeLocation& location );
    3754        // constructs an exception using the given message and the printed
    3855        // representation of the obj (T must have a print method)
    3956  private:
    40         std::list< std::string > errors;
     57        std::list< error > errors;
    4158};
    4259
  • src/Common/VectorMap.h

    raa9ee19 r97f65d5  
    3838        typedef const const_value_type* const_pointer;
    3939       
    40         class iterator : public std::iterator< std::bidirectional_iterator_tag,
     40        class iterator : public std::iterator< std::random_access_iterator_tag,
    4141                                               value_type,
    42                                                                                     difference_type,
    43                                                                                         pointer,
    44                                                                                         reference > {
     42                                                                                   difference_type,
     43                                                                                   pointer,
     44                                                                                   reference > {
    4545        friend class VectorMap;
    4646        friend class const_iterator;
     
    7474                iterator operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
    7575
     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
    7699                bool operator== (const iterator& o) const {
    77100                        return data.first == o.data.first && &data.second == &o.data.second;
    78101                }
     102               
    79103                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; }
    80112        };
    81113
     
    118150                const_iterator operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
    119151
     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
    120181                bool operator== (const const_iterator& o) const {
    121182                        return data.first == o.data.first && &data.second == &o.data.second;
    122183                }
     184               
    123185                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; }
    124194        };
    125195
     
    163233};
    164234
     235template<typename T>
     236typename VectorMap<T>::iterator operator+ (typename VectorMap<T>::difference_type i,
     237                                           const typename VectorMap<T>::iterator& it) {
     238        return it + i;
     239}
     240
     241template<typename T>
     242typename 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
    165247#endif // _VECTORMAP_H
    166248
  • src/Common/utility.h

    raa9ee19 r97f65d5  
    2525#include <sstream>
    2626#include <string>
     27
    2728#include <cassert>
    28 
    2929template< typename T >
    3030static inline T * maybeClone( const T *orig ) {
     
    303303        return group_iterate_t<Args...>(args...);
    304304}
     305
     306struct 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
     321inline std::string to_string( const CodeLocation& location ) {
     322        return location.linenumber >= 0 ? location.filename + ":" + std::to_string(location.linenumber) + " " : "";
     323}
    305324#endif // _UTILITY_H
    306325
Note: See TracChangeset for help on using the changeset viewer.