diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-02-17 15:26:35 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-02-17 16:41:15 +0000 |
commit | 37415eec77438bba2fc61df3e9a396c1e2cbaca8 (patch) | |
tree | d8ed1ea0d957afd906556ae89e8622f79c4690f1 /gcc/rust/expand/rust-macro-expand.h | |
parent | 4c70d7ec770d226bf9ad59b4f03897f6fb10df15 (diff) | |
download | gcc-37415eec77438bba2fc61df3e9a396c1e2cbaca8.zip gcc-37415eec77438bba2fc61df3e9a396c1e2cbaca8.tar.gz gcc-37415eec77438bba2fc61df3e9a396c1e2cbaca8.tar.bz2 |
Semicolon based macro invocation
This allows for macro invocation at the toplevel or as statements. This
patched required us to propogate the delimited token tree fix to include
the delimiter tokens. The rest of the fix was straight forward to call
the apropriate visitors in names resolution and hir lowering.
Some thought will be needed to handle hir lowering for repeating items.
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.h')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index 0f13f9e..d8a2d50 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -130,6 +130,12 @@ private: // Object used to store shared data (between functions) for macro expansion. struct MacroExpander { + enum ContextType + { + ITEM, + BLOCK, + }; + ExpansionCfg cfg; unsigned int expansion_depth = 0; @@ -148,11 +154,13 @@ struct MacroExpander * have similar duck-typed interface and use templates?*/ // should this be public or private? void expand_invoc (AST::MacroInvocation &invoc); + void expand_invoc_semi (AST::MacroInvocationSemi &invoc); // Expands a single declarative macro. AST::ASTFragment expand_decl_macro (Location locus, AST::MacroInvocData &invoc, - AST::MacroRulesDefinition &rules_def); + AST::MacroRulesDefinition &rules_def, + bool semicolon); void expand_cfg_attrs (AST::AttrVec &attrs); bool fails_cfg (const AST::AttrVec &attr) const; @@ -171,7 +179,8 @@ struct MacroExpander AST::ASTFragment transcribe_rule (AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree, - std::map<std::string, MatchedFragment> &matched_fragments); + std::map<std::string, MatchedFragment> &matched_fragments, + bool semicolon, ContextType ctx); bool match_fragment (Parser<MacroInvocLexer> &parser, AST::MacroMatchFragment &fragment); @@ -189,10 +198,22 @@ struct MacroExpander std::vector<std::unique_ptr<AST::Token>> ¯o, std::map<std::string, MatchedFragment> &fragments); + void push_context (ContextType t) { context.push_back (t); } + + ContextType pop_context () + { + ContextType t = context.back (); + context.pop_back (); + return t; + } + + ContextType peek_context () { return context.back (); } + private: AST::Crate &crate; Session &session; SubstitutionScope sub_stack; + std::vector<ContextType> context; public: Resolver::Resolver *resolver; |