diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-21 13:05:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-21 13:05:18 +0000 |
commit | 60b21d2f58f46c93fc33f6192682abfed62d8dd9 (patch) | |
tree | 2f8fd5e728e601f5fa74d71afe1579a5fd3ba440 /gcc/rust/expand/rust-macro-expand.h | |
parent | dfb5921b76589c09e7794f5f8010427b93616e9d (diff) | |
parent | 89490980726d298311107a452bdebeb43a2ff7e6 (diff) | |
download | gcc-60b21d2f58f46c93fc33f6192682abfed62d8dd9.zip gcc-60b21d2f58f46c93fc33f6192682abfed62d8dd9.tar.gz gcc-60b21d2f58f46c93fc33f6192682abfed62d8dd9.tar.bz2 |
Merge #1607
1607: Improve AST Fragment class r=CohenArthur a=CohenArthur
This changes the APIs around creating AST fragments and refactors the class into its own header and source file, hopefully making it easier to use. This will also help creating "unexpanded" AST fragments for proper builtin macro expansion with the new fixed-point algorithm introduced by #1606
`@liushuyu` pinging you since you've worked extensively with the macro system. Would love your review!
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.h')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index c45a3bc..6253a4e 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -230,7 +230,7 @@ struct MacroExpander MacroExpander (AST::Crate &crate, ExpansionCfg cfg, Session &session) : cfg (cfg), crate (crate), session (session), sub_stack (SubstitutionScope ()), - expanded_fragment (AST::ASTFragment::create_error ()), + expanded_fragment (AST::Fragment::create_error ()), resolver (Resolver::Resolver::get ()), mappings (Analysis::Mappings::get ()) {} @@ -246,10 +246,9 @@ struct MacroExpander void expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon); // Expands a single declarative macro. - AST::ASTFragment expand_decl_macro (Location locus, - AST::MacroInvocData &invoc, - AST::MacroRulesDefinition &rules_def, - bool semicolon); + AST::Fragment expand_decl_macro (Location locus, AST::MacroInvocData &invoc, + AST::MacroRulesDefinition &rules_def, + bool semicolon); void expand_cfg_attrs (AST::AttrVec &attrs); bool fails_cfg (const AST::AttrVec &attr) const; @@ -260,7 +259,7 @@ struct MacroExpander bool try_match_rule (AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree); - AST::ASTFragment transcribe_rule ( + AST::Fragment transcribe_rule ( AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree, std::map<std::string, MatchedFragmentContainer> &matched_fragments, bool semicolon, ContextType ctx); @@ -314,16 +313,16 @@ struct MacroExpander ContextType peek_context () { return context.back (); } - void set_expanded_fragment (AST::ASTFragment &&fragment) + void set_expanded_fragment (AST::Fragment &&fragment) { expanded_fragment = std::move (fragment); } - AST::ASTFragment take_expanded_fragment (AST::ASTVisitor &vis) + AST::Fragment take_expanded_fragment (AST::ASTVisitor &vis) { - AST::ASTFragment old_fragment = std::move (expanded_fragment); + AST::Fragment old_fragment = std::move (expanded_fragment); auto accumulator = std::vector<AST::SingleASTNode> (); - expanded_fragment = AST::ASTFragment::create_error (); + expanded_fragment = AST::Fragment::create_error (); auto early_name_resolver = Resolver::EarlyNameResolver (); for (auto &node : old_fragment.get_nodes ()) @@ -345,7 +344,7 @@ struct MacroExpander auto new_nodes = expanded_fragment.get_nodes (); std::move (new_nodes.begin (), new_nodes.end (), std::back_inserter (accumulator)); - expanded_fragment = AST::ASTFragment (accumulator); + expanded_fragment = AST::Fragment::complete (accumulator); } expansion_depth--; } @@ -358,7 +357,7 @@ private: Session &session; SubstitutionScope sub_stack; std::vector<ContextType> context; - AST::ASTFragment expanded_fragment; + AST::Fragment expanded_fragment; public: Resolver::Resolver *resolver; |