MCPcopy Create free account
hub / github.com/ControlCplusControlV/Scribe / walk_expr

Function walk_expr

crates/papyrus/src/ast_optimization.rs:201–315  ·  view source on GitHub ↗

TODO: it would be nice if there wasn't so much cloning in here

(expr: Expr, visitor: &mut V)

Source from the content-addressed store, hash-verified

199
200// TODO: it would be nice if there wasn't so much cloning in here
201fn walk_expr<V: ExpressionVisitor>(expr: Expr, visitor: &mut V) -> Option<Expr> {
202 let expr = visitor.visit_expr(expr);
203 if let Some(expr) = expr {
204 return Some(match expr {
205 //Expr is literal
206 Expr::Literal(ref _x) => expr,
207
208 //Expr is function call
209 Expr::FunctionCall(ExprFunctionCall {
210 function_name,
211 inferred_return_types,
212 inferred_param_types,
213 exprs,
214 }) => Expr::FunctionCall(ExprFunctionCall {
215 function_name,
216 inferred_return_types,
217 inferred_param_types,
218 exprs: Box::new(vec![
219 walk_expr(exprs[0].clone(), visitor).unwrap(),
220 walk_expr(exprs[1].clone(), visitor).unwrap(),
221 ]),
222 }),
223
224 //Expr is if statement
225 Expr::IfStatement(ExprIfStatement {
226 first_expr,
227 second_expr,
228 }) => Expr::IfStatement(ExprIfStatement {
229 first_expr: Box::new(walk_expr(*first_expr, visitor).unwrap()),
230 second_expr: Box::new(ExprBlock {
231 exprs: walk_ast(second_expr.exprs, visitor),
232 }),
233 }),
234
235 //Expr is assignment
236 Expr::Assignment(ExprAssignment {
237 inferred_types,
238 identifiers,
239 rhs,
240 }) => Expr::Assignment(ExprAssignment {
241 identifiers,
242 inferred_types,
243 rhs: Box::new(walk_expr(*rhs, visitor).unwrap()),
244 }),
245
246 //Expr is declare variable
247 Expr::DeclareVariable(ExprDeclareVariable {
248 typed_identifiers,
249 rhs,
250 }) => Expr::DeclareVariable(ExprDeclareVariable {
251 typed_identifiers,
252 rhs: rhs.map(|rhs| Box::new(walk_expr(*rhs, visitor).unwrap())),
253 }),
254
255 //TODO: Expr is function definition
256 Expr::FunctionDefinition(ExprFunctionDefinition {
257 function_name: _,
258 params: _,

Callers 1

walk_astFunction · 0.85

Calls 2

walk_astFunction · 0.85
visit_exprMethod · 0.80

Tested by

no test coverage detected