diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-02-18 18:22:08 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-02-22 11:57:19 +0100 |
commit | ae1f91a698022a5600a2d54e48fc90895ea834fd (patch) | |
tree | f38ee7ecfb7533735272aaae4237144efce0047b /gcc/rust/expand/rust-macro-expand.h | |
parent | 265c223766f1f4525558d086ccc46bd49f7b26e0 (diff) | |
download | gcc-ae1f91a698022a5600a2d54e48fc90895ea834fd.zip gcc-ae1f91a698022a5600a2d54e48fc90895ea834fd.tar.gz gcc-ae1f91a698022a5600a2d54e48fc90895ea834fd.tar.bz2 |
transcribe: Move substitute_metavar in its own function
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.h')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index edb091d..f77acc7 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -183,6 +183,40 @@ struct MacroExpander size_t &match_amount, size_t lo_bound = 0, size_t hi_bound = 0); + /** + * Substitute a metavariable by its given fragment in a transcribing context, + * i.e. replacing $var with the associated fragment. + * + * @param input Tokens given to the transcribing context + * @param fragments Fragments given to the macro substitution + * @param metavar Metavariable to try and replace + * + * @return A token containing the associated fragment expanded into tokens if + * any, or the cloned token if no fragment was associated + */ + static std::vector<std::unique_ptr<AST::Token>> + substitute_metavar (std::vector<std::unique_ptr<AST::Token>> &input, + std::map<std::string, MatchedFragment> &fragments, + std::unique_ptr<AST::Token> &metavar); + + /** + * Substitute a given token by its appropriate representation + * + * @param input Tokens given to the transcribing context + * @param fragments Fragments given to the macro substitution + * @param token Current token to try and substitute + * + * @return A token containing the associated fragment expanded into tokens if + * any, or the cloned token if no fragment was associated, as well as the + * amount of tokens that should be skipped before the next invocation. Since + * this function may consume more than just one token, it is important to skip + * ahead of the input to avoid mis-substitutions + */ + static std::pair<std::vector<std::unique_ptr<AST::Token>>, size_t> + substitute_token (std::vector<std::unique_ptr<AST::Token>> &input, + std::map<std::string, MatchedFragment> &fragments, + std::unique_ptr<AST::Token> &token); + static std::vector<std::unique_ptr<AST::Token>> substitute_tokens (std::vector<std::unique_ptr<AST::Token>> &input, std::vector<std::unique_ptr<AST::Token>> ¯o, |