charon_lib::ast::visitor

Trait AstVisitable

source
pub trait AstVisitable: Any {
    // Required methods
    fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>;
    fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>;

    // Provided methods
    fn name(&self) -> &'static str { ... }
    fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T)) { ... }
    fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T)) { ... }
}
Expand description

An overrideable visitor trait that can be used to conveniently traverse the whole contents of an item. This is useful when e.g. dealing with types, which show up pretty much everywhere in the ast.

This defines three traits:

  • AstVisitable is a trait implemented by all the types listed below; it has a drive[_mut] method that takes a VisitAst[Mut] visitor and calls its methods on all the relevant subvalues of self encountered.
  • VisitAst[Mut] is a (pair of) visitor trait(s) that can be implemented by visitors. To define a visitor, implement VisitAst[Mut] and override the methods you need.

This trait has a drive[_mut] method that knows how to drive a VisitAst[Mut] visitor. This trait is implemented for all the listed types. If listed as override, the corresponding visitor trait has an overrideable method to visit this type. If listed as drive, the type will only be visited by recursing into its contents.

Morally this represents the predicate for<V: VisitAst[Mut]> Self: Drive[Mut]<AstVisitableWrapper<V>>

Required Methods§

source

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

Recursively visit this type with the provided visitor. This calls the visitor’s visit_$any method if it exists, otherwise visit_inner.

source

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

Recursively visit this type with the provided visitor. This calls the visitor’s visit_$any method if it exists, otherwise visit_inner.

Provided Methods§

source

fn name(&self) -> &'static str

The name of the type, used for debug logging.

source

fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))

Visit all occurrences of that type inside self, in pre-order traversal.

source

fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))

Visit all occurrences of that type inside self, in pre-order traversal.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

source§

impl<A: AstVisitable, B: AstVisitable> AstVisitable for Result<A, B>

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

source§

impl<A: AstVisitable, B: AstVisitable> AstVisitable for (A, B)

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

source§

impl<K: Any, T: AstVisitable> AstVisitable for HashMap<K, T>

Manual impl that only visits the values

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

source§

impl<T: AstVisitable> AstVisitable for Option<T>

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

source§

impl<T: AstVisitable> AstVisitable for Box<T>

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

source§

impl<T: AstVisitable> AstVisitable for Vec<T>

source§

fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>

source§

fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>

Implementors§

source§

impl AstVisitable for AggregateKind

source§

impl AstVisitable for BinOp

source§

impl AstVisitable for BorrowKind

source§

impl AstVisitable for BuiltinFunId

source§

impl AstVisitable for CastKind

source§

impl AstVisitable for FieldProjKind

source§

impl AstVisitable for FunId

source§

impl AstVisitable for FunIdOrTraitMethodRef

source§

impl AstVisitable for NullOp

source§

impl AstVisitable for Operand

source§

impl AstVisitable for PlaceKind

source§

impl AstVisitable for ProjectionElem

source§

impl AstVisitable for RawConstantExpr

source§

impl AstVisitable for Rvalue

source§

impl AstVisitable for UnOp

source§

impl AstVisitable for AbortKind

source§

impl AstVisitable for Body

source§

impl AstVisitable for FnOperand

source§

impl AstVisitable for ItemKind

source§

impl AstVisitable for charon_lib::ast::llbc_ast::RawStatement

source§

impl AstVisitable for Switch

source§

impl AstVisitable for ImplElem

source§

impl AstVisitable for PathElem

source§

impl AstVisitable for BuiltinTy

source§

impl AstVisitable for ClosureKind

source§

impl AstVisitable for ConstGeneric

source§

impl AstVisitable for FloatTy

source§

impl AstVisitable for IntegerTy

source§

impl AstVisitable for LiteralTy

source§

impl AstVisitable for RefKind

source§

impl AstVisitable for Region

source§

impl AstVisitable for TraitRefKind

source§

impl AstVisitable for TyKind

source§

impl AstVisitable for TypeDeclKind

source§

impl AstVisitable for TypeId

source§

impl AstVisitable for charon_lib::ast::ullbc_ast::RawStatement

source§

impl AstVisitable for RawTerminator

source§

impl AstVisitable for SwitchTargets

source§

impl AstVisitable for Literal

source§

impl AstVisitable for ScalarValue

source§

impl AstVisitable for BuiltinIndexOp

source§

impl AstVisitable for ConstantExpr

source§

impl AstVisitable for FnPtr

source§

impl AstVisitable for Place

source§

impl AstVisitable for Assert

source§

impl AstVisitable for Call

source§

impl AstVisitable for FunDecl

source§

impl AstVisitable for FunDeclRef

source§

impl AstVisitable for GlobalDecl

source§

impl AstVisitable for GlobalDeclRef

source§

impl AstVisitable for Locals

source§

impl AstVisitable for Opaque

source§

impl AstVisitable for TraitDecl

source§

impl AstVisitable for TraitImpl

source§

impl AstVisitable for TraitItemName

source§

impl AstVisitable for Var

source§

impl AstVisitable for FunDeclId

source§

impl AstVisitable for GlobalDeclId

source§

impl AstVisitable for TraitDeclId

source§

impl AstVisitable for TraitImplId

source§

impl AstVisitable for TranslatedCrate

source§

impl AstVisitable for TypeDeclId

source§

impl AstVisitable for Block

source§

impl AstVisitable for charon_lib::ast::llbc_ast::Statement

source§

impl AstVisitable for ItemMeta

source§

impl AstVisitable for Span

source§

impl AstVisitable for Disambiguator

source§

impl AstVisitable for Name

source§

impl AstVisitable for ClosureInfo

source§

impl AstVisitable for ExistentialPredicate

source§

impl AstVisitable for Field

source§

impl AstVisitable for FieldId

source§

impl AstVisitable for FunSig

source§

impl AstVisitable for GenericArgs

source§

impl AstVisitable for GenericParams

source§

impl AstVisitable for TraitDeclRef

source§

impl AstVisitable for TraitImplRef

source§

impl AstVisitable for TraitRef

source§

impl AstVisitable for TraitTypeConstraint

source§

impl AstVisitable for Ty

source§

impl AstVisitable for TypeDecl

source§

impl AstVisitable for Variant

source§

impl AstVisitable for VariantId

source§

impl AstVisitable for ConstGenericVar

source§

impl AstVisitable for ConstGenericVarId

source§

impl AstVisitable for DeBruijnId

source§

impl AstVisitable for RegionId

source§

impl AstVisitable for RegionVar

source§

impl AstVisitable for TraitClause

source§

impl AstVisitable for TraitClauseId

source§

impl AstVisitable for TypeVar

source§

impl AstVisitable for TypeVarId

source§

impl AstVisitable for BlockData

source§

impl AstVisitable for BlockId

source§

impl AstVisitable for charon_lib::ast::ullbc_ast::Statement

source§

impl AstVisitable for Terminator

source§

impl AstVisitable for FloatValue

source§

impl AstVisitable for VarId

source§

impl AstVisitable for charon_lib::ast::llbc_ast::ExprBody

source§

impl AstVisitable for charon_lib::ast::ullbc_ast::ExprBody

source§

impl<A: AstVisitable, B: AstVisitable> AstVisitable for OutlivesPred<A, B>

source§

impl<I: Idx, T: AstVisitable> AstVisitable for Vector<I, T>

source§

impl<T: AstVisitable + Idx> AstVisitable for DeBruijnVar<T>

source§

impl<T: AstVisitable> AstVisitable for Binder<T>

source§

impl<T: AstVisitable> AstVisitable for RegionBinder<T>