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 | // |
---|
7 | // SemanticError.h -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Mon May 18 07:44:20 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Fri Jul 21 22:18:59 2017 |
---|
13 | // Update Count : 6 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <exception> // for exception |
---|
19 | #include <iostream> // for ostream |
---|
20 | #include <list> // for list |
---|
21 | #include <string> // for string |
---|
22 | |
---|
23 | #include "utility.h" // for CodeLocation, toString |
---|
24 | |
---|
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 | |
---|
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 ); |
---|
47 | void append( const std::string & ); |
---|
48 | bool isEmpty() const; |
---|
49 | void print( std::ostream &os ); |
---|
50 | |
---|
51 | void set_location( const CodeLocation& location ); |
---|
52 | // constructs an exception using the given message and the printed |
---|
53 | // representation of the obj (T must have a print method) |
---|
54 | private: |
---|
55 | std::list< error > errors; |
---|
56 | }; |
---|
57 | |
---|
58 | template< typename T > |
---|
59 | SemanticError::SemanticError( const std::string &error, const T *obj ) { |
---|
60 | append( toString( error, obj ) ); |
---|
61 | } |
---|
62 | |
---|
63 | // Local Variables: // |
---|
64 | // tab-width: 4 // |
---|
65 | // mode: c++ // |
---|
66 | // compile-command: "make install" // |
---|
67 | // End: // |
---|