summaryrefslogtreecommitdiff
path: root/src/include/span.hpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2015-09-06 18:08:38 +0800
committerJohn Hodge <tpg@mutabah.net>2015-09-06 18:08:38 +0800
commit03e211d6eeb3f8f3c6f0b22f77c2074e81443952 (patch)
tree5e07ee69f9020e829e79fb700fa2f35e602b0bcb /src/include/span.hpp
parent0b6d7c51056ed7b8eb25af6041c4feb5e6e23051 (diff)
downloadmrust-03e211d6eeb3f8f3c6f0b22f77c2074e81443952.tar.gz
Rough span support
Diffstat (limited to 'src/include/span.hpp')
-rw-r--r--src/include/span.hpp56
1 files changed, 56 insertions, 0 deletions
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<void(::std::ostream&)> msg) const;
+ void error(ErrorType tag, ::std::function<void(::std::ostream&)> msg) const;
+ void warning(WarningType tag, ::std::function<void(::std::ostream&)> msg) const;
+ void note(::std::function<void(::std::ostream&)> 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)
+