File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -44,5 +44,16 @@ bool typecheckt::typecheck_main()
44
44
error () << e.get_reason () << messaget::eom;
45
45
}
46
46
47
+ catch (const errort &e)
48
+ {
49
+ if (e.what ().empty ())
50
+ error ();
51
+ else
52
+ {
53
+ error ().source_location = e.source_location ();
54
+ error () << e.what () << messaget::eom;
55
+ }
56
+ }
57
+
47
58
return message_handler->get_message_count (messaget::M_ERROR)!=errors_before;
48
59
}
Original file line number Diff line number Diff line change @@ -22,6 +22,38 @@ class typecheckt:public messaget
22
22
23
23
virtual ~typecheckt () { }
24
24
25
+ class errort final
26
+ {
27
+ public:
28
+ std::string what () const
29
+ {
30
+ return message.str ();
31
+ }
32
+
33
+ std::ostringstream &message_ostream ()
34
+ {
35
+ return message;
36
+ }
37
+
38
+ errort with_location (source_locationt _location) &&
39
+ {
40
+ __location = std::move (_location);
41
+ return std::move (*this );
42
+ }
43
+
44
+ const source_locationt &source_location () const
45
+ {
46
+ return __location;
47
+ }
48
+
49
+ protected:
50
+ std::ostringstream message;
51
+ source_locationt __location = source_locationt::nil();
52
+
53
+ template <typename T>
54
+ friend errort operator <<(errort &&e, const T &);
55
+ };
56
+
25
57
protected:
26
58
// main function -- overload this one
27
59
virtual void typecheck ()=0;
@@ -31,4 +63,12 @@ class typecheckt:public messaget
31
63
virtual bool typecheck_main ();
32
64
};
33
65
66
+ // / add to the diagnostic information in the given typecheckt::errort exception
67
+ template <typename T>
68
+ typecheckt::errort operator <<(typecheckt::errort &&e, const T &message)
69
+ {
70
+ e.message_ostream () << message;
71
+ return std::move (e);
72
+ }
73
+
34
74
#endif // CPROVER_UTIL_TYPECHECK_H
You can’t perform that action at this time.
0 commit comments