diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-29 13:37:13 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-01-31 14:16:50 +0100 |
commit | 55fb35c51b2ee6b107204b6a02193cbeef077d01 (patch) | |
tree | db8b1c0c786e6899c768a6f5dd1c7595d6a13223 /gcc/rust/expand/rust-attribute-visitor.cc | |
parent | 7dc41901213d32ff9962f1d54cc6291c38d0e597 (diff) | |
download | gcc-55fb35c51b2ee6b107204b6a02193cbeef077d01.zip gcc-55fb35c51b2ee6b107204b6a02193cbeef077d01.tar.gz gcc-55fb35c51b2ee6b107204b6a02193cbeef077d01.tar.bz2 |
gccrs: ast: Only expand expressions and types if the kind is right
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add assertions and accessors for fragment nodes.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Fix expansion
context typo when visiting `InherentImpl` items.
(AttrVisitor::maybe_expand_expr): Use new Fragment accessor to fetch
properly typed node.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-macro-expand.cc (transcribe_type): Emit parse errors
when trying to parse a type.
Diffstat (limited to 'gcc/rust/expand/rust-attribute-visitor.cc')
-rw-r--r-- | gcc/rust/expand/rust-attribute-visitor.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index 15aedbf..673f043 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -2662,7 +2662,7 @@ AttrVisitor::visit (AST::InherentImpl &impl) for (auto ¶m : impl.get_generic_params ()) param->accept_vis (*this); - expander.push_context (MacroExpander::ContextType::TYPE); + expander.push_context (MacroExpander::ContextType::ITEM); auto &type = impl.get_type (); type->accept_vis (*this); @@ -2706,7 +2706,7 @@ AttrVisitor::visit (AST::TraitImpl &impl) for (auto ¶m : impl.get_generic_params ()) param->accept_vis (*this); - expander.push_context (MacroExpander::ContextType::TYPE); + expander.push_context (MacroExpander::ContextType::ITEM); auto &type = impl.get_type (); type->accept_vis (*this); @@ -3427,11 +3427,13 @@ AttrVisitor::visit (AST::BareFunctionType &type) // no where clause, apparently } + void AttrVisitor::maybe_expand_expr (std::unique_ptr<AST::Expr> &expr) { auto final_fragment = expand_macro_fragment_recursive (); - if (final_fragment.should_expand ()) + if (final_fragment.should_expand () + && final_fragment.is_expression_fragment ()) expr = final_fragment.take_expression_fragment (); } @@ -3439,7 +3441,8 @@ void AttrVisitor::maybe_expand_type (std::unique_ptr<AST::Type> &type) { auto final_fragment = expand_macro_fragment_recursive (); - if (final_fragment.should_expand ()) + if (final_fragment.should_expand () && final_fragment.is_type_fragment ()) type = final_fragment.take_type_fragment (); } + } // namespace Rust |