| 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 | // ErrorObjects.h --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Thierry Delisle
 | 
|---|
| 10 | // Created On       : Wed Feb 28 15:16:47 2018
 | 
|---|
| 11 | // Last Modified By :
 | 
|---|
| 12 | // Last Modified On :
 | 
|---|
| 13 | // Update Count     :
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #pragma once
 | 
|---|
| 17 | 
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include <exception>    // for exception
 | 
|---|
| 20 | #include <iostream>     // for ostream
 | 
|---|
| 21 | #include <list>         // for list
 | 
|---|
| 22 | #include <string>               // for string
 | 
|---|
| 23 | #include <unistd.h>     // for isatty
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include "CodeLocation.h"                                                               // for CodeLocation, toString
 | 
|---|
| 26 | 
 | 
|---|
| 27 | struct error {
 | 
|---|
| 28 |         CodeLocation location;
 | 
|---|
| 29 |         std::string description;
 | 
|---|
| 30 | 
 | 
|---|
| 31 |         error() = default;
 | 
|---|
| 32 |         error( CodeLocation loc, const std::string & str ) : location( loc ), description( str ) {}
 | 
|---|
| 33 | };
 | 
|---|
| 34 | 
 | 
|---|
| 35 | class SemanticErrorException : public std::exception {
 | 
|---|
| 36 |   public:
 | 
|---|
| 37 |         SemanticErrorException() = default;
 | 
|---|
| 38 |         SemanticErrorException( CodeLocation location, std::string error );
 | 
|---|
| 39 |         ~SemanticErrorException() throw() {}
 | 
|---|
| 40 | 
 | 
|---|
| 41 |         void append( SemanticErrorException & other );
 | 
|---|
| 42 |         void append( CodeLocation location, const std::string & );
 | 
|---|
| 43 |         bool isEmpty() const;
 | 
|---|
| 44 |         void print();
 | 
|---|
| 45 |   private:
 | 
|---|
| 46 |         std::list< error > errors;
 | 
|---|
| 47 | };
 | 
|---|
| 48 | 
 | 
|---|
| 49 | void SemanticWarningImpl( CodeLocation location, std::string error );
 | 
|---|
| 50 | 
 | 
|---|
| 51 | template< typename T >
 | 
|---|
| 52 | static inline void SemanticWarningImpl( const T * obj, const std::string & error ) {
 | 
|---|
| 53 |         SemanticWarning( obj->location, toString( error, obj ) );
 | 
|---|
| 54 | }
 | 
|---|
| 55 | 
 | 
|---|
| 56 | template< typename T >
 | 
|---|
| 57 | static inline void SemanticWarningImpl( CodeLocation location, const T * obj, const std::string & error ) {
 | 
|---|
| 58 |         SemanticWarningImpl( location, toString( error, obj ) );
 | 
|---|
| 59 | }
 | 
|---|