source: src/Common/SemanticError.h@ d82daa1

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 d82daa1 was 21f0aa8, checked in by Andrew Beach <ajbeach@…>, 8 years ago

Seperated CodeLocation out from the general utilities.

  • Property mode set to 100644
File size: 1.7 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 : Andrew Beach
12// Last Modified On : Thr Aug 17 14:01:00 2017
13// Update Count : 7
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 "CodeLocation.h" // for CodeLocation, toString
24
25struct 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
39class 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
58template< typename T >
59SemanticError::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: //
Note: See TracBrowser for help on using the repository browser.