diff --git a/unified/extractor/src/languages/swift/swift.rs b/unified/extractor/src/languages/swift/swift.rs index 27e00fba59f3..9bdb142eb28b 100644 --- a/unified/extractor/src/languages/swift/swift.rs +++ b/unified/extractor/src/languages/swift/swift.rs @@ -277,6 +277,18 @@ fn translation_rules() -> Vec> { rule!((sequenceExpr elements: _* @els) => (unresolved_operator_sequence element: {els})), // Prefix unary operators (`!a`, `-x`). rule!((prefixOperatorExpr operator: @@op expression: @operand) => (unary_expr operator: (prefix_operator #{op}) operand: {operand})), + // Postfix unary operators (e.g., `x!`, `x...`, `x++`). + rule!( + (postfixOperatorExpr expression: @operand operator: @@op) + => + (unary_expr operator: (postfix_operator #{op}) operand: {operand}) + ), + // In-out expressions, `&x`, are translated to unary expressions. + rule!( + (inOutExpr ampersand: @@amp expression: @operand) + => + (unary_expr operator: (prefix_operator #{amp}) operand: {operand}) + ), // A parenthesised expression has a single tuple element; elide the // grouping and preserve the expression itself. Actual tuple literals // retain their translated labeled elements as `argument` children. @@ -1393,7 +1405,6 @@ fn translation_rules() -> Vec> { rule!((fallThroughStmt) => (unsupported_node)), rule!((ifConfigDecl) => (unsupported_node)), rule!((implicitlyUnwrappedOptionalType) => (unsupported_node)), - rule!((inOutExpr) => (unsupported_node)), rule!((inlineArrayType) => (unsupported_node)), rule!((keyPathExpr) => (unsupported_node)), rule!((macroDecl) => (unsupported_node)), @@ -1405,7 +1416,6 @@ fn translation_rules() -> Vec> { rule!((packExpansionExpr) => (unsupported_node)), rule!((packExpansionType) => (unsupported_node)), rule!((postfixIfConfigExpr) => (unsupported_node)), - rule!((postfixOperatorExpr) => (unsupported_node)), rule!((poundSourceLocation) => (unsupported_node)), rule!((precedenceGroupDecl) => (unsupported_node)), rule!((someOrAnyType) => (unsupported_node)), 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 588f6aafbd6b..380eb27b2ada 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 @@ -85,6 +85,12 @@ top_level source="⟨body⟩" callee: identifier "swap" source="swap" argument: argument source="⟨value⟩" - value: unsupported_node "&a" source="&a" + value: + unary_expr source="⟨operator⟩⟨operand⟩" + operand: identifier "a" source="a" + operator: prefix_operator "&" source="&" argument source="⟨value⟩" - value: unsupported_node "&b" source="&b" + value: + unary_expr source="⟨operator⟩⟨operand⟩" + operand: identifier "b" source="b" + operator: prefix_operator "&" source="&" 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 cc73dce357e5..b9e63c4a8550 100644 --- a/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output +++ b/unified/extractor/tests/corpus/swift/operators/custom-postfix-operator.output @@ -43,4 +43,7 @@ top_level source="⟨body⟩" variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩" modifier: modifier "let" source="let" pattern: identifier "squared" source="squared" - value: unsupported_node "3^^" source="3^^" + value: + unary_expr source="⟨operand⟩⟨operator⟩" + operand: int_literal "3" source="3" + operator: postfix_operator "^^" source="^^" 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 90faee91bd75..da54bf04c071 100644 --- a/unified/extractor/tests/corpus/swift/operators/partial-range-from.output +++ b/unified/extractor/tests/corpus/swift/operators/partial-range-from.output @@ -35,4 +35,7 @@ top_level source="⟨body⟩" variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩" modifier: modifier "let" source="let" pattern: identifier "range" source="range" - value: unsupported_node "3..." source="3..." + value: + unary_expr source="⟨operand⟩⟨operator⟩" + operand: int_literal "3" source="3" + operator: postfix_operator "..." source="..." diff --git a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected index 36487bd95dca..ef1418bdcbd0 100644 --- a/unified/ql/test/library-tests/controlflow/basicblock-slices.expected +++ b/unified/ql/test/library-tests/controlflow/basicblock-slices.expected @@ -77,9 +77,9 @@ | 90 | cfg.swift:90:3:92:3 | func addOptional | 'func addOptional' | | 90 | cfg.swift:90:20:90:20 | a | 'a -> Block' | | 91 | cfg.swift:91:5:91:5 | a | 'a -> nil -^ ... = ...' | -| 94 | cfg.swift:94:3:94:5 | add | 'add -> Argument -V -^ add(...)' | +| 94 | cfg.swift:94:3:94:5 | add | 'add -> Argument -V temp -^ & ... -^ add(...)' | | 95 | cfg.swift:95:3:95:30 | var tempOptional | 'var tempOptional -V tempOptional -> Optional -> Int -^ GenericTypeExpr -> 10' | -| 96 | cfg.swift:96:3:96:13 | addOptional | 'addOptional -> Argument -V -^ addOptional(...)' | +| 96 | cfg.swift:96:3:96:13 | addOptional | 'addOptional -> Argument -V tempOptional -^ & ... -^ addOptional(...)' | | 97 | cfg.swift:97:10:97:13 | temp | 'temp -> tempOptional -^ ... ! -^ ... + ... -^ ReturnExpr' | | 100 | cfg.swift:100:1:109:1 | class C | 'class C -V C' | | 101 | cfg.swift:101:3:101:16 | let myInt | 'let myInt -V myInt -> Int' |