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 <pierre-emmanuel.patry@embecosm.com>
  • Loading branch information
P-E-P committed Oct 26, 2023
1 parent add64e3 commit 585b020
Show file tree
Hide file tree
Showing 2 changed files with 238 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 585b020

Please sign in to comment.