[−][src]Module c2rust_refactor::matcher
AST pattern matching implementation.
The matching in this module allows matching one AST fragment against another fragment of the same type. The "pattern" fragment can use some special forms to capture parts of the target AST, or to impose additional requirements on the matching.
Matching forms:
-
__x
: An ident starting with double underscores will capture the AST matched against it, and save it in theBindings
. Other idents can also be used if theMatchCtxt
is appropriately configured first.By default, this form captures the largest AST that it encounters. For example, if the target AST is
MyStruct
, it will try first to capture the entire Expr, then try the inner Path, then the innermost Ident. Normally the first attempt succeeds, but if a type is set for the ident in theMatchCtxt
, then it will only capture that type.For itemlikes, a lone ident can't be used as a pattern because it's not a valid itemlike. Use a zero-argument macro invocation
__x!()
instead. -
marked!(x [, label])
: Matchesx
only if the node is marked with the given label. The label defaults to "target" if omitted. -
def!(path)
: Matches a pathExpr
orTy
that refers to a definition whose absolute path ispath
. Specifically, the path of the definition is converted back to an AST using thereflect
module, and the new AST is matched againstpath
. -
typed!(x, ty)
: Matches anExpr
orTy
whose resolved type matchesty
. Specifically, the resolved type of the node is converted back to an AST using thereflect
module, and the new AST is matched againstty
. -
cast!(x)
: Matches theExpr
sx
,x as __t
,x as __t as __u
, etc.
Structs
BindingTypes | A set of binding types, mapping names to binding types. |
Bindings | A set of bindings, mapping names to AST fragments. |
ExprPatternFolder | Automatically generated |
MatchCtxt | Pattern-matching context. Stores configuration that affects pattern matching behavior, and collects bindings captured during the match. |
MultiStmtPatternFolder | Custom |
StmtPatternFolder | Automatically generated |
TyPatternFolder | Automatically generated |
Enums
BindingType | The types of AST fragments that can be used in |
Error |
Traits
Pattern | Trait for AST types that can be used as patterns in a search-and-replace ( |
Subst | |
TryMatch |
Functions
find_first | Find the first place where |
find_first_with | Find the first place where |
flat_map_match_with | |
match_multi_stmt | |
mut_visit_match | Find every match for |
mut_visit_match_with | Find every match for |
parse_bindings | |
replace_expr | Replace all instances of expression |
replace_stmts | Replace all instances of the statement sequence |
Type Definitions
Result |