source: src/Common/SemanticError.h@ 633a642

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 633a642 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
RevLine 
[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
[9ed4f94]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Aug 29 22:03:36 2017
13// Update Count : 17
[51587aa]14//
[51b73452]15
[6b0b624]16#pragma once
[51b73452]17
[9ed4f94]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
[51b73452]23
[9ed4f94]24#include "CodeLocation.h" // for CodeLocation, toString
[294647b]25
[138e29e]26struct error {
27 std::string description;
28 CodeLocation location;
29
30 error() = default;
[9ed4f94]31 error( const std::string & str ) : description( str ) {}
[138e29e]32
[9ed4f94]33 void maybeSet( const CodeLocation & location ) {
[d48e529]34 if( this->location.isUnset() ) {
[138e29e]35 this->location = location;
36 }
37 }
38};
39
[01aeade]40class SemanticError : public std::exception {
41 public:
42 SemanticError();
43 SemanticError( std::string error );
[9ed4f94]44 template< typename T > SemanticError( const std::string & error, const T * obj );
[01aeade]45 ~SemanticError() throw() {}
46
[9ed4f94]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 );
[3906301]53 void append( const std::string & );
[01aeade]54 bool isEmpty() const;
[9ed4f94]55 void print( std::ostream & os );
[01aeade]56
[9ed4f94]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)
[01aeade]60 private:
[138e29e]61 std::list< error > errors;
[51b73452]62};
63
64template< typename T >
[9ed4f94]65SemanticError::SemanticError( const std::string & error, const T * obj ) {
[3906301]66 append( toString( error, obj ) );
[51b73452]67}
68
[51587aa]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.