From 9cc80de0719faa8ceb27f360d0fc5c6e53641112 Mon Sep 17 00:00:00 2001 From: Asger F Date: Wed, 2 Sep 2026 13:59:28 +0200 Subject: [PATCH 01/10] unified: Merge Pattern and TypeExpr into Expr --- unified/extractor/ast_types.yml | 174 +++----- .../extractor/src/languages/swift/swift.rs | 181 ++++----- .../closures/closure-with-capture-list.output | 4 +- .../closure-with-explicit-parameters.output | 12 +- .../closure-with-shorthand-parameters.output | 2 +- .../closures/multi-statement-closure.output | 14 +- .../swift/collections/array-literal.output | 2 +- .../collections/dictionary-literal.output | 2 +- .../collections/dictionary-subscript.output | 2 +- .../empty-array-literal-with-type.output | 10 +- .../swift/collections/set-literal.output | 10 +- .../swift/collections/subscript-access.output | 2 +- .../swift/collections/tuple-literal.output | 2 +- .../collections/tuple-member-access.output | 2 +- ...g-modifier-does-not-leak-to-sibling.output | 8 +- .../swift/control-flow/fallthrough.output | 10 +- .../swift/control-flow/guard-let.output | 16 +- ...t-with-shadowing-in-condition-value.output | 2 +- .../if-let-optional-binding.output | 16 +- .../nested-enum-case-pattern.output | 40 +- .../switch-case-item-where-clauses.output | 7 +- .../control-flow/switch-statement.output | 10 +- .../switch-with-binding-pattern.output | 24 +- ...with-labeled-case-pattern-arguments.output | 34 +- .../control-flow/ternary-expression.output | 2 +- ...with-deeply-nested-path-three-parts.output | 2 +- .../import-with-dotted-path-two-parts.output | 2 +- .../scoped-import-uses-name-pattern.output | 2 +- .../simple-import-with-single-name.output | 2 +- .../expressions/array-type-constructor.output | 32 +- .../expressions/array-type-metatype.output | 14 +- .../expressions/consume-expression.output | 4 +- .../swift/expressions/copy-expression.output | 4 +- .../generic-specialization-expression.output | 10 +- .../expressions/key-path-expression.output | 2 +- .../functions/call-with-inout-argument.output | 4 +- ...onstructor-call-with-type-arguments.output | 10 +- ...nction-with-default-parameter-value.output | 6 +- .../function-with-inout-parameter.output | 2 +- .../function-with-named-parameters.output | 6 +- ...ion-with-parameters-and-return-type.output | 16 +- .../swift/functions/generic-function.output | 10 +- .../swift/functions/generic-type-alias.output | 16 +- .../leading-dot-expression-call.output | 2 +- .../leading-dot-expression-value.output | 2 +- .../functions/nested-function-type.output | 50 +-- .../swift/functions/variadic-function.output | 10 +- .../swift/literals/line-magic-literal.output | 2 +- .../swift/loops/break-and-continue.output | 2 +- .../loops/for-in-over-array-literal.output | 2 +- .../swift/loops/for-in-over-range.output | 2 +- .../loops/for-in-with-where-clause.output | 2 +- .../operators/custom-postfix-operator.output | 2 +- .../swift/operators/partial-range-from.output | 2 +- ...solved-operator-sequence-with-casts.output | 12 +- ...lved-operator-sequence-with-ternary.output | 28 +- .../unresolved-operator-sequence.output | 12 +- .../catch-where-clauses.output | 4 +- .../optionals-and-errors/force-unwrap.output | 2 +- .../nil-coalescing.output | 2 +- .../optional-chaining.output | 2 +- .../optional-enum-case-binding.output | 26 +- .../optional-type-annotation.output | 10 +- .../throwing-function.output | 4 +- .../try-expression-2.output | 2 +- .../try-expression.output | 2 +- ...er-does-not-leak-into-accessor-body.output | 10 +- .../swift/types/class-inheritance.output | 4 +- .../swift/types/class-with-initializer.output | 12 +- .../swift/types/class-with-method.output | 2 +- .../class-with-multiple-base-types.output | 8 +- .../types/class-with-stored-properties.output | 12 +- .../swift/types/computed-property.output | 16 +- .../types/constructor-with-parameters.output | 12 +- .../types/enum-with-associated-values.output | 12 +- .../corpus/swift/types/enum-with-cases.output | 8 +- ...separated-cases-chained-declaration.output | 8 +- .../tests/corpus/swift/types/extension.output | 4 +- ...tion-type-with-convention-attribute.output | 2 +- ...nction-type-with-sendable-attribute.output | 2 +- ...ic-class-parameters-and-constraints.output | 20 +- .../swift/types/generic-type-arguments.output | 18 +- .../swift/types/inline-array-type.output | 2 +- .../swift/types/noncopyable-type.output | 6 +- .../property-with-getter-and-setter.output | 10 +- ...nd-read-write-property-requirements.output | 12 +- .../corpus/swift/types/qualified-type.output | 30 +- .../tests/corpus/swift/types/struct.output | 12 +- ...fier-does-not-leak-into-initializer.output | 8 +- .../corpus/swift/variables/let-binding.output | 2 +- .../variables/let-with-type-annotation.output | 6 +- .../multiple-bindings-on-one-line.output | 4 +- ...y-with-willset-and-didset-observers.output | 6 +- .../tuple-destructuring-binding.output | 14 +- .../corpus/swift/variables/var-binding.output | 2 +- .../variables/var-without-initialiser.output | 6 +- .../ql/lib/codeql/unified/internal/Ast.qll | 375 +++--------------- .../unified/internal/ControlFlowGraph.qll | 1 - .../lib/codeql/unified/internal/FacadeAst.qll | 10 - .../unified/internal/LocalNameBinding.qll | 37 +- .../unified/internal/StaticNameBinding.qll | 12 +- unified/ql/lib/unified.dbscheme | 227 +++-------- .../library-tests/BasicTest/test.expected | 62 +++ .../ql/test/library-tests/BasicTest/test.ql | 4 + 104 files changed, 741 insertions(+), 1173 deletions(-) diff --git a/unified/extractor/ast_types.yml b/unified/extractor/ast_types.yml index dd17a9d584bf..167829166795 100644 --- a/unified/extractor/ast_types.yml +++ b/unified/extractor/ast_types.yml @@ -1,6 +1,7 @@ supertypes: expr: - name_expr + - named_pattern - int_literal - float_literal - boolean_literal @@ -33,25 +34,16 @@ supertypes: - switch_expr - unresolved_operator_sequence - unsupported_node - - pattern - expr_or_type: - - expr - - type_expr + - or_pattern + - conditional_pattern + - bulk_importing_pattern + - generic_type_expr + - inferred_type_expr # An element of an `unresolved_operator_sequence`: either an operand (`expr`) # or one of the infix operators separating the operands. expr_or_operator: - expr - infix_operator - pattern: - - name_pattern - - tuple_pattern - - constructor_pattern - - or_pattern - - conditional_pattern - - ignore_pattern - - expr_equality_pattern - - bulk_importing_pattern - - unsupported_node # A statement is anything that can appear in a block. # This type contains all of 'expr' and has partial overlap with 'member'. # For example, type_alias_declaration can appear either as a stmt or member. @@ -91,13 +83,6 @@ supertypes: - type_alias_declaration - associated_type_declaration - unsupported_node - type_expr: - - named_type_expr - - generic_type_expr - - tuple_type_expr - - function_type_expr - - inferred_type_expr - - unsupported_node type_constraint: - equality_type_constraint - bound_type_constraint @@ -111,10 +96,16 @@ named: top_level: body: block - # An identifier used in the context of an expression + # An identifier used as a name reference. name_expr: identifier: identifier + # An identifier that introduces a binding, optionally applying a nested pattern. + named_pattern: + modifier*: modifier + identifier: identifier + sub_pattern?: expr + # An integer literal int_literal: @@ -175,11 +166,10 @@ named: # # Method calls are represented as a call whose `function` is a `member_access_expr`. # - # Constructor calls are marked by a language-specific modifier, and the target may be - # a `type_expr` if the parser can deduce that the target is a type. + # Constructor calls are marked by a language-specific modifier. call_expr: modifier*: modifier - callee: expr_or_type + callee: expr argument*: argument argument: @@ -189,13 +179,9 @@ named: # Member access, such as `obj.member`. # - # The base may be a type expression when it is a static member access like `Array.method`. - # In ambiguous cases where the parser cannot distinguish static and instance member access, the base - # will be typically be an expression. - # # For `super.x` the base will be an instance of `super_expr`. member_access_expr: - base: expr_or_type + base: expr member: identifier # A type expression that refers to a type inferred from the contextual type. @@ -211,8 +197,8 @@ named: modifier*: modifier capture_declaration*: variable_declaration parameter*: parameter - return_type?: type_expr - body: block + return_type?: expr + body?: block array_literal: element*: expr @@ -228,26 +214,25 @@ named: key: expr value: expr - # A tuple expression, such as `(a, b, c)`. + # A tuple expression, pattern, or type, such as `(a, b, c)`. tuple_expr: - element*: expr + element*: argument # A parameter. # # `type` is its declared type annotation (if any) # # `pattern` binds the parameter's internal name(s). For a simple parameter this is a - # `name_pattern`, but may be an arbitrary pattern for languages where patterns may appear - # in the parameter list. + # `named_pattern`, but may be an arbitrary expression where languages allow destructuring. # # `external_name` is the name by which to call sites refer to the parameter, if the parameter # can be passed as a named parameter. For example, the Swift function `func greet(person id: String)` - # would have `person` as the external name and a `name_pattern` wrapping `id` is the parameter's pattern. + # would have `person` as the external name and a `named_pattern` wrapping `id` as the parameter's pattern. parameter: modifier*: modifier external_name?: identifier - type?: type_expr - pattern?: pattern + type?: expr + pattern?: expr default?: expr # An expression that does nothing. Used where the grammar permits an @@ -279,8 +264,8 @@ named: # `chained_declaration` modifier so the grouping can be recovered downstream. variable_declaration: modifier*: modifier - pattern: pattern - type?: type_expr + pattern: expr + type?: expr value?: expr # Evaluate 'condition', and if false, execute 'else' which must break from the enclosing block scope (return, break, etc). @@ -323,7 +308,7 @@ named: import_declaration: modifier*: modifier imported_expr: expr # Qualified names are encoded as a chain of member_access_expr ending with a name_expr - pattern?: pattern # Binds local names in scope (possibly via bulk_importing_pattern) + pattern?: expr # Binds local names in scope (possibly via bulk_importing_pattern) # `typealias Name = Type` type_alias_declaration: @@ -331,7 +316,7 @@ named: name: identifier type_parameter*: type_parameter type_constraint*: type_constraint - type: type_expr + type: expr # A top-level function declaration. function_declaration: @@ -340,13 +325,13 @@ named: type_parameter*: type_parameter type_constraint*: type_constraint parameter*: parameter - return_type?: type_expr + return_type?: expr body?: block # `for pattern in iterable [where guard] { body }`. for_each_stmt: modifier*: modifier - pattern: pattern + pattern: expr iterable: expr guard?: expr body?: block @@ -372,7 +357,7 @@ named: catch_clause: modifier*: modifier - pattern?: pattern + pattern?: expr body: block # `switch value { case pattern: body case ...: default: body }` @@ -386,7 +371,7 @@ named: # A `default:` entry has no pattern. switch_case: modifier*: modifier - pattern?: pattern + pattern?: expr body: block # Evaluate 'expr' and match its result against 'pattern', and return true if it matches. @@ -396,7 +381,7 @@ named: # # Java: 'if (x instanceof Foo y && w ...) { ... }' pattern_guard_expr: - pattern: pattern + pattern: expr value: expr # A type cast expression, such as `x as T`, `x as? T`, or `x as! T`. The @@ -404,49 +389,19 @@ named: type_cast_expr: expr: expr operator: infix_operator - type: type_expr + type: expr # A type-test expression, such as `x is T`. Yields a boolean indicating # whether `expr` is an instance of `type`. type_test_expr: expr: expr - operator: infix_operator - type: type_expr - - # An identifier that introduces a variable. - # - # When used as a pattern, the pattern matches anything and binds its incoming value to the variable - name_pattern: - modifier*: modifier - identifier: identifier - sub_pattern?: pattern - - # A pattern matching anything, binding no variables, usually using the syntax "_" - ignore_pattern: - - # A pattern that matches if the incoming value is equal to the value of the given expression. - # Used for literal patterns in switch (e.g. `case 1:`). - expr_equality_pattern: - expr: expr - - # A tuple pattern such as `(a, b)` in `let (a, b) = pair`. - # - # Elements of the tuple pattern can have names, such as Swift's `let (foo: x, bar: y) = tuple`. - tuple_pattern: - modifier*: modifier - element*: pattern_element - - # A pattern such as `Some(x)` where `Some` is the constructor and `x` is an element. - # The element names are interpreted as argument labels and/or field names. - constructor_pattern: - modifier*: modifier - constructor: expr_or_type - element*: pattern_element + operator?: infix_operator + type: expr # A disjunction pattern that matches if any of its sub-patterns match. or_pattern: modifier*: modifier - pattern*: pattern + pattern*: expr # A pattern that matches against a nested pattern, and subsequently checks a condition. # The match is rejected if the condition does not hold. @@ -454,22 +409,7 @@ named: conditional_pattern: modifier*: modifier condition: expr - pattern: pattern - - # A pattern with an optional associated name. - pattern_element: - modifier*: modifier - key?: identifier - pattern: pattern - - # A pattern that checks if the incoming value has the given type, and if so, the - # value is matched against the given nested pattern (and succeeds iff the nested match succeeds). - # - # In Swift: `if let y = x as? Foo` is a pattern_guard_expr containing a type_test_pattern - # In Java: `x instanceof Foo y` is a type_test_pattern wrapping a name_pattern - type_test_pattern: - pattern: pattern - type: type_expr + pattern: expr # A '*' pattern that imports all members of the incoming value into the local scope # Currently this can only appear in import declarations. @@ -495,21 +435,21 @@ named: type_parameter: modifier*: modifier name: identifier - bound?: type_expr + bound?: expr # A generic constraint of the form `T == U`, requiring two types to be # equal. Appears in `where` clauses on generic declarations # (e.g. Swift `func foo() where T == U`). equality_type_constraint: - left: type_expr - right: type_expr + left: expr + right: expr # A generic constraint of the form `T: Bound`, requiring a type parameter # to conform to (or inherit from) some other type. Appears in `where` # clauses on generic declarations (e.g. Swift `where T: Equatable`). bound_type_constraint: - type: type_expr - bound: type_expr + type: expr + bound: expr # `infix operator +++` (and the like) — a declaration of a custom operator. operator_syntax_declaration: @@ -541,7 +481,7 @@ named: # kind should be included as a modifier on this node. base_type: modifier*: modifier - type: type_expr + type: expr constructor_declaration: modifier*: modifier @@ -568,7 +508,7 @@ named: name: identifier accessor_kind: accessor_kind parameter*: parameter - type?: type_expr + type?: expr body?: block # "get", "set", or a language-specific kind like "didSet" @@ -582,29 +522,11 @@ named: associated_type_declaration: modifier*: modifier name: identifier - bound?: type_expr - - named_type_expr: - qualifier?: type_expr - name: identifier + bound?: expr generic_type_expr: - base: type_expr - type_argument*: type_expr - - # A tuple type such as `(Int, String)` or `(a: A, b: B)`. - tuple_type_expr: - element*: tuple_type_element - - # An element of a `tuple_type_expr`, optionally carrying a label. - tuple_type_element: - name?: identifier - type: type_expr - - # A function type such as `(Int, String) -> Bool` or `(x: Int) -> Bool`. - function_type_expr: - parameter*: parameter - return_type: type_expr + base: expr + type_argument*: expr # A modifier such as 'static', 'public', or 'async'. For now this is just a leaf node with a string value. modifier: diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 6396d4addd75..9f389c66650a 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -30,16 +30,13 @@ struct SwiftContext { /// True while translating the parameters of a `functionType`. swift-syntax /// models a function type's parameters with the same `tupleTypeElement` /// kind as a tuple type's elements, so the shared `tupleTypeElement` rule - /// reads this to emit a `parameter` (function-type param) rather than a - /// `tuple_type_element` (tuple-type element). The `tupleType` / - /// `functionType` rules each set it for their direct children, so nested - /// types are translated in the correct context. + /// reads this to emit a `parameter` (function-type parameter) rather than + /// an `argument` (tuple element). The `tupleType` / `functionType` rules + /// each set it for their direct children, so nested types are translated + /// in the correct context. in_function_type: bool, - /// True while translating the argument list of an enum-case - /// `constructor_pattern` (e.g. `case .foo(let x, 3)`). Read by the - /// `labeledExpr` rules so a bare expression argument becomes an - /// `expr_equality_pattern` (wrapped in a `pattern_element`) rather than a - /// call `argument`. + /// True while translating a pattern. Optional chaining in this context is + /// represented as an `Optional.some` call rather than being unwrapped. in_pattern: bool, } @@ -159,28 +156,22 @@ fn translation_rules() -> Vec> { // (hex/binary/octal, single- vs multi-line, raw): each is a single // `*LiteralExpr` kind, so one rule per literal type suffices. rule!((integerLiteralExpr) @@node => expr { - let value = tree!((int_literal #{node})); - if ctx.in_pattern { tree!((expr_equality_pattern expr: {value})) } else { value } + tree!((int_literal #{node})) }), rule!((floatLiteralExpr) @@node => expr { - let value = tree!((float_literal #{node})); - if ctx.in_pattern { tree!((expr_equality_pattern expr: {value})) } else { value } + tree!((float_literal #{node})) }), rule!((booleanLiteralExpr) @@node => expr { - let value = tree!((boolean_literal #{node})); - if ctx.in_pattern { tree!((expr_equality_pattern expr: {value})) } else { value } + tree!((boolean_literal #{node})) }), rule!((nilLiteralExpr) @@node => expr { - let value = tree!((builtin_expr #{node})); - if ctx.in_pattern { tree!((expr_equality_pattern expr: {value})) } else { value } + tree!((builtin_expr #{node})) }), rule!((stringLiteralExpr) @@node => expr { - let value = tree!((string_literal #{node})); - if ctx.in_pattern { tree!((expr_equality_pattern expr: {value})) } else { value } + tree!((string_literal #{node})) }), rule!((regexLiteralExpr) @@node => expr { - let value = tree!((regex_literal #{node})); - if ctx.in_pattern { tree!((expr_equality_pattern expr: {value})) } else { value } + tree!((regex_literal #{node})) }), // ---- Names ---- // A function reference spelled with argument labels (`f(x:y:z:)`) is a @@ -195,12 +186,7 @@ fn translation_rules() -> Vec> { (unsupported_node) ), rule!((declReferenceExpr baseName: (identifier) @name) => expr { - let name = tree!((name_expr identifier: (identifier #{name}))); - if ctx.in_pattern { - tree!((expr_equality_pattern expr: {name})) - } else { - name - } + tree!((name_expr identifier: (identifier #{name}))) }), // A bare name reference (`x`), and an operator used as a value (`+` in // `reduce(0, +)`), are both `declReferenceExpr`; its `baseName` is the @@ -208,8 +194,7 @@ fn translation_rules() -> Vec> { rule!((declReferenceExpr baseName: @name) => (name_expr identifier: (identifier #{name}))), // A discard `_` used as an expression — e.g. the target of a discarding // assignment `_ = x`. swift-syntax models it as a `discardAssignmentExpr`; - // the target AST has no expression-level discard (only `ignore_pattern`, - // which is a pattern), so it becomes a `name_expr` over the `_` token. + // the target AST represents it as a `name_expr` over the `_` token. rule!((discardAssignmentExpr wildcard: @@w) => (name_expr identifier: (identifier #{w}))), // A generic specialization in expression position (`C`, // `Array`) is represented by swift-syntax as a @@ -222,7 +207,7 @@ fn translation_rules() -> Vec> { genericArgumentClause: (genericArgumentClause arguments: (genericArgument argument: @args)*)) => (generic_type_expr - base: (named_type_expr name: (identifier #{name})) + base: (name_expr identifier: (identifier #{name})) type_argument: {args}) ), // ---- Operators ---- @@ -357,7 +342,7 @@ fn translation_rules() -> Vec> { result.push(tree!( (variable_declaration modifier: {ctx.outer_modifiers.clone()} - pattern: (name_pattern identifier: (identifier #{name})) + pattern: (named_pattern identifier: (identifier #{name})) type: {ty} value: {val}) )); @@ -465,7 +450,7 @@ fn translation_rules() -> Vec> { rule!( (enumCaseParameter firstName: _? @@name type: @ty) => - (parameter pattern: (name_pattern identifier: (identifier #{name}))? type: {ty}) + (parameter pattern: (named_pattern identifier: (identifier #{name}))? type: {ty}) ), // An enum element with associated values (`case circle(radius: Double)`) // becomes a nested `class_like_declaration` whose constructor carries the @@ -491,7 +476,7 @@ fn translation_rules() -> Vec> { modifier: {ctx.outer_modifiers.clone()} modifier: {chained_modifier(&mut ctx)} modifier: (modifier "enum_case") - pattern: (name_pattern identifier: (identifier #{name})) + pattern: (named_pattern identifier: (identifier #{name})) value: {val}) ), rule!( @@ -501,7 +486,7 @@ fn translation_rules() -> Vec> { modifier: {ctx.outer_modifiers.clone()} modifier: {chained_modifier(&mut ctx)} modifier: (modifier "enum_case") - pattern: (name_pattern identifier: (identifier #{name}))) + pattern: (named_pattern identifier: (identifier #{name}))) ), // Enum cases. A single `case` declaration may carry modifiers // (e.g. `indirect`) and list several comma-separated elements; each @@ -527,20 +512,19 @@ fn translation_rules() -> Vec> { rule!( (identifierPattern identifier: @name) => - (name_pattern identifier: (identifier #{name})) + (named_pattern identifier: (identifier #{name})) ), // A `let`/`var` value-binding pattern (`let x`) inside a case or `if case` - // introduces a new binding; it unwraps to its inner pattern (a - // `name_pattern`). + // introduces a new binding; it unwraps to its inner expression. rule!((valueBindingPattern pattern: @p) => pattern { p }), // A tuple destructuring pattern (`let (a, b) = …`). A labelled element - // (`let (x: a) = …`) carries its label through as the `pattern_element` - // key; unlabelled elements have no key. - rule!((tuplePattern elements: _* @els) => (tuple_pattern element: {els})), + // (`let (x: a) = …`) carries its label through as the `argument` name; + // unlabelled elements have no name. + rule!((tuplePattern elements: _* @els) => (tuple_expr element: {els})), rule!( (tuplePatternElement label: _? @@label pattern: @p) => - (pattern_element key: (identifier #{label})? pattern: {p}) + (argument name: (identifier #{label})? value: {p}) ), // A type-casting pattern (`case is T`). Not yet supported, so it is // mapped to `unsupported_node` — an explicit reminder that this needs @@ -550,7 +534,7 @@ fn translation_rules() -> Vec> { // A wildcard *binding* pattern (`let _ = x`, `for _ in xs`). swift-syntax // models this as a `wildcardPattern`, distinct from the `_` match form // handled by the context-aware `discardAssignmentExpr` rule. - rule!((wildcardPattern) => (ignore_pattern)), + rule!((wildcardPattern) @@wildcard => (name_expr identifier: (identifier #{wildcard}))), // An expression pattern only establishes pattern context; its child // determines the concrete pattern shape. rule!((expressionPattern expression: @@e) => expr { @@ -611,7 +595,7 @@ fn translation_rules() -> Vec> { }; tree!((parameter external_name: {external} - pattern: (name_pattern identifier: (identifier #{name})) + pattern: (named_pattern identifier: (identifier #{name})) type: {ty} default: {val})) } @@ -629,7 +613,7 @@ fn translation_rules() -> Vec> { => (call_expr callee: (generic_type_expr - base: (named_type_expr name: (identifier "Array")) + base: (name_expr identifier: (identifier "Array")) type_argument: {element}) argument: {args} argument: (argument value: {tc})) @@ -641,7 +625,7 @@ fn translation_rules() -> Vec> { => (call_expr callee: (generic_type_expr - base: (named_type_expr name: (identifier "Array")) + base: (name_expr identifier: (identifier "Array")) type_argument: {element}) argument: {args}) ), @@ -663,20 +647,11 @@ fn translation_rules() -> Vec> { ctx.in_pattern = false; ctx.translate(rawCallee) })?; - if ctx.in_pattern { - tree!((constructor_pattern constructor: {callee} element: {args})) - } else { - tree!((call_expr callee: {callee} argument: {args})) - } + tree!((call_expr callee: {callee} argument: {args})) } ), - // A call argument or an enum-case pattern argument. When translating an - // enum-case `constructor_pattern`'s arguments (`ctx.in_pattern`), a - // `patternExpr` argument (`let x`) becomes a bound `name_pattern`, a - // wildcard (`_`) becomes an `ignore_pattern`, and any other expression - // becomes an `expr_equality_pattern`; each is wrapped in a - // `pattern_element` carrying the optional argument label as its `key`. - // Otherwise the argument keeps its label as the `name` and its value. + // A call or enum-case pattern argument. Both use the shared `argument` + // shape, preserving the optional label as `name` and the child as `value`. // The pattern-only shapes (`patternExpr`, `discardAssignmentExpr`) are // matched first; they never occur as ordinary call arguments. rule!( @@ -687,40 +662,26 @@ fn translation_rules() -> Vec> { arguments: _* @elements)) => argument { - if ctx.in_pattern { - tree!((pattern_element - key: (identifier #{lbl})? - pattern: (constructor_pattern - constructor: {constructor} - element: {elements}))) - } else { - tree!((argument - name: (identifier #{lbl})? - value: (call_expr callee: {constructor} argument: {elements}))) - } + tree!((argument + name: (identifier #{lbl})? + value: (call_expr callee: {constructor} argument: {elements}))) } ), rule!( (labeledExpr label: _? @@lbl expression: (patternExpr pattern: @p)) => - (pattern_element key: (identifier #{lbl})? pattern: {p}) + (argument name: (identifier #{lbl})? value: {p}) ), rule!( (labeledExpr label: _? @@lbl expression: (discardAssignmentExpr) @@wildcard) => - (pattern_element key: (identifier #{lbl})? pattern: (ignore_pattern #{wildcard})) + (argument name: (identifier #{lbl})? value: (name_expr identifier: (identifier #{wildcard}))) ), rule!( (labeledExpr label: _? @@lbl expression: @val) => argument { - if ctx.in_pattern { - tree!((pattern_element - key: (identifier #{lbl})? - pattern: {val})) - } else { - tree!((argument name: (identifier #{lbl})? value: {val})) - } + tree!((argument name: (identifier #{lbl})? value: {val})) } ), // Member access (`list.append`). The `declName` is itself a @@ -737,7 +698,7 @@ fn translation_rules() -> Vec> { => (member_access_expr base: (generic_type_expr - base: (named_type_expr name: (identifier "Array")) + base: (name_expr identifier: (identifier "Array")) type_argument: {element}) member: (identifier #{member})) ), @@ -783,7 +744,7 @@ fn translation_rules() -> Vec> { ), // A closure capture (`[weak self]`, `[x]`, `[y = expr]`). The optional // ownership specifier (`weak`/`unowned`) becomes a modifier; the - // captured name becomes the bound `name_pattern`; an explicit capture + // captured name becomes the bound `name_expr`; an explicit capture // initializer (`[y = expr]`) becomes the bound value. rule!( (closureCapture @@ -793,7 +754,7 @@ fn translation_rules() -> Vec> { => (variable_declaration modifier: (modifier #{spec})? - pattern: (name_pattern identifier: (identifier #{name})) + pattern: (named_pattern identifier: (identifier #{name})) value: {val}) ), // A closure parameter clause (`(x: Int, y)`) unwraps to its parameters. @@ -803,14 +764,14 @@ fn translation_rules() -> Vec> { rule!( (closureParameter firstName: @name type: _? @ty) => - (parameter pattern: (name_pattern identifier: (identifier #{name})) type: {ty}) + (parameter pattern: (named_pattern identifier: (identifier #{name})) type: {ty}) ), // A shorthand closure parameter (`x` in `{ x, y in … }`): a bare name // with no parentheses and no type. rule!( (closureShorthandParameter name: @name) => - (parameter pattern: (name_pattern identifier: (identifier #{name}))) + (parameter pattern: (named_pattern identifier: (identifier #{name}))) ), // ---- Control flow ---- // An `if`/`else` expression. Conditions are joined via `and_chain`; the @@ -881,18 +842,18 @@ fn translation_rules() -> Vec> { => (pattern_guard_expr value: {val} - pattern: (constructor_pattern - constructor: (member_access_expr base: (named_type_expr name: (identifier "Optional")) member: (identifier "some")) - element: (pattern_element pattern: (name_pattern identifier: (identifier #{name}))))) + pattern: (call_expr + callee: (member_access_expr base: (name_expr identifier: (identifier "Optional")) member: (identifier "some")) + argument: (argument value: (named_pattern identifier: (identifier #{name}))))) ), rule!( (optionalBindingCondition pattern: (identifierPattern identifier: @name)) => (pattern_guard_expr value: (name_expr identifier: (identifier #{name})) - pattern: (constructor_pattern - constructor: (member_access_expr base: (named_type_expr name: (identifier "Optional")) member: (identifier "some")) - element: (pattern_element pattern: (name_pattern identifier: (identifier #{name}))))) + pattern: (call_expr + callee: (member_access_expr base: (name_expr identifier: (identifier "Optional")) member: (identifier "some")) + argument: (argument value: (named_pattern identifier: (identifier #{name}))))) ), // A single condition in an `if`/`while`/`guard` condition list unwraps to // its inner expression; `and_chain` joins multiple with `&&`. @@ -964,11 +925,11 @@ fn translation_rules() -> Vec> { rule!((optionalChainingExpr expression: @@inner) => expr { let inner = ctx.translate(inner)?.into_iter().next().ok_or("optional chaining expression has no child")?; if ctx.in_pattern { - tree!((constructor_pattern - constructor: (member_access_expr - base: (named_type_expr name: (identifier "Optional")) + tree!((call_expr + callee: (member_access_expr + base: (name_expr identifier: (identifier "Optional")) member: (identifier "some")) - element: (pattern_element pattern: {inner}))) + argument: (argument value: {inner}))) } else { inner } @@ -1029,7 +990,7 @@ fn translation_rules() -> Vec> { // `importPathComponent`s) becomes a `name_expr`/`member_access_expr` // chain (via `member_chain`). A scoped import (`import struct Foo.Bar`) // has an `importKindSpecifier` and binds the last path component as a - // `name_pattern`; a plain import (`import Foundation`) has none and uses + // `name_expr`; a plain import (`import Foundation`) has none and uses // a `bulk_importing_pattern` spanning the whole declaration. Any leading // attributes (`@_exported`) and access modifiers (`public`) become // `modifier`s. @@ -1046,7 +1007,7 @@ fn translation_rules() -> Vec> { Some(_) => None, // scoped import, no bulk import }; let last = *parts.last().ok_or("import has no path")?; - let pattern = tree!((name_pattern identifier: (identifier #{last}) sub_pattern: {bulk_import})); + let pattern = tree!((named_pattern identifier: (identifier #{last}) sub_pattern: {bulk_import})); tree!((import_declaration modifier: (modifier #{kind})? modifier: {attrs} @@ -1075,75 +1036,75 @@ fn translation_rules() -> Vec> { genericArgumentClause: (genericArgumentClause arguments: (genericArgument argument: @args)*)) => (generic_type_expr - base: (named_type_expr name: (identifier #{name})) + base: (name_expr identifier: (identifier #{name})) type_argument: {args}) ), // A named type (`Int`). `identifierType.name` is the type-name token. - rule!((identifierType name: @@n) => (named_type_expr name: (identifier #{n}))), + rule!((identifierType name: @@n) => (name_expr identifier: (identifier #{n}))), // A qualified type (`Outer.Inner`, `NSString.CompareOptions`). swift-syntax - // nests these as `memberType` nodes; preserve the nesting in the - // named_type_expr qualifier field. + // nests these as `memberType` nodes; preserve the nesting as ordinary + // member access. rule!( (memberType baseType: @base name: @@name) => - (named_type_expr qualifier: {base} name: (identifier #{name})) + (member_access_expr base: {base} member: (identifier #{name})) ), // Sugared types desugar to `generic_type_expr`: `T?` -> Optional, // `[T]` -> Array, `[K: V]` -> Dictionary. rule!( (optionalType wrappedType: @w) => - (generic_type_expr base: (named_type_expr name: (identifier "Optional")) type_argument: {w}) + (generic_type_expr base: (name_expr identifier: (identifier "Optional")) type_argument: {w}) ), rule!( (arrayType element: @e) => - (generic_type_expr base: (named_type_expr name: (identifier "Array")) type_argument: {e}) + (generic_type_expr base: (name_expr identifier: (identifier "Array")) type_argument: {e}) ), rule!( (dictionaryType key: @k value: @v) => - (generic_type_expr base: (named_type_expr name: (identifier "Dictionary")) type_argument: {k} type_argument: {v}) + (generic_type_expr base: (name_expr identifier: (identifier "Dictionary")) type_argument: {k} type_argument: {v}) ), // A tuple type (`(Int, String)`) or function type (`(Int) -> Bool`). // Both hold their contents as `tupleTypeElement`s, but a tuple element - // maps to `tuple_type_element` while a function parameter maps to - // `parameter`. Each container sets `ctx.in_function_type` for its direct + // maps to `argument` while a function parameter maps to `parameter`. + // Each container sets `ctx.in_function_type` for its direct // children (and translates them explicitly, so a nested type is // translated in the right context) and the shared `tupleTypeElement` // rule below reads it. An element's label (`firstName`) is optional. rule!( (tupleType elements: _* @@elems) => - tuple_type_expr { + tuple_expr { ctx.in_function_type = false; let mut out = Vec::new(); for e in elems { out.extend(ctx.translate(e)?); } - tree!((tuple_type_expr element: {out})) + tree!((tuple_expr element: {out})) } ), rule!( (functionType parameters: _* @@params returnClause: (returnClause type: @ret)) => - function_type_expr { + function_expr { ctx.in_function_type = true; let mut out = Vec::new(); for p in params { out.extend(ctx.translate(p)?); } - tree!((function_type_expr parameter: {out} return_type: {ret})) + tree!((function_expr parameter: {out} return_type: {ret})) } ), rule!( (tupleTypeElement firstName: _? @@name type: @ty) => - tuple_type_element { + argument { if ctx.in_function_type { tree!((parameter external_name: (identifier #{name})? type: {ty})) } else { - tree!((tuple_type_element name: (identifier #{name})? type: {ty})) + tree!((argument name: (identifier #{name})? value: {ty})) } } ), diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output index 6833344de16d..d9203985ad59 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output @@ -67,7 +67,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "f" value: function_expr @@ -75,7 +75,7 @@ top_level variable_declaration modifier: modifier "weak" pattern: - name_pattern + named_pattern identifier: identifier "self" body: block diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output index c20da77c72cb..f9ba376b2272 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output @@ -69,21 +69,21 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "f" value: function_expr parameter: parameter type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "x" return_type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output index 1b07604e02c5..a5a074d48a78 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output @@ -46,7 +46,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "f" value: function_expr diff --git a/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output index 4fbc1c8f71f0..b5fb2465fce4 100644 --- a/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output +++ b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output @@ -100,28 +100,28 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "f" value: function_expr parameter: parameter type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "x" return_type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "y" value: binary_expr diff --git a/unified/extractor/tests/corpus/swift/collections/array-literal.output b/unified/extractor/tests/corpus/swift/collections/array-literal.output index c6ea2c2094fa..37d02ffec267 100644 --- a/unified/extractor/tests/corpus/swift/collections/array-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/array-literal.output @@ -48,7 +48,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "xs" value: array_literal diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output index edd306a69cbd..689ab33ce2fe 100644 --- a/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output @@ -59,6 +59,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "d" value: map_literal "[\"a\": 1, \"b\": 2]" diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output index e2f939e0683c..e24550673f80 100644 --- a/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output @@ -48,7 +48,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "v" value: call_expr diff --git a/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output index e9a70a43bb42..51b535de7ee2 100644 --- a/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output +++ b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output @@ -44,14 +44,14 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "xs" type: generic_type_expr base: - named_type_expr - name: identifier "Array" + name_expr + identifier: identifier "Array" type_argument: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" value: array_literal "[]" diff --git a/unified/extractor/tests/corpus/swift/collections/set-literal.output b/unified/extractor/tests/corpus/swift/collections/set-literal.output index a06670231ebb..a0bfaab57804 100644 --- a/unified/extractor/tests/corpus/swift/collections/set-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/set-literal.output @@ -63,16 +63,16 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "s" type: generic_type_expr base: - named_type_expr - name: identifier "Set" + name_expr + identifier: identifier "Set" type_argument: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" value: array_literal element: diff --git a/unified/extractor/tests/corpus/swift/collections/subscript-access.output b/unified/extractor/tests/corpus/swift/collections/subscript-access.output index ec24f0c1f1df..2ae548bfe1d0 100644 --- a/unified/extractor/tests/corpus/swift/collections/subscript-access.output +++ b/unified/extractor/tests/corpus/swift/collections/subscript-access.output @@ -45,7 +45,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "first" value: call_expr diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-literal.output b/unified/extractor/tests/corpus/swift/collections/tuple-literal.output index facbc2fcbb45..74d505ab5b8c 100644 --- a/unified/extractor/tests/corpus/swift/collections/tuple-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/tuple-literal.output @@ -52,6 +52,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "t" value: tuple_expr "(1, \"two\", 3.0)" diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output index 6ecbd22eebe0..30298ed89865 100644 --- a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output +++ b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output @@ -38,7 +38,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "n" value: member_access_expr diff --git a/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output b/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output index 800647eb7474..bb3c49721f44 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output +++ b/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output @@ -91,7 +91,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" value: int_literal "1" switch_expr @@ -101,10 +101,8 @@ top_level case: switch_case pattern: - expr_equality_pattern - expr: - name_expr - identifier: identifier "someConstant" + name_expr + identifier: identifier "someConstant" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output index 9cfe81048402..79bea22bbe24 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output +++ b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output @@ -92,10 +92,10 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "x" body: block @@ -106,9 +106,7 @@ top_level identifier: identifier "x" case: switch_case - pattern: - expr_equality_pattern - expr: int_literal "1" + pattern: int_literal "1" body: block stmt: unsupported_node "fallthrough" diff --git a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output index d739eca564b5..9c0fbc37926e 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output +++ b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output @@ -44,17 +44,17 @@ top_level condition: pattern_guard_expr pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: - named_type_expr - name: identifier "Optional" + name_expr + identifier: identifier "Optional" member: identifier "some" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "value" value: name_expr diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output index 2a0676513f23..808b1dd610c9 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output @@ -68,7 +68,7 @@ top_level condition: pattern_guard_expr pattern: - name_pattern + named_pattern identifier: identifier "x" value: binary_expr diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output index d1bcf82b0faa..5f26de40c1b3 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output @@ -57,17 +57,17 @@ top_level condition: pattern_guard_expr pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: - named_type_expr - name: identifier "Optional" + name_expr + identifier: identifier "Optional" member: identifier "some" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "value" value: name_expr diff --git a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output index 66a6f32dab4d..c6eae5b793f0 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output @@ -166,27 +166,27 @@ top_level case: switch_case pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "received" - element: - pattern_element - pattern: - constructor_pattern - constructor: + argument: + argument + value: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "some" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "value" - pattern_element - pattern: - name_pattern + argument + value: + named_pattern identifier: identifier "timestamp" body: block @@ -206,17 +206,17 @@ top_level identifier: identifier "timestamp" switch_case pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: name_expr identifier: identifier "Type" member: identifier "some" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "value" body: block diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output b/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output index 9d2041aa2ad1..c60b3ffb7284 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output @@ -170,7 +170,7 @@ top_level operator: infix_operator ">" right: int_literal "0" pattern: - name_pattern + named_pattern identifier: identifier "x" body: block @@ -195,10 +195,9 @@ top_level operator: infix_operator "<" right: int_literal "0" pattern: - name_pattern + named_pattern identifier: identifier "y" - expr_equality_pattern - expr: int_literal "0" + int_literal "0" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output index a88579852947..c14948ae54e9 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output @@ -130,9 +130,7 @@ top_level identifier: identifier "x" case: switch_case - pattern: - expr_equality_pattern - expr: int_literal "1" + pattern: int_literal "1" body: block stmt: @@ -147,10 +145,8 @@ top_level pattern: or_pattern pattern: - expr_equality_pattern - expr: int_literal "2" - expr_equality_pattern - expr: int_literal "3" + int_literal "2" + int_literal "3" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output index 90bb6b44e6e5..3db9aa3ddcc3 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output @@ -126,15 +126,15 @@ top_level case: switch_case pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "circle" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "r" body: block @@ -150,15 +150,15 @@ top_level identifier: identifier "r" switch_case pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "square" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "s" body: block diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output index 20b17d160e44..269eed5906ab 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output @@ -134,17 +134,15 @@ top_level case: switch_case pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "implicit" - element: - pattern_element - key: identifier "isAcknowledged" - pattern: - expr_equality_pattern - expr: boolean_literal "false" + argument: + argument + name: identifier "isAcknowledged" + value: boolean_literal "false" body: block stmt: @@ -157,18 +155,20 @@ top_level value: string_literal "\"yes\"" switch_case pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "thread" - element: - pattern_element - key: identifier "threadRowId" - pattern: ignore_pattern "_" - pattern_element - pattern: - name_pattern + argument: + argument + name: identifier "threadRowId" + value: + name_expr + identifier: identifier "_" + argument + value: + named_pattern identifier: identifier "rowId" body: block diff --git a/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output index 88c7bc1b886c..360835a10799 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output +++ b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output @@ -53,7 +53,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "y" value: if_expr diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output index ed16e68e219d..b423f1c0e14e 100644 --- a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output @@ -38,6 +38,6 @@ top_level member: identifier "Networking" member: identifier "URLSession" pattern: - name_pattern + named_pattern identifier: identifier "URLSession" sub_pattern: bulk_importing_pattern "import Foundation.Networking.URLSession" diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output index 88f08baa19ce..074dd8a1cca7 100644 --- a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output @@ -32,6 +32,6 @@ top_level identifier: identifier "Foundation" member: identifier "Networking" pattern: - name_pattern + named_pattern identifier: identifier "Networking" sub_pattern: bulk_importing_pattern "import Foundation.Networking" diff --git a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output index 93319c522981..376a7cefd43c 100644 --- a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output +++ b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output @@ -34,5 +34,5 @@ top_level identifier: identifier "Foundation" member: identifier "Date" pattern: - name_pattern + named_pattern identifier: identifier "Date" diff --git a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output index 31261cd952c3..600df253234b 100644 --- a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output +++ b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output @@ -26,6 +26,6 @@ top_level name_expr identifier: identifier "Foundation" pattern: - name_pattern + named_pattern identifier: identifier "Foundation" sub_pattern: bulk_importing_pattern "import Foundation" diff --git a/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output b/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output index 43f1c8a553da..4f74f03a5de0 100644 --- a/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output +++ b/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output @@ -131,43 +131,43 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "values" value: call_expr callee: generic_type_expr base: - named_type_expr - name: identifier "Array" + name_expr + identifier: identifier "Array" type_argument: generic_type_expr base: - named_type_expr - name: identifier "Result" + name_expr + identifier: identifier "Result" type_argument: - named_type_expr - name: identifier "Void" + name_expr + identifier: identifier "Void" variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "initialized" value: call_expr callee: generic_type_expr base: - named_type_expr - name: identifier "Array" + name_expr + identifier: identifier "Array" type_argument: generic_type_expr base: - named_type_expr - name: identifier "Result" + name_expr + identifier: identifier "Result" type_argument: - named_type_expr - name: identifier "Void" + name_expr + identifier: identifier "Void" argument: argument name: identifier "unsafeUninitializedCapacity" @@ -178,11 +178,11 @@ top_level parameter: parameter pattern: - name_pattern + named_pattern identifier: identifier "_" parameter pattern: - name_pattern + named_pattern identifier: identifier "count" body: block diff --git a/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output b/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output index f06917190b3a..95262f0c5487 100644 --- a/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output +++ b/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output @@ -55,21 +55,21 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "type" value: member_access_expr base: generic_type_expr base: - named_type_expr - name: identifier "Array" + name_expr + identifier: identifier "Array" type_argument: generic_type_expr base: - named_type_expr - name: identifier "Result" + name_expr + identifier: identifier "Result" type_argument: - named_type_expr - name: identifier "Void" + name_expr + identifier: identifier "Void" member: identifier "self" diff --git a/unified/extractor/tests/corpus/swift/expressions/consume-expression.output b/unified/extractor/tests/corpus/swift/expressions/consume-expression.output index f20f89b72558..50ac9b41dbae 100644 --- a/unified/extractor/tests/corpus/swift/expressions/consume-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/consume-expression.output @@ -69,7 +69,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "original" value: array_literal @@ -80,6 +80,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "consumed" value: unsupported_node "consume original" diff --git a/unified/extractor/tests/corpus/swift/expressions/copy-expression.output b/unified/extractor/tests/corpus/swift/expressions/copy-expression.output index 9f065b046a90..c12051aca725 100644 --- a/unified/extractor/tests/corpus/swift/expressions/copy-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/copy-expression.output @@ -69,7 +69,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "original" value: array_literal @@ -80,6 +80,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "copied" value: unsupported_node "copy original" diff --git a/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output b/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output index 94cdf978b9d2..0871c64a4d64 100644 --- a/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output @@ -49,15 +49,15 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "numbers" value: call_expr callee: generic_type_expr base: - named_type_expr - name: identifier "Array" + name_expr + identifier: identifier "Array" type_argument: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output b/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output index a803e9e594fd..461d9fc4b89f 100644 --- a/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output @@ -43,6 +43,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "keyPath" value: unsupported_node "\\String.count" diff --git a/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output b/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output index 3dae9884c81e..542f7e54730e 100644 --- a/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output +++ b/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output @@ -76,13 +76,13 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "a" value: int_literal "1" variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "b" value: int_literal "2" call_expr diff --git a/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output b/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output index 37afdfa0d639..bb7b5fce65d5 100644 --- a/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output +++ b/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output @@ -92,15 +92,15 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" value: call_expr callee: generic_type_expr base: - named_type_expr - name: identifier "C" + name_expr + identifier: identifier "C" type_argument: - named_type_expr - name: identifier "Foo" + name_expr + identifier: identifier "Foo" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output index 3495a13106fb..bff9c6018540 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output @@ -70,10 +70,10 @@ top_level parameter: parameter type: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" pattern: - name_pattern + named_pattern identifier: identifier "name" default: string_literal "\"world\"" body: diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output b/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output index 232fb6dc2dbc..9c3aa054e1f9 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output @@ -68,7 +68,7 @@ top_level external_name: identifier "_" type: unsupported_node "inout Int" pattern: - name_pattern + named_pattern identifier: identifier "x" body: block diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output index 7488edbcb231..2c577f940197 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output @@ -62,10 +62,10 @@ top_level parameter external_name: identifier "person" type: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" pattern: - name_pattern + named_pattern identifier: identifier "name" body: block diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output index e69b19307674..0acf938ebe4f 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output @@ -79,22 +79,22 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "a" parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "b" return_type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/functions/generic-function.output b/unified/extractor/tests/corpus/swift/functions/generic-function.output index dc7831410e23..6cf4caef5b12 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-function.output @@ -72,14 +72,14 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "T" + name_expr + identifier: identifier "T" pattern: - name_pattern + named_pattern identifier: identifier "x" return_type: - named_type_expr - name: identifier "T" + name_expr + identifier: identifier "T" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output b/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output index 36737bd95bda..d60ce9b27b27 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output @@ -61,17 +61,17 @@ top_level type_parameter name: identifier "T" bound: - named_type_expr - name: identifier "Equatable" + name_expr + identifier: identifier "Equatable" type_parameter name: identifier "U" type: generic_type_expr base: - named_type_expr - name: identifier "Dictionary" + name_expr + identifier: identifier "Dictionary" type_argument: - named_type_expr - name: identifier "T" - named_type_expr - name: identifier "U" + name_expr + identifier: identifier "T" + name_expr + identifier: identifier "U" diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output index a5b38e1e2bea..7b7aab7984fc 100644 --- a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output @@ -45,7 +45,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "y" value: call_expr diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output index 41128b61818e..8b374c20c858 100644 --- a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output @@ -35,7 +35,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" value: member_access_expr diff --git a/unified/extractor/tests/corpus/swift/functions/nested-function-type.output b/unified/extractor/tests/corpus/swift/functions/nested-function-type.output index d9ce0cd7a976..0428a5a5356d 100644 --- a/unified/extractor/tests/corpus/swift/functions/nested-function-type.output +++ b/unified/extractor/tests/corpus/swift/functions/nested-function-type.output @@ -107,50 +107,50 @@ top_level type_alias_declaration name: identifier "NestedFunction" type: - function_type_expr + function_expr parameter: parameter type: - function_type_expr + function_expr parameter: parameter type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" return_type: - named_type_expr - name: identifier "Bool" + name_expr + identifier: identifier "Bool" return_type: - named_type_expr - name: identifier "Bool" + name_expr + identifier: identifier "Bool" type_alias_declaration name: identifier "MixedParametersAndTuples" type: - function_type_expr + function_expr parameter: parameter type: - function_type_expr + function_expr parameter: parameter type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" return_type: - named_type_expr - name: identifier "Bool" + name_expr + identifier: identifier "Bool" parameter type: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" return_type: - tuple_type_expr + tuple_expr element: - tuple_type_element - type: - named_type_expr - name: identifier "Bool" - tuple_type_element - type: - named_type_expr - name: identifier "Int" + argument + value: + name_expr + identifier: identifier "Bool" + argument + value: + name_expr + identifier: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/functions/variadic-function.output b/unified/extractor/tests/corpus/swift/functions/variadic-function.output index 78c20ffc01e9..9a87fa620158 100644 --- a/unified/extractor/tests/corpus/swift/functions/variadic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/variadic-function.output @@ -83,14 +83,14 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "values" return_type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output b/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output index 1616055fc16c..d0fe61074147 100644 --- a/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output +++ b/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output @@ -35,6 +35,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "currentLine" value: unsupported_node "#line" diff --git a/unified/extractor/tests/corpus/swift/loops/break-and-continue.output b/unified/extractor/tests/corpus/swift/loops/break-and-continue.output index 7ce869998272..524dfc851553 100644 --- a/unified/extractor/tests/corpus/swift/loops/break-and-continue.output +++ b/unified/extractor/tests/corpus/swift/loops/break-and-continue.output @@ -104,7 +104,7 @@ top_level stmt: for_each_stmt pattern: - name_pattern + named_pattern identifier: identifier "x" iterable: name_expr diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output index 2d8db27bfe85..d8d851da1ec4 100644 --- a/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output @@ -62,7 +62,7 @@ top_level stmt: for_each_stmt pattern: - name_pattern + named_pattern identifier: identifier "x" iterable: array_literal diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output index cb8b4e67b68d..1299d445a0ec 100644 --- a/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output @@ -54,7 +54,7 @@ top_level stmt: for_each_stmt pattern: - name_pattern + named_pattern identifier: identifier "i" iterable: binary_expr diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output index 6659039029f3..50632ecf9f33 100644 --- a/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output +++ b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output @@ -60,7 +60,7 @@ top_level stmt: for_each_stmt pattern: - name_pattern + named_pattern identifier: identifier "x" iterable: name_expr diff --git a/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output b/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output index 5067671aa997..a16f291fbfab 100644 --- a/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output +++ b/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output @@ -43,6 +43,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "squared" value: unsupported_node "3^^" diff --git a/unified/extractor/tests/corpus/swift/operators/partial-range-from.output b/unified/extractor/tests/corpus/swift/operators/partial-range-from.output index 1b9208cedf8b..300d3e7c2e69 100644 --- a/unified/extractor/tests/corpus/swift/operators/partial-range-from.output +++ b/unified/extractor/tests/corpus/swift/operators/partial-range-from.output @@ -35,6 +35,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "range" value: unsupported_node "3..." diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output index a0563c7bc88b..27e81c82766e 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output @@ -99,18 +99,18 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Any" + name_expr + identifier: identifier "Any" pattern: - name_pattern + named_pattern identifier: identifier "a" parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "b" body: block diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output index 57274c32a9c2..3bd9a4e920cb 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output @@ -105,38 +105,38 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Bool" + name_expr + identifier: identifier "Bool" pattern: - name_pattern + named_pattern identifier: identifier "c" parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "a" parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "b" parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "d" return_type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output index 46dc8ca6ae89..dc652b757aba 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output @@ -72,18 +72,18 @@ top_level parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "a" parameter external_name: identifier "_" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "b" body: block diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output index 79b7879d35fa..7c50ddc7bbf8 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output @@ -168,7 +168,7 @@ top_level name_expr identifier: identifier "e" pattern: - name_pattern + named_pattern identifier: identifier "e" conditional_pattern condition: @@ -182,7 +182,7 @@ top_level name_expr identifier: identifier "f" pattern: - name_pattern + named_pattern identifier: identifier "f" body: block diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output index 2c6fd1a6f763..a7014629e1b0 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output @@ -35,7 +35,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "n" value: unary_expr diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output index 31a039ad0065..c90fe3ae7f36 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output @@ -40,7 +40,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "n" value: binary_expr diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output index b69b0ae47d50..8f07d4a51d8a 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output @@ -50,7 +50,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "n" value: member_access_expr diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output index 7b1eb1eea3b4..35e1a7319ed2 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output @@ -80,25 +80,25 @@ top_level condition: pattern_guard_expr pattern: - constructor_pattern - constructor: + call_expr + callee: member_access_expr base: - named_type_expr - name: identifier "Optional" + name_expr + identifier: identifier "Optional" member: identifier "some" - element: - pattern_element - pattern: - constructor_pattern - constructor: + argument: + argument + value: + call_expr + callee: member_access_expr base: inferred_type_expr "." member: identifier "some" - element: - pattern_element - pattern: - name_pattern + argument: + argument + value: + named_pattern identifier: identifier "value" value: name_expr diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output index 1927b494ef9a..132f3a424475 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output @@ -41,14 +41,14 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" type: generic_type_expr base: - named_type_expr - name: identifier "Optional" + name_expr + identifier: identifier "Optional" type_argument: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" value: builtin_expr "nil" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output index e68b4c3c57ac..03ad472b33e0 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output @@ -58,8 +58,8 @@ top_level function_declaration name: identifier "read" return_type: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output index aafc0c67c217..c7fe32e98bd4 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output @@ -42,7 +42,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "result" value: unary_expr diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output index 5b1b0b24d0fa..269d77f7c0ad 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output @@ -42,7 +42,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "result" value: unary_expr diff --git a/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output b/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output index c05bc7794437..9bcd96de183b 100644 --- a/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output +++ b/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output @@ -101,8 +101,8 @@ top_level name: identifier "p" accessor_kind: accessor_kind "get" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: @@ -113,10 +113,8 @@ top_level case: switch_case pattern: - expr_equality_pattern - expr: - name_expr - identifier: identifier "someConstant" + name_expr + identifier: identifier "someConstant" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/types/class-inheritance.output b/unified/extractor/tests/corpus/swift/types/class-inheritance.output index 12328f4acb0d..9eff2e05f4a7 100644 --- a/unified/extractor/tests/corpus/swift/types/class-inheritance.output +++ b/unified/extractor/tests/corpus/swift/types/class-inheritance.output @@ -38,5 +38,5 @@ top_level base_type: base_type type: - named_type_expr - name: identifier "Animal" + name_expr + identifier: identifier "Animal" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output index 83945d89e3a0..814badd5672d 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output @@ -97,19 +97,19 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "x" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" constructor_declaration parameter: parameter type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "x" body: block diff --git a/unified/extractor/tests/corpus/swift/types/class-with-method.output b/unified/extractor/tests/corpus/swift/types/class-with-method.output index f45cb31e53ad..6d705579a6df 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-method.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-method.output @@ -84,7 +84,7 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "n" value: int_literal "0" function_declaration diff --git a/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output b/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output index e66b88e9be3d..3075db477518 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output @@ -43,9 +43,9 @@ top_level base_type: base_type type: - named_type_expr - name: identifier "Control" + name_expr + identifier: identifier "Control" base_type type: - named_type_expr - name: identifier "Drawable" + name_expr + identifier: identifier "Drawable" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output index e184426eb755..456632aee765 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output @@ -68,16 +68,16 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "x" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "y" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/types/computed-property.output b/unified/extractor/tests/corpus/swift/types/computed-property.output index 24e816be0091..d1472abad268 100644 --- a/unified/extractor/tests/corpus/swift/types/computed-property.output +++ b/unified/extractor/tests/corpus/swift/types/computed-property.output @@ -108,26 +108,26 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "w" type: - named_type_expr - name: identifier "Double" + name_expr + identifier: identifier "Double" variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "h" type: - named_type_expr - name: identifier "Double" + name_expr + identifier: identifier "Double" accessor_declaration modifier: modifier "var" name: identifier "area" accessor_kind: accessor_kind "get" type: - named_type_expr - name: identifier "Double" + name_expr + identifier: identifier "Double" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output index c9be21dd156a..9b943de8c8d1 100644 --- a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output +++ b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output @@ -72,17 +72,17 @@ top_level parameter external_name: identifier "width" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "w" parameter external_name: identifier "height" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" pattern: - name_pattern + named_pattern identifier: identifier "h" body: block "init(width w: Int, height h: Int) {}" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output index 399239bbea30..b8a86a5b57d7 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output @@ -81,10 +81,10 @@ top_level parameter: parameter type: - named_type_expr - name: identifier "Double" + name_expr + identifier: identifier "Double" pattern: - name_pattern + named_pattern identifier: identifier "radius" body: block "circle(radius: Double)" class_like_declaration @@ -95,9 +95,9 @@ top_level parameter: parameter type: - named_type_expr - name: identifier "Double" + name_expr + identifier: identifier "Double" pattern: - name_pattern + named_pattern identifier: identifier "side" body: block "square(side: Double)" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output index f081c2a82046..a73235cbdc53 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output @@ -72,20 +72,20 @@ top_level variable_declaration modifier: modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "north" variable_declaration modifier: modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "south" variable_declaration modifier: modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "east" variable_declaration modifier: modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "west" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output index 6a4ea95e9a62..840e6fd1425c 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output @@ -51,26 +51,26 @@ top_level variable_declaration modifier: modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "clubs" variable_declaration modifier: modifier "chained_declaration" modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "diamonds" variable_declaration modifier: modifier "chained_declaration" modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "hearts" variable_declaration modifier: modifier "chained_declaration" modifier "enum_case" pattern: - name_pattern + named_pattern identifier: identifier "spades" diff --git a/unified/extractor/tests/corpus/swift/types/extension.output b/unified/extractor/tests/corpus/swift/types/extension.output index 1b1d02ebddad..943674ae2d4d 100644 --- a/unified/extractor/tests/corpus/swift/types/extension.output +++ b/unified/extractor/tests/corpus/swift/types/extension.output @@ -75,8 +75,8 @@ top_level function_declaration name: identifier "squared" return_type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output b/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output index 3d484d6f65d8..d7dc17326afe 100644 --- a/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output +++ b/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output @@ -65,7 +65,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "callback" type: unsupported_node "@convention(c) () -> Void" value: diff --git a/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output b/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output index ef9f838dadbe..3228b81bc456 100644 --- a/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output +++ b/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output @@ -58,7 +58,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "handler" type: unsupported_node "@Sendable () -> Void" value: diff --git a/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output b/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output index 26b17599ae00..0b1152ce4678 100644 --- a/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output +++ b/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output @@ -73,22 +73,22 @@ top_level type_parameter name: identifier "T" bound: - named_type_expr - name: identifier "Equatable" + name_expr + identifier: identifier "Equatable" type_parameter name: identifier "U" type_constraint: bound_type_constraint type: - named_type_expr - name: identifier "U" + name_expr + identifier: identifier "U" bound: - named_type_expr - name: identifier "Equatable" + name_expr + identifier: identifier "Equatable" equality_type_constraint left: - named_type_expr - name: identifier "U" + name_expr + identifier: identifier "U" right: - named_type_expr - name: identifier "T" + name_expr + identifier: identifier "T" diff --git a/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output b/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output index ce12c853d9d5..3c3310d0dbed 100644 --- a/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output +++ b/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output @@ -63,21 +63,21 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "cache" type: generic_type_expr base: - named_type_expr - name: identifier "Dictionary" + name_expr + identifier: identifier "Dictionary" type_argument: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" generic_type_expr base: - named_type_expr - name: identifier "Array" + name_expr + identifier: identifier "Array" type_argument: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" value: map_literal "[:]" diff --git a/unified/extractor/tests/corpus/swift/types/inline-array-type.output b/unified/extractor/tests/corpus/swift/types/inline-array-type.output index 5f70d9d55168..b0e08711e9a2 100644 --- a/unified/extractor/tests/corpus/swift/types/inline-array-type.output +++ b/unified/extractor/tests/corpus/swift/types/inline-array-type.output @@ -66,7 +66,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "triple" type: unsupported_node "[3 of Int]" value: diff --git a/unified/extractor/tests/corpus/swift/types/noncopyable-type.output b/unified/extractor/tests/corpus/swift/types/noncopyable-type.output index 4fb13ca13ece..784a0139a760 100644 --- a/unified/extractor/tests/corpus/swift/types/noncopyable-type.output +++ b/unified/extractor/tests/corpus/swift/types/noncopyable-type.output @@ -64,8 +64,8 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "descriptor" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output index 951768cd8444..60183b0ff7b5 100644 --- a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output +++ b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output @@ -115,7 +115,7 @@ top_level modifier "var" modifier "private" pattern: - name_pattern + named_pattern identifier: identifier "_v" value: int_literal "0" accessor_declaration @@ -123,8 +123,8 @@ top_level name: identifier "v" accessor_kind: accessor_kind "get" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: @@ -139,8 +139,8 @@ top_level name: identifier "v" accessor_kind: accessor_kind "set" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output index 83362740bb1e..fa1f7771e511 100644 --- a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output +++ b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output @@ -88,18 +88,18 @@ top_level name: identifier "foo" accessor_kind: accessor_kind "get" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" accessor_declaration name: identifier "bar" accessor_kind: accessor_kind "get" type: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" accessor_declaration modifier: modifier "chained_declaration" name: identifier "bar" accessor_kind: accessor_kind "set" type: - named_type_expr - name: identifier "String" + name_expr + identifier: identifier "String" diff --git a/unified/extractor/tests/corpus/swift/types/qualified-type.output b/unified/extractor/tests/corpus/swift/types/qualified-type.output index f561dc6ab2dc..12dd46786964 100644 --- a/unified/extractor/tests/corpus/swift/types/qualified-type.output +++ b/unified/extractor/tests/corpus/swift/types/qualified-type.output @@ -115,25 +115,25 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "value" type: - named_type_expr - qualifier: - named_type_expr - name: identifier "Outer" - name: identifier "Inner" + member_access_expr + base: + name_expr + identifier: identifier "Outer" + member: identifier "Inner" variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "nested" type: - named_type_expr - qualifier: - named_type_expr - qualifier: - named_type_expr - name: identifier "Outer" - name: identifier "Inner" - name: identifier "Deep" + member_access_expr + base: + member_access_expr + base: + name_expr + identifier: identifier "Outer" + member: identifier "Inner" + member: identifier "Deep" diff --git a/unified/extractor/tests/corpus/swift/types/struct.output b/unified/extractor/tests/corpus/swift/types/struct.output index 57fb25c9e193..6ea2d81c0c67 100644 --- a/unified/extractor/tests/corpus/swift/types/struct.output +++ b/unified/extractor/tests/corpus/swift/types/struct.output @@ -68,16 +68,16 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "y" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output b/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output index d159cd6b37cb..d6d9516b93f5 100644 --- a/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output +++ b/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output @@ -68,7 +68,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" value: switch_expr @@ -78,10 +78,8 @@ top_level case: switch_case pattern: - expr_equality_pattern - expr: - name_expr - identifier: identifier "someConstant" + name_expr + identifier: identifier "someConstant" body: block stmt: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/let-binding.output b/unified/extractor/tests/corpus/swift/variables/let-binding.output index 4774eb3eeca8..00cf7be87c3f 100644 --- a/unified/extractor/tests/corpus/swift/variables/let-binding.output +++ b/unified/extractor/tests/corpus/swift/variables/let-binding.output @@ -32,6 +32,6 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output index a56feb445ace..112cca7e7b07 100644 --- a/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output +++ b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output @@ -38,9 +38,9 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output index 9470a578ad62..1c46136955ff 100644 --- a/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output +++ b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output @@ -43,7 +43,7 @@ top_level variable_declaration modifier: modifier "let" pattern: - name_pattern + named_pattern identifier: identifier "x" value: int_literal "1" variable_declaration @@ -51,6 +51,6 @@ top_level modifier "let" modifier "chained_declaration" pattern: - name_pattern + named_pattern identifier: identifier "y" value: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output index 8071d5d52900..79945f6fb16b 100644 --- a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output +++ b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output @@ -108,11 +108,11 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "x" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" value: int_literal "0" accessor_declaration modifier: diff --git a/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output index 6b6bd81115ed..8fc96f0feeba 100644 --- a/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output +++ b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output @@ -43,15 +43,15 @@ top_level variable_declaration modifier: modifier "let" pattern: - tuple_pattern + tuple_expr element: - pattern_element - pattern: - name_pattern + argument + value: + named_pattern identifier: identifier "a" - pattern_element - pattern: - name_pattern + argument + value: + named_pattern identifier: identifier "b" value: name_expr diff --git a/unified/extractor/tests/corpus/swift/variables/var-binding.output b/unified/extractor/tests/corpus/swift/variables/var-binding.output index 63498105dc75..babfbc9583bf 100644 --- a/unified/extractor/tests/corpus/swift/variables/var-binding.output +++ b/unified/extractor/tests/corpus/swift/variables/var-binding.output @@ -32,6 +32,6 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "x" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output index d841ce2bb583..0a01e0cc8ac2 100644 --- a/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output +++ b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output @@ -32,8 +32,8 @@ top_level variable_declaration modifier: modifier "var" pattern: - name_pattern + named_pattern identifier: identifier "x" type: - named_type_expr - name: identifier "Int" + name_expr + identifier: identifier "Int" diff --git a/unified/ql/lib/codeql/unified/internal/Ast.qll b/unified/ql/lib/codeql/unified/internal/Ast.qll index cf927e257a9c..cd5f8a7aaf00 100644 --- a/unified/ql/lib/codeql/unified/internal/Ast.qll +++ b/unified/ql/lib/codeql/unified/internal/Ast.qll @@ -124,7 +124,7 @@ module Unified { final F::Parameter getAParameter() { result = this.getParameter(_) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_accessor_declaration_type(this, result) } + final F::Expr getType() { unified_accessor_declaration_type(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -206,7 +206,7 @@ module Unified { final override string getAPrimaryQlClass() { result = "AssociatedTypeDeclaration" } /** Gets the node corresponding to the field `bound`. */ - final F::TypeExpr getBound() { unified_associated_type_declaration_bound(this, result) } + final F::Expr getBound() { unified_associated_type_declaration_bound(this, result) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getModifier(int i) { @@ -239,7 +239,7 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_base_type_def(this, result) } + final F::Expr getType() { unified_base_type_def(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -296,10 +296,10 @@ module Unified { final override string getAPrimaryQlClass() { result = "BoundTypeConstraint" } /** Gets the node corresponding to the field `bound`. */ - final F::TypeExpr getBound() { unified_bound_type_constraint_def(this, result, _) } + final F::Expr getBound() { unified_bound_type_constraint_def(this, result, _) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_bound_type_constraint_def(this, _, result) } + final F::Expr getType() { unified_bound_type_constraint_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -327,7 +327,7 @@ module Unified { } /** A class representing `bulk_importing_pattern` nodes. */ - class BulkImportingPattern extends @unified_bulk_importing_pattern, F::Pattern { + class BulkImportingPattern extends @unified_bulk_importing_pattern, F::Expr { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "BulkImportingPattern" } @@ -357,7 +357,7 @@ module Unified { final F::Argument getAnArgument() { result = this.getArgument(_) } /** Gets the node corresponding to the field `callee`. */ - final F::ExprOrType getCallee() { unified_call_expr_def(this, result) } + final F::Expr getCallee() { unified_call_expr_def(this, result) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getModifier(int i) { unified_call_expr_modifier(this, i, result) } @@ -390,7 +390,7 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_catch_clause_pattern(this, result) } + final F::Expr getPattern() { unified_catch_clause_pattern(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -480,7 +480,7 @@ module Unified { } /** A class representing `conditional_pattern` nodes. */ - class ConditionalPattern extends @unified_conditional_pattern, F::Pattern { + class ConditionalPattern extends @unified_conditional_pattern, F::Expr { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "ConditionalPattern" } @@ -494,7 +494,7 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_conditional_pattern_def(this, _, result) } + final F::Expr getPattern() { unified_conditional_pattern_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -542,36 +542,6 @@ module Unified { } } - /** A class representing `constructor_pattern` nodes. */ - class ConstructorPattern extends @unified_constructor_pattern, F::Pattern { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "ConstructorPattern" } - - /** Gets the node corresponding to the field `constructor`. */ - final F::ExprOrType getConstructor() { unified_constructor_pattern_def(this, result) } - - /** Gets the node corresponding to the field `element`. */ - final F::PatternElement getElement(int i) { - unified_constructor_pattern_element(this, i, result) - } - - /** Gets the node corresponding to the field `element`. */ - final F::PatternElement getAnElement() { result = this.getElement(_) } - - /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getModifier(int i) { unified_constructor_pattern_modifier(this, i, result) } - - /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getAModifier() { result = this.getModifier(_) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_constructor_pattern_def(this, result) or - unified_constructor_pattern_element(this, _, result) or - unified_constructor_pattern_modifier(this, _, result) - } - } - /** A class representing `continue_expr` nodes. */ class ContinueExpr extends @unified_continue_expr, F::Expr { /** Gets the name of the primary QL class for this element. */ @@ -646,10 +616,10 @@ module Unified { final override string getAPrimaryQlClass() { result = "EqualityTypeConstraint" } /** Gets the node corresponding to the field `left`. */ - final F::TypeExpr getLeft() { unified_equality_type_constraint_def(this, result, _) } + final F::Expr getLeft() { unified_equality_type_constraint_def(this, result, _) } /** Gets the node corresponding to the field `right`. */ - final F::TypeExpr getRight() { unified_equality_type_constraint_def(this, _, result) } + final F::Expr getRight() { unified_equality_type_constraint_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -658,24 +628,10 @@ module Unified { } } - class Expr extends @unified_expr, F::ExprOrOperator, F::ExprOrType, F::Stmt { } - - /** A class representing `expr_equality_pattern` nodes. */ - class ExprEqualityPattern extends @unified_expr_equality_pattern, F::Pattern { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "ExprEqualityPattern" } - - /** Gets the node corresponding to the field `expr`. */ - final F::Expr getExpr() { unified_expr_equality_pattern_def(this, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { unified_expr_equality_pattern_def(this, result) } - } + class Expr extends @unified_expr, F::ExprOrOperator, F::Stmt { } class ExprOrOperator extends @unified_expr_or_operator, F::AstNode { } - class ExprOrType extends @unified_expr_or_type, F::AstNode { } - /** A class representing `fixity` tokens. */ class Fixity extends @unified_token_fixity, F::AstNode, F::Token { /** Gets the name of the primary QL class for this element. */ @@ -709,7 +665,7 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_for_each_stmt_def(this, _, result) } + final F::Expr getPattern() { unified_for_each_stmt_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -747,7 +703,7 @@ module Unified { final F::Parameter getAParameter() { result = this.getParameter(_) } /** Gets the node corresponding to the field `return_type`. */ - final F::TypeExpr getReturnType() { unified_function_declaration_return_type(this, result) } + final F::Expr getReturnType() { unified_function_declaration_return_type(this, result) } /** Gets the node corresponding to the field `type_constraint`. */ final F::TypeConstraint getTypeConstraint(int i) { @@ -783,7 +739,7 @@ module Unified { final override string getAPrimaryQlClass() { result = "FunctionExpr" } /** Gets the node corresponding to the field `body`. */ - final F::Block getBody() { unified_function_expr_def(this, result) } + final F::Block getBody() { unified_function_expr_body(this, result) } /** Gets the node corresponding to the field `capture_declaration`. */ final F::VariableDeclaration getCaptureDeclaration(int i) { @@ -806,11 +762,11 @@ module Unified { final F::Parameter getAParameter() { result = this.getParameter(_) } /** Gets the node corresponding to the field `return_type`. */ - final F::TypeExpr getReturnType() { unified_function_expr_return_type(this, result) } + final F::Expr getReturnType() { unified_function_expr_return_type(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { - unified_function_expr_def(this, result) or + unified_function_expr_body(this, result) or unified_function_expr_capture_declaration(this, _, result) or unified_function_expr_modifier(this, _, result) or unified_function_expr_parameter(this, _, result) or @@ -818,42 +774,21 @@ module Unified { } } - /** A class representing `function_type_expr` nodes. */ - class FunctionTypeExpr extends @unified_function_type_expr, F::TypeExpr { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "FunctionTypeExpr" } - - /** Gets the node corresponding to the field `parameter`. */ - final F::Parameter getParameter(int i) { unified_function_type_expr_parameter(this, i, result) } - - /** Gets the node corresponding to the field `parameter`. */ - final F::Parameter getAParameter() { result = this.getParameter(_) } - - /** Gets the node corresponding to the field `return_type`. */ - final F::TypeExpr getReturnType() { unified_function_type_expr_def(this, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_function_type_expr_parameter(this, _, result) or - unified_function_type_expr_def(this, result) - } - } - /** A class representing `generic_type_expr` nodes. */ - class GenericTypeExpr extends @unified_generic_type_expr, F::TypeExpr { + class GenericTypeExpr extends @unified_generic_type_expr, F::Expr { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "GenericTypeExpr" } /** Gets the node corresponding to the field `base`. */ - final F::TypeExpr getBase() { unified_generic_type_expr_def(this, result) } + final F::Expr getBase() { unified_generic_type_expr_def(this, result) } /** Gets the node corresponding to the field `type_argument`. */ - final F::TypeExpr getTypeArgument(int i) { + final F::Expr getTypeArgument(int i) { unified_generic_type_expr_type_argument(this, i, result) } /** Gets the node corresponding to the field `type_argument`. */ - final F::TypeExpr getATypeArgument() { result = this.getTypeArgument(_) } + final F::Expr getATypeArgument() { result = this.getTypeArgument(_) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -907,12 +842,6 @@ module Unified { } } - /** A class representing `ignore_pattern` tokens. */ - class IgnorePattern extends @unified_token_ignore_pattern, F::Pattern, F::Token { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "IgnorePattern" } - } - /** A class representing `import_declaration` nodes. */ class ImportDeclaration extends @unified_import_declaration, F::Stmt { /** Gets the name of the primary QL class for this element. */ @@ -928,7 +857,7 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_import_declaration_pattern(this, result) } + final F::Expr getPattern() { unified_import_declaration_pattern(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -939,7 +868,7 @@ module Unified { } /** A class representing `inferred_type_expr` tokens. */ - class InferredTypeExpr extends @unified_token_inferred_type_expr, F::Token, F::TypeExpr { + class InferredTypeExpr extends @unified_token_inferred_type_expr, F::Expr, F::Token { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "InferredTypeExpr" } } @@ -1038,7 +967,7 @@ module Unified { final override string getAPrimaryQlClass() { result = "MemberAccessExpr" } /** Gets the node corresponding to the field `base`. */ - final F::ExprOrType getBase() { unified_member_access_expr_def(this, result, _) } + final F::Expr getBase() { unified_member_access_expr_def(this, result, _) } /** Gets the node corresponding to the field `member`. */ final F::Identifier getMember() { unified_member_access_expr_def(this, _, result) } @@ -1068,45 +997,28 @@ module Unified { final override F::AstNode getAFieldOrChild() { unified_name_expr_def(this, result) } } - /** A class representing `name_pattern` nodes. */ - class NamePattern extends @unified_name_pattern, F::Pattern { + /** A class representing `named_pattern` nodes. */ + class NamedPattern extends @unified_named_pattern, F::Expr { /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "NamePattern" } + final override string getAPrimaryQlClass() { result = "NamedPattern" } /** Gets the node corresponding to the field `identifier`. */ - final F::Identifier getIdentifier() { unified_name_pattern_def(this, result) } + final F::Identifier getIdentifier() { unified_named_pattern_def(this, result) } /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getModifier(int i) { unified_name_pattern_modifier(this, i, result) } + final F::Modifier getModifier(int i) { unified_named_pattern_modifier(this, i, result) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `sub_pattern`. */ - final F::Pattern getSubPattern() { unified_name_pattern_sub_pattern(this, result) } + final F::Expr getSubPattern() { unified_named_pattern_sub_pattern(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { - unified_name_pattern_def(this, result) or - unified_name_pattern_modifier(this, _, result) or - unified_name_pattern_sub_pattern(this, result) - } - } - - /** A class representing `named_type_expr` nodes. */ - class NamedTypeExpr extends @unified_named_type_expr, F::TypeExpr { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "NamedTypeExpr" } - - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_named_type_expr_def(this, result) } - - /** Gets the node corresponding to the field `qualifier`. */ - final F::TypeExpr getQualifier() { unified_named_type_expr_qualifier(this, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_named_type_expr_def(this, result) or unified_named_type_expr_qualifier(this, result) + unified_named_pattern_def(this, result) or + unified_named_pattern_modifier(this, _, result) or + unified_named_pattern_sub_pattern(this, result) } } @@ -1144,7 +1056,7 @@ module Unified { } /** A class representing `or_pattern` nodes. */ - class OrPattern extends @unified_or_pattern, F::Pattern { + class OrPattern extends @unified_or_pattern, F::Expr { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "OrPattern" } @@ -1155,10 +1067,10 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern(int i) { unified_or_pattern_pattern(this, i, result) } + final F::Expr getPattern(int i) { unified_or_pattern_pattern(this, i, result) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getAPattern() { result = this.getPattern(_) } + final F::Expr getAPattern() { result = this.getPattern(_) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -1184,10 +1096,10 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_parameter_pattern(this, result) } + final F::Expr getPattern() { unified_parameter_pattern(this, result) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_parameter_type(this, result) } + final F::Expr getType() { unified_parameter_type(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -1199,40 +1111,13 @@ module Unified { } } - class Pattern extends @unified_pattern, F::Expr { } - - /** A class representing `pattern_element` nodes. */ - class PatternElement extends @unified_pattern_element, F::AstNode { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "PatternElement" } - - /** Gets the node corresponding to the field `key`. */ - final F::Identifier getKey() { unified_pattern_element_key(this, result) } - - /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getModifier(int i) { unified_pattern_element_modifier(this, i, result) } - - /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getAModifier() { result = this.getModifier(_) } - - /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_pattern_element_def(this, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_pattern_element_key(this, result) or - unified_pattern_element_modifier(this, _, result) or - unified_pattern_element_def(this, result) - } - } - /** A class representing `pattern_guard_expr` nodes. */ class PatternGuardExpr extends @unified_pattern_guard_expr, F::Expr { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "PatternGuardExpr" } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_pattern_guard_expr_def(this, result, _) } + final F::Expr getPattern() { unified_pattern_guard_expr_def(this, result, _) } /** Gets the node corresponding to the field `value`. */ final F::Expr getValue() { unified_pattern_guard_expr_def(this, _, result) } @@ -1303,7 +1188,7 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_switch_case_pattern(this, result) } + final F::Expr getPattern() { unified_switch_case_pattern(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -1399,73 +1284,15 @@ module Unified { final override string getAPrimaryQlClass() { result = "TupleExpr" } /** Gets the node corresponding to the field `element`. */ - final F::Expr getElement(int i) { unified_tuple_expr_element(this, i, result) } + final F::Argument getElement(int i) { unified_tuple_expr_element(this, i, result) } /** Gets the node corresponding to the field `element`. */ - final F::Expr getAnElement() { result = this.getElement(_) } + final F::Argument getAnElement() { result = this.getElement(_) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { unified_tuple_expr_element(this, _, result) } } - /** A class representing `tuple_pattern` nodes. */ - class TuplePattern extends @unified_tuple_pattern, F::Pattern { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "TuplePattern" } - - /** Gets the node corresponding to the field `element`. */ - final F::PatternElement getElement(int i) { unified_tuple_pattern_element(this, i, result) } - - /** Gets the node corresponding to the field `element`. */ - final F::PatternElement getAnElement() { result = this.getElement(_) } - - /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getModifier(int i) { unified_tuple_pattern_modifier(this, i, result) } - - /** Gets the node corresponding to the field `modifier`. */ - final F::Modifier getAModifier() { result = this.getModifier(_) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_tuple_pattern_element(this, _, result) or - unified_tuple_pattern_modifier(this, _, result) - } - } - - /** A class representing `tuple_type_element` nodes. */ - class TupleTypeElement extends @unified_tuple_type_element, F::AstNode { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "TupleTypeElement" } - - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_tuple_type_element_name(this, result) } - - /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_tuple_type_element_def(this, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_tuple_type_element_name(this, result) or unified_tuple_type_element_def(this, result) - } - } - - /** A class representing `tuple_type_expr` nodes. */ - class TupleTypeExpr extends @unified_tuple_type_expr, F::TypeExpr { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "TupleTypeExpr" } - - /** Gets the node corresponding to the field `element`. */ - final F::TupleTypeElement getElement(int i) { unified_tuple_type_expr_element(this, i, result) } - - /** Gets the node corresponding to the field `element`. */ - final F::TupleTypeElement getAnElement() { result = this.getElement(_) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_tuple_type_expr_element(this, _, result) - } - } - /** A class representing `type_alias_declaration` nodes. */ class TypeAliasDeclaration extends @unified_type_alias_declaration, F::Member, F::Stmt { /** Gets the name of the primary QL class for this element. */ @@ -1483,7 +1310,7 @@ module Unified { final F::Identifier getName() { unified_type_alias_declaration_def(this, result, _) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_type_alias_declaration_def(this, _, result) } + final F::Expr getType() { unified_type_alias_declaration_def(this, _, result) } /** Gets the node corresponding to the field `type_constraint`. */ final F::TypeConstraint getTypeConstraint(int i) { @@ -1523,7 +1350,7 @@ module Unified { final F::InfixOperator getOperator() { unified_type_cast_expr_def(this, _, result, _) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_type_cast_expr_def(this, _, _, result) } + final F::Expr getType() { unified_type_cast_expr_def(this, _, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -1535,15 +1362,13 @@ module Unified { class TypeConstraint extends @unified_type_constraint, F::AstNode { } - class TypeExpr extends @unified_type_expr, F::ExprOrType { } - /** A class representing `type_parameter` nodes. */ class TypeParameter extends @unified_type_parameter, F::AstNode { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "TypeParameter" } /** Gets the node corresponding to the field `bound`. */ - final F::TypeExpr getBound() { unified_type_parameter_bound(this, result) } + final F::Expr getBound() { unified_type_parameter_bound(this, result) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getModifier(int i) { unified_type_parameter_modifier(this, i, result) } @@ -1568,37 +1393,19 @@ module Unified { final override string getAPrimaryQlClass() { result = "TypeTestExpr" } /** Gets the node corresponding to the field `expr`. */ - final F::Expr getExpr() { unified_type_test_expr_def(this, result, _, _) } + final F::Expr getExpr() { unified_type_test_expr_def(this, result, _) } /** Gets the node corresponding to the field `operator`. */ - final F::InfixOperator getOperator() { unified_type_test_expr_def(this, _, result, _) } - - /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_type_test_expr_def(this, _, _, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { - unified_type_test_expr_def(this, result, _, _) or - unified_type_test_expr_def(this, _, result, _) or - unified_type_test_expr_def(this, _, _, result) - } - } - - /** A class representing `type_test_pattern` nodes. */ - class TypeTestPattern extends @unified_type_test_pattern, F::AstNode { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "TypeTestPattern" } - - /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_type_test_pattern_def(this, result, _) } + final F::InfixOperator getOperator() { unified_type_test_expr_operator(this, result) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_type_test_pattern_def(this, _, result) } + final F::Expr getType() { unified_type_test_expr_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { - unified_type_test_pattern_def(this, result, _) or - unified_type_test_pattern_def(this, _, result) + unified_type_test_expr_def(this, result, _) or + unified_type_test_expr_operator(this, result) or + unified_type_test_expr_def(this, _, result) } } @@ -1639,9 +1446,7 @@ module Unified { } /** A class representing `unsupported_node` tokens. */ - class UnsupportedNode extends @unified_token_unsupported_node, F::Expr, F::Member, F::Pattern, - F::Token, F::TypeExpr - { + class UnsupportedNode extends @unified_token_unsupported_node, F::Expr, F::Member, F::Token { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "UnsupportedNode" } } @@ -1658,10 +1463,10 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `pattern`. */ - final F::Pattern getPattern() { unified_variable_declaration_def(this, result) } + final F::Expr getPattern() { unified_variable_declaration_def(this, result) } /** Gets the node corresponding to the field `type`. */ - final F::TypeExpr getType() { unified_variable_declaration_type(this, result) } + final F::Expr getType() { unified_variable_declaration_type(this, result) } /** Gets the node corresponding to the field `value`. */ final F::Expr getValue() { unified_variable_declaration_value(this, result) } @@ -1798,12 +1603,6 @@ module Unified { or result = node.(ConstructorDeclaration).getParameter(i) and name = "getParameter" or - result = node.(ConstructorPattern).getConstructor() and i = -1 and name = "getConstructor" - or - result = node.(ConstructorPattern).getElement(i) and name = "getElement" - or - result = node.(ConstructorPattern).getModifier(i) and name = "getModifier" - or result = node.(ContinueExpr).getLabel() and i = -1 and name = "getLabel" or result = node.(DestructorDeclaration).getBody() and i = -1 and name = "getBody" @@ -1820,8 +1619,6 @@ module Unified { or result = node.(EqualityTypeConstraint).getRight() and i = -1 and name = "getRight" or - result = node.(ExprEqualityPattern).getExpr() and i = -1 and name = "getExpr" - or result = node.(ForEachStmt).getBody() and i = -1 and name = "getBody" or result = node.(ForEachStmt).getGuard() and i = -1 and name = "getGuard" @@ -1856,10 +1653,6 @@ module Unified { or result = node.(FunctionExpr).getReturnType() and i = -1 and name = "getReturnType" or - result = node.(FunctionTypeExpr).getParameter(i) and name = "getParameter" - or - result = node.(FunctionTypeExpr).getReturnType() and i = -1 and name = "getReturnType" - or result = node.(GenericTypeExpr).getBase() and i = -1 and name = "getBase" or result = node.(GenericTypeExpr).getTypeArgument(i) and name = "getTypeArgument" @@ -1900,15 +1693,11 @@ module Unified { or result = node.(NameExpr).getIdentifier() and i = -1 and name = "getIdentifier" or - result = node.(NamePattern).getIdentifier() and i = -1 and name = "getIdentifier" - or - result = node.(NamePattern).getModifier(i) and name = "getModifier" - or - result = node.(NamePattern).getSubPattern() and i = -1 and name = "getSubPattern" + result = node.(NamedPattern).getIdentifier() and i = -1 and name = "getIdentifier" or - result = node.(NamedTypeExpr).getName() and i = -1 and name = "getName" + result = node.(NamedPattern).getModifier(i) and name = "getModifier" or - result = node.(NamedTypeExpr).getQualifier() and i = -1 and name = "getQualifier" + result = node.(NamedPattern).getSubPattern() and i = -1 and name = "getSubPattern" or result = node.(OperatorSyntaxDeclaration).getFixity() and i = -1 and name = "getFixity" or @@ -1934,12 +1723,6 @@ module Unified { or result = node.(Parameter).getType() and i = -1 and name = "getType" or - result = node.(PatternElement).getKey() and i = -1 and name = "getKey" - or - result = node.(PatternElement).getModifier(i) and name = "getModifier" - or - result = node.(PatternElement).getPattern() and i = -1 and name = "getPattern" - or result = node.(PatternGuardExpr).getPattern() and i = -1 and name = "getPattern" or result = node.(PatternGuardExpr).getValue() and i = -1 and name = "getValue" @@ -1970,16 +1753,6 @@ module Unified { or result = node.(TupleExpr).getElement(i) and name = "getElement" or - result = node.(TuplePattern).getElement(i) and name = "getElement" - or - result = node.(TuplePattern).getModifier(i) and name = "getModifier" - or - result = node.(TupleTypeElement).getName() and i = -1 and name = "getName" - or - result = node.(TupleTypeElement).getType() and i = -1 and name = "getType" - or - result = node.(TupleTypeExpr).getElement(i) and name = "getElement" - or result = node.(TypeAliasDeclaration).getModifier(i) and name = "getModifier" or result = node.(TypeAliasDeclaration).getName() and i = -1 and name = "getName" @@ -2008,10 +1781,6 @@ module Unified { or result = node.(TypeTestExpr).getType() and i = -1 and name = "getType" or - result = node.(TypeTestPattern).getPattern() and i = -1 and name = "getPattern" - or - result = node.(TypeTestPattern).getType() and i = -1 and name = "getType" - or result = node.(UnaryExpr).getOperand() and i = -1 and name = "getOperand" or result = node.(UnaryExpr).getOperator() and i = -1 and name = "getOperator" @@ -2087,8 +1856,6 @@ module UnifiedFinal { final class ConstructorDeclaration = F::ConstructorDeclaration; - final class ConstructorPattern = F::ConstructorPattern; - final class ContinueExpr = F::ContinueExpr; final class DestructorDeclaration = F::DestructorDeclaration; @@ -2101,12 +1868,8 @@ module UnifiedFinal { final class Expr = F::Expr; - final class ExprEqualityPattern = F::ExprEqualityPattern; - final class ExprOrOperator = F::ExprOrOperator; - final class ExprOrType = F::ExprOrType; - final class Fixity = F::Fixity; final class FloatLiteral = F::FloatLiteral; @@ -2117,8 +1880,6 @@ module UnifiedFinal { final class FunctionExpr = F::FunctionExpr; - final class FunctionTypeExpr = F::FunctionTypeExpr; - final class GenericTypeExpr = F::GenericTypeExpr; final class GuardIfStmt = F::GuardIfStmt; @@ -2127,8 +1888,6 @@ module UnifiedFinal { final class IfExpr = F::IfExpr; - final class IgnorePattern = F::IgnorePattern; - final class ImportDeclaration = F::ImportDeclaration; final class InferredTypeExpr = F::InferredTypeExpr; @@ -2153,9 +1912,7 @@ module UnifiedFinal { final class NameExpr = F::NameExpr; - final class NamePattern = F::NamePattern; - - final class NamedTypeExpr = F::NamedTypeExpr; + final class NamedPattern = F::NamedPattern; final class Operator = F::Operator; @@ -2165,10 +1922,6 @@ module UnifiedFinal { final class Parameter = F::Parameter; - final class Pattern = F::Pattern; - - final class PatternElement = F::PatternElement; - final class PatternGuardExpr = F::PatternGuardExpr; final class PostfixOperator = F::PostfixOperator; @@ -2197,26 +1950,16 @@ module UnifiedFinal { final class TupleExpr = F::TupleExpr; - final class TuplePattern = F::TuplePattern; - - final class TupleTypeElement = F::TupleTypeElement; - - final class TupleTypeExpr = F::TupleTypeExpr; - final class TypeAliasDeclaration = F::TypeAliasDeclaration; final class TypeCastExpr = F::TypeCastExpr; final class TypeConstraint = F::TypeConstraint; - final class TypeExpr = F::TypeExpr; - final class TypeParameter = F::TypeParameter; final class TypeTestExpr = F::TypeTestExpr; - final class TypeTestPattern = F::TypeTestPattern; - final class UnaryExpr = F::UnaryExpr; final class UnresolvedOperatorSequence = F::UnresolvedOperatorSequence; diff --git a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll index 15db0eb3836e..2e4a7dfc4c3a 100644 --- a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll +++ b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll @@ -128,7 +128,6 @@ private module Ast implements AstSig { // TODO support foreach guard // - // TODO: Expr != Pattern Expr getVariable() { result = super.getPattern() } Expr getCollection() { result = super.getIterable() } diff --git a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll index 3da8de4b8f03..3262de611441 100644 --- a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll +++ b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll @@ -74,14 +74,4 @@ module Unified { ) } } - - /** The base class for all patterns. */ - class Pattern extends G::Pattern { - /** Gets the immediately-enclosing pattern in which this is a nested pattern. */ - Pattern getEnclosingPattern() { - result = this.getParent() - or - result = this.getParent().(PatternElement).getParent() - } - } } diff --git a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll index 5a44080464cc..870612cf3ebc 100644 --- a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll @@ -168,7 +168,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig Date: Wed, 2 Sep 2026 14:26:12 +0200 Subject: [PATCH 02/10] unified: Preserve 'var' and 'let' pattern modifiers in AST --- unified/extractor/ast_types.yml | 6 ++ .../extractor/src/languages/swift/swift.rs | 8 +- ...t-with-shadowing-in-condition-value.output | 84 ++++++++++++++++++- ...et-with-shadowing-in-condition-value.swift | 4 + .../nested-enum-case-pattern.output | 54 ++++++------ .../switch-case-item-where-clauses.output | 14 +++- .../switch-with-binding-pattern.output | 14 +++- ...with-labeled-case-pattern-arguments.output | 7 +- .../catch-where-clauses.output | 14 +++- .../optional-enum-case-binding.output | 7 +- .../ql/lib/codeql/unified/internal/Ast.qll | 26 ++++++ .../unified/internal/LocalNameBinding.qll | 2 + unified/ql/lib/unified.dbscheme | 16 +++- 13 files changed, 210 insertions(+), 46 deletions(-) diff --git a/unified/extractor/ast_types.yml b/unified/extractor/ast_types.yml index 167829166795..b6f1d6bcfa79 100644 --- a/unified/extractor/ast_types.yml +++ b/unified/extractor/ast_types.yml @@ -2,6 +2,7 @@ supertypes: expr: - name_expr - named_pattern + - expr_pattern - int_literal - float_literal - boolean_literal @@ -106,6 +107,11 @@ named: identifier: identifier sub_pattern?: expr + # A pattern expression with modifiers, such as `let x` or `var x`. + expr_pattern: + modifier*: modifier + expr: expr + # An integer literal int_literal: diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 9f389c66650a..6fcaca5f7c5a 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -515,8 +515,12 @@ fn translation_rules() -> Vec> { (named_pattern identifier: (identifier #{name})) ), // A `let`/`var` value-binding pattern (`let x`) inside a case or `if case` - // introduces a new binding; it unwraps to its inner expression. - rule!((valueBindingPattern pattern: @p) => pattern { p }), + // preserves the binding specifier around its inner pattern. + rule!( + (valueBindingPattern bindingSpecifier: @@spec pattern: @p) + => + (expr_pattern modifier: (modifier #{spec}) expr: {p}) + ), // A tuple destructuring pattern (`let (a, b) = …`). A labelled element // (`let (x: a) = …`) carries its label through as the `argument` name; // unlabelled elements have no name. diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output index 808b1dd610c9..68181bb1b334 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output @@ -2,6 +2,10 @@ if case let x = x + 10 { print(x) } +if case var y = y + 10 { + y += 1 +} + --- sourceFile @@ -57,6 +61,54 @@ sourceFile bindingSpecifier: let caseKeyword: case ifKeyword: if + codeBlockItem + item: + expressionStmt + expression: + ifExpr + body: + codeBlock + leftBrace: { + rightBrace: } + statements: + codeBlockItem + item: + infixOperatorExpr + operator: + binaryOperatorExpr + operator: binaryOperator "+=" + leftOperand: + declReferenceExpr + baseName: identifier "y" + rightOperand: + integerLiteralExpr + literal: integerLiteral "1" + conditions: + conditionElement + condition: + matchingPatternCondition + initializer: + initializerClause + equal: = + value: + infixOperatorExpr + operator: + binaryOperatorExpr + operator: binaryOperator "+" + leftOperand: + declReferenceExpr + baseName: identifier "y" + rightOperand: + integerLiteralExpr + literal: integerLiteral "10" + pattern: + valueBindingPattern + pattern: + identifierPattern + identifier: identifier "y" + bindingSpecifier: var + caseKeyword: case + ifKeyword: if --- @@ -68,8 +120,11 @@ top_level condition: pattern_guard_expr pattern: - named_pattern - identifier: identifier "x" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "x" value: binary_expr left: @@ -89,3 +144,28 @@ top_level value: name_expr identifier: identifier "x" + if_expr + condition: + pattern_guard_expr + pattern: + expr_pattern + modifier: modifier "var" + expr: + named_pattern + identifier: identifier "y" + value: + binary_expr + left: + name_expr + identifier: identifier "y" + operator: infix_operator "+" + right: int_literal "10" + then: + block + stmt: + compound_assign_expr + target: + name_expr + identifier: identifier "y" + operator: infix_operator "+=" + value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift index c57c8ae5b67c..0939555e91ad 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift +++ b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.swift @@ -1,3 +1,7 @@ if case let x = x + 10 { print(x) } + +if case var y = y + 10 { + y += 1 +} diff --git a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output index c6eae5b793f0..fd2230d05c9d 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output @@ -166,28 +166,31 @@ top_level case: switch_case pattern: - call_expr - callee: - member_access_expr - base: inferred_type_expr "." - member: identifier "received" - argument: - argument - value: - call_expr - callee: - member_access_expr - base: inferred_type_expr "." - member: identifier "some" - argument: - argument - value: - named_pattern - identifier: identifier "value" - argument - value: - named_pattern - identifier: identifier "timestamp" + expr_pattern + modifier: modifier "let" + expr: + call_expr + callee: + member_access_expr + base: inferred_type_expr "." + member: identifier "received" + argument: + argument + value: + call_expr + callee: + member_access_expr + base: inferred_type_expr "." + member: identifier "some" + argument: + argument + value: + named_pattern + identifier: identifier "value" + argument + value: + named_pattern + identifier: identifier "timestamp" body: block stmt: @@ -216,8 +219,11 @@ top_level argument: argument value: - named_pattern - identifier: identifier "value" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "value" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output b/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output index c60b3ffb7284..045c37f682f6 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output @@ -170,8 +170,11 @@ top_level operator: infix_operator ">" right: int_literal "0" pattern: - named_pattern - identifier: identifier "x" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "x" body: block stmt: @@ -195,8 +198,11 @@ top_level operator: infix_operator "<" right: int_literal "0" pattern: - named_pattern - identifier: identifier "y" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "y" int_literal "0" body: block diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output index 3db9aa3ddcc3..02362e80068d 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output @@ -134,8 +134,11 @@ top_level argument: argument value: - named_pattern - identifier: identifier "r" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "r" body: block stmt: @@ -158,8 +161,11 @@ top_level argument: argument value: - named_pattern - identifier: identifier "s" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "s" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output index 269eed5906ab..61a1096d69b3 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output @@ -168,8 +168,11 @@ top_level identifier: identifier "_" argument value: - named_pattern - identifier: identifier "rowId" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "rowId" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output index 7c50ddc7bbf8..c44fbeade974 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output @@ -168,8 +168,11 @@ top_level name_expr identifier: identifier "e" pattern: - named_pattern - identifier: identifier "e" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "e" conditional_pattern condition: call_expr @@ -182,8 +185,11 @@ top_level name_expr identifier: identifier "f" pattern: - named_pattern - identifier: identifier "f" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "f" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output index 35e1a7319ed2..6ff9453e3296 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output @@ -98,8 +98,11 @@ top_level argument: argument value: - named_pattern - identifier: identifier "value" + expr_pattern + modifier: modifier "let" + expr: + named_pattern + identifier: identifier "value" value: name_expr identifier: identifier "input" diff --git a/unified/ql/lib/codeql/unified/internal/Ast.qll b/unified/ql/lib/codeql/unified/internal/Ast.qll index cd5f8a7aaf00..3a211b830349 100644 --- a/unified/ql/lib/codeql/unified/internal/Ast.qll +++ b/unified/ql/lib/codeql/unified/internal/Ast.qll @@ -632,6 +632,26 @@ module Unified { class ExprOrOperator extends @unified_expr_or_operator, F::AstNode { } + /** A class representing `expr_pattern` nodes. */ + class ExprPattern extends @unified_expr_pattern, F::Expr { + /** Gets the name of the primary QL class for this element. */ + final override string getAPrimaryQlClass() { result = "ExprPattern" } + + /** Gets the node corresponding to the field `expr`. */ + final F::Expr getExpr() { unified_expr_pattern_def(this, result) } + + /** Gets the node corresponding to the field `modifier`. */ + final F::Modifier getModifier(int i) { unified_expr_pattern_modifier(this, i, result) } + + /** Gets the node corresponding to the field `modifier`. */ + final F::Modifier getAModifier() { result = this.getModifier(_) } + + /** Gets a field or child node of this node. */ + final override F::AstNode getAFieldOrChild() { + unified_expr_pattern_def(this, result) or unified_expr_pattern_modifier(this, _, result) + } + } + /** A class representing `fixity` tokens. */ class Fixity extends @unified_token_fixity, F::AstNode, F::Token { /** Gets the name of the primary QL class for this element. */ @@ -1619,6 +1639,10 @@ module Unified { or result = node.(EqualityTypeConstraint).getRight() and i = -1 and name = "getRight" or + result = node.(ExprPattern).getExpr() and i = -1 and name = "getExpr" + or + result = node.(ExprPattern).getModifier(i) and name = "getModifier" + or result = node.(ForEachStmt).getBody() and i = -1 and name = "getBody" or result = node.(ForEachStmt).getGuard() and i = -1 and name = "getGuard" @@ -1870,6 +1894,8 @@ module UnifiedFinal { final class ExprOrOperator = F::ExprOrOperator; + final class ExprPattern = F::ExprPattern; + final class Fixity = F::Fixity; final class FloatLiteral = F::FloatLiteral; diff --git a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll index 870612cf3ebc..0aaf3c017f9e 100644 --- a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll @@ -285,6 +285,8 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig Date: Wed, 2 Sep 2026 23:04:09 +0200 Subject: [PATCH 03/10] unified: Let bare identifiers appear in expr, pattern, and type context --- unified/extractor/ast_types.yml | 12 +- .../extractor/src/languages/swift/swift.rs | 85 +++--- .../closures/closure-with-capture-list.output | 12 +- .../closure-with-explicit-parameters.output | 20 +- .../closure-with-shorthand-parameters.output | 12 +- .../closures/multi-statement-closure.output | 28 +- .../swift/closures/trailing-closure.output | 8 +- .../swift/collections/array-literal.output | 4 +- .../collections/dictionary-literal.output | 4 +- .../collections/dictionary-subscript.output | 8 +- .../empty-array-literal-with-type.output | 12 +- .../swift/collections/set-literal.output | 12 +- .../swift/collections/subscript-access.output | 8 +- .../swift/collections/tuple-literal.output | 4 +- .../collections/tuple-member-access.output | 8 +- ...g-modifier-does-not-leak-to-sibling.output | 16 +- .../swift/control-flow/defer-statement.output | 4 +- .../swift/control-flow/fallthrough.output | 12 +- .../swift/control-flow/guard-let.output | 13 +- ...t-with-shadowing-in-condition-value.output | 28 +- .../control-flow/if-else-if-chain.output | 20 +- .../corpus/swift/control-flow/if-else.output | 20 +- .../if-let-optional-binding.output | 21 +- .../swift/control-flow/if-statement.output | 12 +- .../nested-enum-case-pattern.output | 40 +-- .../switch-case-item-where-clauses.output | 32 +-- .../control-flow/switch-statement.output | 16 +- .../switch-with-binding-pattern.output | 28 +- ...with-labeled-case-pattern-arguments.output | 24 +- .../control-flow/ternary-expression.output | 8 +- ...er-additive-expression-is-desugared.output | 8 +- ...with-deeply-nested-path-three-parts.output | 4 +- .../import-with-dotted-path-two-parts.output | 4 +- .../scoped-import-uses-name-pattern.output | 8 +- .../simple-import-with-single-name.output | 4 +- .../expressions/array-type-constructor.output | 44 +--- .../expressions/array-type-metatype.output | 16 +- .../expressions/consume-expression.output | 8 +- .../swift/expressions/copy-expression.output | 8 +- .../generic-specialization-expression.output | 12 +- .../expressions/key-path-expression.output | 4 +- .../functions/call-with-inout-argument.output | 12 +- ...onstructor-call-with-type-arguments.output | 12 +- ...nction-call-with-labelled-arguments.output | 4 +- .../swift/functions/function-call.output | 4 +- ...nction-with-default-parameter-value.output | 16 +- .../function-with-inout-parameter.output | 8 +- .../function-with-named-parameters.output | 16 +- .../function-with-no-parameters.output | 4 +- ...ion-with-parameters-and-return-type.output | 28 +- .../swift/functions/generic-function.output | 16 +- .../swift/functions/generic-type-alias.output | 14 +- .../leading-dot-expression-call.output | 4 +- .../leading-dot-expression-value.output | 4 +- .../corpus/swift/functions/method-call.output | 4 +- .../functions/nested-function-type.output | 32 +-- .../swift/functions/variadic-function.output | 20 +- .../swift/literals/line-magic-literal.output | 4 +- .../swift/loops/break-and-continue.output | 24 +- .../loops/for-in-over-array-literal.output | 12 +- .../swift/loops/for-in-over-range.output | 12 +- .../loops/for-in-with-where-clause.output | 20 +- .../swift/loops/repeat-while-loop.output | 8 +- .../corpus/swift/loops/while-loop.output | 8 +- .../corpus/swift/operators/addition.output | 8 +- .../corpus/swift/operators/comparison.output | 8 +- .../operators/custom-postfix-operator.output | 4 +- .../corpus/swift/operators/division.output | 8 +- .../corpus/swift/operators/equality.output | 8 +- .../corpus/swift/operators/logical-and.output | 8 +- .../corpus/swift/operators/logical-not.output | 4 +- .../corpus/swift/operators/logical-or.output | 8 +- .../swift/operators/multiplication.output | 8 +- ...cedence-addition-and-multiplication.output | 12 +- .../operators/parenthesised-expression.output | 4 +- .../swift/operators/partial-range-from.output | 4 +- .../corpus/swift/operators/subtraction.output | 8 +- ...solved-operator-sequence-with-casts.output | 34 +-- ...lved-operator-sequence-with-ternary.output | 48 +--- .../unresolved-operator-sequence.output | 25 +- .../catch-where-clauses.output | 36 +-- .../optionals-and-errors/do-catch.output | 12 +- .../optionals-and-errors/force-unwrap.output | 8 +- .../nil-coalescing.output | 8 +- .../optional-chaining.output | 8 +- .../optional-enum-case-binding.output | 20 +- .../optional-type-annotation.output | 12 +- .../throwing-function.output | 4 +- .../try-expression-2.output | 8 +- .../try-expression.output | 8 +- ...er-does-not-leak-into-accessor-body.output | 12 +- .../swift/types/class-inheritance.output | 4 +- .../swift/types/class-with-initializer.output | 24 +- .../swift/types/class-with-method.output | 8 +- .../class-with-multiple-base-types.output | 8 +- .../types/class-with-stored-properties.output | 16 +- .../swift/types/computed-property.output | 28 +- .../types/constructor-with-parameters.output | 16 +- .../types/enum-with-associated-values.output | 16 +- .../corpus/swift/types/enum-with-cases.output | 16 +- ...separated-cases-chained-declaration.output | 16 +- .../tests/corpus/swift/types/extension.output | 12 +- ...tion-type-with-convention-attribute.output | 4 +- ...nction-type-with-sendable-attribute.output | 4 +- ...ic-class-parameters-and-constraints.output | 20 +- .../swift/types/generic-type-arguments.output | 19 +- .../swift/types/inline-array-type.output | 4 +- .../swift/types/noncopyable-type.output | 8 +- .../property-with-getter-and-setter.output | 24 +- ...nd-read-write-property-requirements.output | 12 +- .../corpus/swift/types/qualified-type.output | 16 +- .../tests/corpus/swift/types/struct.output | 16 +- .../corpus/swift/variables/assignment.output | 4 +- ...fier-does-not-leak-into-initializer.output | 12 +- .../variables/compound-assignment.output | 4 +- .../corpus/swift/variables/let-binding.output | 4 +- .../variables/let-with-type-annotation.output | 8 +- .../multiple-bindings-on-one-line.output | 8 +- ...y-with-willset-and-didset-observers.output | 24 +- .../tuple-destructuring-binding.output | 12 +- .../corpus/swift/variables/var-binding.output | 4 +- .../variables/var-without-initialiser.output | 8 +- .../ql/lib/codeql/unified/internal/Ast.qll | 26 +- .../unified/internal/LocalNameBinding.qll | 27 +- .../unified/internal/NameBindingPlugin.qll | 21 +- .../internal/NameBindingPluginSwift.qll | 41 ++- .../unified/internal/StaticNameBinding.qll | 34 ++- unified/ql/lib/unified.dbscheme | 17 +- .../library-tests/BasicTest/test.expected | 246 +++++++++++------- .../ql/test/library-tests/BasicTest/test.ql | 2 +- 130 files changed, 695 insertions(+), 1370 deletions(-) diff --git a/unified/extractor/ast_types.yml b/unified/extractor/ast_types.yml index b6f1d6bcfa79..552fb8d89b64 100644 --- a/unified/extractor/ast_types.yml +++ b/unified/extractor/ast_types.yml @@ -1,6 +1,6 @@ supertypes: expr: - - name_expr + - identifier - named_pattern - expr_pattern - int_literal @@ -97,15 +97,11 @@ named: top_level: body: block - # An identifier used as a name reference. - name_expr: - identifier: identifier - - # An identifier that introduces a binding, optionally applying a nested pattern. + # An identifier pattern that applies a nested pattern. Used for scoped imports. named_pattern: modifier*: modifier identifier: identifier - sub_pattern?: expr + sub_pattern: expr # A pattern expression with modifiers, such as `let x` or `var x`. expr_pattern: @@ -313,7 +309,7 @@ named: # import_declaration: modifier*: modifier - imported_expr: expr # Qualified names are encoded as a chain of member_access_expr ending with a name_expr + imported_expr: expr # Qualified names are encoded as a chain of member_access_expr ending with an identifier pattern?: expr # Binds local names in scope (possibly via bulk_importing_pattern) # `typealias Name = Type` diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 6fcaca5f7c5a..1dd3d6a6bfd8 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -105,7 +105,7 @@ fn make_or_pattern( } /// Translate a multi-part identifier (for example `Foo.Bar.Baz`) into a -/// `member_access_expr` chain rooted at a `name_expr` over the first +/// `member_access_expr` chain rooted at an `identifier` for the first /// part. Panics on an empty input because the grammar's `_+` quantifier /// guarantees at least one part. fn member_chain( @@ -116,7 +116,7 @@ fn member_chain( let first = iter .next() .expect("identifier with `part:` must have at least one part"); - let init = tree!((name_expr identifier: (identifier #{first}))); + let init = tree!((identifier #{first})); iter.fold( init, |acc, elem| tree!((member_access_expr base: {acc} member: (identifier #{elem}))), @@ -186,16 +186,16 @@ fn translation_rules() -> Vec> { (unsupported_node) ), rule!((declReferenceExpr baseName: (identifier) @name) => expr { - tree!((name_expr identifier: (identifier #{name}))) + tree!((identifier #{name})) }), // A bare name reference (`x`), and an operator used as a value (`+` in // `reduce(0, +)`), are both `declReferenceExpr`; its `baseName` is the // referenced identifier / operator symbol. - rule!((declReferenceExpr baseName: @name) => (name_expr identifier: (identifier #{name}))), + rule!((declReferenceExpr baseName: @name) => (identifier #{name})), // A discard `_` used as an expression — e.g. the target of a discarding // assignment `_ = x`. swift-syntax models it as a `discardAssignmentExpr`; - // the target AST represents it as a `name_expr` over the `_` token. - rule!((discardAssignmentExpr wildcard: @@w) => (name_expr identifier: (identifier #{w}))), + // the target AST represents it as an `identifier` over the `_` token. + rule!((discardAssignmentExpr wildcard: @@w) => (identifier #{w})), // A generic specialization in expression position (`C`, // `Array`) is represented by swift-syntax as a // `genericSpecializationExpr`. When used as a call target @@ -207,7 +207,7 @@ fn translation_rules() -> Vec> { genericArgumentClause: (genericArgumentClause arguments: (genericArgument argument: @args)*)) => (generic_type_expr - base: (name_expr identifier: (identifier #{name})) + base: (identifier #{name}) type_argument: {args}) ), // ---- Operators ---- @@ -342,7 +342,7 @@ fn translation_rules() -> Vec> { result.push(tree!( (variable_declaration modifier: {ctx.outer_modifiers.clone()} - pattern: (named_pattern identifier: (identifier #{name})) + pattern: (identifier #{name}) type: {ty} value: {val}) )); @@ -450,7 +450,7 @@ fn translation_rules() -> Vec> { rule!( (enumCaseParameter firstName: _? @@name type: @ty) => - (parameter pattern: (named_pattern identifier: (identifier #{name}))? type: {ty}) + (parameter pattern: (identifier #{name})? type: {ty}) ), // An enum element with associated values (`case circle(radius: Double)`) // becomes a nested `class_like_declaration` whose constructor carries the @@ -476,7 +476,7 @@ fn translation_rules() -> Vec> { modifier: {ctx.outer_modifiers.clone()} modifier: {chained_modifier(&mut ctx)} modifier: (modifier "enum_case") - pattern: (named_pattern identifier: (identifier #{name})) + pattern: (identifier #{name}) value: {val}) ), rule!( @@ -486,7 +486,7 @@ fn translation_rules() -> Vec> { modifier: {ctx.outer_modifiers.clone()} modifier: {chained_modifier(&mut ctx)} modifier: (modifier "enum_case") - pattern: (named_pattern identifier: (identifier #{name}))) + pattern: (identifier #{name})) ), // Enum cases. A single `case` declaration may carry modifiers // (e.g. `indirect`) and list several comma-separated elements; each @@ -512,7 +512,7 @@ fn translation_rules() -> Vec> { rule!( (identifierPattern identifier: @name) => - (named_pattern identifier: (identifier #{name})) + (identifier #{name}) ), // A `let`/`var` value-binding pattern (`let x`) inside a case or `if case` // preserves the binding specifier around its inner pattern. @@ -538,7 +538,7 @@ fn translation_rules() -> Vec> { // A wildcard *binding* pattern (`let _ = x`, `for _ in xs`). swift-syntax // models this as a `wildcardPattern`, distinct from the `_` match form // handled by the context-aware `discardAssignmentExpr` rule. - rule!((wildcardPattern) @@wildcard => (name_expr identifier: (identifier #{wildcard}))), + rule!((wildcardPattern) @@wildcard => (identifier #{wildcard})), // An expression pattern only establishes pattern context; its child // determines the concrete pattern shape. rule!((expressionPattern expression: @@e) => expr { @@ -599,7 +599,7 @@ fn translation_rules() -> Vec> { }; tree!((parameter external_name: {external} - pattern: (named_pattern identifier: (identifier #{name})) + pattern: (identifier #{name}) type: {ty} default: {val})) } @@ -617,7 +617,7 @@ fn translation_rules() -> Vec> { => (call_expr callee: (generic_type_expr - base: (name_expr identifier: (identifier "Array")) + base: (identifier "Array") type_argument: {element}) argument: {args} argument: (argument value: {tc})) @@ -629,7 +629,7 @@ fn translation_rules() -> Vec> { => (call_expr callee: (generic_type_expr - base: (name_expr identifier: (identifier "Array")) + base: (identifier "Array") type_argument: {element}) argument: {args}) ), @@ -679,7 +679,7 @@ fn translation_rules() -> Vec> { rule!( (labeledExpr label: _? @@lbl expression: (discardAssignmentExpr) @@wildcard) => - (argument name: (identifier #{lbl})? value: (name_expr identifier: (identifier #{wildcard}))) + (argument name: (identifier #{lbl})? value: (identifier #{wildcard})) ), rule!( (labeledExpr label: _? @@lbl expression: @val) @@ -702,7 +702,7 @@ fn translation_rules() -> Vec> { => (member_access_expr base: (generic_type_expr - base: (name_expr identifier: (identifier "Array")) + base: (identifier "Array") type_argument: {element}) member: (identifier #{member})) ), @@ -748,7 +748,7 @@ fn translation_rules() -> Vec> { ), // A closure capture (`[weak self]`, `[x]`, `[y = expr]`). The optional // ownership specifier (`weak`/`unowned`) becomes a modifier; the - // captured name becomes the bound `name_expr`; an explicit capture + // captured name becomes the bound `identifier`; an explicit capture // initializer (`[y = expr]`) becomes the bound value. rule!( (closureCapture @@ -758,7 +758,7 @@ fn translation_rules() -> Vec> { => (variable_declaration modifier: (modifier #{spec})? - pattern: (named_pattern identifier: (identifier #{name})) + pattern: (identifier #{name}) value: {val}) ), // A closure parameter clause (`(x: Int, y)`) unwraps to its parameters. @@ -768,14 +768,14 @@ fn translation_rules() -> Vec> { rule!( (closureParameter firstName: @name type: _? @ty) => - (parameter pattern: (named_pattern identifier: (identifier #{name})) type: {ty}) + (parameter pattern: (identifier #{name}) type: {ty}) ), // A shorthand closure parameter (`x` in `{ x, y in … }`): a bare name // with no parentheses and no type. rule!( (closureShorthandParameter name: @name) => - (parameter pattern: (named_pattern identifier: (identifier #{name}))) + (parameter pattern: (identifier #{name})) ), // ---- Control flow ---- // An `if`/`else` expression. Conditions are joined via `and_chain`; the @@ -847,17 +847,21 @@ fn translation_rules() -> Vec> { (pattern_guard_expr value: {val} pattern: (call_expr - callee: (member_access_expr base: (name_expr identifier: (identifier "Optional")) member: (identifier "some")) - argument: (argument value: (named_pattern identifier: (identifier #{name}))))) + callee: (member_access_expr base: (identifier "Optional") member: (identifier "some")) + argument: (argument value: (expr_pattern + modifier: (modifier "let") + expr: (identifier #{name}))))) ), rule!( (optionalBindingCondition pattern: (identifierPattern identifier: @name)) => (pattern_guard_expr - value: (name_expr identifier: (identifier #{name})) + value: (identifier #{name}) pattern: (call_expr - callee: (member_access_expr base: (name_expr identifier: (identifier "Optional")) member: (identifier "some")) - argument: (argument value: (named_pattern identifier: (identifier #{name}))))) + callee: (member_access_expr base: (identifier "Optional") member: (identifier "some")) + argument: (argument value: (expr_pattern + modifier: (modifier "let") + expr: (identifier #{name}))))) ), // A single condition in an `if`/`while`/`guard` condition list unwraps to // its inner expression; `and_chain` joins multiple with `&&`. @@ -931,7 +935,7 @@ fn translation_rules() -> Vec> { if ctx.in_pattern { tree!((call_expr callee: (member_access_expr - base: (name_expr identifier: (identifier "Optional")) + base: (identifier "Optional") member: (identifier "some")) argument: (argument value: {inner}))) } else { @@ -991,10 +995,10 @@ fn translation_rules() -> Vec> { rule!((forceUnwrapExpr expression: @e) => (unary_expr operator: (postfix_operator "!") operand: {e})), // ---- Imports ---- // An import declaration. The dotted path (a list of - // `importPathComponent`s) becomes a `name_expr`/`member_access_expr` + // `importPathComponent`s) becomes an `identifier`/`member_access_expr` // chain (via `member_chain`). A scoped import (`import struct Foo.Bar`) // has an `importKindSpecifier` and binds the last path component as a - // `name_expr`; a plain import (`import Foundation`) has none and uses + // raw identifier; a plain import (`import Foundation`) has none and uses // a `bulk_importing_pattern` spanning the whole declaration. Any leading // attributes (`@_exported`) and access modifiers (`public`) become // `modifier`s. @@ -1006,12 +1010,13 @@ fn translation_rules() -> Vec> { path: (importPathComponent name: @@parts)*) => import_declaration { - let bulk_import = match kind { - None => Some(tree!((bulk_importing_pattern))), - Some(_) => None, // scoped import, no bulk import - }; let last = *parts.last().ok_or("import has no path")?; - let pattern = tree!((named_pattern identifier: (identifier #{last}) sub_pattern: {bulk_import})); + let pattern = match kind { + None => tree!((named_pattern + identifier: (identifier #{last}) + sub_pattern: (bulk_importing_pattern))), + Some(_) => tree!((identifier #{last})), + }; tree!((import_declaration modifier: (modifier #{kind})? modifier: {attrs} @@ -1040,11 +1045,11 @@ fn translation_rules() -> Vec> { genericArgumentClause: (genericArgumentClause arguments: (genericArgument argument: @args)*)) => (generic_type_expr - base: (name_expr identifier: (identifier #{name})) + base: (identifier #{name}) type_argument: {args}) ), // A named type (`Int`). `identifierType.name` is the type-name token. - rule!((identifierType name: @@n) => (name_expr identifier: (identifier #{n}))), + rule!((identifierType name: @@n) => (identifier #{n})), // A qualified type (`Outer.Inner`, `NSString.CompareOptions`). swift-syntax // nests these as `memberType` nodes; preserve the nesting as ordinary // member access. @@ -1058,17 +1063,17 @@ fn translation_rules() -> Vec> { rule!( (optionalType wrappedType: @w) => - (generic_type_expr base: (name_expr identifier: (identifier "Optional")) type_argument: {w}) + (generic_type_expr base: (identifier "Optional") type_argument: {w}) ), rule!( (arrayType element: @e) => - (generic_type_expr base: (name_expr identifier: (identifier "Array")) type_argument: {e}) + (generic_type_expr base: (identifier "Array") type_argument: {e}) ), rule!( (dictionaryType key: @k value: @v) => - (generic_type_expr base: (name_expr identifier: (identifier "Dictionary")) type_argument: {k} type_argument: {v}) + (generic_type_expr base: (identifier "Dictionary") type_argument: {k} type_argument: {v}) ), // A tuple type (`(Int, String)`) or function type (`(Int) -> Bool`). // Both hold their contents as `tupleTypeElement`s, but a tuple element diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output index d9203985ad59..04779c095df8 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output @@ -66,24 +66,18 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "f" + pattern: identifier "f" value: function_expr capture_declaration: variable_declaration modifier: modifier "weak" - pattern: - named_pattern - identifier: identifier "self" + pattern: identifier "self" body: block stmt: call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "self" + base: identifier "self" member: identifier "doThing" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output index f9ba376b2272..dca87eb8bebc 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-explicit-parameters.output @@ -68,28 +68,18 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "f" + pattern: identifier "f" value: function_expr parameter: parameter - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "x" - return_type: - name_expr - identifier: identifier "Int" + type: identifier "Int" + pattern: identifier "x" + return_type: identifier "Int" body: block stmt: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator "*" right: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output index a5a074d48a78..2473ae994abe 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-shorthand-parameters.output @@ -45,19 +45,13 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "f" + pattern: identifier "f" value: function_expr body: block stmt: binary_expr - left: - name_expr - identifier: identifier "$0" + left: identifier "$0" operator: infix_operator "+" - right: - name_expr - identifier: identifier "$1" + right: identifier "$1" diff --git a/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output index b5fb2465fce4..83b9fec3302a 100644 --- a/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output +++ b/unified/extractor/tests/corpus/swift/closures/multi-statement-closure.output @@ -99,42 +99,28 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "f" + pattern: identifier "f" value: function_expr parameter: parameter - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "x" - return_type: - name_expr - identifier: identifier "Int" + type: identifier "Int" + pattern: identifier "x" + return_type: identifier "Int" body: block stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "y" + pattern: identifier "y" value: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator "+" right: int_literal "1" return_expr value: binary_expr - left: - name_expr - identifier: identifier "y" + left: identifier "y" operator: infix_operator "*" right: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/closures/trailing-closure.output b/unified/extractor/tests/corpus/swift/closures/trailing-closure.output index 3e26ff27eb58..83bdf051b24a 100644 --- a/unified/extractor/tests/corpus/swift/closures/trailing-closure.output +++ b/unified/extractor/tests/corpus/swift/closures/trailing-closure.output @@ -46,9 +46,7 @@ top_level call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "xs" + base: identifier "xs" member: identifier "map" argument: argument @@ -58,8 +56,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "$0" + left: identifier "$0" operator: infix_operator "*" right: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/collections/array-literal.output b/unified/extractor/tests/corpus/swift/collections/array-literal.output index 37d02ffec267..b6fd3a4331bc 100644 --- a/unified/extractor/tests/corpus/swift/collections/array-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/array-literal.output @@ -47,9 +47,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "xs" + pattern: identifier "xs" value: array_literal element: diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output index 689ab33ce2fe..f2a2be74c780 100644 --- a/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-literal.output @@ -58,7 +58,5 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "d" + pattern: identifier "d" value: map_literal "[\"a\": 1, \"b\": 2]" diff --git a/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output index e24550673f80..bf67e55bd23d 100644 --- a/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output +++ b/unified/extractor/tests/corpus/swift/collections/dictionary-subscript.output @@ -47,14 +47,10 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "v" + pattern: identifier "v" value: call_expr - callee: - name_expr - identifier: identifier "d" + callee: identifier "d" argument: argument value: string_literal "\"key\"" diff --git a/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output index 51b535de7ee2..5e562153961b 100644 --- a/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output +++ b/unified/extractor/tests/corpus/swift/collections/empty-array-literal-with-type.output @@ -43,15 +43,9 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "xs" + pattern: identifier "xs" type: generic_type_expr - base: - name_expr - identifier: identifier "Array" - type_argument: - name_expr - identifier: identifier "Int" + base: identifier "Array" + type_argument: identifier "Int" value: array_literal "[]" diff --git a/unified/extractor/tests/corpus/swift/collections/set-literal.output b/unified/extractor/tests/corpus/swift/collections/set-literal.output index a0bfaab57804..071c7c4fcb70 100644 --- a/unified/extractor/tests/corpus/swift/collections/set-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/set-literal.output @@ -62,17 +62,11 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "s" + pattern: identifier "s" type: generic_type_expr - base: - name_expr - identifier: identifier "Set" - type_argument: - name_expr - identifier: identifier "Int" + base: identifier "Set" + type_argument: identifier "Int" value: array_literal element: diff --git a/unified/extractor/tests/corpus/swift/collections/subscript-access.output b/unified/extractor/tests/corpus/swift/collections/subscript-access.output index 2ae548bfe1d0..6067a9a90684 100644 --- a/unified/extractor/tests/corpus/swift/collections/subscript-access.output +++ b/unified/extractor/tests/corpus/swift/collections/subscript-access.output @@ -44,14 +44,10 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "first" + pattern: identifier "first" value: call_expr - callee: - name_expr - identifier: identifier "xs" + callee: identifier "xs" argument: argument value: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-literal.output b/unified/extractor/tests/corpus/swift/collections/tuple-literal.output index 74d505ab5b8c..5d7742f744bc 100644 --- a/unified/extractor/tests/corpus/swift/collections/tuple-literal.output +++ b/unified/extractor/tests/corpus/swift/collections/tuple-literal.output @@ -51,7 +51,5 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "t" + pattern: identifier "t" value: tuple_expr "(1, \"two\", 3.0)" diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output index 30298ed89865..84496832c073 100644 --- a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output +++ b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output @@ -37,12 +37,8 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "n" + pattern: identifier "n" value: member_access_expr - base: - name_expr - identifier: identifier "t" + base: identifier "t" member: identifier "0" diff --git a/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output b/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output index bb3c49721f44..1a50d875f783 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output +++ b/unified/extractor/tests/corpus/swift/control-flow/binding-modifier-does-not-leak-to-sibling.output @@ -90,26 +90,18 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: int_literal "1" switch_expr - value: - name_expr - identifier: identifier "y" + value: identifier "y" case: switch_case - pattern: - name_expr - identifier: identifier "someConstant" + pattern: identifier "someConstant" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"matched\"" diff --git a/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output b/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output index 6e8ec9ae3b9a..8032d521df75 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output +++ b/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output @@ -86,9 +86,7 @@ top_level stmt: unsupported_node "defer { print(\"cleanup\") }" call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"work\"" diff --git a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output index 79bea22bbe24..bc8943e35763 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output +++ b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output @@ -91,19 +91,13 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "x" + type: identifier "Int" + pattern: identifier "x" body: block stmt: switch_expr - value: - name_expr - identifier: identifier "x" + value: identifier "x" case: switch_case pattern: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output index 9c0fbc37926e..6a694affb251 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output +++ b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output @@ -47,18 +47,15 @@ top_level call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "Optional" + base: identifier "Optional" member: identifier "some" argument: argument value: - named_pattern - identifier: identifier "value" - value: - name_expr - identifier: identifier "optional" + expr_pattern + modifier: modifier "let" + expr: identifier "value" + value: identifier "optional" else: block stmt: return_expr "return" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output index 68181bb1b334..699609a26309 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-case-let-with-shadowing-in-condition-value.output @@ -122,50 +122,36 @@ top_level pattern: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "x" + expr: identifier "x" value: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator "+" right: int_literal "10" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "x" + value: identifier "x" if_expr condition: pattern_guard_expr pattern: expr_pattern modifier: modifier "var" - expr: - named_pattern - identifier: identifier "y" + expr: identifier "y" value: binary_expr - left: - name_expr - identifier: identifier "y" + left: identifier "y" operator: infix_operator "+" right: int_literal "10" then: block stmt: compound_assign_expr - target: - name_expr - identifier: identifier "y" + target: identifier "y" operator: infix_operator "+=" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output b/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output index 35f1c2c46d2c..82c5b6c468ca 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-else-if-chain.output @@ -115,18 +115,14 @@ top_level if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: int_literal "1" @@ -134,18 +130,14 @@ top_level if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator "<" right: int_literal "0" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: int_literal "2" @@ -153,9 +145,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: int_literal "3" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-else.output b/unified/extractor/tests/corpus/swift/control-flow/if-else.output index 744b5c51ab24..86c3b9cd876c 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-else.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-else.output @@ -80,35 +80,25 @@ top_level if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "x" + value: identifier "x" else: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: unary_expr - operand: - name_expr - identifier: identifier "x" + operand: identifier "x" operator: prefix_operator "-" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output index 5f26de40c1b3..096f4c6c3c8e 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output @@ -60,27 +60,20 @@ top_level call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "Optional" + base: identifier "Optional" member: identifier "some" argument: argument value: - named_pattern - identifier: identifier "value" - value: - name_expr - identifier: identifier "optional" + expr_pattern + modifier: modifier "let" + expr: identifier "value" + value: identifier "optional" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "value" + value: identifier "value" diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-statement.output b/unified/extractor/tests/corpus/swift/control-flow/if-statement.output index 77bba019ffb9..c0a7cfd021d8 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-statement.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-statement.output @@ -55,20 +55,14 @@ top_level if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "x" + value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output index fd2230d05c9d..59a8198ed919 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output @@ -160,9 +160,7 @@ top_level block stmt: switch_expr - value: - name_expr - identifier: identifier "event" + value: identifier "event" case: switch_case pattern: @@ -184,58 +182,40 @@ top_level member: identifier "some" argument: argument - value: - named_pattern - identifier: identifier "value" + value: identifier "value" argument - value: - named_pattern - identifier: identifier "timestamp" + value: identifier "timestamp" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "value" + value: identifier "value" argument - value: - name_expr - identifier: identifier "timestamp" + value: identifier "timestamp" switch_case pattern: call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "Type" + base: identifier "Type" member: identifier "some" argument: argument value: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "value" + expr: identifier "value" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "value" + value: identifier "value" switch_case body: block diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output b/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output index 045c37f682f6..77adadc261b1 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-case-item-where-clauses.output @@ -155,33 +155,25 @@ top_level block stmt: switch_expr - value: - name_expr - identifier: identifier "n" + value: identifier "n" case: switch_case pattern: conditional_pattern condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" pattern: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "x" + expr: identifier "x" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"positive\"" @@ -192,25 +184,19 @@ top_level conditional_pattern condition: binary_expr - left: - name_expr - identifier: identifier "y" + left: identifier "y" operator: infix_operator "<" right: int_literal "0" pattern: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "y" + expr: identifier "y" int_literal "0" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"non-positive\"" @@ -219,9 +205,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"other\"" diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output index c14948ae54e9..3ba92e37ab8f 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-statement.output @@ -125,9 +125,7 @@ top_level block stmt: switch_expr - value: - name_expr - identifier: identifier "x" + value: identifier "x" case: switch_case pattern: int_literal "1" @@ -135,9 +133,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"one\"" @@ -151,9 +147,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"two or three\"" @@ -162,9 +156,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"other\"" diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output index 02362e80068d..466c3fbb6989 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output @@ -120,9 +120,7 @@ top_level block stmt: switch_expr - value: - name_expr - identifier: identifier "shape" + value: identifier "shape" case: switch_case pattern: @@ -136,21 +134,15 @@ top_level value: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "r" + expr: identifier "r" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "r" + value: identifier "r" switch_case pattern: call_expr @@ -163,18 +155,12 @@ top_level value: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "s" + expr: identifier "s" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "s" + value: identifier "s" diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output index 61a1096d69b3..532b72eab51f 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output @@ -128,9 +128,7 @@ top_level block stmt: switch_expr - value: - name_expr - identifier: identifier "x" + value: identifier "x" case: switch_case pattern: @@ -147,9 +145,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"yes\"" @@ -163,25 +159,17 @@ top_level argument: argument name: identifier "threadRowId" - value: - name_expr - identifier: identifier "_" + value: identifier "_" argument value: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "rowId" + expr: identifier "rowId" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "rowId" + value: identifier "rowId" diff --git a/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output index 360835a10799..299d84c7822f 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output +++ b/unified/extractor/tests/corpus/swift/control-flow/ternary-expression.output @@ -52,16 +52,12 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "y" + pattern: identifier "y" value: if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" then: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output b/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output index 982309ffa5af..e27b9c7089ec 100644 --- a/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output +++ b/unified/extractor/tests/corpus/swift/desugar/another-additive-expression-is-desugared.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "foo" + left: identifier "foo" operator: infix_operator "+" - right: - name_expr - identifier: identifier "bar" + right: identifier "bar" diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output index b423f1c0e14e..9c7f425f41b6 100644 --- a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output @@ -32,9 +32,7 @@ top_level member_access_expr base: member_access_expr - base: - name_expr - identifier: identifier "Foundation" + base: identifier "Foundation" member: identifier "Networking" member: identifier "URLSession" pattern: diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output index 074dd8a1cca7..e3b18f34db1c 100644 --- a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output @@ -27,9 +27,7 @@ top_level import_declaration imported_expr: member_access_expr - base: - name_expr - identifier: identifier "Foundation" + base: identifier "Foundation" member: identifier "Networking" pattern: named_pattern diff --git a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output index 376a7cefd43c..451067727e35 100644 --- a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output +++ b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output @@ -29,10 +29,6 @@ top_level modifier: modifier "struct" imported_expr: member_access_expr - base: - name_expr - identifier: identifier "Foundation" + base: identifier "Foundation" member: identifier "Date" - pattern: - named_pattern - identifier: identifier "Date" + pattern: identifier "Date" diff --git a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output index 600df253234b..6b4e171983d4 100644 --- a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output +++ b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output @@ -22,9 +22,7 @@ top_level block stmt: import_declaration - imported_expr: - name_expr - identifier: identifier "Foundation" + imported_expr: identifier "Foundation" pattern: named_pattern identifier: identifier "Foundation" diff --git a/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output b/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output index 4f74f03a5de0..19a7d4df0774 100644 --- a/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output +++ b/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output @@ -130,44 +130,28 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "values" + pattern: identifier "values" value: call_expr callee: generic_type_expr - base: - name_expr - identifier: identifier "Array" + base: identifier "Array" type_argument: generic_type_expr - base: - name_expr - identifier: identifier "Result" - type_argument: - name_expr - identifier: identifier "Void" + base: identifier "Result" + type_argument: identifier "Void" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "initialized" + pattern: identifier "initialized" value: call_expr callee: generic_type_expr - base: - name_expr - identifier: identifier "Array" + base: identifier "Array" type_argument: generic_type_expr - base: - name_expr - identifier: identifier "Result" - type_argument: - name_expr - identifier: identifier "Void" + base: identifier "Result" + type_argument: identifier "Void" argument: argument name: identifier "unsafeUninitializedCapacity" @@ -177,18 +161,12 @@ top_level function_expr parameter: parameter - pattern: - named_pattern - identifier: identifier "_" + pattern: identifier "_" parameter - pattern: - named_pattern - identifier: identifier "count" + pattern: identifier "count" body: block stmt: assign_expr - target: - name_expr - identifier: identifier "count" + target: identifier "count" value: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output b/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output index 95262f0c5487..2a7f9df2cf05 100644 --- a/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output +++ b/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output @@ -54,22 +54,14 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "type" + pattern: identifier "type" value: member_access_expr base: generic_type_expr - base: - name_expr - identifier: identifier "Array" + base: identifier "Array" type_argument: generic_type_expr - base: - name_expr - identifier: identifier "Result" - type_argument: - name_expr - identifier: identifier "Void" + base: identifier "Result" + type_argument: identifier "Void" member: identifier "self" diff --git a/unified/extractor/tests/corpus/swift/expressions/consume-expression.output b/unified/extractor/tests/corpus/swift/expressions/consume-expression.output index 50ac9b41dbae..aedba985574d 100644 --- a/unified/extractor/tests/corpus/swift/expressions/consume-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/consume-expression.output @@ -68,9 +68,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "original" + pattern: identifier "original" value: array_literal element: @@ -79,7 +77,5 @@ top_level int_literal "3" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "consumed" + pattern: identifier "consumed" value: unsupported_node "consume original" diff --git a/unified/extractor/tests/corpus/swift/expressions/copy-expression.output b/unified/extractor/tests/corpus/swift/expressions/copy-expression.output index c12051aca725..448dd95e78b3 100644 --- a/unified/extractor/tests/corpus/swift/expressions/copy-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/copy-expression.output @@ -68,9 +68,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "original" + pattern: identifier "original" value: array_literal element: @@ -79,7 +77,5 @@ top_level int_literal "3" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "copied" + pattern: identifier "copied" value: unsupported_node "copy original" diff --git a/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output b/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output index 0871c64a4d64..b8b3a5a7903f 100644 --- a/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/generic-specialization-expression.output @@ -48,16 +48,10 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "numbers" + pattern: identifier "numbers" value: call_expr callee: generic_type_expr - base: - name_expr - identifier: identifier "Array" - type_argument: - name_expr - identifier: identifier "Int" + base: identifier "Array" + type_argument: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output b/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output index 461d9fc4b89f..c71105e4ee2e 100644 --- a/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/key-path-expression.output @@ -42,7 +42,5 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "keyPath" + pattern: identifier "keyPath" value: unsupported_node "\\String.count" diff --git a/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output b/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output index 542f7e54730e..13e99e707a86 100644 --- a/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output +++ b/unified/extractor/tests/corpus/swift/functions/call-with-inout-argument.output @@ -75,20 +75,14 @@ top_level stmt: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "a" + pattern: identifier "a" value: int_literal "1" variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "b" + pattern: identifier "b" value: int_literal "2" call_expr - callee: - name_expr - identifier: identifier "swap" + callee: identifier "swap" argument: argument value: unsupported_node "&a" diff --git a/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output b/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output index bb7b5fce65d5..364a2022cc62 100644 --- a/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output +++ b/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output @@ -91,16 +91,10 @@ top_level name: identifier "T" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: call_expr callee: generic_type_expr - base: - name_expr - identifier: identifier "C" - type_argument: - name_expr - identifier: identifier "Foo" + base: identifier "C" + type_argument: identifier "Foo" diff --git a/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output index f885d5762f2d..b8ff5468aa88 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output +++ b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output @@ -33,9 +33,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "greet" + callee: identifier "greet" argument: argument name: identifier "person" diff --git a/unified/extractor/tests/corpus/swift/functions/function-call.output b/unified/extractor/tests/corpus/swift/functions/function-call.output index a1e2859ccd6a..35cac76d7bd1 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-call.output +++ b/unified/extractor/tests/corpus/swift/functions/function-call.output @@ -32,9 +32,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "foo" + callee: identifier "foo" argument: argument value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output index bff9c6018540..ed4989826cd6 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output @@ -69,22 +69,14 @@ top_level name: identifier "greet" parameter: parameter - type: - name_expr - identifier: identifier "String" - pattern: - named_pattern - identifier: identifier "name" + type: identifier "String" + pattern: identifier "name" default: string_literal "\"world\"" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "name" + value: identifier "name" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output b/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output index 9c3aa054e1f9..a568b9da17e7 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output @@ -67,15 +67,11 @@ top_level parameter external_name: identifier "_" type: unsupported_node "inout Int" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" body: block stmt: compound_assign_expr - target: - name_expr - identifier: identifier "x" + target: identifier "x" operator: infix_operator "+=" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output index 2c577f940197..fb23a5bd55bf 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output @@ -61,21 +61,13 @@ top_level parameter: parameter external_name: identifier "person" - type: - name_expr - identifier: identifier "String" - pattern: - named_pattern - identifier: identifier "name" + type: identifier "String" + pattern: identifier "name" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "name" + value: identifier "name" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output index 4ddc26ae94d6..99ba3a45e2e1 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output @@ -57,9 +57,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"hello\"" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output index 0acf938ebe4f..6f5d2aa98f9d 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output @@ -78,33 +78,19 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "a" + type: identifier "Int" + pattern: identifier "a" parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "b" - return_type: - name_expr - identifier: identifier "Int" + type: identifier "Int" + pattern: identifier "b" + return_type: identifier "Int" body: block stmt: return_expr value: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "+" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/functions/generic-function.output b/unified/extractor/tests/corpus/swift/functions/generic-function.output index 6cf4caef5b12..e296b760ccaa 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-function.output @@ -71,19 +71,11 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "T" - pattern: - named_pattern - identifier: identifier "x" - return_type: - name_expr - identifier: identifier "T" + type: identifier "T" + pattern: identifier "x" + return_type: identifier "T" body: block stmt: return_expr - value: - name_expr - identifier: identifier "x" + value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output b/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output index d60ce9b27b27..6bc55e07b0af 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output @@ -60,18 +60,12 @@ top_level type_parameter: type_parameter name: identifier "T" - bound: - name_expr - identifier: identifier "Equatable" + bound: identifier "Equatable" type_parameter name: identifier "U" type: generic_type_expr - base: - name_expr - identifier: identifier "Dictionary" + base: identifier "Dictionary" type_argument: - name_expr - identifier: identifier "T" - name_expr - identifier: identifier "U" + identifier "T" + identifier "U" diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output index 7b7aab7984fc..92da0bab18f6 100644 --- a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output @@ -44,9 +44,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "y" + pattern: identifier "y" value: call_expr callee: diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output index 8b374c20c858..310d9278f54a 100644 --- a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output @@ -34,9 +34,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: member_access_expr base: inferred_type_expr "." diff --git a/unified/extractor/tests/corpus/swift/functions/method-call.output b/unified/extractor/tests/corpus/swift/functions/method-call.output index 3c0b150b8235..eb6985200bd8 100644 --- a/unified/extractor/tests/corpus/swift/functions/method-call.output +++ b/unified/extractor/tests/corpus/swift/functions/method-call.output @@ -35,9 +35,7 @@ top_level call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "list" + base: identifier "list" member: identifier "append" argument: argument diff --git a/unified/extractor/tests/corpus/swift/functions/nested-function-type.output b/unified/extractor/tests/corpus/swift/functions/nested-function-type.output index 0428a5a5356d..9f2f1c9f8ccc 100644 --- a/unified/extractor/tests/corpus/swift/functions/nested-function-type.output +++ b/unified/extractor/tests/corpus/swift/functions/nested-function-type.output @@ -114,15 +114,9 @@ top_level function_expr parameter: parameter - type: - name_expr - identifier: identifier "Int" - return_type: - name_expr - identifier: identifier "Bool" - return_type: - name_expr - identifier: identifier "Bool" + type: identifier "Int" + return_type: identifier "Bool" + return_type: identifier "Bool" type_alias_declaration name: identifier "MixedParametersAndTuples" type: @@ -133,24 +127,14 @@ top_level function_expr parameter: parameter - type: - name_expr - identifier: identifier "Int" - return_type: - name_expr - identifier: identifier "Bool" + type: identifier "Int" + return_type: identifier "Bool" parameter - type: - name_expr - identifier: identifier "String" + type: identifier "String" return_type: tuple_expr element: argument - value: - name_expr - identifier: identifier "Bool" + value: identifier "Bool" argument - value: - name_expr - identifier: identifier "Int" + value: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/functions/variadic-function.output b/unified/extractor/tests/corpus/swift/functions/variadic-function.output index 9a87fa620158..888d71b41895 100644 --- a/unified/extractor/tests/corpus/swift/functions/variadic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/variadic-function.output @@ -82,15 +82,9 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "values" - return_type: - name_expr - identifier: identifier "Int" + type: identifier "Int" + pattern: identifier "values" + return_type: identifier "Int" body: block stmt: @@ -99,14 +93,10 @@ top_level call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "values" + base: identifier "values" member: identifier "reduce" argument: argument value: int_literal "0" argument - value: - name_expr - identifier: identifier "+" + value: identifier "+" diff --git a/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output b/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output index d0fe61074147..291ab41d8fe4 100644 --- a/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output +++ b/unified/extractor/tests/corpus/swift/literals/line-magic-literal.output @@ -34,7 +34,5 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "currentLine" + pattern: identifier "currentLine" value: unsupported_node "#line" diff --git a/unified/extractor/tests/corpus/swift/loops/break-and-continue.output b/unified/extractor/tests/corpus/swift/loops/break-and-continue.output index 524dfc851553..4143f2a5b99b 100644 --- a/unified/extractor/tests/corpus/swift/loops/break-and-continue.output +++ b/unified/extractor/tests/corpus/swift/loops/break-and-continue.output @@ -103,21 +103,15 @@ top_level block stmt: for_each_stmt - pattern: - named_pattern - identifier: identifier "x" - iterable: - name_expr - identifier: identifier "xs" + pattern: identifier "x" + iterable: identifier "xs" body: block stmt: if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator "<" right: int_literal "0" then: @@ -126,20 +120,14 @@ top_level if_expr condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "100" then: block stmt: break_expr "break" call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "x" + value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output index d8d851da1ec4..3eb9c22f53a7 100644 --- a/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-array-literal.output @@ -61,9 +61,7 @@ top_level block stmt: for_each_stmt - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" iterable: array_literal element: @@ -74,11 +72,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "x" + value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output index 1299d445a0ec..2dd2f67df8b2 100644 --- a/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output +++ b/unified/extractor/tests/corpus/swift/loops/for-in-over-range.output @@ -53,9 +53,7 @@ top_level block stmt: for_each_stmt - pattern: - named_pattern - identifier: identifier "i" + pattern: identifier "i" iterable: binary_expr left: int_literal "0" @@ -65,11 +63,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "i" + value: identifier "i" diff --git a/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output index 50632ecf9f33..febf7450e2d1 100644 --- a/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output +++ b/unified/extractor/tests/corpus/swift/loops/for-in-with-where-clause.output @@ -59,28 +59,18 @@ top_level block stmt: for_each_stmt - pattern: - named_pattern - identifier: identifier "x" - iterable: - name_expr - identifier: identifier "xs" + pattern: identifier "x" + iterable: identifier "xs" guard: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "x" + value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output b/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output index 71c49fd2cd10..025cdb19f63f 100644 --- a/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output +++ b/unified/extractor/tests/corpus/swift/loops/repeat-while-loop.output @@ -52,15 +52,11 @@ top_level block stmt: compound_assign_expr - target: - name_expr - identifier: identifier "x" + target: identifier "x" operator: infix_operator "-=" value: int_literal "1" condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/loops/while-loop.output b/unified/extractor/tests/corpus/swift/loops/while-loop.output index 1132c6f9f819..54b3c20d61ab 100644 --- a/unified/extractor/tests/corpus/swift/loops/while-loop.output +++ b/unified/extractor/tests/corpus/swift/loops/while-loop.output @@ -51,17 +51,13 @@ top_level while_stmt condition: binary_expr - left: - name_expr - identifier: identifier "x" + left: identifier "x" operator: infix_operator ">" right: int_literal "0" body: block stmt: compound_assign_expr - target: - name_expr - identifier: identifier "x" + target: identifier "x" operator: infix_operator "-=" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/operators/addition.output b/unified/extractor/tests/corpus/swift/operators/addition.output index 9ba0f4de4770..d7607c50c10c 100644 --- a/unified/extractor/tests/corpus/swift/operators/addition.output +++ b/unified/extractor/tests/corpus/swift/operators/addition.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "+" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/comparison.output b/unified/extractor/tests/corpus/swift/operators/comparison.output index 49bb8c996f2c..98d11f401bc8 100644 --- a/unified/extractor/tests/corpus/swift/operators/comparison.output +++ b/unified/extractor/tests/corpus/swift/operators/comparison.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "<" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output b/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output index a16f291fbfab..df8ad5e47745 100644 --- a/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output +++ b/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output @@ -42,7 +42,5 @@ top_level unsupported_node "postfix operator ^^" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "squared" + pattern: identifier "squared" value: unsupported_node "3^^" diff --git a/unified/extractor/tests/corpus/swift/operators/division.output b/unified/extractor/tests/corpus/swift/operators/division.output index f15dce8e8ea5..306a3639b3e1 100644 --- a/unified/extractor/tests/corpus/swift/operators/division.output +++ b/unified/extractor/tests/corpus/swift/operators/division.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "/" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/equality.output b/unified/extractor/tests/corpus/swift/operators/equality.output index 7cf139ffa18d..7280d13ff1aa 100644 --- a/unified/extractor/tests/corpus/swift/operators/equality.output +++ b/unified/extractor/tests/corpus/swift/operators/equality.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "==" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/logical-and.output b/unified/extractor/tests/corpus/swift/operators/logical-and.output index 32a71ed1088c..102b83ec6ed4 100644 --- a/unified/extractor/tests/corpus/swift/operators/logical-and.output +++ b/unified/extractor/tests/corpus/swift/operators/logical-and.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "&&" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/logical-not.output b/unified/extractor/tests/corpus/swift/operators/logical-not.output index 1e80aa2ca71e..03476b41def3 100644 --- a/unified/extractor/tests/corpus/swift/operators/logical-not.output +++ b/unified/extractor/tests/corpus/swift/operators/logical-not.output @@ -20,7 +20,5 @@ top_level block stmt: unary_expr - operand: - name_expr - identifier: identifier "a" + operand: identifier "a" operator: prefix_operator "!" diff --git a/unified/extractor/tests/corpus/swift/operators/logical-or.output b/unified/extractor/tests/corpus/swift/operators/logical-or.output index b75d018dea71..8a447d8bb9fd 100644 --- a/unified/extractor/tests/corpus/swift/operators/logical-or.output +++ b/unified/extractor/tests/corpus/swift/operators/logical-or.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "||" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/multiplication.output b/unified/extractor/tests/corpus/swift/operators/multiplication.output index 387c16439c48..0313287d9431 100644 --- a/unified/extractor/tests/corpus/swift/operators/multiplication.output +++ b/unified/extractor/tests/corpus/swift/operators/multiplication.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "*" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output b/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output index f458c3ef847c..abbc1c6d5782 100644 --- a/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output +++ b/unified/extractor/tests/corpus/swift/operators/operator-precedence-addition-and-multiplication.output @@ -33,16 +33,10 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "+" right: binary_expr - left: - name_expr - identifier: identifier "b" + left: identifier "b" operator: infix_operator "*" - right: - name_expr - identifier: identifier "c" + right: identifier "c" diff --git a/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output b/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output index 0324476ce994..1c8de726f41a 100644 --- a/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output +++ b/unified/extractor/tests/corpus/swift/operators/parenthesised-expression.output @@ -41,6 +41,4 @@ top_level binary_expr left: tuple_expr "(a + b)" operator: infix_operator "*" - right: - name_expr - identifier: identifier "c" + right: identifier "c" diff --git a/unified/extractor/tests/corpus/swift/operators/partial-range-from.output b/unified/extractor/tests/corpus/swift/operators/partial-range-from.output index 300d3e7c2e69..6b0a834494ec 100644 --- a/unified/extractor/tests/corpus/swift/operators/partial-range-from.output +++ b/unified/extractor/tests/corpus/swift/operators/partial-range-from.output @@ -34,7 +34,5 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "range" + pattern: identifier "range" value: unsupported_node "3..." diff --git a/unified/extractor/tests/corpus/swift/operators/subtraction.output b/unified/extractor/tests/corpus/swift/operators/subtraction.output index 5c6fd51a2d38..63b4662fb575 100644 --- a/unified/extractor/tests/corpus/swift/operators/subtraction.output +++ b/unified/extractor/tests/corpus/swift/operators/subtraction.output @@ -25,10 +25,6 @@ top_level block stmt: binary_expr - left: - name_expr - identifier: identifier "a" + left: identifier "a" operator: infix_operator "-" - right: - name_expr - identifier: identifier "b" + right: identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output index 27e81c82766e..f557670b2ff7 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output @@ -98,44 +98,30 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Any" - pattern: - named_pattern - identifier: identifier "a" + type: identifier "Any" + pattern: identifier "a" parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "b" + type: identifier "Int" + pattern: identifier "b" body: block stmt: unresolved_operator_sequence element: - name_expr - identifier: identifier "_" + identifier "_" infix_operator "=" - name_expr - identifier: identifier "a" + identifier "a" infix_operator "as" unsupported_node "Int" infix_operator ".&" - name_expr - identifier: identifier "b" + identifier "b" unresolved_operator_sequence element: - name_expr - identifier: identifier "_" + identifier "_" infix_operator "=" - name_expr - identifier: identifier "a" + identifier "a" infix_operator "is" unsupported_node "Int" infix_operator ".&" - name_expr - identifier: identifier "b" + identifier "b" diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output index 3bd9a4e920cb..4d33c7dbd388 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output @@ -104,39 +104,21 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Bool" - pattern: - named_pattern - identifier: identifier "c" + type: identifier "Bool" + pattern: identifier "c" parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "a" + type: identifier "Int" + pattern: identifier "a" parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "b" + type: identifier "Int" + pattern: identifier "b" parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "d" - return_type: - name_expr - identifier: identifier "Int" + type: identifier "Int" + pattern: identifier "d" + return_type: identifier "Int" body: block stmt: @@ -144,14 +126,10 @@ top_level value: unresolved_operator_sequence element: - name_expr - identifier: identifier "c" + identifier "c" infix_operator "?" - name_expr - identifier: identifier "a" + identifier "a" infix_operator ":" - name_expr - identifier: identifier "b" + identifier "b" infix_operator ".&" - name_expr - identifier: identifier "d" + identifier "d" diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output index dc652b757aba..477de980d2da 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output @@ -71,30 +71,19 @@ top_level parameter: parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "a" + type: identifier "Int" + pattern: identifier "a" parameter external_name: identifier "_" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "b" + type: identifier "Int" + pattern: identifier "b" body: block stmt: unresolved_operator_sequence element: - name_expr - identifier: identifier "_" + identifier "_" infix_operator "=" - name_expr - identifier: identifier "a" + identifier "a" infix_operator ".&" - name_expr - identifier: identifier "b" + identifier "b" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output index c44fbeade974..3a603e8f504c 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/catch-where-clauses.output @@ -147,9 +147,7 @@ top_level unary_expr operand: call_expr - callee: - name_expr - identifier: identifier "foo" + callee: identifier "foo" operator: prefix_operator "try" catch_clause: catch_clause @@ -159,44 +157,30 @@ top_level conditional_pattern condition: call_expr - callee: - name_expr - identifier: identifier "isNetworkError" + callee: identifier "isNetworkError" argument: argument - value: - name_expr - identifier: identifier "e" + value: identifier "e" pattern: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "e" + expr: identifier "e" conditional_pattern condition: call_expr - callee: - name_expr - identifier: identifier "isTimeout" + callee: identifier "isTimeout" argument: argument - value: - name_expr - identifier: identifier "f" + value: identifier "f" pattern: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "f" + expr: identifier "f" body: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"retry\"" @@ -205,9 +189,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument value: string_literal "\"fallback\"" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output index 81491b295fc1..8db6319fd778 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/do-catch.output @@ -68,9 +68,7 @@ top_level unary_expr operand: call_expr - callee: - name_expr - identifier: identifier "foo" + callee: identifier "foo" operator: prefix_operator "try" catch_clause: catch_clause @@ -78,11 +76,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "error" + value: identifier "error" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output index a7014629e1b0..c977adaaa3f3 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/force-unwrap.output @@ -34,12 +34,8 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "n" + pattern: identifier "n" value: unary_expr - operand: - name_expr - identifier: identifier "opt" + operand: identifier "opt" operator: postfix_operator "!" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output index c90fe3ae7f36..c8b6a85d6203 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/nil-coalescing.output @@ -39,13 +39,9 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "n" + pattern: identifier "n" value: binary_expr - left: - name_expr - identifier: identifier "opt" + left: identifier "opt" operator: infix_operator "??" right: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output index 8f07d4a51d8a..6752c80348ce 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output @@ -49,15 +49,11 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "n" + pattern: identifier "n" value: member_access_expr base: member_access_expr - base: - name_expr - identifier: identifier "obj" + base: identifier "obj" member: identifier "foo" member: identifier "bar" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output index 6ff9453e3296..c94032771ccf 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output @@ -83,9 +83,7 @@ top_level call_expr callee: member_access_expr - base: - name_expr - identifier: identifier "Optional" + base: identifier "Optional" member: identifier "some" argument: argument @@ -100,21 +98,13 @@ top_level value: expr_pattern modifier: modifier "let" - expr: - named_pattern - identifier: identifier "value" - value: - name_expr - identifier: identifier "input" + expr: identifier "value" + value: identifier "input" then: block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "value" + value: identifier "value" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output index 132f3a424475..dd73c9899745 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-type-annotation.output @@ -40,15 +40,9 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" type: generic_type_expr - base: - name_expr - identifier: identifier "Optional" - type_argument: - name_expr - identifier: identifier "Int" + base: identifier "Optional" + type_argument: identifier "Int" value: builtin_expr "nil" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output index 03ad472b33e0..33346c4f38b8 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output @@ -57,9 +57,7 @@ top_level stmt: function_declaration name: identifier "read" - return_type: - name_expr - identifier: identifier "String" + return_type: identifier "String" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output index c7fe32e98bd4..faacc2583539 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression-2.output @@ -41,14 +41,10 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "result" + pattern: identifier "result" value: unary_expr operand: call_expr - callee: - name_expr - identifier: identifier "foo" + callee: identifier "foo" operator: prefix_operator "try!" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output index 269d77f7c0ad..a5e07f561208 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/try-expression.output @@ -41,14 +41,10 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "result" + pattern: identifier "result" value: unary_expr operand: call_expr - callee: - name_expr - identifier: identifier "foo" + callee: identifier "foo" operator: prefix_operator "try?" diff --git a/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output b/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output index 9bcd96de183b..a69eaa87ec54 100644 --- a/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output +++ b/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output @@ -100,21 +100,15 @@ top_level modifier: modifier "var" name: identifier "p" accessor_kind: accessor_kind "get" - type: - name_expr - identifier: identifier "Int" + type: identifier "Int" body: block stmt: switch_expr - value: - name_expr - identifier: identifier "y" + value: identifier "y" case: switch_case - pattern: - name_expr - identifier: identifier "someConstant" + pattern: identifier "someConstant" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/types/class-inheritance.output b/unified/extractor/tests/corpus/swift/types/class-inheritance.output index 9eff2e05f4a7..497d55d2a638 100644 --- a/unified/extractor/tests/corpus/swift/types/class-inheritance.output +++ b/unified/extractor/tests/corpus/swift/types/class-inheritance.output @@ -37,6 +37,4 @@ top_level name: identifier "Dog" base_type: base_type - type: - name_expr - identifier: identifier "Animal" + type: identifier "Animal" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output index 814badd5672d..a1821edafa1d 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output @@ -96,31 +96,19 @@ top_level member: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "x" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "x" + type: identifier "Int" constructor_declaration parameter: parameter - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "x" + type: identifier "Int" + pattern: identifier "x" body: block stmt: assign_expr target: member_access_expr - base: - name_expr - identifier: identifier "self" + base: identifier "self" member: identifier "x" - value: - name_expr - identifier: identifier "x" + value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-method.output b/unified/extractor/tests/corpus/swift/types/class-with-method.output index 6d705579a6df..b0a95f9aefe2 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-method.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-method.output @@ -83,9 +83,7 @@ top_level member: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "n" + pattern: identifier "n" value: int_literal "0" function_declaration name: identifier "bump" @@ -93,8 +91,6 @@ top_level block stmt: compound_assign_expr - target: - name_expr - identifier: identifier "n" + target: identifier "n" operator: infix_operator "+=" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output b/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output index 3075db477518..20db0ee87754 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output @@ -42,10 +42,6 @@ top_level name: identifier "Button" base_type: base_type - type: - name_expr - identifier: identifier "Control" + type: identifier "Control" base_type - type: - name_expr - identifier: identifier "Drawable" + type: identifier "Drawable" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output index 456632aee765..440f2a9bae5c 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output @@ -67,17 +67,9 @@ top_level member: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "x" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "x" + type: identifier "Int" variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "y" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "y" + type: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/types/computed-property.output b/unified/extractor/tests/corpus/swift/types/computed-property.output index d1472abad268..e02bf629c7b7 100644 --- a/unified/extractor/tests/corpus/swift/types/computed-property.output +++ b/unified/extractor/tests/corpus/swift/types/computed-property.output @@ -107,37 +107,23 @@ top_level member: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "w" - type: - name_expr - identifier: identifier "Double" + pattern: identifier "w" + type: identifier "Double" variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "h" - type: - name_expr - identifier: identifier "Double" + pattern: identifier "h" + type: identifier "Double" accessor_declaration modifier: modifier "var" name: identifier "area" accessor_kind: accessor_kind "get" - type: - name_expr - identifier: identifier "Double" + type: identifier "Double" body: block stmt: return_expr value: binary_expr - left: - name_expr - identifier: identifier "w" + left: identifier "w" operator: infix_operator "*" - right: - name_expr - identifier: identifier "h" + right: identifier "h" diff --git a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output index 9b943de8c8d1..e3ca48312608 100644 --- a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output +++ b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output @@ -71,18 +71,10 @@ top_level parameter: parameter external_name: identifier "width" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "w" + type: identifier "Int" + pattern: identifier "w" parameter external_name: identifier "height" - type: - name_expr - identifier: identifier "Int" - pattern: - named_pattern - identifier: identifier "h" + type: identifier "Int" + pattern: identifier "h" body: block "init(width w: Int, height h: Int) {}" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output index b8a86a5b57d7..b8038d1797ac 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output @@ -80,12 +80,8 @@ top_level constructor_declaration parameter: parameter - type: - name_expr - identifier: identifier "Double" - pattern: - named_pattern - identifier: identifier "radius" + type: identifier "Double" + pattern: identifier "radius" body: block "circle(radius: Double)" class_like_declaration modifier: modifier "enum_case" @@ -94,10 +90,6 @@ top_level constructor_declaration parameter: parameter - type: - name_expr - identifier: identifier "Double" - pattern: - named_pattern - identifier: identifier "side" + type: identifier "Double" + pattern: identifier "side" body: block "square(side: Double)" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output index a73235cbdc53..99e3792af512 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output @@ -71,21 +71,13 @@ top_level member: variable_declaration modifier: modifier "enum_case" - pattern: - named_pattern - identifier: identifier "north" + pattern: identifier "north" variable_declaration modifier: modifier "enum_case" - pattern: - named_pattern - identifier: identifier "south" + pattern: identifier "south" variable_declaration modifier: modifier "enum_case" - pattern: - named_pattern - identifier: identifier "east" + pattern: identifier "east" variable_declaration modifier: modifier "enum_case" - pattern: - named_pattern - identifier: identifier "west" + pattern: identifier "west" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output index 840e6fd1425c..4e7353b2ec2a 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output @@ -50,27 +50,19 @@ top_level member: variable_declaration modifier: modifier "enum_case" - pattern: - named_pattern - identifier: identifier "clubs" + pattern: identifier "clubs" variable_declaration modifier: modifier "chained_declaration" modifier "enum_case" - pattern: - named_pattern - identifier: identifier "diamonds" + pattern: identifier "diamonds" variable_declaration modifier: modifier "chained_declaration" modifier "enum_case" - pattern: - named_pattern - identifier: identifier "hearts" + pattern: identifier "hearts" variable_declaration modifier: modifier "chained_declaration" modifier "enum_case" - pattern: - named_pattern - identifier: identifier "spades" + pattern: identifier "spades" diff --git a/unified/extractor/tests/corpus/swift/types/extension.output b/unified/extractor/tests/corpus/swift/types/extension.output index 943674ae2d4d..fac2a1ee614f 100644 --- a/unified/extractor/tests/corpus/swift/types/extension.output +++ b/unified/extractor/tests/corpus/swift/types/extension.output @@ -74,19 +74,13 @@ top_level member: function_declaration name: identifier "squared" - return_type: - name_expr - identifier: identifier "Int" + return_type: identifier "Int" body: block stmt: return_expr value: binary_expr - left: - name_expr - identifier: identifier "self" + left: identifier "self" operator: infix_operator "*" - right: - name_expr - identifier: identifier "self" + right: identifier "self" diff --git a/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output b/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output index d7dc17326afe..1522ef79c8a4 100644 --- a/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output +++ b/unified/extractor/tests/corpus/swift/types/function-type-with-convention-attribute.output @@ -64,9 +64,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "callback" + pattern: identifier "callback" type: unsupported_node "@convention(c) () -> Void" value: function_expr diff --git a/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output b/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output index 3228b81bc456..8478fad42c7e 100644 --- a/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output +++ b/unified/extractor/tests/corpus/swift/types/function-type-with-sendable-attribute.output @@ -57,9 +57,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "handler" + pattern: identifier "handler" type: unsupported_node "@Sendable () -> Void" value: function_expr diff --git a/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output b/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output index 0b1152ce4678..bab8e792f82e 100644 --- a/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output +++ b/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output @@ -72,23 +72,13 @@ top_level type_parameter: type_parameter name: identifier "T" - bound: - name_expr - identifier: identifier "Equatable" + bound: identifier "Equatable" type_parameter name: identifier "U" type_constraint: bound_type_constraint - type: - name_expr - identifier: identifier "U" - bound: - name_expr - identifier: identifier "Equatable" + type: identifier "U" + bound: identifier "Equatable" equality_type_constraint - left: - name_expr - identifier: identifier "U" - right: - name_expr - identifier: identifier "T" + left: identifier "U" + right: identifier "T" diff --git a/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output b/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output index 3c3310d0dbed..17cdddf083fb 100644 --- a/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output +++ b/unified/extractor/tests/corpus/swift/types/generic-type-arguments.output @@ -62,22 +62,13 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "cache" + pattern: identifier "cache" type: generic_type_expr - base: - name_expr - identifier: identifier "Dictionary" + base: identifier "Dictionary" type_argument: - name_expr - identifier: identifier "String" + identifier "String" generic_type_expr - base: - name_expr - identifier: identifier "Array" - type_argument: - name_expr - identifier: identifier "Int" + base: identifier "Array" + type_argument: identifier "Int" value: map_literal "[:]" diff --git a/unified/extractor/tests/corpus/swift/types/inline-array-type.output b/unified/extractor/tests/corpus/swift/types/inline-array-type.output index b0e08711e9a2..0be81cb39306 100644 --- a/unified/extractor/tests/corpus/swift/types/inline-array-type.output +++ b/unified/extractor/tests/corpus/swift/types/inline-array-type.output @@ -65,9 +65,7 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "triple" + pattern: identifier "triple" type: unsupported_node "[3 of Int]" value: array_literal diff --git a/unified/extractor/tests/corpus/swift/types/noncopyable-type.output b/unified/extractor/tests/corpus/swift/types/noncopyable-type.output index 784a0139a760..7239db059235 100644 --- a/unified/extractor/tests/corpus/swift/types/noncopyable-type.output +++ b/unified/extractor/tests/corpus/swift/types/noncopyable-type.output @@ -63,9 +63,5 @@ top_level member: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "descriptor" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "descriptor" + type: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output index 60183b0ff7b5..9bf243aae9bb 100644 --- a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output +++ b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output @@ -114,40 +114,28 @@ top_level modifier: modifier "var" modifier "private" - pattern: - named_pattern - identifier: identifier "_v" + pattern: identifier "_v" value: int_literal "0" accessor_declaration modifier: modifier "var" name: identifier "v" accessor_kind: accessor_kind "get" - type: - name_expr - identifier: identifier "Int" + type: identifier "Int" body: block stmt: return_expr - value: - name_expr - identifier: identifier "_v" + value: identifier "_v" accessor_declaration modifier: modifier "var" modifier "chained_declaration" name: identifier "v" accessor_kind: accessor_kind "set" - type: - name_expr - identifier: identifier "Int" + type: identifier "Int" body: block stmt: assign_expr - target: - name_expr - identifier: identifier "_v" - value: - name_expr - identifier: identifier "newValue" + target: identifier "_v" + value: identifier "newValue" diff --git a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output index fa1f7771e511..2ed1dc4cc3f2 100644 --- a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output +++ b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output @@ -87,19 +87,13 @@ top_level accessor_declaration name: identifier "foo" accessor_kind: accessor_kind "get" - type: - name_expr - identifier: identifier "Int" + type: identifier "Int" accessor_declaration name: identifier "bar" accessor_kind: accessor_kind "get" - type: - name_expr - identifier: identifier "String" + type: identifier "String" accessor_declaration modifier: modifier "chained_declaration" name: identifier "bar" accessor_kind: accessor_kind "set" - type: - name_expr - identifier: identifier "String" + type: identifier "String" diff --git a/unified/extractor/tests/corpus/swift/types/qualified-type.output b/unified/extractor/tests/corpus/swift/types/qualified-type.output index 12dd46786964..cf3cf07d832b 100644 --- a/unified/extractor/tests/corpus/swift/types/qualified-type.output +++ b/unified/extractor/tests/corpus/swift/types/qualified-type.output @@ -114,26 +114,18 @@ top_level name: identifier "Deep" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "value" + pattern: identifier "value" type: member_access_expr - base: - name_expr - identifier: identifier "Outer" + base: identifier "Outer" member: identifier "Inner" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "nested" + pattern: identifier "nested" type: member_access_expr base: member_access_expr - base: - name_expr - identifier: identifier "Outer" + base: identifier "Outer" member: identifier "Inner" member: identifier "Deep" diff --git a/unified/extractor/tests/corpus/swift/types/struct.output b/unified/extractor/tests/corpus/swift/types/struct.output index 6ea2d81c0c67..eb04e0e5d79c 100644 --- a/unified/extractor/tests/corpus/swift/types/struct.output +++ b/unified/extractor/tests/corpus/swift/types/struct.output @@ -67,17 +67,9 @@ top_level member: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "x" + type: identifier "Int" variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "y" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "y" + type: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/variables/assignment.output b/unified/extractor/tests/corpus/swift/variables/assignment.output index a011eb76cafc..a81c74dd6c29 100644 --- a/unified/extractor/tests/corpus/swift/variables/assignment.output +++ b/unified/extractor/tests/corpus/swift/variables/assignment.output @@ -25,7 +25,5 @@ top_level block stmt: assign_expr - target: - name_expr - identifier: identifier "x" + target: identifier "x" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output b/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output index d6d9516b93f5..6776009f62bb 100644 --- a/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output +++ b/unified/extractor/tests/corpus/swift/variables/binding-modifier-does-not-leak-into-initializer.output @@ -67,19 +67,13 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: switch_expr - value: - name_expr - identifier: identifier "y" + value: identifier "y" case: switch_case - pattern: - name_expr - identifier: identifier "someConstant" + pattern: identifier "someConstant" body: block stmt: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/compound-assignment.output b/unified/extractor/tests/corpus/swift/variables/compound-assignment.output index 485b5044ad69..0189512f9abd 100644 --- a/unified/extractor/tests/corpus/swift/variables/compound-assignment.output +++ b/unified/extractor/tests/corpus/swift/variables/compound-assignment.output @@ -25,8 +25,6 @@ top_level block stmt: compound_assign_expr - target: - name_expr - identifier: identifier "x" + target: identifier "x" operator: infix_operator "+=" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/let-binding.output b/unified/extractor/tests/corpus/swift/variables/let-binding.output index 00cf7be87c3f..d4cefc129d47 100644 --- a/unified/extractor/tests/corpus/swift/variables/let-binding.output +++ b/unified/extractor/tests/corpus/swift/variables/let-binding.output @@ -31,7 +31,5 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output index 112cca7e7b07..8a28988e8b9d 100644 --- a/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output +++ b/unified/extractor/tests/corpus/swift/variables/let-with-type-annotation.output @@ -37,10 +37,6 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "x" + type: identifier "Int" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output index 1c46136955ff..2ab4bc96691f 100644 --- a/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output +++ b/unified/extractor/tests/corpus/swift/variables/multiple-bindings-on-one-line.output @@ -42,15 +42,11 @@ top_level stmt: variable_declaration modifier: modifier "let" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: int_literal "1" variable_declaration modifier: modifier "let" modifier "chained_declaration" - pattern: - named_pattern - identifier: identifier "y" + pattern: identifier "y" value: int_literal "2" diff --git a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output index 79945f6fb16b..8531885ad9d0 100644 --- a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output +++ b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output @@ -107,12 +107,8 @@ top_level member: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "x" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "x" + type: identifier "Int" value: int_literal "0" accessor_declaration modifier: @@ -124,14 +120,10 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "newValue" + value: identifier "newValue" accessor_declaration modifier: modifier "var" @@ -142,11 +134,7 @@ top_level block stmt: call_expr - callee: - name_expr - identifier: identifier "print" + callee: identifier "print" argument: argument - value: - name_expr - identifier: identifier "oldValue" + value: identifier "oldValue" diff --git a/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output index 8fc96f0feeba..1036f85b4e94 100644 --- a/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output +++ b/unified/extractor/tests/corpus/swift/variables/tuple-destructuring-binding.output @@ -46,13 +46,7 @@ top_level tuple_expr element: argument - value: - named_pattern - identifier: identifier "a" + value: identifier "a" argument - value: - named_pattern - identifier: identifier "b" - value: - name_expr - identifier: identifier "pair" + value: identifier "b" + value: identifier "pair" diff --git a/unified/extractor/tests/corpus/swift/variables/var-binding.output b/unified/extractor/tests/corpus/swift/variables/var-binding.output index babfbc9583bf..a2c717034c0d 100644 --- a/unified/extractor/tests/corpus/swift/variables/var-binding.output +++ b/unified/extractor/tests/corpus/swift/variables/var-binding.output @@ -31,7 +31,5 @@ top_level stmt: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "x" + pattern: identifier "x" value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output index 0a01e0cc8ac2..7996077c0d36 100644 --- a/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output +++ b/unified/extractor/tests/corpus/swift/variables/var-without-initialiser.output @@ -31,9 +31,5 @@ top_level stmt: variable_declaration modifier: modifier "var" - pattern: - named_pattern - identifier: identifier "x" - type: - name_expr - identifier: identifier "Int" + pattern: identifier "x" + type: identifier "Int" diff --git a/unified/ql/lib/codeql/unified/internal/Ast.qll b/unified/ql/lib/codeql/unified/internal/Ast.qll index 3a211b830349..cb8861ba3feb 100644 --- a/unified/ql/lib/codeql/unified/internal/Ast.qll +++ b/unified/ql/lib/codeql/unified/internal/Ast.qll @@ -835,7 +835,7 @@ module Unified { } /** A class representing `identifier` tokens. */ - class Identifier extends @unified_token_identifier, F::AstNode, F::Token { + class Identifier extends @unified_token_identifier, F::Expr, F::Token { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "Identifier" } } @@ -1005,25 +1005,13 @@ module Unified { final override string getAPrimaryQlClass() { result = "Modifier" } } - /** A class representing `name_expr` nodes. */ - class NameExpr extends @unified_name_expr, F::Expr { - /** Gets the name of the primary QL class for this element. */ - final override string getAPrimaryQlClass() { result = "NameExpr" } - - /** Gets the node corresponding to the field `identifier`. */ - final F::Identifier getIdentifier() { unified_name_expr_def(this, result) } - - /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { unified_name_expr_def(this, result) } - } - /** A class representing `named_pattern` nodes. */ class NamedPattern extends @unified_named_pattern, F::Expr { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "NamedPattern" } /** Gets the node corresponding to the field `identifier`. */ - final F::Identifier getIdentifier() { unified_named_pattern_def(this, result) } + final F::Identifier getIdentifier() { unified_named_pattern_def(this, result, _) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getModifier(int i) { unified_named_pattern_modifier(this, i, result) } @@ -1032,13 +1020,13 @@ module Unified { final F::Modifier getAModifier() { result = this.getModifier(_) } /** Gets the node corresponding to the field `sub_pattern`. */ - final F::Expr getSubPattern() { unified_named_pattern_sub_pattern(this, result) } + final F::Expr getSubPattern() { unified_named_pattern_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { - unified_named_pattern_def(this, result) or + unified_named_pattern_def(this, result, _) or unified_named_pattern_modifier(this, _, result) or - unified_named_pattern_sub_pattern(this, result) + unified_named_pattern_def(this, _, result) } } @@ -1715,8 +1703,6 @@ module Unified { or result = node.(MemberAccessExpr).getMember() and i = -1 and name = "getMember" or - result = node.(NameExpr).getIdentifier() and i = -1 and name = "getIdentifier" - or result = node.(NamedPattern).getIdentifier() and i = -1 and name = "getIdentifier" or result = node.(NamedPattern).getModifier(i) and name = "getModifier" @@ -1936,8 +1922,6 @@ module UnifiedFinal { final class Modifier = F::Modifier; - final class NameExpr = F::NameExpr; - final class NamedPattern = F::NamedPattern; final class Operator = F::Operator; diff --git a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll index 0aaf3c017f9e..2682c7b39301 100644 --- a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll @@ -5,6 +5,7 @@ private import unified private import unified as U private import codeql.namebinding.LocalNameBinding +private import codeql.unified.internal.NameBindingPlugin private module LocalNameBindingInput implements LocalNameBindingInputSig { class AstNode = U::AstNode; @@ -188,6 +189,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig; */ predicate isTrivialNameAlias(NameDeclaration decl) { exists(ImportDeclaration imprt | - decl = getIdentifierFromRef(imprt.getPattern()) and + decl = getImportBindingIdentifier(imprt) and decl.getName() = getIdentifierFromRef(imprt.getImportedExpr()).getValue() ) } diff --git a/unified/ql/lib/unified.dbscheme b/unified/ql/lib/unified.dbscheme index a2a455022598..d589fc70b3ad 100644 --- a/unified/ql/lib/unified.dbscheme +++ b/unified/ql/lib/unified.dbscheme @@ -443,7 +443,7 @@ unified_equality_type_constraint_def( int right: @unified_expr ref ); -@unified_expr = @unified_array_literal | @unified_assign_expr | @unified_binary_expr | @unified_block | @unified_break_expr | @unified_bulk_importing_pattern | @unified_call_expr | @unified_compound_assign_expr | @unified_conditional_pattern | @unified_continue_expr | @unified_expr_pattern | @unified_function_expr | @unified_generic_type_expr | @unified_if_expr | @unified_key_value_pair | @unified_map_literal | @unified_member_access_expr | @unified_name_expr | @unified_named_pattern | @unified_or_pattern | @unified_pattern_guard_expr | @unified_return_expr | @unified_switch_expr | @unified_throw_expr | @unified_token_boolean_literal | @unified_token_builtin_expr | @unified_token_empty_expr | @unified_token_float_literal | @unified_token_inferred_type_expr | @unified_token_int_literal | @unified_token_regex_literal | @unified_token_string_literal | @unified_token_super_expr | @unified_token_unsupported_node | @unified_try_expr | @unified_tuple_expr | @unified_type_cast_expr | @unified_type_test_expr | @unified_unary_expr | @unified_unresolved_operator_sequence +@unified_expr = @unified_array_literal | @unified_assign_expr | @unified_binary_expr | @unified_block | @unified_break_expr | @unified_bulk_importing_pattern | @unified_call_expr | @unified_compound_assign_expr | @unified_conditional_pattern | @unified_continue_expr | @unified_expr_pattern | @unified_function_expr | @unified_generic_type_expr | @unified_if_expr | @unified_key_value_pair | @unified_map_literal | @unified_member_access_expr | @unified_named_pattern | @unified_or_pattern | @unified_pattern_guard_expr | @unified_return_expr | @unified_switch_expr | @unified_throw_expr | @unified_token_boolean_literal | @unified_token_builtin_expr | @unified_token_empty_expr | @unified_token_float_literal | @unified_token_identifier | @unified_token_inferred_type_expr | @unified_token_int_literal | @unified_token_regex_literal | @unified_token_string_literal | @unified_token_super_expr | @unified_token_unsupported_node | @unified_try_expr | @unified_tuple_expr | @unified_type_cast_expr | @unified_type_test_expr | @unified_unary_expr | @unified_unresolved_operator_sequence @unified_expr_or_operator = @unified_expr | @unified_token_infix_operator @@ -653,11 +653,6 @@ unified_member_access_expr_def( int member: @unified_token_identifier ref ); -unified_name_expr_def( - unique int id: @unified_name_expr, - int identifier: @unified_token_identifier ref -); - #keyset[unified_named_pattern, index] unified_named_pattern_modifier( int unified_named_pattern: @unified_named_pattern ref, @@ -665,14 +660,10 @@ unified_named_pattern_modifier( unique int modifier: @unified_token_modifier ref ); -unified_named_pattern_sub_pattern( - unique int unified_named_pattern: @unified_named_pattern ref, - unique int sub_pattern: @unified_expr ref -); - unified_named_pattern_def( unique int id: @unified_named_pattern, - int identifier: @unified_token_identifier ref + int identifier: @unified_token_identifier ref, + int sub_pattern: @unified_expr ref ); @unified_operator = @unified_token_infix_operator | @unified_token_postfix_operator | @unified_token_prefix_operator @@ -998,7 +989,7 @@ unified_trivia_tokeninfo( string value: string ref ); -@unified_ast_node = @unified_accessor_declaration | @unified_argument | @unified_array_literal | @unified_assign_expr | @unified_associated_type_declaration | @unified_base_type | @unified_binary_expr | @unified_block | @unified_bound_type_constraint | @unified_break_expr | @unified_bulk_importing_pattern | @unified_call_expr | @unified_catch_clause | @unified_class_like_declaration | @unified_compound_assign_expr | @unified_conditional_pattern | @unified_constructor_declaration | @unified_continue_expr | @unified_destructor_declaration | @unified_do_while_stmt | @unified_equality_type_constraint | @unified_expr_pattern | @unified_for_each_stmt | @unified_function_declaration | @unified_function_expr | @unified_generic_type_expr | @unified_guard_if_stmt | @unified_if_expr | @unified_import_declaration | @unified_initializer_declaration | @unified_key_value_pair | @unified_labeled_stmt | @unified_map_literal | @unified_member_access_expr | @unified_name_expr | @unified_named_pattern | @unified_operator_syntax_declaration | @unified_or_pattern | @unified_parameter | @unified_pattern_guard_expr | @unified_return_expr | @unified_switch_case | @unified_switch_expr | @unified_throw_expr | @unified_token | @unified_top_level | @unified_trivia_token | @unified_try_expr | @unified_tuple_expr | @unified_type_alias_declaration | @unified_type_cast_expr | @unified_type_parameter | @unified_type_test_expr | @unified_unary_expr | @unified_unresolved_operator_sequence | @unified_variable_declaration | @unified_while_stmt +@unified_ast_node = @unified_accessor_declaration | @unified_argument | @unified_array_literal | @unified_assign_expr | @unified_associated_type_declaration | @unified_base_type | @unified_binary_expr | @unified_block | @unified_bound_type_constraint | @unified_break_expr | @unified_bulk_importing_pattern | @unified_call_expr | @unified_catch_clause | @unified_class_like_declaration | @unified_compound_assign_expr | @unified_conditional_pattern | @unified_constructor_declaration | @unified_continue_expr | @unified_destructor_declaration | @unified_do_while_stmt | @unified_equality_type_constraint | @unified_expr_pattern | @unified_for_each_stmt | @unified_function_declaration | @unified_function_expr | @unified_generic_type_expr | @unified_guard_if_stmt | @unified_if_expr | @unified_import_declaration | @unified_initializer_declaration | @unified_key_value_pair | @unified_labeled_stmt | @unified_map_literal | @unified_member_access_expr | @unified_named_pattern | @unified_operator_syntax_declaration | @unified_or_pattern | @unified_parameter | @unified_pattern_guard_expr | @unified_return_expr | @unified_switch_case | @unified_switch_expr | @unified_throw_expr | @unified_token | @unified_top_level | @unified_trivia_token | @unified_try_expr | @unified_tuple_expr | @unified_type_alias_declaration | @unified_type_cast_expr | @unified_type_parameter | @unified_type_test_expr | @unified_unary_expr | @unified_unresolved_operator_sequence | @unified_variable_declaration | @unified_while_stmt unified_ast_node_location( unique int node: @unified_ast_node ref, diff --git a/unified/ql/test/library-tests/BasicTest/test.expected b/unified/ql/test/library-tests/BasicTest/test.expected index 2f0237557687..0194a63380d7 100644 --- a/unified/ql/test/library-tests/BasicTest/test.expected +++ b/unified/ql/test/library-tests/BasicTest/test.expected @@ -1,101 +1,155 @@ -nameExpr -| name_expr.swift:1:9:1:9 | NameExpr | y | -| test.swift:1:8:1:17 | NameExpr | Foundation | -| test.swift:4:21:4:29 | NameExpr | Equatable | -| test.swift:5:16:5:18 | NameExpr | Array | -| test.swift:5:17:5:17 | NameExpr | T | -| test.swift:7:31:7:31 | NameExpr | T | -| test.swift:8:9:8:13 | NameExpr | items | -| test.swift:8:22:8:25 | NameExpr | item | -| test.swift:11:27:11:27 | NameExpr | T | -| test.swift:11:33:11:36 | NameExpr | Bool | -| test.swift:12:16:12:20 | NameExpr | items | -| test.swift:12:31:12:34 | NameExpr | item | -| test.swift:19:16:19:18 | NameExpr | Int | -| test.swift:20:25:20:27 | NameExpr | Int | -| test.swift:20:33:20:39 | NameExpr | Element | -| test.swift:20:33:20:40 | NameExpr | Optional | -| test.swift:24:15:24:24 | NameExpr | Collection | -| test.swift:24:36:24:36 | NameExpr | T | -| test.swift:24:49:24:49 | NameExpr | T | -| test.swift:24:55:24:65 | NameExpr | Array | -| test.swift:24:56:24:56 | NameExpr | T | -| test.swift:25:18:25:22 | NameExpr | Array | -| test.swift:25:24:25:28 | NameExpr | first | -| test.swift:26:17:26:22 | NameExpr | second | -| test.swift:27:13:27:18 | NameExpr | result | -| test.swift:27:29:27:32 | NameExpr | item | -| test.swift:28:13:28:18 | NameExpr | result | -| test.swift:28:27:28:30 | NameExpr | item | -| test.swift:31:12:31:17 | NameExpr | result | -| test.swift:35:23:35:32 | NameExpr | DataSource | -| test.swift:36:25:36:25 | NameExpr | T | -| test.swift:37:23:37:25 | NameExpr | Array | -| test.swift:37:24:37:24 | NameExpr | T | -| test.swift:39:16:39:18 | NameExpr | Int | -| test.swift:40:16:40:19 | NameExpr | data | -| test.swift:43:18:43:21 | NameExpr | Bool | -| test.swift:44:9:44:12 | NameExpr | data | -| test.swift:47:25:47:27 | NameExpr | Int | -| test.swift:47:33:47:33 | NameExpr | T | -| test.swift:47:33:47:34 | NameExpr | Optional | -| test.swift:48:15:48:19 | NameExpr | index | -| test.swift:48:29:48:33 | NameExpr | index | -| test.swift:48:37:48:40 | NameExpr | data | -| test.swift:49:16:49:19 | NameExpr | data | -| test.swift:49:21:49:25 | NameExpr | index | -| test.swift:52:22:52:22 | NameExpr | T | -| test.swift:53:9:53:12 | NameExpr | data | -| test.swift:53:21:53:24 | NameExpr | item | -| test.swift:58:31:58:35 | NameExpr | Error | -| test.swift:59:18:59:24 | NameExpr | Success | -| test.swift:60:18:60:24 | NameExpr | Failure | -| test.swift:62:31:62:37 | NameExpr | Success | -| test.swift:62:43:62:43 | NameExpr | U | -| test.swift:62:49:62:54 | NameExpr | Result | -| test.swift:62:56:62:56 | NameExpr | U | -| test.swift:62:59:62:65 | NameExpr | Failure | -| test.swift:63:16:63:19 | NameExpr | self | -| test.swift:65:29:65:37 | NameExpr | transform | -| test.swift:65:39:65:43 | NameExpr | value | -| test.swift:67:29:67:33 | NameExpr | error | -| test.swift:74:24:74:27 | NameExpr | Bool | -| test.swift:76:16:76:19 | NameExpr | self | -| test.swift:76:21:76:21 | NameExpr | i | -| test.swift:76:26:76:29 | NameExpr | self | -| test.swift:76:31:76:31 | NameExpr | i | -| test.swift:85:27:85:29 | NameExpr | Array | -| test.swift:85:28:85:28 | NameExpr | T | -| test.swift:85:44:85:44 | NameExpr | T | -| test.swift:85:47:85:47 | NameExpr | T | -| test.swift:85:53:85:53 | NameExpr | T | -| test.swift:85:59:85:59 | NameExpr | T | -| test.swift:85:59:85:60 | NameExpr | Optional | -| test.swift:86:12:86:17 | NameExpr | values | -| test.swift:87:12:87:17 | NameExpr | values | -| test.swift:87:38:87:43 | NameExpr | values | -| test.swift:87:49:87:57 | NameExpr | transform | +identifier +| name_expr.swift:1:5:1:5 | x | x | +| name_expr.swift:1:9:1:9 | y | y | +| strings.swift:1:5:1:5 | x | x | +| test.swift:1:8:1:17 | Foundation | Foundation | +| test.swift:1:8:1:17 | Foundation | Foundation | +| test.swift:4:8:4:16 | Container | Container | +| test.swift:4:18:4:18 | T | T | +| test.swift:4:21:4:29 | Equatable | Equatable | +| test.swift:5:9:5:13 | items | items | +| test.swift:5:16:5:18 | Array | Array | +| test.swift:5:17:5:17 | T | T | +| test.swift:7:19:7:21 | add | add | +| test.swift:7:23:7:23 | _ | _ | +| test.swift:7:25:7:28 | item | item | +| test.swift:7:31:7:31 | T | T | +| test.swift:8:9:8:13 | items | items | +| test.swift:8:15:8:20 | append | append | +| test.swift:8:22:8:25 | item | item | +| test.swift:11:10:11:17 | contains | contains | +| test.swift:11:19:11:19 | _ | _ | +| test.swift:11:21:11:24 | item | item | +| test.swift:11:27:11:27 | T | T | +| test.swift:11:33:11:36 | Bool | Bool | +| test.swift:12:16:12:20 | items | items | +| test.swift:12:22:12:29 | contains | contains | +| test.swift:12:31:12:34 | item | item | +| test.swift:17:10:17:19 | DataSource | DataSource | +| test.swift:18:20:18:26 | Element | Element | +| test.swift:19:9:19:13 | count | count | +| test.swift:19:16:19:18 | Int | Int | +| test.swift:20:10:20:13 | item | item | +| test.swift:20:15:20:16 | at | at | +| test.swift:20:18:20:22 | index | index | +| test.swift:20:25:20:27 | Int | Int | +| test.swift:20:33:20:39 | Element | Element | +| test.swift:20:33:20:40 | Optional | Optional | +| test.swift:24:6:24:10 | merge | merge | +| test.swift:24:12:24:12 | T | T | +| test.swift:24:15:24:24 | Collection | Collection | +| test.swift:24:27:24:27 | _ | _ | +| test.swift:24:29:24:33 | first | first | +| test.swift:24:36:24:36 | T | T | +| test.swift:24:39:24:39 | _ | _ | +| test.swift:24:41:24:46 | second | second | +| test.swift:24:49:24:49 | T | T | +| test.swift:24:55:24:65 | Array | Array | +| test.swift:24:56:24:56 | T | T | +| test.swift:24:58:24:64 | Element | Element | +| test.swift:25:9:25:14 | result | result | +| test.swift:25:18:25:22 | Array | Array | +| test.swift:25:24:25:28 | first | first | +| test.swift:26:9:26:12 | item | item | +| test.swift:26:17:26:22 | second | second | +| test.swift:27:13:27:18 | result | result | +| test.swift:27:20:27:27 | contains | contains | +| test.swift:27:29:27:32 | item | item | +| test.swift:28:13:28:18 | result | result | +| test.swift:28:20:28:25 | append | append | +| test.swift:28:27:28:30 | item | item | +| test.swift:31:12:31:17 | result | result | +| test.swift:35:7:35:17 | DataManager | DataManager | +| test.swift:35:19:35:19 | T | T | +| test.swift:35:23:35:32 | DataSource | DataSource | +| test.swift:36:15:36:21 | Element | Element | +| test.swift:36:25:36:25 | T | T | +| test.swift:37:17:37:20 | data | data | +| test.swift:37:23:37:25 | Array | Array | +| test.swift:37:24:37:24 | T | T | +| test.swift:39:9:39:13 | count | count | +| test.swift:39:16:39:18 | Int | Int | +| test.swift:40:16:40:19 | data | data | +| test.swift:40:21:40:25 | count | count | +| test.swift:43:9:43:15 | isEmpty | isEmpty | +| test.swift:43:18:43:21 | Bool | Bool | +| test.swift:44:9:44:12 | data | data | +| test.swift:44:14:44:20 | isEmpty | isEmpty | +| test.swift:47:10:47:13 | item | item | +| test.swift:47:15:47:16 | at | at | +| test.swift:47:18:47:22 | index | index | +| test.swift:47:25:47:27 | Int | Int | +| test.swift:47:33:47:33 | T | T | +| test.swift:47:33:47:34 | Optional | Optional | +| test.swift:48:15:48:19 | index | index | +| test.swift:48:29:48:33 | index | index | +| test.swift:48:37:48:40 | data | data | +| test.swift:48:42:48:46 | count | count | +| test.swift:49:16:49:19 | data | data | +| test.swift:49:21:49:25 | index | index | +| test.swift:52:10:52:12 | add | add | +| test.swift:52:14:52:14 | _ | _ | +| test.swift:52:16:52:19 | item | item | +| test.swift:52:22:52:22 | T | T | +| test.swift:53:9:53:12 | data | data | +| test.swift:53:14:53:19 | append | append | +| test.swift:53:21:53:24 | item | item | +| test.swift:58:6:58:11 | Result | Result | +| test.swift:58:13:58:19 | Success | Success | +| test.swift:58:22:58:28 | Failure | Failure | +| test.swift:58:31:58:35 | Error | Error | +| test.swift:59:10:59:16 | success | success | +| test.swift:59:18:59:24 | Success | Success | +| test.swift:60:10:60:16 | failure | failure | +| test.swift:60:18:60:24 | Failure | Failure | +| test.swift:62:10:62:12 | map | map | +| test.swift:62:14:62:14 | U | U | +| test.swift:62:17:62:17 | _ | _ | +| test.swift:62:19:62:27 | transform | transform | +| test.swift:62:31:62:37 | Success | Success | +| test.swift:62:43:62:43 | U | U | +| test.swift:62:49:62:54 | Result | Result | +| test.swift:62:56:62:56 | U | U | +| test.swift:62:59:62:65 | Failure | Failure | +| test.swift:63:16:63:19 | self | self | +| test.swift:64:15:64:21 | success | success | +| test.swift:64:27:64:31 | value | value | +| test.swift:65:21:65:27 | success | success | +| test.swift:65:29:65:37 | transform | transform | +| test.swift:65:39:65:43 | value | value | +| test.swift:66:15:66:21 | failure | failure | +| test.swift:66:27:66:31 | error | error | +| test.swift:67:21:67:27 | failure | failure | +| test.swift:67:29:67:33 | error | error | +| test.swift:73:11:73:15 | Array | Array | +| test.swift:74:10:74:17 | isSorted | isSorted | +| test.swift:74:24:74:27 | Bool | Bool | +| test.swift:75:13:75:13 | i | i | +| test.swift:76:16:76:19 | self | self | +| test.swift:76:21:76:21 | i | i | +| test.swift:76:26:76:29 | self | self | +| test.swift:76:31:76:31 | i | i | +| test.swift:85:6:85:12 | combine | combine | +| test.swift:85:14:85:14 | T | T | +| test.swift:85:17:85:17 | _ | _ | +| test.swift:85:19:85:24 | values | values | +| test.swift:85:27:85:29 | Array | Array | +| test.swift:85:28:85:28 | T | T | +| test.swift:85:32:85:40 | transform | transform | +| test.swift:85:44:85:44 | T | T | +| test.swift:85:47:85:47 | T | T | +| test.swift:85:53:85:53 | T | T | +| test.swift:85:59:85:59 | T | T | +| test.swift:85:59:85:60 | Optional | Optional | +| test.swift:86:12:86:17 | values | values | +| test.swift:86:19:86:25 | isEmpty | isEmpty | +| test.swift:87:12:87:17 | values | values | +| test.swift:87:19:87:27 | dropFirst | dropFirst | +| test.swift:87:31:87:36 | reduce | reduce | +| test.swift:87:38:87:43 | values | values | +| test.swift:87:49:87:57 | transform | transform | namedPattern -| name_expr.swift:1:5:1:5 | NamedPattern | x | -| strings.swift:1:5:1:5 | NamedPattern | x | | test.swift:1:1:1:17 | NamedPattern | Foundation | -| test.swift:5:9:5:13 | NamedPattern | items | -| test.swift:7:25:7:28 | NamedPattern | item | -| test.swift:11:21:11:24 | NamedPattern | item | -| test.swift:20:18:20:22 | NamedPattern | index | -| test.swift:24:29:24:33 | NamedPattern | first | -| test.swift:24:41:24:46 | NamedPattern | second | -| test.swift:25:9:25:14 | NamedPattern | result | -| test.swift:26:9:26:12 | NamedPattern | item | -| test.swift:37:17:37:20 | NamedPattern | data | -| test.swift:47:18:47:22 | NamedPattern | index | -| test.swift:52:16:52:19 | NamedPattern | item | -| test.swift:62:19:62:27 | NamedPattern | transform | -| test.swift:64:27:64:31 | NamedPattern | value | -| test.swift:66:27:66:31 | NamedPattern | error | -| test.swift:75:13:75:13 | NamedPattern | i | -| test.swift:85:19:85:24 | NamedPattern | values | -| test.swift:85:32:85:40 | NamedPattern | transform | unsupported stringValue | strings.swift:1:9:1:15 | "hello" | "hello" | diff --git a/unified/ql/test/library-tests/BasicTest/test.ql b/unified/ql/test/library-tests/BasicTest/test.ql index 3baa88102715..f06c7b0138c9 100644 --- a/unified/ql/test/library-tests/BasicTest/test.ql +++ b/unified/ql/test/library-tests/BasicTest/test.ql @@ -1,6 +1,6 @@ import unified -query predicate nameExpr(NameExpr node, string value) { value = node.getIdentifier().getValue() } +query predicate identifier(Identifier node, string value) { value = node.getValue() } query predicate namedPattern(NamedPattern node, string value) { value = node.getIdentifier().getValue() From 9cd018a018bea4d43b6e735a7f0e278d159572e1 Mon Sep 17 00:00:00 2001 From: Asger F Date: Thu, 3 Sep 2026 09:22:06 +0200 Subject: [PATCH 04/10] unified: Invert definition of plugin hook --- .../codeql/unified/internal/LocalNameBinding.qll | 15 +++++++-------- .../codeql/unified/internal/NameBindingPlugin.qll | 4 ++-- .../unified/internal/NameBindingPluginSwift.qll | 9 ++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll index 2682c7b39301..e48290179082 100644 --- a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll @@ -189,7 +189,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig Date: Thu, 3 Sep 2026 10:39:23 +0200 Subject: [PATCH 05/10] unified: Clean up API a bit --- .../lib/codeql/unified/internal/FacadeAst.qll | 8 + .../unified/internal/LocalNameBinding.qll | 203 ++++++++---------- .../unified/internal/NameBindingPlugin.qll | 10 +- .../internal/NameBindingPluginSwift.qll | 48 ++--- 4 files changed, 118 insertions(+), 151 deletions(-) diff --git a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll index 3262de611441..ec17e6505c95 100644 --- a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll +++ b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll @@ -55,6 +55,14 @@ module Unified { // just strip the quotes here and ignore escape sequences. result = this.(StringLiteral).getValue().regexpCapture("\"(.*)\"", 1) } + + /** Gets the immediately-enclosing expression, skipping over intermediate sub-nodes like `Argument`, and without crossing a function boundary. */ + Expr getEnclosingExpr() { + result = this.getParent() and + not result instanceof Callable + or + result = this.getParent().(Argument).getParent() + } } /** A binary expression. */ diff --git a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll index e48290179082..df95034cdf85 100644 --- a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll @@ -186,119 +186,94 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig Date: Thu, 3 Sep 2026 11:06:10 +0200 Subject: [PATCH 06/10] unified: Rename identifier -> name_node unified: Rename back to Identifier --- unified/extractor/ast_types.yml | 34 +++--- .../extractor/src/languages/swift/swift.rs | 84 ++++++------- .../closures/closure-with-capture-list.output | 2 +- .../swift/closures/trailing-closure.output | 2 +- .../collections/tuple-member-access.output | 2 +- .../swift/control-flow/defer-statement.output | 2 +- .../control-flow/discard-statement.output | 4 +- .../swift/control-flow/fallthrough.output | 4 +- .../swift/control-flow/guard-let.output | 2 +- .../if-let-optional-binding.output | 2 +- .../nested-enum-case-pattern.output | 6 +- .../switch-with-binding-pattern.output | 4 +- ...with-labeled-case-pattern-arguments.output | 8 +- ...with-deeply-nested-path-three-parts.output | 6 +- .../import-with-dotted-path-two-parts.output | 4 +- .../scoped-import-uses-name-pattern.output | 2 +- .../simple-import-with-single-name.output | 2 +- .../expressions/array-type-constructor.output | 2 +- .../expressions/array-type-metatype.output | 2 +- .../expressions/unsafe-expression.output | 2 +- ...onstructor-call-with-type-arguments.output | 6 +- ...nction-call-with-labelled-arguments.output | 2 +- ...nction-with-default-parameter-value.output | 2 +- .../function-with-inout-parameter.output | 4 +- .../function-with-named-parameters.output | 4 +- .../function-with-no-parameters.output | 2 +- ...ion-with-parameters-and-return-type.output | 6 +- .../swift/functions/generic-function.output | 6 +- .../swift/functions/generic-type-alias.output | 6 +- .../leading-dot-expression-call.output | 2 +- .../leading-dot-expression-value.output | 2 +- .../corpus/swift/functions/method-call.output | 2 +- .../functions/nested-function-type.output | 4 +- .../swift/functions/variadic-function.output | 6 +- ...solved-operator-sequence-with-casts.output | 6 +- ...lved-operator-sequence-with-ternary.output | 10 +- .../unresolved-operator-sequence.output | 6 +- .../optional-chaining.output | 4 +- .../optional-enum-case-binding.output | 4 +- .../throwing-function.output | 2 +- ...er-does-not-leak-into-accessor-body.output | 2 +- .../swift/types/class-inheritance.output | 2 +- .../swift/types/class-with-initializer.output | 4 +- .../swift/types/class-with-method.output | 4 +- .../class-with-multiple-base-types.output | 2 +- .../types/class-with-stored-properties.output | 2 +- .../swift/types/computed-property.output | 4 +- ...nditional-compilation-in-class-body.output | 2 +- .../types/constructor-with-parameters.output | 6 +- .../corpus/swift/types/empty-class.output | 2 +- .../types/enum-with-associated-values.output | 6 +- .../corpus/swift/types/enum-with-cases.output | 2 +- ...separated-cases-chained-declaration.output | 2 +- .../tests/corpus/swift/types/extension.output | 4 +- ...ic-class-parameters-and-constraints.output | 6 +- .../swift/types/noncopyable-type.output | 2 +- .../property-with-getter-and-setter.output | 6 +- .../swift/types/protocol-declaration.output | 4 +- ...nd-read-write-property-requirements.output | 38 +++++- ...and-read-write-property-requirements.swift | 1 + .../corpus/swift/types/qualified-type.output | 12 +- .../tests/corpus/swift/types/struct.output | 2 +- ...y-with-willset-and-didset-observers.output | 6 +- .../unified/internal/AnalysisQuality.qll | 2 +- .../ql/lib/codeql/unified/internal/Ast.qll | 112 +++++++++--------- .../unified/internal/ControlFlowGraph.qll | 12 +- .../lib/codeql/unified/internal/FacadeAst.qll | 2 +- .../unified/internal/LocalNameBinding.qll | 37 +++--- .../unified/internal/NameBindingPlugin.qll | 4 +- .../internal/NameBindingPluginSwift.qll | 4 +- .../unified/internal/StaticNameBinding.qll | 14 +-- unified/ql/lib/unified.dbscheme | 42 +++---- unified/ql/lib/utils/test/TestUtils.qll | 4 +- .../ql/test/library-tests/BasicTest/test.ql | 2 +- 74 files changed, 326 insertions(+), 292 deletions(-) diff --git a/unified/extractor/ast_types.yml b/unified/extractor/ast_types.yml index 552fb8d89b64..28f152c24e1e 100644 --- a/unified/extractor/ast_types.yml +++ b/unified/extractor/ast_types.yml @@ -97,10 +97,10 @@ named: top_level: body: block - # An identifier pattern that applies a nested pattern. Used for scoped imports. + # A name pattern that applies a nested pattern. Used for scoped imports. named_pattern: modifier*: modifier - identifier: identifier + name_node: identifier sub_pattern: expr # A pattern expression with modifiers, such as `let x` or `var x`. @@ -176,7 +176,7 @@ named: argument: modifier*: modifier - name?: identifier + name_node?: identifier value: expr # Member access, such as `obj.member`. @@ -184,7 +184,7 @@ named: # For `super.x` the base will be an instance of `super_expr`. member_access_expr: base: expr - member: identifier + member_name_node: identifier # A type expression that refers to a type inferred from the contextual type. # This is used to translate Swift's leading-dot syntax, `.foo`, which means `T.foo` where @@ -232,7 +232,7 @@ named: # would have `person` as the external name and a `named_pattern` wrapping `id` as the parameter's pattern. parameter: modifier*: modifier - external_name?: identifier + external_name_node?: identifier type?: expr pattern?: expr default?: expr @@ -279,17 +279,17 @@ named: # `break` (with optional label) break_expr: - label?: identifier + label_name_node?: identifier # `continue` (with optional label) continue_expr: - label?: identifier + label_name_node?: identifier # A labeled statement, such as `outer: for ... { ... }`. The labeled # statement appears as the `stmt` field; `break`/`continue` may target # the label. labeled_stmt: - label: identifier + label_name_node: identifier stmt: stmt # `return value` or bare `return` @@ -315,7 +315,7 @@ named: # `typealias Name = Type` type_alias_declaration: modifier*: modifier - name: identifier + name_node: identifier type_parameter*: type_parameter type_constraint*: type_constraint type: expr @@ -323,7 +323,7 @@ named: # A top-level function declaration. function_declaration: modifier*: modifier - name: identifier + name_node: identifier type_parameter*: type_parameter type_constraint*: type_constraint parameter*: parameter @@ -418,7 +418,7 @@ named: bulk_importing_pattern: modifier*: modifier - # An simple unqualified identifier token + # A simple unqualified name token identifier: # A node that we don't yet translate @@ -436,7 +436,7 @@ named: type_parameter: modifier*: modifier - name: identifier + name_node: identifier bound?: expr # A generic constraint of the form `T == U`, requiring two types to be @@ -456,7 +456,7 @@ named: # `infix operator +++` (and the like) — a declaration of a custom operator. operator_syntax_declaration: modifier*: modifier - name: identifier + name_node: identifier # The fixity specifier (`prefix`, `infix`, `postfix`), when applicable. fixity?: fixity # The declared precedence level, when present (e.g. Swift's @@ -471,7 +471,7 @@ named: # no `name`; the extended type appears as a `base_type`. class_like_declaration: modifier*: modifier - name?: identifier + name_node?: identifier type_parameter*: type_parameter type_constraint*: type_constraint base_type*: base_type @@ -487,7 +487,7 @@ named: constructor_declaration: modifier*: modifier - name?: identifier + name_node?: identifier parameter*: parameter body: block @@ -507,7 +507,7 @@ named: # (each observer also tagged with `chained_declaration`). accessor_declaration: modifier*: modifier - name: identifier + name_node: identifier accessor_kind: accessor_kind parameter*: parameter type?: expr @@ -523,7 +523,7 @@ named: associated_type_declaration: modifier*: modifier - name: identifier + name_node: identifier bound?: expr generic_type_expr: diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 1dd3d6a6bfd8..d5c79fe92690 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -8,10 +8,10 @@ use yeast::{ConcreteDesugarer, DesugaringConfig, PhaseKind, Rule, rule, tree}; /// post-hoc mutation. #[derive(Clone, Default)] struct SwiftContext { - /// Identifier node for the property name. Set by the accessor-bearing + /// Name node for the property name. Set by the accessor-bearing /// `variableDecl` rule before translating the accessor block; read by the /// inner `accessorDecl` rules to name each `accessor_declaration`. - property_name: Option, + property_name_node: Option, /// Translated type node for the property type. Set (for computed /// properties) by the accessor-bearing `variableDecl` rule; read by the /// inner `accessorDecl` rules. Left `None` for stored properties with @@ -105,7 +105,7 @@ fn make_or_pattern( } /// Translate a multi-part identifier (for example `Foo.Bar.Baz`) into a -/// `member_access_expr` chain rooted at an `identifier` for the first +/// `member_access_expr` chain rooted at a `name_node` for the first /// part. Panics on an empty input because the grammar's `_+` quantifier /// guarantees at least one part. fn member_chain( @@ -119,7 +119,7 @@ fn member_chain( let init = tree!((identifier #{first})); iter.fold( init, - |acc, elem| tree!((member_access_expr base: {acc} member: (identifier #{elem}))), + |acc, elem| tree!((member_access_expr base: {acc} member_name_node: (identifier #{elem}))), ) } @@ -194,7 +194,7 @@ fn translation_rules() -> Vec> { rule!((declReferenceExpr baseName: @name) => (identifier #{name})), // A discard `_` used as an expression — e.g. the target of a discarding // assignment `_ = x`. swift-syntax models it as a `discardAssignmentExpr`; - // the target AST represents it as an `identifier` over the `_` token. + // the target AST represents it as a `name_node` over the `_` token. rule!((discardAssignmentExpr wildcard: @@w) => (identifier #{w})), // A generic specialization in expression position (`C`, // `Array`) is represented by swift-syntax as a @@ -299,7 +299,7 @@ fn translation_rules() -> Vec> { => (accessor_declaration modifier: (modifier #{spec}) - name: (identifier #{name}) + name_node: (identifier #{name}) type: {ty} accessor_kind: (accessor_kind "get") body: (block stmt: {body})) @@ -330,7 +330,7 @@ fn translation_rules() -> Vec> { => member* { ctx.outer_modifiers = vec![tree!((modifier #{spec}))]; - ctx.property_name = Some(tree!((identifier #{name}))); + ctx.property_name_node = Some(tree!((identifier #{name}))); let mut result = Vec::new(); if let Some(val) = val { // Stored property with observers: the initializer is not part @@ -377,7 +377,7 @@ fn translation_rules() -> Vec> { }; let chained = chained_modifier(&mut ctx); let name = ctx - .property_name + .property_name_node .ok_or("accessor outside property context")?; let ty = ctx.property_type; let body = match body { @@ -391,7 +391,7 @@ fn translation_rules() -> Vec> { (accessor_declaration modifier: {binding} modifier: {chained} - name: {name} + name_node: {name} type: {ty} accessor_kind: (accessor_kind #{spec}) body: {body}) @@ -466,7 +466,7 @@ fn translation_rules() -> Vec> { modifier: {ctx.outer_modifiers.clone()} modifier: {chained_modifier(&mut ctx)} modifier: (modifier "enum_case") - name: (identifier #{name}) + name_node: (identifier #{name}) member: (constructor_declaration parameter: {params} body: (block))) ), rule!( @@ -528,7 +528,7 @@ fn translation_rules() -> Vec> { rule!( (tuplePatternElement label: _? @@label pattern: @p) => - (argument name: (identifier #{label})? value: {p}) + (argument name_node: (identifier #{label})? value: {p}) ), // A type-casting pattern (`case is T`). Not yet supported, so it is // mapped to `unsupported_node` — an explicit reminder that this needs @@ -560,7 +560,7 @@ fn translation_rules() -> Vec> { body: (codeBlock statements: _* @body)) => (function_declaration - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {type_params} parameter: {params} return_type: {ret} @@ -575,7 +575,7 @@ fn translation_rules() -> Vec> { returnClause: (returnClause type: @ret)?)) => (function_declaration - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {type_params} parameter: {params} return_type: {ret} @@ -598,7 +598,7 @@ fn translation_rules() -> Vec> { None => (None, first), }; tree!((parameter - external_name: {external} + external_name_node: {external} pattern: (identifier #{name}) type: {ty} default: {val})) @@ -667,25 +667,25 @@ fn translation_rules() -> Vec> { => argument { tree!((argument - name: (identifier #{lbl})? + name_node: (identifier #{lbl})? value: (call_expr callee: {constructor} argument: {elements}))) } ), rule!( (labeledExpr label: _? @@lbl expression: (patternExpr pattern: @p)) => - (argument name: (identifier #{lbl})? value: {p}) + (argument name_node: (identifier #{lbl})? value: {p}) ), rule!( (labeledExpr label: _? @@lbl expression: (discardAssignmentExpr) @@wildcard) => - (argument name: (identifier #{lbl})? value: (identifier #{wildcard})) + (argument name_node: (identifier #{lbl})? value: (identifier #{wildcard})) ), rule!( (labeledExpr label: _? @@lbl expression: @val) => argument { - tree!((argument name: (identifier #{lbl})? value: {val})) + tree!((argument name_node: (identifier #{lbl})? value: {val})) } ), // Member access (`list.append`). The `declName` is itself a @@ -704,24 +704,24 @@ fn translation_rules() -> Vec> { base: (generic_type_expr base: (identifier "Array") type_argument: {element}) - member: (identifier #{member})) + member_name_node: (identifier #{member})) ), rule!( (memberAccessExpr base: @base declName: (declReferenceExpr baseName: @member)) => - (member_access_expr base: {base} member: (identifier #{member})) + (member_access_expr base: {base} member_name_node: (identifier #{member})) ), rule!( (memberAccessExpr period: @dot declName: (declReferenceExpr baseName: @member)) => - (member_access_expr base: (inferred_type_expr #{dot}) member: (identifier #{member})) + (member_access_expr base: (inferred_type_expr #{dot}) member_name_node: (identifier #{member})) ), // Control transfer, one rule per keyword. `return` carries an optional // value; `break` / `continue` an optional target label; `throw` its // thrown expression. rule!((returnStmt expression: _? @val) => (return_expr value: {val})), - rule!((breakStmt label: _? @@lbl) => (break_expr label: (identifier #{lbl})?)), - rule!((continueStmt label: _? @@lbl) => (continue_expr label: (identifier #{lbl})?)), + rule!((breakStmt label: _? @@lbl) => (break_expr label_name_node: (identifier #{lbl})?)), + rule!((continueStmt label: _? @@lbl) => (continue_expr label_name_node: (identifier #{lbl})?)), rule!((throwStmt expression: @val) => (throw_expr value: {val})), // ---- Closures ---- // A closure (`{ (x: Int) -> Int in … }`) becomes a `function_expr`. The @@ -748,7 +748,7 @@ fn translation_rules() -> Vec> { ), // A closure capture (`[weak self]`, `[x]`, `[y = expr]`). The optional // ownership specifier (`weak`/`unowned`) becomes a modifier; the - // captured name becomes the bound `identifier`; an explicit capture + // captured name becomes the bound `name_node`; an explicit capture // initializer (`[y = expr]`) becomes the bound value. rule!( (closureCapture @@ -847,7 +847,7 @@ fn translation_rules() -> Vec> { (pattern_guard_expr value: {val} pattern: (call_expr - callee: (member_access_expr base: (identifier "Optional") member: (identifier "some")) + callee: (member_access_expr base: (identifier "Optional") member_name_node: (identifier "some")) argument: (argument value: (expr_pattern modifier: (modifier "let") expr: (identifier #{name}))))) @@ -858,7 +858,7 @@ fn translation_rules() -> Vec> { (pattern_guard_expr value: (identifier #{name}) pattern: (call_expr - callee: (member_access_expr base: (identifier "Optional") member: (identifier "some")) + callee: (member_access_expr base: (identifier "Optional") member_name_node: (identifier "some")) argument: (argument value: (expr_pattern modifier: (modifier "let") expr: (identifier #{name}))))) @@ -905,7 +905,7 @@ fn translation_rules() -> Vec> { rule!( (labeledStmt label: @@lbl statement: @stmt) => - (labeled_stmt label: (identifier #{lbl}) stmt: {stmt}) + (labeled_stmt label_name_node: (identifier #{lbl}) stmt: {stmt}) ), // ---- Collections ---- // An array literal (`[1, 2, 3]`). Each `arrayElement` unwraps to its @@ -936,7 +936,7 @@ fn translation_rules() -> Vec> { tree!((call_expr callee: (member_access_expr base: (identifier "Optional") - member: (identifier "some")) + member_name_node: (identifier "some")) argument: (argument value: {inner}))) } else { inner @@ -995,10 +995,10 @@ fn translation_rules() -> Vec> { rule!((forceUnwrapExpr expression: @e) => (unary_expr operator: (postfix_operator "!") operand: {e})), // ---- Imports ---- // An import declaration. The dotted path (a list of - // `importPathComponent`s) becomes an `identifier`/`member_access_expr` + // `importPathComponent`s) becomes a `name_node`/`member_access_expr` // chain (via `member_chain`). A scoped import (`import struct Foo.Bar`) // has an `importKindSpecifier` and binds the last path component as a - // raw identifier; a plain import (`import Foundation`) has none and uses + // raw name node; a plain import (`import Foundation`) has none and uses // a `bulk_importing_pattern` spanning the whole declaration. Any leading // attributes (`@_exported`) and access modifiers (`public`) become // `modifier`s. @@ -1013,7 +1013,7 @@ fn translation_rules() -> Vec> { let last = *parts.last().ok_or("import has no path")?; let pattern = match kind { None => tree!((named_pattern - identifier: (identifier #{last}) + name_node: (identifier #{last}) sub_pattern: (bulk_importing_pattern))), Some(_) => tree!((identifier #{last})), }; @@ -1056,7 +1056,7 @@ fn translation_rules() -> Vec> { rule!( (memberType baseType: @base name: @@name) => - (member_access_expr base: {base} member: (identifier #{name})) + (member_access_expr base: {base} member_name_node: (identifier #{name})) ), // Sugared types desugar to `generic_type_expr`: `T?` -> Optional, // `[T]` -> Array, `[K: V]` -> Dictionary. @@ -1111,9 +1111,9 @@ fn translation_rules() -> Vec> { => argument { if ctx.in_function_type { - tree!((parameter external_name: (identifier #{name})? type: {ty})) + tree!((parameter external_name_node: (identifier #{name})? type: {ty})) } else { - tree!((argument name: (identifier #{name})? value: {ty})) + tree!((argument name_node: (identifier #{name})? value: {ty})) } } ), @@ -1134,7 +1134,7 @@ fn translation_rules() -> Vec> { (type_parameter modifier: {attrs} modifier: (modifier #{spec})? - name: (identifier #{name}) + name_node: (identifier #{name}) bound: {bound}) ), rule!( @@ -1165,7 +1165,7 @@ fn translation_rules() -> Vec> { (class_like_declaration modifier: (modifier #{kind}) modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {params} type_constraint: {parameter_constraints} type_constraint: {declaration_constraints} @@ -1188,7 +1188,7 @@ fn translation_rules() -> Vec> { (class_like_declaration modifier: (modifier #{kind}) modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {params} type_constraint: {parameter_constraints} type_constraint: {declaration_constraints} @@ -1211,7 +1211,7 @@ fn translation_rules() -> Vec> { (class_like_declaration modifier: (modifier #{kind}) modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {params} type_constraint: {parameter_constraints} type_constraint: {declaration_constraints} @@ -1232,7 +1232,7 @@ fn translation_rules() -> Vec> { (class_like_declaration modifier: (modifier #{kind}) modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {params} type_constraint: {declaration_constraints} base_type: {bases.into_iter().map(|ty| tree!((base_type type: {ty})))} @@ -1253,7 +1253,7 @@ fn translation_rules() -> Vec> { (class_like_declaration modifier: (modifier #{kind}) modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) base_type: {bases.into_iter().map(|ty| tree!((base_type type: {ty})))} member: {members}) ), @@ -1294,7 +1294,7 @@ fn translation_rules() -> Vec> { => (type_alias_declaration modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) type_parameter: {type_params} r#type: {val}) ), @@ -1307,7 +1307,7 @@ fn translation_rules() -> Vec> { => (associated_type_declaration modifier: {mods} - name: (identifier #{name}) + name_node: (identifier #{name}) bound: {bound}) ), // ---- Fallbacks ---- diff --git a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output index 04779c095df8..64de98c7b745 100644 --- a/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output +++ b/unified/extractor/tests/corpus/swift/closures/closure-with-capture-list.output @@ -80,4 +80,4 @@ top_level callee: member_access_expr base: identifier "self" - member: identifier "doThing" + member_name_node: identifier "doThing" diff --git a/unified/extractor/tests/corpus/swift/closures/trailing-closure.output b/unified/extractor/tests/corpus/swift/closures/trailing-closure.output index 83bdf051b24a..399075b488db 100644 --- a/unified/extractor/tests/corpus/swift/closures/trailing-closure.output +++ b/unified/extractor/tests/corpus/swift/closures/trailing-closure.output @@ -47,7 +47,7 @@ top_level callee: member_access_expr base: identifier "xs" - member: identifier "map" + member_name_node: identifier "map" argument: argument value: diff --git a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output index 84496832c073..ed31af94f0aa 100644 --- a/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output +++ b/unified/extractor/tests/corpus/swift/collections/tuple-member-access.output @@ -41,4 +41,4 @@ top_level value: member_access_expr base: identifier "t" - member: identifier "0" + member_name_node: identifier "0" diff --git a/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output b/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output index 8032d521df75..0a9adb11a990 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output +++ b/unified/extractor/tests/corpus/swift/control-flow/defer-statement.output @@ -80,7 +80,7 @@ top_level block stmt: function_declaration - name: identifier "withCleanup" + name_node: identifier "withCleanup" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/control-flow/discard-statement.output b/unified/extractor/tests/corpus/swift/control-flow/discard-statement.output index 7e0eac29c0fc..8fc2dfb9d963 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/discard-statement.output +++ b/unified/extractor/tests/corpus/swift/control-flow/discard-statement.output @@ -69,13 +69,13 @@ top_level stmt: class_like_declaration modifier: modifier "struct" - name: identifier "Resource" + name_node: identifier "Resource" base_type: base_type type: unsupported_node "~Copyable" member: function_declaration - name: identifier "close" + name_node: identifier "close" body: block stmt: unsupported_node "discard self" diff --git a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output index bc8943e35763..a0920ac436aa 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output +++ b/unified/extractor/tests/corpus/swift/control-flow/fallthrough.output @@ -87,10 +87,10 @@ top_level block stmt: function_declaration - name: identifier "classify" + name_node: identifier "classify" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "x" body: diff --git a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output index 6a694affb251..2eb1682529f1 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/guard-let.output +++ b/unified/extractor/tests/corpus/swift/control-flow/guard-let.output @@ -48,7 +48,7 @@ top_level callee: member_access_expr base: identifier "Optional" - member: identifier "some" + member_name_node: identifier "some" argument: argument value: diff --git a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output index 096f4c6c3c8e..1a09a2874e9a 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output +++ b/unified/extractor/tests/corpus/swift/control-flow/if-let-optional-binding.output @@ -61,7 +61,7 @@ top_level callee: member_access_expr base: identifier "Optional" - member: identifier "some" + member_name_node: identifier "some" argument: argument value: diff --git a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output index 59a8198ed919..4d0afdcb77db 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/nested-enum-case-pattern.output @@ -171,7 +171,7 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "received" + member_name_node: identifier "received" argument: argument value: @@ -179,7 +179,7 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "some" + member_name_node: identifier "some" argument: argument value: identifier "value" @@ -201,7 +201,7 @@ top_level callee: member_access_expr base: identifier "Type" - member: identifier "some" + member_name_node: identifier "some" argument: argument value: diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output index 466c3fbb6989..5820da95f35c 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-binding-pattern.output @@ -128,7 +128,7 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "circle" + member_name_node: identifier "circle" argument: argument value: @@ -149,7 +149,7 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "square" + member_name_node: identifier "square" argument: argument value: diff --git a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output index 532b72eab51f..aca699ad6f74 100644 --- a/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output +++ b/unified/extractor/tests/corpus/swift/control-flow/switch-with-labeled-case-pattern-arguments.output @@ -136,10 +136,10 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "implicit" + member_name_node: identifier "implicit" argument: argument - name: identifier "isAcknowledged" + name_node: identifier "isAcknowledged" value: boolean_literal "false" body: block @@ -155,10 +155,10 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "thread" + member_name_node: identifier "thread" argument: argument - name: identifier "threadRowId" + name_node: identifier "threadRowId" value: identifier "_" argument value: diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output index 9c7f425f41b6..85e830e07383 100644 --- a/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-deeply-nested-path-three-parts.output @@ -33,9 +33,9 @@ top_level base: member_access_expr base: identifier "Foundation" - member: identifier "Networking" - member: identifier "URLSession" + member_name_node: identifier "Networking" + member_name_node: identifier "URLSession" pattern: named_pattern - identifier: identifier "URLSession" + name_node: identifier "URLSession" sub_pattern: bulk_importing_pattern "import Foundation.Networking.URLSession" diff --git a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output index e3b18f34db1c..966d399f070d 100644 --- a/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output +++ b/unified/extractor/tests/corpus/swift/desugar/import-with-dotted-path-two-parts.output @@ -28,8 +28,8 @@ top_level imported_expr: member_access_expr base: identifier "Foundation" - member: identifier "Networking" + member_name_node: identifier "Networking" pattern: named_pattern - identifier: identifier "Networking" + name_node: identifier "Networking" sub_pattern: bulk_importing_pattern "import Foundation.Networking" diff --git a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output index 451067727e35..6983e5408fbc 100644 --- a/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output +++ b/unified/extractor/tests/corpus/swift/desugar/scoped-import-uses-name-pattern.output @@ -30,5 +30,5 @@ top_level imported_expr: member_access_expr base: identifier "Foundation" - member: identifier "Date" + member_name_node: identifier "Date" pattern: identifier "Date" diff --git a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output index 6b4e171983d4..a7c401563932 100644 --- a/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output +++ b/unified/extractor/tests/corpus/swift/desugar/simple-import-with-single-name.output @@ -25,5 +25,5 @@ top_level imported_expr: identifier "Foundation" pattern: named_pattern - identifier: identifier "Foundation" + name_node: identifier "Foundation" sub_pattern: bulk_importing_pattern "import Foundation" diff --git a/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output b/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output index 19a7d4df0774..be59a73183d9 100644 --- a/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output +++ b/unified/extractor/tests/corpus/swift/expressions/array-type-constructor.output @@ -154,7 +154,7 @@ top_level type_argument: identifier "Void" argument: argument - name: identifier "unsafeUninitializedCapacity" + name_node: identifier "unsafeUninitializedCapacity" value: int_literal "1" argument value: diff --git a/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output b/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output index 2a7f9df2cf05..080cf34bb3c1 100644 --- a/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output +++ b/unified/extractor/tests/corpus/swift/expressions/array-type-metatype.output @@ -64,4 +64,4 @@ top_level generic_type_expr base: identifier "Result" type_argument: identifier "Void" - member: identifier "self" + member_name_node: identifier "self" diff --git a/unified/extractor/tests/corpus/swift/expressions/unsafe-expression.output b/unified/extractor/tests/corpus/swift/expressions/unsafe-expression.output index 2bdc964ddeaa..a91bf6e2684c 100644 --- a/unified/extractor/tests/corpus/swift/expressions/unsafe-expression.output +++ b/unified/extractor/tests/corpus/swift/expressions/unsafe-expression.output @@ -46,6 +46,6 @@ top_level block stmt: function_declaration - name: identifier "doWork" + name_node: identifier "doWork" body: block "func doWork() {}" unsupported_node "unsafe doWork()" diff --git a/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output b/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output index 364a2022cc62..baf959c0cc86 100644 --- a/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output +++ b/unified/extractor/tests/corpus/swift/functions/constructor-call-with-type-arguments.output @@ -82,13 +82,13 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Foo" + name_node: identifier "Foo" class_like_declaration modifier: modifier "class" - name: identifier "C" + name_node: identifier "C" type_parameter: type_parameter - name: identifier "T" + name_node: identifier "T" variable_declaration modifier: modifier "let" pattern: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output index b8ff5468aa88..81c2af30295d 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output +++ b/unified/extractor/tests/corpus/swift/functions/function-call-with-labelled-arguments.output @@ -36,5 +36,5 @@ top_level callee: identifier "greet" argument: argument - name: identifier "person" + name_node: identifier "person" value: string_literal "\"Bob\"" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output index ed4989826cd6..3d4c6483cb50 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-default-parameter-value.output @@ -66,7 +66,7 @@ top_level block stmt: function_declaration - name: identifier "greet" + name_node: identifier "greet" parameter: parameter type: identifier "String" diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output b/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output index a568b9da17e7..198bb22bb29f 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-inout-parameter.output @@ -62,10 +62,10 @@ top_level block stmt: function_declaration - name: identifier "increment" + name_node: identifier "increment" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: unsupported_node "inout Int" pattern: identifier "x" body: diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output index fb23a5bd55bf..6ad2a386ae8e 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-named-parameters.output @@ -57,10 +57,10 @@ top_level block stmt: function_declaration - name: identifier "greet" + name_node: identifier "greet" parameter: parameter - external_name: identifier "person" + external_name_node: identifier "person" type: identifier "String" pattern: identifier "name" body: diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output index 99ba3a45e2e1..39c0b67786e2 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-no-parameters.output @@ -52,7 +52,7 @@ top_level block stmt: function_declaration - name: identifier "greet" + name_node: identifier "greet" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output index 6f5d2aa98f9d..88311a0596e7 100644 --- a/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output +++ b/unified/extractor/tests/corpus/swift/functions/function-with-parameters-and-return-type.output @@ -74,14 +74,14 @@ top_level block stmt: function_declaration - name: identifier "add" + name_node: identifier "add" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "a" parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "b" return_type: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/functions/generic-function.output b/unified/extractor/tests/corpus/swift/functions/generic-function.output index e296b760ccaa..646ee6196166 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-function.output @@ -64,13 +64,13 @@ top_level block stmt: function_declaration - name: identifier "identity" + name_node: identifier "identity" type_parameter: type_parameter - name: identifier "T" + name_node: identifier "T" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "T" pattern: identifier "x" return_type: identifier "T" diff --git a/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output b/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output index 6bc55e07b0af..459aec5b784c 100644 --- a/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output +++ b/unified/extractor/tests/corpus/swift/functions/generic-type-alias.output @@ -56,13 +56,13 @@ top_level block stmt: type_alias_declaration - name: identifier "Box" + name_node: identifier "Box" type_parameter: type_parameter - name: identifier "T" + name_node: identifier "T" bound: identifier "Equatable" type_parameter - name: identifier "U" + name_node: identifier "U" type: generic_type_expr base: identifier "Dictionary" diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output index 92da0bab18f6..5cb220bbb681 100644 --- a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-call.output @@ -50,7 +50,7 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "some" + member_name_node: identifier "some" argument: argument value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output index 310d9278f54a..1c2eab54b2ef 100644 --- a/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output +++ b/unified/extractor/tests/corpus/swift/functions/leading-dot-expression-value.output @@ -38,4 +38,4 @@ top_level value: member_access_expr base: inferred_type_expr "." - member: identifier "foo" + member_name_node: identifier "foo" diff --git a/unified/extractor/tests/corpus/swift/functions/method-call.output b/unified/extractor/tests/corpus/swift/functions/method-call.output index eb6985200bd8..52a36238c2d5 100644 --- a/unified/extractor/tests/corpus/swift/functions/method-call.output +++ b/unified/extractor/tests/corpus/swift/functions/method-call.output @@ -36,7 +36,7 @@ top_level callee: member_access_expr base: identifier "list" - member: identifier "append" + member_name_node: identifier "append" argument: argument value: int_literal "1" diff --git a/unified/extractor/tests/corpus/swift/functions/nested-function-type.output b/unified/extractor/tests/corpus/swift/functions/nested-function-type.output index 9f2f1c9f8ccc..b14135c1065c 100644 --- a/unified/extractor/tests/corpus/swift/functions/nested-function-type.output +++ b/unified/extractor/tests/corpus/swift/functions/nested-function-type.output @@ -105,7 +105,7 @@ top_level block stmt: type_alias_declaration - name: identifier "NestedFunction" + name_node: identifier "NestedFunction" type: function_expr parameter: @@ -118,7 +118,7 @@ top_level return_type: identifier "Bool" return_type: identifier "Bool" type_alias_declaration - name: identifier "MixedParametersAndTuples" + name_node: identifier "MixedParametersAndTuples" type: function_expr parameter: diff --git a/unified/extractor/tests/corpus/swift/functions/variadic-function.output b/unified/extractor/tests/corpus/swift/functions/variadic-function.output index 888d71b41895..79384b19b20f 100644 --- a/unified/extractor/tests/corpus/swift/functions/variadic-function.output +++ b/unified/extractor/tests/corpus/swift/functions/variadic-function.output @@ -78,10 +78,10 @@ top_level block stmt: function_declaration - name: identifier "sum" + name_node: identifier "sum" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "values" return_type: identifier "Int" @@ -94,7 +94,7 @@ top_level callee: member_access_expr base: identifier "values" - member: identifier "reduce" + member_name_node: identifier "reduce" argument: argument value: int_literal "0" diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output index f557670b2ff7..d78fb757a8d9 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-casts.output @@ -94,14 +94,14 @@ top_level block stmt: function_declaration - name: identifier "casts" + name_node: identifier "casts" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Any" pattern: identifier "a" parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "b" body: diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output index 4d33c7dbd388..80e0f7285631 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence-with-ternary.output @@ -100,22 +100,22 @@ top_level block stmt: function_declaration - name: identifier "choose" + name_node: identifier "choose" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Bool" pattern: identifier "c" parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "a" parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "b" parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "d" return_type: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output index 477de980d2da..ae2da42f2d43 100644 --- a/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output +++ b/unified/extractor/tests/corpus/swift/operators/unresolved-operator-sequence.output @@ -67,14 +67,14 @@ top_level block stmt: function_declaration - name: identifier "combine" + name_node: identifier "combine" parameter: parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "a" parameter - external_name: identifier "_" + external_name_node: identifier "_" type: identifier "Int" pattern: identifier "b" body: diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output index 6752c80348ce..42b65ed696b0 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-chaining.output @@ -55,5 +55,5 @@ top_level base: member_access_expr base: identifier "obj" - member: identifier "foo" - member: identifier "bar" + member_name_node: identifier "foo" + member_name_node: identifier "bar" diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output index c94032771ccf..05223133226b 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/optional-enum-case-binding.output @@ -84,7 +84,7 @@ top_level callee: member_access_expr base: identifier "Optional" - member: identifier "some" + member_name_node: identifier "some" argument: argument value: @@ -92,7 +92,7 @@ top_level callee: member_access_expr base: inferred_type_expr "." - member: identifier "some" + member_name_node: identifier "some" argument: argument value: diff --git a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output index 33346c4f38b8..7915e7ee92f8 100644 --- a/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output +++ b/unified/extractor/tests/corpus/swift/optionals-and-errors/throwing-function.output @@ -56,7 +56,7 @@ top_level block stmt: function_declaration - name: identifier "read" + name_node: identifier "read" return_type: identifier "String" body: block diff --git a/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output b/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output index a69eaa87ec54..0c839689dce0 100644 --- a/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output +++ b/unified/extractor/tests/corpus/swift/types/binding-modifier-does-not-leak-into-accessor-body.output @@ -98,7 +98,7 @@ top_level stmt: accessor_declaration modifier: modifier "var" - name: identifier "p" + name_node: identifier "p" accessor_kind: accessor_kind "get" type: identifier "Int" body: diff --git a/unified/extractor/tests/corpus/swift/types/class-inheritance.output b/unified/extractor/tests/corpus/swift/types/class-inheritance.output index 497d55d2a638..28af5a0f7086 100644 --- a/unified/extractor/tests/corpus/swift/types/class-inheritance.output +++ b/unified/extractor/tests/corpus/swift/types/class-inheritance.output @@ -34,7 +34,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Dog" + name_node: identifier "Dog" base_type: base_type type: identifier "Animal" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output index a1821edafa1d..8027fd0fca8c 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-initializer.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-initializer.output @@ -92,7 +92,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Point" + name_node: identifier "Point" member: variable_declaration modifier: modifier "var" @@ -110,5 +110,5 @@ top_level target: member_access_expr base: identifier "self" - member: identifier "x" + member_name_node: identifier "x" value: identifier "x" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-method.output b/unified/extractor/tests/corpus/swift/types/class-with-method.output index b0a95f9aefe2..f0b8cbf68dfb 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-method.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-method.output @@ -79,14 +79,14 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Counter" + name_node: identifier "Counter" member: variable_declaration modifier: modifier "var" pattern: identifier "n" value: int_literal "0" function_declaration - name: identifier "bump" + name_node: identifier "bump" body: block stmt: diff --git a/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output b/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output index 20db0ee87754..f6c87accee27 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-multiple-base-types.output @@ -39,7 +39,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Button" + name_node: identifier "Button" base_type: base_type type: identifier "Control" diff --git a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output index 440f2a9bae5c..a2eea59d3e87 100644 --- a/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output +++ b/unified/extractor/tests/corpus/swift/types/class-with-stored-properties.output @@ -63,7 +63,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Point" + name_node: identifier "Point" member: variable_declaration modifier: modifier "var" diff --git a/unified/extractor/tests/corpus/swift/types/computed-property.output b/unified/extractor/tests/corpus/swift/types/computed-property.output index e02bf629c7b7..ab7c072ae40d 100644 --- a/unified/extractor/tests/corpus/swift/types/computed-property.output +++ b/unified/extractor/tests/corpus/swift/types/computed-property.output @@ -103,7 +103,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Rect" + name_node: identifier "Rect" member: variable_declaration modifier: modifier "var" @@ -115,7 +115,7 @@ top_level type: identifier "Double" accessor_declaration modifier: modifier "var" - name: identifier "area" + name_node: identifier "area" accessor_kind: accessor_kind "get" type: identifier "Double" body: diff --git a/unified/extractor/tests/corpus/swift/types/conditional-compilation-in-class-body.output b/unified/extractor/tests/corpus/swift/types/conditional-compilation-in-class-body.output index 2c530111b9ca..b184e9b33ea1 100644 --- a/unified/extractor/tests/corpus/swift/types/conditional-compilation-in-class-body.output +++ b/unified/extractor/tests/corpus/swift/types/conditional-compilation-in-class-body.output @@ -83,5 +83,5 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "C" + name_node: identifier "C" member: unsupported_node "#if DEBUG\n init(x: Int) {}\n deinit {}\n#endif" diff --git a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output index e3ca48312608..d594e9c48df4 100644 --- a/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output +++ b/unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output @@ -65,16 +65,16 @@ top_level stmt: class_like_declaration modifier: modifier "struct" - name: identifier "Size" + name_node: identifier "Size" member: constructor_declaration parameter: parameter - external_name: identifier "width" + external_name_node: identifier "width" type: identifier "Int" pattern: identifier "w" parameter - external_name: identifier "height" + external_name_node: identifier "height" type: identifier "Int" pattern: identifier "h" body: block "init(width w: Int, height h: Int) {}" diff --git a/unified/extractor/tests/corpus/swift/types/empty-class.output b/unified/extractor/tests/corpus/swift/types/empty-class.output index 6693744c9b43..27bb4b5e67cd 100644 --- a/unified/extractor/tests/corpus/swift/types/empty-class.output +++ b/unified/extractor/tests/corpus/swift/types/empty-class.output @@ -26,4 +26,4 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Foo" + name_node: identifier "Foo" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output index b8038d1797ac..6e4bf71fe920 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-associated-values.output @@ -71,11 +71,11 @@ top_level stmt: class_like_declaration modifier: modifier "enum" - name: identifier "Shape" + name_node: identifier "Shape" member: class_like_declaration modifier: modifier "enum_case" - name: identifier "circle" + name_node: identifier "circle" member: constructor_declaration parameter: @@ -85,7 +85,7 @@ top_level body: block "circle(radius: Double)" class_like_declaration modifier: modifier "enum_case" - name: identifier "square" + name_node: identifier "square" member: constructor_declaration parameter: diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output index 99e3792af512..7c9184a774b3 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-cases.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-cases.output @@ -67,7 +67,7 @@ top_level stmt: class_like_declaration modifier: modifier "enum" - name: identifier "Direction" + name_node: identifier "Direction" member: variable_declaration modifier: modifier "enum_case" diff --git a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output index 4e7353b2ec2a..87b81b333d2f 100644 --- a/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output +++ b/unified/extractor/tests/corpus/swift/types/enum-with-comma-separated-cases-chained-declaration.output @@ -46,7 +46,7 @@ top_level stmt: class_like_declaration modifier: modifier "enum" - name: identifier "Suit" + name_node: identifier "Suit" member: variable_declaration modifier: modifier "enum_case" diff --git a/unified/extractor/tests/corpus/swift/types/extension.output b/unified/extractor/tests/corpus/swift/types/extension.output index fac2a1ee614f..3b0621788175 100644 --- a/unified/extractor/tests/corpus/swift/types/extension.output +++ b/unified/extractor/tests/corpus/swift/types/extension.output @@ -70,10 +70,10 @@ top_level stmt: class_like_declaration modifier: modifier "extension" - name: identifier "Int" + name_node: identifier "Int" member: function_declaration - name: identifier "squared" + name_node: identifier "squared" return_type: identifier "Int" body: block diff --git a/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output b/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output index bab8e792f82e..92b1713cebad 100644 --- a/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output +++ b/unified/extractor/tests/corpus/swift/types/generic-class-parameters-and-constraints.output @@ -68,13 +68,13 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Box" + name_node: identifier "Box" type_parameter: type_parameter - name: identifier "T" + name_node: identifier "T" bound: identifier "Equatable" type_parameter - name: identifier "U" + name_node: identifier "U" type_constraint: bound_type_constraint type: identifier "U" diff --git a/unified/extractor/tests/corpus/swift/types/noncopyable-type.output b/unified/extractor/tests/corpus/swift/types/noncopyable-type.output index 7239db059235..970d21683f6e 100644 --- a/unified/extractor/tests/corpus/swift/types/noncopyable-type.output +++ b/unified/extractor/tests/corpus/swift/types/noncopyable-type.output @@ -56,7 +56,7 @@ top_level stmt: class_like_declaration modifier: modifier "struct" - name: identifier "FileHandle" + name_node: identifier "FileHandle" base_type: base_type type: unsupported_node "~Copyable" diff --git a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output index 9bf243aae9bb..0641e6e30931 100644 --- a/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output +++ b/unified/extractor/tests/corpus/swift/types/property-with-getter-and-setter.output @@ -108,7 +108,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "Box" + name_node: identifier "Box" member: variable_declaration modifier: @@ -118,7 +118,7 @@ top_level value: int_literal "0" accessor_declaration modifier: modifier "var" - name: identifier "v" + name_node: identifier "v" accessor_kind: accessor_kind "get" type: identifier "Int" body: @@ -130,7 +130,7 @@ top_level modifier: modifier "var" modifier "chained_declaration" - name: identifier "v" + name_node: identifier "v" accessor_kind: accessor_kind "set" type: identifier "Int" body: diff --git a/unified/extractor/tests/corpus/swift/types/protocol-declaration.output b/unified/extractor/tests/corpus/swift/types/protocol-declaration.output index e848fb23eb3f..1521bc349b92 100644 --- a/unified/extractor/tests/corpus/swift/types/protocol-declaration.output +++ b/unified/extractor/tests/corpus/swift/types/protocol-declaration.output @@ -42,8 +42,8 @@ top_level stmt: class_like_declaration modifier: modifier "protocol" - name: identifier "Drawable" + name_node: identifier "Drawable" member: function_declaration - name: identifier "draw" + name_node: identifier "draw" body: block "func draw()" diff --git a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output index 2ed1dc4cc3f2..37e084520a18 100644 --- a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output +++ b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.output @@ -1,6 +1,7 @@ protocol P { var foo: Int { get } var bar: String { get set } + var count: Int { get } } --- @@ -71,6 +72,31 @@ sourceFile attributes: leftBrace: { rightBrace: } + memberBlockItem + decl: + variableDecl + attributes: + modifiers: + bindingSpecifier: var + bindings: + patternBinding + pattern: + identifierPattern + identifier: identifier "count" + typeAnnotation: + typeAnnotation + colon: : + type: + identifierType + name: identifier "Int" + accessorBlock: + accessorBlock + accessors: + accessorDecl + accessorSpecifier: get + attributes: + leftBrace: { + rightBrace: } modifiers: protocolKeyword: protocol @@ -82,18 +108,22 @@ top_level stmt: class_like_declaration modifier: modifier "protocol" - name: identifier "P" + name_node: identifier "P" member: accessor_declaration - name: identifier "foo" + name_node: identifier "foo" accessor_kind: accessor_kind "get" type: identifier "Int" accessor_declaration - name: identifier "bar" + name_node: identifier "bar" accessor_kind: accessor_kind "get" type: identifier "String" accessor_declaration modifier: modifier "chained_declaration" - name: identifier "bar" + name_node: identifier "bar" accessor_kind: accessor_kind "set" type: identifier "String" + accessor_declaration + name_node: identifier "count" + accessor_kind: accessor_kind "get" + type: identifier "Int" diff --git a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift index 44299edc15b9..24abb0e89fff 100644 --- a/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift +++ b/unified/extractor/tests/corpus/swift/types/protocol-with-read-only-and-read-write-property-requirements.swift @@ -1,4 +1,5 @@ protocol P { var foo: Int { get } var bar: String { get set } + var count: Int { get } } diff --git a/unified/extractor/tests/corpus/swift/types/qualified-type.output b/unified/extractor/tests/corpus/swift/types/qualified-type.output index cf3cf07d832b..4512e9e6c54d 100644 --- a/unified/extractor/tests/corpus/swift/types/qualified-type.output +++ b/unified/extractor/tests/corpus/swift/types/qualified-type.output @@ -103,22 +103,22 @@ top_level stmt: class_like_declaration modifier: modifier "struct" - name: identifier "Outer" + name_node: identifier "Outer" member: class_like_declaration modifier: modifier "struct" - name: identifier "Inner" + name_node: identifier "Inner" member: class_like_declaration modifier: modifier "struct" - name: identifier "Deep" + name_node: identifier "Deep" variable_declaration modifier: modifier "let" pattern: identifier "value" type: member_access_expr base: identifier "Outer" - member: identifier "Inner" + member_name_node: identifier "Inner" variable_declaration modifier: modifier "let" pattern: identifier "nested" @@ -127,5 +127,5 @@ top_level base: member_access_expr base: identifier "Outer" - member: identifier "Inner" - member: identifier "Deep" + member_name_node: identifier "Inner" + member_name_node: identifier "Deep" diff --git a/unified/extractor/tests/corpus/swift/types/struct.output b/unified/extractor/tests/corpus/swift/types/struct.output index eb04e0e5d79c..133a2935acd7 100644 --- a/unified/extractor/tests/corpus/swift/types/struct.output +++ b/unified/extractor/tests/corpus/swift/types/struct.output @@ -63,7 +63,7 @@ top_level stmt: class_like_declaration modifier: modifier "struct" - name: identifier "Point" + name_node: identifier "Point" member: variable_declaration modifier: modifier "let" diff --git a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output index 8531885ad9d0..c574ee74d788 100644 --- a/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output +++ b/unified/extractor/tests/corpus/swift/variables/property-with-willset-and-didset-observers.output @@ -103,7 +103,7 @@ top_level stmt: class_like_declaration modifier: modifier "class" - name: identifier "C" + name_node: identifier "C" member: variable_declaration modifier: modifier "var" @@ -114,7 +114,7 @@ top_level modifier: modifier "var" modifier "chained_declaration" - name: identifier "x" + name_node: identifier "x" accessor_kind: accessor_kind "willSet" body: block @@ -128,7 +128,7 @@ top_level modifier: modifier "var" modifier "chained_declaration" - name: identifier "x" + name_node: identifier "x" accessor_kind: accessor_kind "didSet" body: block diff --git a/unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll b/unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll index 6f899bba4283..d1568edfff80 100644 --- a/unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll +++ b/unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll @@ -4,7 +4,7 @@ private import codeql.unified.internal.StaticNameBinding private import codeql.unified.internal.LocalNameBinding private import codeql.unified.internal.NameBindingPlugin -/** Stats about identifiers that static name binding could resolve. */ +/** Stats about name nodes that static name binding could resolve. */ module StaticNameResolutionStats implements EntityStatsSig { /** * Holds if `name` has been positively identified as referring to a value, so static name binding diff --git a/unified/ql/lib/codeql/unified/internal/Ast.qll b/unified/ql/lib/codeql/unified/internal/Ast.qll index cb8861ba3feb..61898be7ed43 100644 --- a/unified/ql/lib/codeql/unified/internal/Ast.qll +++ b/unified/ql/lib/codeql/unified/internal/Ast.qll @@ -112,8 +112,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_accessor_declaration_def(this, _, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_accessor_declaration_def(this, _, result) } /** Gets the node corresponding to the field `parameter`. */ final F::Parameter getParameter(int i) { @@ -154,8 +154,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_argument_name(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_argument_name_node(this, result) } /** Gets the node corresponding to the field `value`. */ final F::Expr getValue() { unified_argument_def(this, result) } @@ -163,7 +163,7 @@ module Unified { /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { unified_argument_modifier(this, _, result) or - unified_argument_name(this, result) or + unified_argument_name_node(this, result) or unified_argument_def(this, result) } } @@ -216,8 +216,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_associated_type_declaration_def(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_associated_type_declaration_def(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -313,11 +313,13 @@ module Unified { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "BreakExpr" } - /** Gets the node corresponding to the field `label`. */ - final F::Identifier getLabel() { unified_break_expr_label(this, result) } + /** Gets the node corresponding to the field `label_name_node`. */ + final F::Identifier getLabelNameNode() { unified_break_expr_label_name_node(this, result) } /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { unified_break_expr_label(this, result) } + final override F::AstNode getAFieldOrChild() { + unified_break_expr_label_name_node(this, result) + } } /** A class representing `builtin_expr` tokens. */ @@ -427,8 +429,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_class_like_declaration_name(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_class_like_declaration_name_node(this, result) } /** Gets the node corresponding to the field `type_constraint`. */ final F::TypeConstraint getTypeConstraint(int i) { @@ -451,7 +453,7 @@ module Unified { unified_class_like_declaration_base_type(this, _, result) or unified_class_like_declaration_member(this, _, result) or unified_class_like_declaration_modifier(this, _, result) or - unified_class_like_declaration_name(this, result) or + unified_class_like_declaration_name_node(this, result) or unified_class_like_declaration_type_constraint(this, _, result) or unified_class_like_declaration_type_parameter(this, _, result) } @@ -522,8 +524,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_constructor_declaration_name(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_constructor_declaration_name_node(this, result) } /** Gets the node corresponding to the field `parameter`. */ final F::Parameter getParameter(int i) { @@ -537,7 +539,7 @@ module Unified { final override F::AstNode getAFieldOrChild() { unified_constructor_declaration_def(this, result) or unified_constructor_declaration_modifier(this, _, result) or - unified_constructor_declaration_name(this, result) or + unified_constructor_declaration_name_node(this, result) or unified_constructor_declaration_parameter(this, _, result) } } @@ -547,11 +549,13 @@ module Unified { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "ContinueExpr" } - /** Gets the node corresponding to the field `label`. */ - final F::Identifier getLabel() { unified_continue_expr_label(this, result) } + /** Gets the node corresponding to the field `label_name_node`. */ + final F::Identifier getLabelNameNode() { unified_continue_expr_label_name_node(this, result) } /** Gets a field or child node of this node. */ - final override F::AstNode getAFieldOrChild() { unified_continue_expr_label(this, result) } + final override F::AstNode getAFieldOrChild() { + unified_continue_expr_label_name_node(this, result) + } } /** A class representing `destructor_declaration` nodes. */ @@ -711,8 +715,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_function_declaration_def(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_function_declaration_def(this, result) } /** Gets the node corresponding to the field `parameter`. */ final F::Parameter getParameter(int i) { @@ -952,8 +956,8 @@ module Unified { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "LabeledStmt" } - /** Gets the node corresponding to the field `label`. */ - final F::Identifier getLabel() { unified_labeled_stmt_def(this, result, _) } + /** Gets the node corresponding to the field `label_name_node`. */ + final F::Identifier getLabelNameNode() { unified_labeled_stmt_def(this, result, _) } /** Gets the node corresponding to the field `stmt`. */ final F::Stmt getStmt() { unified_labeled_stmt_def(this, _, result) } @@ -989,8 +993,8 @@ module Unified { /** Gets the node corresponding to the field `base`. */ final F::Expr getBase() { unified_member_access_expr_def(this, result, _) } - /** Gets the node corresponding to the field `member`. */ - final F::Identifier getMember() { unified_member_access_expr_def(this, _, result) } + /** Gets the node corresponding to the field `member_name_node`. */ + final F::Identifier getMemberNameNode() { unified_member_access_expr_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -1010,22 +1014,22 @@ module Unified { /** Gets the name of the primary QL class for this element. */ final override string getAPrimaryQlClass() { result = "NamedPattern" } - /** Gets the node corresponding to the field `identifier`. */ - final F::Identifier getIdentifier() { unified_named_pattern_def(this, result, _) } - /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getModifier(int i) { unified_named_pattern_modifier(this, i, result) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_named_pattern_def(this, result, _) } + /** Gets the node corresponding to the field `sub_pattern`. */ final F::Expr getSubPattern() { unified_named_pattern_def(this, _, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { - unified_named_pattern_def(this, result, _) or unified_named_pattern_modifier(this, _, result) or + unified_named_pattern_def(this, result, _) or unified_named_pattern_def(this, _, result) } } @@ -1048,8 +1052,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_operator_syntax_declaration_def(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_operator_syntax_declaration_def(this, result) } /** Gets the node corresponding to the field `precedence`. */ final F::Expr getPrecedence() { unified_operator_syntax_declaration_precedence(this, result) } @@ -1094,8 +1098,8 @@ module Unified { /** Gets the node corresponding to the field `default`. */ final F::Expr getDefault() { unified_parameter_default(this, result) } - /** Gets the node corresponding to the field `external_name`. */ - final F::Identifier getExternalName() { unified_parameter_external_name(this, result) } + /** Gets the node corresponding to the field `external_name_node`. */ + final F::Identifier getExternalNameNode() { unified_parameter_external_name_node(this, result) } /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getModifier(int i) { unified_parameter_modifier(this, i, result) } @@ -1112,7 +1116,7 @@ module Unified { /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { unified_parameter_default(this, result) or - unified_parameter_external_name(this, result) or + unified_parameter_external_name_node(this, result) or unified_parameter_modifier(this, _, result) or unified_parameter_pattern(this, result) or unified_parameter_type(this, result) @@ -1314,8 +1318,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_type_alias_declaration_def(this, result, _) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_type_alias_declaration_def(this, result, _) } /** Gets the node corresponding to the field `type`. */ final F::Expr getType() { unified_type_alias_declaration_def(this, _, result) } @@ -1384,8 +1388,8 @@ module Unified { /** Gets the node corresponding to the field `modifier`. */ final F::Modifier getAModifier() { result = this.getModifier(_) } - /** Gets the node corresponding to the field `name`. */ - final F::Identifier getName() { unified_type_parameter_def(this, result) } + /** Gets the node corresponding to the field `name_node`. */ + final F::Identifier getNameNode() { unified_type_parameter_def(this, result) } /** Gets a field or child node of this node. */ final override F::AstNode getAFieldOrChild() { @@ -1523,7 +1527,7 @@ module Unified { or result = node.(AccessorDeclaration).getModifier(i) and name = "getModifier" or - result = node.(AccessorDeclaration).getName() and i = -1 and name = "getName" + result = node.(AccessorDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(AccessorDeclaration).getParameter(i) and name = "getParameter" or @@ -1531,7 +1535,7 @@ module Unified { or result = node.(Argument).getModifier(i) and name = "getModifier" or - result = node.(Argument).getName() and i = -1 and name = "getName" + result = node.(Argument).getNameNode() and i = -1 and name = "getNameNode" or result = node.(Argument).getValue() and i = -1 and name = "getValue" or @@ -1545,7 +1549,7 @@ module Unified { or result = node.(AssociatedTypeDeclaration).getModifier(i) and name = "getModifier" or - result = node.(AssociatedTypeDeclaration).getName() and i = -1 and name = "getName" + result = node.(AssociatedTypeDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(BaseType).getModifier(i) and name = "getModifier" or @@ -1563,7 +1567,7 @@ module Unified { or result = node.(BoundTypeConstraint).getType() and i = -1 and name = "getType" or - result = node.(BreakExpr).getLabel() and i = -1 and name = "getLabel" + result = node.(BreakExpr).getLabelNameNode() and i = -1 and name = "getLabelNameNode" or result = node.(BulkImportingPattern).getModifier(i) and name = "getModifier" or @@ -1585,7 +1589,7 @@ module Unified { or result = node.(ClassLikeDeclaration).getModifier(i) and name = "getModifier" or - result = node.(ClassLikeDeclaration).getName() and i = -1 and name = "getName" + result = node.(ClassLikeDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(ClassLikeDeclaration).getTypeConstraint(i) and name = "getTypeConstraint" or @@ -1607,11 +1611,11 @@ module Unified { or result = node.(ConstructorDeclaration).getModifier(i) and name = "getModifier" or - result = node.(ConstructorDeclaration).getName() and i = -1 and name = "getName" + result = node.(ConstructorDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(ConstructorDeclaration).getParameter(i) and name = "getParameter" or - result = node.(ContinueExpr).getLabel() and i = -1 and name = "getLabel" + result = node.(ContinueExpr).getLabelNameNode() and i = -1 and name = "getLabelNameNode" or result = node.(DestructorDeclaration).getBody() and i = -1 and name = "getBody" or @@ -1645,7 +1649,7 @@ module Unified { or result = node.(FunctionDeclaration).getModifier(i) and name = "getModifier" or - result = node.(FunctionDeclaration).getName() and i = -1 and name = "getName" + result = node.(FunctionDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(FunctionDeclaration).getParameter(i) and name = "getParameter" or @@ -1693,7 +1697,7 @@ module Unified { or result = node.(KeyValuePair).getValue() and i = -1 and name = "getValue" or - result = node.(LabeledStmt).getLabel() and i = -1 and name = "getLabel" + result = node.(LabeledStmt).getLabelNameNode() and i = -1 and name = "getLabelNameNode" or result = node.(LabeledStmt).getStmt() and i = -1 and name = "getStmt" or @@ -1701,19 +1705,19 @@ module Unified { or result = node.(MemberAccessExpr).getBase() and i = -1 and name = "getBase" or - result = node.(MemberAccessExpr).getMember() and i = -1 and name = "getMember" - or - result = node.(NamedPattern).getIdentifier() and i = -1 and name = "getIdentifier" + result = node.(MemberAccessExpr).getMemberNameNode() and i = -1 and name = "getMemberNameNode" or result = node.(NamedPattern).getModifier(i) and name = "getModifier" or + result = node.(NamedPattern).getNameNode() and i = -1 and name = "getNameNode" + or result = node.(NamedPattern).getSubPattern() and i = -1 and name = "getSubPattern" or result = node.(OperatorSyntaxDeclaration).getFixity() and i = -1 and name = "getFixity" or result = node.(OperatorSyntaxDeclaration).getModifier(i) and name = "getModifier" or - result = node.(OperatorSyntaxDeclaration).getName() and i = -1 and name = "getName" + result = node.(OperatorSyntaxDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(OperatorSyntaxDeclaration).getPrecedence() and i = -1 and @@ -1725,7 +1729,7 @@ module Unified { or result = node.(Parameter).getDefault() and i = -1 and name = "getDefault" or - result = node.(Parameter).getExternalName() and i = -1 and name = "getExternalName" + result = node.(Parameter).getExternalNameNode() and i = -1 and name = "getExternalNameNode" or result = node.(Parameter).getModifier(i) and name = "getModifier" or @@ -1765,7 +1769,7 @@ module Unified { or result = node.(TypeAliasDeclaration).getModifier(i) and name = "getModifier" or - result = node.(TypeAliasDeclaration).getName() and i = -1 and name = "getName" + result = node.(TypeAliasDeclaration).getNameNode() and i = -1 and name = "getNameNode" or result = node.(TypeAliasDeclaration).getType() and i = -1 and name = "getType" or @@ -1783,7 +1787,7 @@ module Unified { or result = node.(TypeParameter).getModifier(i) and name = "getModifier" or - result = node.(TypeParameter).getName() and i = -1 and name = "getName" + result = node.(TypeParameter).getNameNode() and i = -1 and name = "getNameNode" or result = node.(TypeTestExpr).getExpr() and i = -1 and name = "getExpr" or diff --git a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll index 2e4a7dfc4c3a..371eb3c3bcd2 100644 --- a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll +++ b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll @@ -239,9 +239,9 @@ private module Input implements InputSig1, InputSig2 { class Label extends string { Label() { - any(LabeledStmt l).getLabel().getValue() = this or - any(BreakExpr b).getLabel().getValue() = this or - any(ContinueExpr c).getLabel().getValue() = this + any(LabeledStmt l).getLabelNameNode().getValue() = this or + any(BreakExpr b).getLabelNameNode().getValue() = this or + any(ContinueExpr c).getLabelNameNode().getValue() = this } string toString() { result = this } @@ -249,7 +249,7 @@ private module Input implements InputSig1, InputSig2 { private Label getLabelOfStmt(Stmt s) { exists(LabeledStmt l | s = l.getStmt() | - result = l.getLabel().getValue() or + result = l.getLabelNameNode().getValue() or result = getLabelOfStmt(l) ) } @@ -257,9 +257,9 @@ private module Input implements InputSig1, InputSig2 { predicate hasLabel(Ast::AstNode n, Label l) { l = getLabelOfStmt(n) or - l = n.(BreakExpr).getLabel().getValue() + l = n.(BreakExpr).getLabelNameNode().getValue() or - l = n.(ContinueExpr).getLabel().getValue() + l = n.(ContinueExpr).getLabelNameNode().getValue() } class CallableContext = Void; diff --git a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll index ec17e6505c95..bd5b1149b6e0 100644 --- a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll +++ b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll @@ -77,7 +77,7 @@ module Unified { Expr getNamedArgument(string name) { exists(Argument arg | arg = this.getAnArgument() and - arg.getName().getValue() = name and + arg.getNameNode().getValue() = name and result = arg.getValue() ) } diff --git a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll index df95034cdf85..019373a01987 100644 --- a/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll @@ -102,7 +102,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig Date: Thu, 3 Sep 2026 11:09:16 +0200 Subject: [PATCH 07/10] unified: Add getName() convenience predicates --- .../unified/internal/ControlFlowGraph.qll | 12 +-- .../lib/codeql/unified/internal/FacadeAst.qll | 77 ++++++++++++++++++- .../internal/NameBindingPluginSwift.qll | 2 +- .../unified/internal/StaticNameBinding.qll | 2 +- unified/ql/lib/utils/test/TestUtils.qll | 4 +- .../ql/test/library-tests/BasicTest/test.ql | 4 +- 6 files changed, 87 insertions(+), 14 deletions(-) diff --git a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll index 371eb3c3bcd2..ef14141c606e 100644 --- a/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll +++ b/unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll @@ -239,9 +239,9 @@ private module Input implements InputSig1, InputSig2 { class Label extends string { Label() { - any(LabeledStmt l).getLabelNameNode().getValue() = this or - any(BreakExpr b).getLabelNameNode().getValue() = this or - any(ContinueExpr c).getLabelNameNode().getValue() = this + any(LabeledStmt l).getLabelName() = this or + any(BreakExpr b).getLabelName() = this or + any(ContinueExpr c).getLabelName() = this } string toString() { result = this } @@ -249,7 +249,7 @@ private module Input implements InputSig1, InputSig2 { private Label getLabelOfStmt(Stmt s) { exists(LabeledStmt l | s = l.getStmt() | - result = l.getLabelNameNode().getValue() or + result = l.getLabelName() or result = getLabelOfStmt(l) ) } @@ -257,9 +257,9 @@ private module Input implements InputSig1, InputSig2 { predicate hasLabel(Ast::AstNode n, Label l) { l = getLabelOfStmt(n) or - l = n.(BreakExpr).getLabelNameNode().getValue() + l = n.(BreakExpr).getLabelName() or - l = n.(ContinueExpr).getLabelNameNode().getValue() + l = n.(ContinueExpr).getLabelName() } class CallableContext = Void; diff --git a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll index bd5b1149b6e0..dcec57f0a4ae 100644 --- a/unified/ql/lib/codeql/unified/internal/FacadeAst.qll +++ b/unified/ql/lib/codeql/unified/internal/FacadeAst.qll @@ -65,6 +65,81 @@ module Unified { } } + class AccessorDeclaration extends G::AccessorDeclaration { + /** Gets the name of this accessor. */ + string getName() { result = this.getNameNode().getValue() } + } + + class Argument extends G::Argument { + /** Gets the name of this argument. */ + string getName() { result = this.getNameNode().getValue() } + } + + class AssociatedTypeDeclaration extends G::AssociatedTypeDeclaration { + /** Gets the name of this associated type. */ + string getName() { result = this.getNameNode().getValue() } + } + + class BreakExpr extends G::BreakExpr { + /** Gets the label name targeted by this break. */ + string getLabelName() { result = this.getLabelNameNode().getValue() } + } + + class ClassLikeDeclaration extends G::ClassLikeDeclaration { + /** Gets the name of this declaration. */ + string getName() { result = this.getNameNode().getValue() } + } + + class ConstructorDeclaration extends G::ConstructorDeclaration { + /** Gets the name of this constructor. */ + string getName() { result = this.getNameNode().getValue() } + } + + class ContinueExpr extends G::ContinueExpr { + /** Gets the label name targeted by this continue. */ + string getLabelName() { result = this.getLabelNameNode().getValue() } + } + + class FunctionDeclaration extends G::FunctionDeclaration { + /** Gets the name of this function. */ + string getName() { result = this.getNameNode().getValue() } + } + + class LabeledStmt extends G::LabeledStmt { + /** Gets the label name of this statement. */ + string getLabelName() { result = this.getLabelNameNode().getValue() } + } + + class MemberAccessExpr extends G::MemberAccessExpr { + /** Gets the member name of this access. */ + string getMemberName() { result = this.getMemberNameNode().getValue() } + } + + class NamedPattern extends G::NamedPattern { + /** Gets the name bound by this pattern. */ + string getName() { result = this.getNameNode().getValue() } + } + + class OperatorSyntaxDeclaration extends G::OperatorSyntaxDeclaration { + /** Gets the name of this operator. */ + string getName() { result = this.getNameNode().getValue() } + } + + class Parameter extends G::Parameter { + /** Gets the external name of this parameter. */ + string getExternalName() { result = this.getExternalNameNode().getValue() } + } + + class TypeAliasDeclaration extends G::TypeAliasDeclaration { + /** Gets the name of this type alias. */ + string getName() { result = this.getNameNode().getValue() } + } + + class TypeParameter extends G::TypeParameter { + /** Gets the name of this type parameter. */ + string getName() { result = this.getNameNode().getValue() } + } + /** A binary expression. */ class BinaryExpr extends G::BinaryExpr { /** Gets an operand of this binary expression. */ @@ -77,7 +152,7 @@ module Unified { Expr getNamedArgument(string name) { exists(Argument arg | arg = this.getAnArgument() and - arg.getNameNode().getValue() = name and + arg.getName() = name and result = arg.getValue() ) } diff --git a/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll b/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll index fa9b4b8a2c74..644aaa6df54c 100644 --- a/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll +++ b/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll @@ -81,7 +81,7 @@ class SwiftPackageTarget extends ModuleScopeRepr, CallExpr { SwiftPackageTarget() { this.getFile().getBaseName() = "Package.swift" and - this.getCallee().(MemberAccessExpr).getMemberNameNode().getValue() = targetKind and + this.getCallee().(MemberAccessExpr).getMemberName() = targetKind and targetKind = [ "target", "executableTarget", "testTarget", "systemLibrary", "binaryTarget", "plugin", diff --git a/unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll b/unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll index 62e0998bb5b8..26d94f0591fb 100644 --- a/unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll +++ b/unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll @@ -163,7 +163,7 @@ private NameBindingNode getNodeFromUncertainScope(AstNode n) { result.isLocalNam predicate readStep(NameBindingNode node1, string name, NameBindingNode node2) { exists(MemberAccessExpr expr | node1 = getNodeFromRef(expr.getBase()) and - name = expr.getMemberNameNode().getValue() and + name = expr.getMemberName() and node2 = getNodeFromRef(expr) ) or diff --git a/unified/ql/lib/utils/test/TestUtils.qll b/unified/ql/lib/utils/test/TestUtils.qll index 911929c9771f..6a7fbae3d592 100644 --- a/unified/ql/lib/utils/test/TestUtils.qll +++ b/unified/ql/lib/utils/test/TestUtils.qll @@ -4,9 +4,9 @@ private import codeql.unified.internal.StaticNameBinding private string deriveClassName(ClassLikeDeclaration cls) { not exists(cls.getParent().getEnclosingClass()) and - result = cls.getNameNode().getValue() + result = cls.getName() or - result = deriveClassName(cls.getParent().getEnclosingClass()) + "." + cls.getNameNode().getValue() + result = deriveClassName(cls.getParent().getEnclosingClass()) + "." + cls.getName() } private string defaultName(NameDeclaration decl) { diff --git a/unified/ql/test/library-tests/BasicTest/test.ql b/unified/ql/test/library-tests/BasicTest/test.ql index 4f8528b31d75..75fea1330e4a 100644 --- a/unified/ql/test/library-tests/BasicTest/test.ql +++ b/unified/ql/test/library-tests/BasicTest/test.ql @@ -2,9 +2,7 @@ import unified query predicate identifier(Identifier node, string value) { value = node.getValue() } -query predicate namedPattern(NamedPattern node, string value) { - value = node.getNameNode().getValue() -} +query predicate namedPattern(NamedPattern node, string value) { value = node.getName() } query predicate unsupported(UnsupportedNode node, string value) { value = node.getValue() } From 99ffe04c77e43432fdfc2cc2ff4295bd8d8e29b9 Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 4 Sep 2026 13:17:28 +0200 Subject: [PATCH 08/10] unified: Fix a bad comment --- unified/extractor/ast_types.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unified/extractor/ast_types.yml b/unified/extractor/ast_types.yml index 28f152c24e1e..82b49f981180 100644 --- a/unified/extractor/ast_types.yml +++ b/unified/extractor/ast_types.yml @@ -97,7 +97,7 @@ named: top_level: body: block - # A name pattern that applies a nested pattern. Used for scoped imports. + # A pattern that binds the incoming value to a name, and then applies it to a sub-pattern. named_pattern: modifier*: modifier name_node: identifier From bafa95be37998e9d74a543498d4ce71927efa1ec Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 4 Sep 2026 13:25:50 +0200 Subject: [PATCH 09/10] unified: Add test for unbound var in PatternGuardExpr --- .../ql/test/library-tests/local-name-binding/test.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unified/ql/test/library-tests/local-name-binding/test.swift b/unified/ql/test/library-tests/local-name-binding/test.swift index b5d0469e8a44..5e9adaa03d87 100644 --- a/unified/ql/test/library-tests/local-name-binding/test.swift +++ b/unified/ql/test/library-tests/local-name-binding/test.swift @@ -354,3 +354,11 @@ func t38(value: E38) { // $ access=E38 print(y) // $ access=y1 } } + +// A non-binding pattern in a guard refers to an existing variable +func t39(value: Int) { + let x = 1 // name=x1 + guard case x = value else { // $ access=value MISSING: access=x1 + return + } +} From 777ff0af97773719fb11b060da1b3f59398e75f7 Mon Sep 17 00:00:00 2001 From: Asger F Date: Fri, 4 Sep 2026 13:26:50 +0200 Subject: [PATCH 10/10] unified: Fix the aforementioned bug --- .../ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll | 4 +++- unified/ql/test/library-tests/local-name-binding/test.swift | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll b/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll index 644aaa6df54c..dbfa0222cfdd 100644 --- a/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll +++ b/unified/ql/lib/codeql/unified/internal/NameBindingPluginSwift.qll @@ -44,12 +44,14 @@ class NameBindingPluginSwift extends NameBindingPlugin { /** Holds if `node` is in a context where a bare name node should be seen as a reference rather than a declaration. */ private predicate isUnboundPattern(Expr node) { - // 'case/catch' start an unbound-pattern context, 'let/var' terminate it + // 'case/catch/guard' start an unbound-pattern context, 'let/var' terminate it ( node = any(SwitchCase c).getPattern() or node = any(CatchClause c).getPattern() or + node = any(PatternGuardExpr c).getPattern() + or isUnboundPattern(node.(Expr).getEnclosingExpr()) ) and not node.(ExprPattern).hasModifier(["let", "var"]) diff --git a/unified/ql/test/library-tests/local-name-binding/test.swift b/unified/ql/test/library-tests/local-name-binding/test.swift index 5e9adaa03d87..23d71d8f6dcd 100644 --- a/unified/ql/test/library-tests/local-name-binding/test.swift +++ b/unified/ql/test/library-tests/local-name-binding/test.swift @@ -358,7 +358,7 @@ func t38(value: E38) { // $ access=E38 // A non-binding pattern in a guard refers to an existing variable func t39(value: Int) { let x = 1 // name=x1 - guard case x = value else { // $ access=value MISSING: access=x1 + guard case x = value else { // $ access=value access=x1 return } }