[51587aa] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[3906301] | 7 | // SemanticError.cc -- |
---|
[51587aa] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[01aeade] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Tue May 19 07:21:25 2015 |
---|
| 13 | // Update Count : 1 |
---|
[51587aa] | 14 | // |
---|
[51b7345] | 15 | |
---|
[bf2438c] | 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 |
---|
[51b7345] | 21 | |
---|
[bf2438c] | 22 | #include "Common/utility.h" // for to_string, CodeLocation (ptr only) |
---|
[51b7345] | 23 | #include "SemanticError.h" |
---|
| 24 | |
---|
[138e29e] | 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 | |
---|
[01aeade] | 30 | SemanticError::SemanticError() { |
---|
[51b7345] | 31 | } |
---|
| 32 | |
---|
[01aeade] | 33 | SemanticError::SemanticError( std::string error ) { |
---|
[138e29e] | 34 | append( error ); |
---|
[51b7345] | 35 | } |
---|
| 36 | |
---|
[01aeade] | 37 | void SemanticError::append( SemanticError &other ) { |
---|
[138e29e] | 38 | errors.splice( errors.end(), other.errors ); |
---|
[3906301] | 39 | } |
---|
| 40 | |
---|
| 41 | void SemanticError::append( const std::string & msg ) { |
---|
[138e29e] | 42 | errors.emplace_back( error_str() + msg ); |
---|
[51b7345] | 43 | } |
---|
| 44 | |
---|
[01aeade] | 45 | bool SemanticError::isEmpty() const { |
---|
| 46 | return errors.empty(); |
---|
[51b7345] | 47 | } |
---|
| 48 | |
---|
[01aeade] | 49 | void SemanticError::print( std::ostream &os ) { |
---|
[138e29e] | 50 | using std::to_string; |
---|
| 51 | for(auto err : errors) { |
---|
| 52 | os << to_string( err.location ) << err.description << '\n'; |
---|
| 53 | } |
---|
[51b7345] | 54 | } |
---|
[01aeade] | 55 | |
---|
[294647b] | 56 | void SemanticError::set_location( const CodeLocation& location ) { |
---|
[138e29e] | 57 | errors.begin()->maybeSet( location ); |
---|
[294647b] | 58 | } |
---|
| 59 | |
---|
[51587aa] | 60 | // Local Variables: // |
---|
| 61 | // tab-width: 4 // |
---|
| 62 | // mode: c++ // |
---|
| 63 | // compile-command: "make install" // |
---|
| 64 | // End: // |
---|