[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.h -- |
---|
[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 |
---|
[fb114fa1] | 12 | // Last Modified On : Sat Sep 24 15:13:42 2016 |
---|
| 13 | // Update Count : 5 |
---|
[51587aa] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #ifndef SEMANTICERROR_H |
---|
| 17 | #define SEMANTICERROR_H |
---|
| 18 | |
---|
[bf2438c] | 19 | #include <exception> // for exception |
---|
| 20 | #include <iostream> // for ostream |
---|
| 21 | #include <list> // for list |
---|
| 22 | #include <string> // for string |
---|
[51b7345] | 23 | |
---|
[bf2438c] | 24 | #include "utility.h" // for CodeLocation, toString |
---|
[294647b] | 25 | |
---|
[138e29e] | 26 | struct error { |
---|
| 27 | std::string description; |
---|
| 28 | CodeLocation location; |
---|
| 29 | |
---|
| 30 | error() = default; |
---|
| 31 | error( const std::string& str ) : description( str ) {} |
---|
| 32 | |
---|
| 33 | void maybeSet( const CodeLocation& location ) { |
---|
| 34 | if( this->location.linenumber < 0 ) { |
---|
| 35 | this->location = location; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | }; |
---|
| 39 | |
---|
[01aeade] | 40 | class SemanticError : public std::exception { |
---|
| 41 | public: |
---|
| 42 | SemanticError(); |
---|
| 43 | SemanticError( std::string error ); |
---|
| 44 | template< typename T > SemanticError( const std::string &error, const T *obj ); |
---|
| 45 | ~SemanticError() throw() {} |
---|
| 46 | |
---|
| 47 | void append( SemanticError &other ); |
---|
[3906301] | 48 | void append( const std::string & ); |
---|
[01aeade] | 49 | bool isEmpty() const; |
---|
| 50 | void print( std::ostream &os ); |
---|
| 51 | |
---|
[294647b] | 52 | void set_location( const CodeLocation& location ); |
---|
[01aeade] | 53 | // constructs an exception using the given message and the printed |
---|
| 54 | // representation of the obj (T must have a print method) |
---|
| 55 | private: |
---|
[138e29e] | 56 | std::list< error > errors; |
---|
[51b7345] | 57 | }; |
---|
| 58 | |
---|
| 59 | template< typename T > |
---|
[01aeade] | 60 | SemanticError::SemanticError( const std::string &error, const T *obj ) { |
---|
[3906301] | 61 | append( toString( error, obj ) ); |
---|
[51b7345] | 62 | } |
---|
| 63 | |
---|
[01aeade] | 64 | #endif // SEMANTICERROR_H |
---|
| 65 | |
---|
[51587aa] | 66 | // Local Variables: // |
---|
| 67 | // tab-width: 4 // |
---|
| 68 | // mode: c++ // |
---|
| 69 | // compile-command: "make install" // |
---|
| 70 | // End: // |
---|