Skip to content

Commit f712562

Browse files
committed
unified: Use template choices in accessor rules
Cleans the code up a bit. I had to use a scoped context to get things to behave correctly. We really ought to give each interpolation its own copy of the context as it was when the template was invoked. That way, changes to the context in one interpolation cannot affect changes in another interpolation.
1 parent 35a3440 commit f712562

1 file changed

Lines changed: 14 additions & 30 deletions

File tree

  • unified/extractor/src/languages/swift

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ impl SwiftContext {
6060
}
6161
}
6262

63-
/// Build a freshly-created `chained_declaration` modifier node if
64-
/// `ctx.is_chained`, else `None`.
65-
fn chained_modifier(ctx: &mut yeast::build::BuildCtx<'_, SwiftContext>) -> Option<yeast::OutputId> {
66-
if ctx.is_chained {
67-
Some(tree!((modifier "chained_declaration")))
68-
} else {
69-
None
70-
}
71-
}
72-
7363
fn implicit_parameterless_initializer(
7464
ctx: &mut yeast::build::BuildCtx<'_, SwiftContext>,
7565
members: &[yeast::OutputId],
@@ -425,22 +415,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
425415
_ => None,
426416
};
427417
let param_ty = ctx.property_type;
428-
let param = match (param_name, implicit_param_name) {
429-
(Some(n), _) => {
430-
Some(tree!((parameter pattern: (identifier #{n}) type: {param_ty})))
431-
}
432-
(None, Some(n)) => {
433-
let n = n.to_string();
434-
Some(tree!((parameter
435-
modifier: (modifier "generated")
436-
pattern: (identifier #{n} location: {spec})
437-
type: {param_ty}
438-
location: {spec})))
439-
}
440-
(None, None) => None,
441-
};
442418
let modifiers = ctx.outer_modifiers.clone();
443-
let chained = chained_modifier(&mut ctx);
444419
let name = ctx
445420
.property_name_node
446421
.ok_or("accessor outside property context")?;
@@ -450,19 +425,28 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
450425
None
451426
};
452427
let body = match body {
453-
Some(block) => {
428+
Some(block) => ctx.scoped(|ctx| {
454429
ctx.reset();
455-
ctx.translate(block)?.into_iter().next()
456-
}
430+
ctx.translate(block)
431+
})?.into_iter().next(),
457432
None => None,
458433
};
459434
tree!((accessor_declaration
460435
modifier: {modifiers}
461-
modifier: {chained}
436+
modifier: [(modifier "chained_declaration") if { ctx.is_chained }]
462437
name_node: {name}
463438
return_type: {return_ty}
464439
accessor_kind: (accessor_kind #{spec})
465-
parameter: {param}
440+
parameter: [
441+
(parameter
442+
pattern: (identifier #{param_name})
443+
type: {param_ty})
444+
(parameter
445+
modifier: (modifier "generated")
446+
pattern: (identifier #{implicit_param_name} location: {spec})
447+
type: {param_ty}
448+
location: {spec})
449+
]
466450
body: {body}
467451
location: {spec}
468452
location: {body}))

0 commit comments

Comments
 (0)