From 03e211d6eeb3f8f3c6f0b22f77c2074e81443952 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 6 Sep 2015 18:08:38 +0800 Subject: Rough span support --- src/include/span.hpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/include/span.hpp (limited to 'src/include/span.hpp') diff --git a/src/include/span.hpp b/src/include/span.hpp new file mode 100644 index 00000000..c8c61627 --- /dev/null +++ b/src/include/span.hpp @@ -0,0 +1,56 @@ +/* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * include/span.hpp + * - Spans and error handling + */ + +#pragma once + +enum ErrorType +{ + E0000, +}; +enum WarningType +{ + W0000, +}; + +struct ProtoSpan +{ + ::std::string filename; + + unsigned int start_line; + unsigned int start_ofs; +}; +struct Span +{ + ::std::string filename; + + unsigned int start_line; + unsigned int start_ofs; + unsigned int end_line; + unsigned int end_ofs; + + Span(::std::string filename, unsigned int start_line, unsigned int start_ofs, unsigned int end_line, unsigned int end_ofs): + filename(filename), + start_line(start_line), + start_ofs(start_ofs), + end_line(end_line), + end_ofs(end_ofs) + {} + Span(): + filename(""), + start_line(0), start_ofs(0), + end_line(0), end_ofs(0) + {} + + void bug(::std::function msg) const; + void error(ErrorType tag, ::std::function msg) const; + void warning(WarningType tag, ::std::function msg) const; + void note(::std::function msg) const; +}; + +#define ERROR(span, code, msg) do { (span).error(code, [](::std::ostream& os) { os << msg; }); throw ::std::runtime_error("Error fell through" #code); } while(0) + -- cgit v1.2.3