source: src/Common/SemanticError.h@ 61255ad

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 61255ad was d48e529, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Begin to introduce support for yylloc in the parser and extend CodeLocation to include start column and end column/line number information

  • Property mode set to 100644
File size: 1.9 KB
Line 
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 : Tue Aug 29 22:03:36 2017
13// Update Count : 17
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#include <unistd.h> // for isatty
23
24#include "CodeLocation.h" // for CodeLocation, toString
25
26struct 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.isUnset() ) {
35 this->location = location;
36 }
37 }
38};
39
40class 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 static inline const std::string & error_str() {
48 static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
49 return str;
50 }
51
52 void append( SemanticError & other );
53 void append( const std::string & );
54 bool isEmpty() const;
55 void print( std::ostream & os );
56
57 void set_location( const CodeLocation & location );
58 // constructs an exception using the given message and the printed representation of the obj (T must have a print
59 // method)
60 private:
61 std::list< error > errors;
62};
63
64template< typename T >
65SemanticError::SemanticError( const std::string & error, const T * obj ) {
66 append( toString( error, obj ) );
67}
68
69// Local Variables: //
70// tab-width: 4 //
71// mode: c++ //
72// compile-command: "make install" //
73// End: //
Note: See TracBrowser for help on using the repository browser.