Swift: clean up VarDecl, NamedPattern and SwitchStmt interactions

* `variables` under `CaseStmt` are now AST children, which solves
  orphan `VarDecl`s in that case
* reordered `CaseStmt` AST children to be `labels > variables > body`
  (was `body > labels`)
* made `NamedPattern::getVarDecl` an extracted property instead of
  `getName`
* The above led to duplicate DB entities because of a quirk in the
  Swift compiler code. This is solved by tweaking the extraction of
  `variables` under `CaseStmt` to not use `getCaseBodyVariables`.
This commit is contained in:
Paolo Tranquilli
2023-10-23 12:37:32 +02:00
parent 140ff723e4
commit f22d60f011
36 changed files with 602 additions and 327 deletions

View File

@@ -868,7 +868,7 @@ class IsPattern(Pattern):
sub_pattern: optional[Pattern] | child
class NamedPattern(Pattern):
name: string
var_decl: VarDecl
class OptionalSomePattern(Pattern):
sub_pattern: Pattern | child
@@ -884,6 +884,7 @@ class TypedPattern(Pattern):
type_repr: optional["TypeRepr"] | child
@group("stmt")
@qltest.test_with("SwitchStmt")
class CaseLabelItem(AstNode):
pattern: Pattern | child
guard: optional[Expr] | child
@@ -948,10 +949,11 @@ class BreakStmt(Stmt):
target_name: optional[string]
target: optional[Stmt]
@qltest.test_with("SwitchStmt")
class CaseStmt(Stmt):
body: Stmt | child
labels: list[CaseLabelItem] | child
variables: list[VarDecl]
variables: list[VarDecl] | child
body: Stmt | child
class ContinueStmt(Stmt):
target_name: optional[string]