Skip to content

Commit

Permalink
Add a new visitor that gathers context information
Browse files Browse the repository at this point in the history
This visitor is intended to be used by other visitors that require
context at some point for a given item.

gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Add multiple
	context saving calls.
	* ast/rust-ast-visitor.h (class DefaultASTVisitor): Make visit
	functions virtual.
	(class ContextualASTVisitor): Add a stack like container for the
	current context chain.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P authored and CohenArthur committed Nov 6, 2023
1 parent 4068593 commit 95325d7
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 184 deletions.
24 changes: 24 additions & 0 deletions gcc/rust/ast/rust-ast-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1447,5 +1447,29 @@ DefaultASTVisitor::visit (AST::BareFunctionType &type)
visit (type.get_return_type ());
}

void
ContextualASTVisitor::visit (AST::Crate &crate)
{
push_context (Context::CRATE);
DefaultASTVisitor::visit (crate);
pop_context ();
}

void
ContextualASTVisitor::visit (AST::InherentImpl &impl)
{
push_context (Context::INHERENT_IMPL);
DefaultASTVisitor::visit (impl);
pop_context ();
}

void
ContextualASTVisitor::visit (AST::TraitImpl &impl)
{
push_context (Context::TRAIT_IMPL);
DefaultASTVisitor::visit (impl);
pop_context ();
}

} // namespace AST
} // namespace Rust
Loading

0 comments on commit 95325d7

Please sign in to comment.