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