aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-04-15 16:31:45 +0630
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-04-15 16:31:45 +0630
commitb83bdd0d45223b789ec99bdc16d42fb646fdb8e2 (patch)
treeaf7995443345ff6ef727d2b26f281473a6c654c8 /asm
parentc748ed8386bc8fd9f3795a02330e07095222ff68 (diff)
downloadovm-b83bdd0d45223b789ec99bdc16d42fb646fdb8e2.tar.gz
ovm-b83bdd0d45223b789ec99bdc16d42fb646fdb8e2.tar.bz2
ovm-b83bdd0d45223b789ec99bdc16d42fb646fdb8e2.zip
preprocesser function now only returns a pp_err_t
We leave the parameter tokens alone, considering it constant, while the parameter vec_out is used to hold the new stream of tokens. This allows the caller to have a before and after view on the token stream and reduces the worry of double frees.
Diffstat (limited to 'asm')
-rw-r--r--asm/preprocesser.cpp16
-rw-r--r--asm/preprocesser.hpp3
2 files changed, 12 insertions, 7 deletions
diff --git a/asm/preprocesser.cpp b/asm/preprocesser.cpp
index 1245ff7..c0cf9e2 100644
--- a/asm/preprocesser.cpp
+++ b/asm/preprocesser.cpp
@@ -27,13 +27,17 @@ using std::pair, std::vector, std::make_pair, std::string, std::string_view;
delete t; \
});
-pair<vector<token_t *>, pp_err_t> preprocesser(vector<token_t *> &tokens)
+pp_err_t preprocesser(const vector<token_t *> &tokens,
+ vector<token_t *> &vec_out)
{
vector<token_t *> use_block_tokens;
pp_err_t pperr{pp_err_type_t::OK};
std::tie(use_block_tokens, pperr) = preprocess_use_blocks(tokens);
if (pperr.type != pp_err_type_t::OK)
- return ERR(pperr);
+ {
+ vec_out = tokens;
+ return pperr;
+ }
vector<token_t *> const_block_tokens;
std::tie(const_block_tokens, pperr) =
@@ -41,12 +45,14 @@ pair<vector<token_t *>, pp_err_t> preprocesser(vector<token_t *> &tokens)
if (pperr.type != pp_err_type_t::OK)
{
VCLEAR(tokens);
- tokens = use_block_tokens;
- return ERR(pperr);
+ vec_out = use_block_tokens;
+ return pperr;
}
VCLEAR(use_block_tokens);
- return VAL(const_block_tokens);
+ vec_out = const_block_tokens;
+
+ return pp_err_t{pp_err_type_t::OK};
}
pair<vector<token_t *>, pp_err_t>
diff --git a/asm/preprocesser.hpp b/asm/preprocesser.hpp
index f4cb3bb..ed5a421 100644
--- a/asm/preprocesser.hpp
+++ b/asm/preprocesser.hpp
@@ -42,8 +42,7 @@ struct pp_err_t
std::ostream &operator<<(std::ostream &, pp_err_t &);
-std::pair<std::vector<token_t *>, pp_err_t>
-preprocesser(std::vector<token_t *> &);
+pp_err_t preprocesser(const std::vector<token_t *> &, std::vector<token_t *> &);
std::pair<std::vector<token_t *>, pp_err_t>
preprocess_const_blocks(const std::vector<token_t *> &);