diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-04-15 16:31:45 +0630 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-04-15 16:31:45 +0630 |
commit | b83bdd0d45223b789ec99bdc16d42fb646fdb8e2 (patch) | |
tree | af7995443345ff6ef727d2b26f281473a6c654c8 /asm/preprocesser.cpp | |
parent | c748ed8386bc8fd9f3795a02330e07095222ff68 (diff) | |
download | ovm-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/preprocesser.cpp')
-rw-r--r-- | asm/preprocesser.cpp | 16 |
1 files changed, 11 insertions, 5 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> |