[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
|
---|
[21f0aa8] | 11 | // Last Modified By : Andrew Beach
|
---|
| 12 | // Last Modified On : Thr Aug 17 14:01:00 2017
|
---|
| 13 | // Update Count : 7
|
---|
[51587aa] | 14 | //
|
---|
[51b73452] | 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[51b73452] | 17 |
|
---|
[bf2438c] | 18 | #include <exception> // for exception
|
---|
| 19 | #include <iostream> // for ostream
|
---|
| 20 | #include <list> // for list
|
---|
| 21 | #include <string> // for string
|
---|
[51b73452] | 22 |
|
---|
[21f0aa8] | 23 | #include "CodeLocation.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;
|
---|
[51b73452] | 56 | };
|
---|
| 57 |
|
---|
| 58 | template< typename T >
|
---|
[01aeade] | 59 | SemanticError::SemanticError( const std::string &error, const T *obj ) {
|
---|
[3906301] | 60 | append( toString( error, obj ) );
|
---|
[51b73452] | 61 | }
|
---|
| 62 |
|
---|
[51587aa] | 63 | // Local Variables: //
|
---|
| 64 | // tab-width: 4 //
|
---|
| 65 | // mode: c++ //
|
---|
| 66 | // compile-command: "make install" //
|
---|
| 67 | // End: //
|
---|