aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-04-15 04:46:11 +0630
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-04-15 04:55:51 +0630
commit81efc9006d9ebcb0587d1d4d5ee7a1b9d2996026 (patch)
tree99169cc5970fbdb4d7360547f94a302287736b3b
parent929e5a3d0dddf425f800e6479756005736c47e7b (diff)
downloadovm-81efc9006d9ebcb0587d1d4d5ee7a1b9d2996026.tar.gz
ovm-81efc9006d9ebcb0587d1d4d5ee7a1b9d2996026.tar.bz2
ovm-81efc9006d9ebcb0587d1d4d5ee7a1b9d2996026.zip
Implement printing of pp_err_t
Another great thing for C++: the ability to tell it how to print structures the way I want. In C it's either: 1) Write a function to print the structure out (preferably to a file pointer) 2) Write a function to return a string (allocated on the heap) which represents it Both are not fun to write, whereas it's much easier to write this.
-rw-r--r--asm/preprocesser.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/asm/preprocesser.cpp b/asm/preprocesser.cpp
index e87a505..31cf6a7 100644
--- a/asm/preprocesser.cpp
+++ b/asm/preprocesser.cpp
@@ -63,6 +63,31 @@ preprocess_use_blocks(vector<token_t *> tokens)
return VAL(new_tokens);
}
+
+std::ostream &operator<<(std::ostream &os, pp_err_t &err)
+{
+ os << "PREPROCESSING_";
+ switch (err.type)
+ {
+ case OK:
+ return os << "OK";
+ case EXPECTED_NAME:
+ return os << "EXPECTED_NAME";
+ case EXPECTED_STRING:
+ return os << "EXPECTED_STRING";
+ case EXPECTED_END:
+ return os << "EXPECTED_END";
+ case FILE_NONEXISTENT:
+ return os << "FILE_NONEXISTENT";
+ case FILE_PARSE_ERROR:
+ return os << "FILE_PARSE_ERROR -> \n\t[" << err.reference->content
+ << "]: " << lerr_as_cstr(err.lerr);
+ case UNKNOWN_NAME:
+ return os << "UNKNOWN_NAME";
+ }
+ return os;
+}
+
pp_err_t::pp_err_t(pp_err_type_t e)
: reference{nullptr}, type{e}, lerr{lerr_t::OK}
{}