|
1 | 1 | use codeql_extractor::extractor::desugaring; |
2 | | -use yeast::{ConcreteDesugarer, DesugaringConfig, Rule, tree}; |
| 2 | +use yeast::{tree, ConcreteDesugarer, DesugaringConfig, Rule}; |
3 | 3 |
|
4 | 4 | /// User context propagated from outer rules down to the inner rules that |
5 | 5 | /// emit the corresponding output declarations, so that each emitted node |
@@ -51,10 +51,9 @@ impl SwiftContext { |
51 | 51 | /// Called before recursively translating a body / initializer |
52 | 52 | /// slot. Most rules mutate `ctx` in place — the framework invokes |
53 | 53 | /// each rule with a private clone of the user context, so |
54 | | - /// mutations are discarded on rule exit anyway. Rules that need |
55 | | - /// the outer context intact *after* the reset-and-translate (see |
56 | | - /// e.g. the `property_binding` willSet/didSet rule) wrap the |
57 | | - /// mutation in `ctx.scoped(...)` instead. |
| 54 | + /// mutations are discarded on rule exit anyway. Output-template |
| 55 | + /// interpolations additionally restore the context after evaluation, |
| 56 | + /// preventing mutations from leaking into sibling fields. |
58 | 57 | fn reset(&mut self) { |
59 | 58 | *self = SwiftContext::default(); |
60 | 59 | } |
@@ -371,17 +370,13 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> { |
371 | 370 | let mut result = Vec::new(); |
372 | 371 | if let Some(val) = val { |
373 | 372 | // Stored property with observers: the initializer is not part |
374 | | - // of the binding, so translate it in a reset scope. |
375 | | - let val = ctx.scoped(|ctx| { |
376 | | - ctx.reset(); |
377 | | - ctx.translate(val) |
378 | | - }); |
| 373 | + // of the binding, so translate it in a reset interpolation. |
379 | 374 | result.push(tree!( |
380 | 375 | (variable_declaration |
381 | 376 | modifier: {ctx.outer_modifiers.clone()} |
382 | 377 | pattern: (identifier #{name}) |
383 | 378 | type: {ty} |
384 | | - value: {val}) |
| 379 | + value: {ctx.reset(); val}) |
385 | 380 | )); |
386 | 381 | } |
387 | 382 | for acc in accessors.into_iter() { |
@@ -736,19 +731,11 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> { |
736 | 731 | trailingClosure: _? @trailing |
737 | 732 | additionalTrailingClosures: _* @additional) |
738 | 733 | => |
739 | | - expr { |
740 | | - // Always translate the callee in non-pattern context. |
741 | | - let callee = ctx.scoped(|ctx| { |
742 | | - ctx.in_pattern = false; |
743 | | - ctx.translate(rawCallee) |
744 | | - }); |
745 | | - tree!((call_expr |
746 | | - callee: {callee} |
747 | | - argument: {args} |
748 | | - argument: {trailing.map(|trailing| tree!((argument value: {trailing})))} |
749 | | - argument: {additional} |
750 | | - )) |
751 | | - } |
| 734 | + (call_expr |
| 735 | + callee: {ctx.in_pattern = false; rawCallee} |
| 736 | + argument: {args} |
| 737 | + argument: {trailing.map(|trailing| tree!((argument value: {trailing})))} |
| 738 | + argument: {additional}) |
752 | 739 | ), |
753 | 740 | // A call or enum-case pattern argument. |
754 | 741 | rule!( |
|
0 commit comments