mirror of
https://github.com/github/codeql.git
synced 2026-07-31 07:22:56 +02:00
unified: Add corpus cases for currently-unsupported Swift constructs
Add corpus test cases that witness Swift constructs the swift-syntax mapping does not yet handle, so they map to `unsupported_node` (or, for unfoldable operator chains, `unresolved_operator_sequence`). These document the current behaviour and give us a place to observe the diff when each construct is eventually supported. The cases are placed alongside the feature they exercise: - functions: `inout` parameter types and `&`-prefixed inout arguments. - expressions: key paths, generic specialization in expression position (`Array<Int>()`), `copy`/`consume` expressions, and `unsafe` expressions. - operators: unresolved operator sequences (pointwise operators the parser cannot fold), custom postfix operators, and partial ranges. - control-flow: `fallthrough`, `defer`, and `discard` statements. - types: `actor` declarations, inline array types (`[3 of Int]`), function-type attributes (`@convention(c)`, `@Sendable`), noncopyable (`~Copyable`) types, and conditional compilation in a class body. - literals: the `#line` magic literal. The conditional-compilation case is worth calling out because it swallows members: swift-syntax reports a structured `ifConfigDecl` whose branches hold ordinary member items, but with no rule for it the whole `#if` block collapses into a single `unsupported_node`, so the declarations inside are not extracted at all. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
func withCleanup() {
|
||||
defer { print("cleanup") }
|
||||
print("work")
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
functionDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
deferStmt
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
functionCallExpr
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
arguments:
|
||||
labeledExpr
|
||||
expression:
|
||||
stringLiteralExpr
|
||||
closingQuote: "
|
||||
openingQuote: "
|
||||
segments:
|
||||
stringSegment
|
||||
content: stringSegment "cleanup"
|
||||
additionalTrailingClosures:
|
||||
calledExpression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "print"
|
||||
deferKeyword: defer
|
||||
codeBlockItem
|
||||
item:
|
||||
functionCallExpr
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
arguments:
|
||||
labeledExpr
|
||||
expression:
|
||||
stringLiteralExpr
|
||||
closingQuote: "
|
||||
openingQuote: "
|
||||
segments:
|
||||
stringSegment
|
||||
content: stringSegment "work"
|
||||
additionalTrailingClosures:
|
||||
calledExpression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "print"
|
||||
name: identifier "withCleanup"
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
funcKeyword: func
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
function_declaration
|
||||
name: identifier "withCleanup"
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
unsupported_node "defer { print(\"cleanup\") }"
|
||||
call_expr
|
||||
callee:
|
||||
name_expr
|
||||
identifier: identifier "print"
|
||||
argument:
|
||||
argument
|
||||
value: string_literal "\"work\""
|
||||
@@ -0,0 +1,4 @@
|
||||
func withCleanup() {
|
||||
defer { print("cleanup") }
|
||||
print("work")
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
struct Resource: ~Copyable {
|
||||
consuming func close() {
|
||||
discard self
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
structDecl
|
||||
attributes:
|
||||
name: identifier "Resource"
|
||||
inheritanceClause:
|
||||
inheritanceClause
|
||||
colon: :
|
||||
inheritedTypes:
|
||||
inheritedType
|
||||
type:
|
||||
suppressedType
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Copyable"
|
||||
withoutTilde: prefixOperator "~"
|
||||
memberBlock:
|
||||
memberBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
members:
|
||||
memberBlockItem
|
||||
decl:
|
||||
functionDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
discardStmt
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: self
|
||||
discardKeyword: discard
|
||||
name: identifier "close"
|
||||
modifiers:
|
||||
declModifier
|
||||
name: consuming
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
funcKeyword: func
|
||||
modifiers:
|
||||
structKeyword: struct
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
class_like_declaration
|
||||
modifier: modifier "struct"
|
||||
name: identifier "Resource"
|
||||
base_type:
|
||||
base_type
|
||||
type: unsupported_node "~Copyable"
|
||||
member:
|
||||
function_declaration
|
||||
name: identifier "close"
|
||||
body:
|
||||
block
|
||||
stmt: unsupported_node "discard self"
|
||||
@@ -0,0 +1,5 @@
|
||||
struct Resource: ~Copyable {
|
||||
consuming func close() {
|
||||
discard self
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
func classify(_ x: Int) {
|
||||
switch x {
|
||||
case 1:
|
||||
fallthrough
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
functionDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
expressionStmt
|
||||
expression:
|
||||
switchExpr
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
cases:
|
||||
switchCase
|
||||
label:
|
||||
switchCaseLabel
|
||||
colon: :
|
||||
caseKeyword: case
|
||||
caseItems:
|
||||
switchCaseItem
|
||||
pattern:
|
||||
expressionPattern
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "1"
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
fallThroughStmt
|
||||
fallthroughKeyword: fallthrough
|
||||
switchCase
|
||||
label:
|
||||
switchDefaultLabel
|
||||
colon: :
|
||||
defaultKeyword: default
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
breakStmt
|
||||
breakKeyword: break
|
||||
subject:
|
||||
declReferenceExpr
|
||||
baseName: identifier "x"
|
||||
switchKeyword: switch
|
||||
name: identifier "classify"
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
firstName: _
|
||||
secondName: identifier "x"
|
||||
funcKeyword: func
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
function_declaration
|
||||
name: identifier "classify"
|
||||
parameter:
|
||||
parameter
|
||||
external_name: identifier "_"
|
||||
type:
|
||||
named_type_expr
|
||||
name: identifier "Int"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "x"
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
switch_expr
|
||||
value:
|
||||
name_expr
|
||||
identifier: identifier "x"
|
||||
case:
|
||||
switch_case
|
||||
pattern:
|
||||
expr_equality_pattern
|
||||
expr: int_literal "1"
|
||||
body:
|
||||
block
|
||||
stmt: unsupported_node "fallthrough"
|
||||
switch_case
|
||||
body:
|
||||
block
|
||||
stmt: break_expr "break"
|
||||
@@ -0,0 +1,8 @@
|
||||
func classify(_ x: Int) {
|
||||
switch x {
|
||||
case 1:
|
||||
fallthrough
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
let original = [1, 2, 3]
|
||||
let consumed = consume original
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
arrayExpr
|
||||
elements:
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "1"
|
||||
trailingComma: ,
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "2"
|
||||
trailingComma: ,
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "3"
|
||||
leftSquare: [
|
||||
rightSquare: ]
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "original"
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
consumeExpr
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "original"
|
||||
consumeKeyword: consume
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "consumed"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "original"
|
||||
value:
|
||||
array_literal
|
||||
element:
|
||||
int_literal "1"
|
||||
int_literal "2"
|
||||
int_literal "3"
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "consumed"
|
||||
value: unsupported_node "consume original"
|
||||
@@ -0,0 +1,2 @@
|
||||
let original = [1, 2, 3]
|
||||
let consumed = consume original
|
||||
@@ -0,0 +1,85 @@
|
||||
let original = [1, 2, 3]
|
||||
let copied = copy original
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
arrayExpr
|
||||
elements:
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "1"
|
||||
trailingComma: ,
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "2"
|
||||
trailingComma: ,
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "3"
|
||||
leftSquare: [
|
||||
rightSquare: ]
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "original"
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
copyExpr
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "original"
|
||||
copyKeyword: copy
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "copied"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "original"
|
||||
value:
|
||||
array_literal
|
||||
element:
|
||||
int_literal "1"
|
||||
int_literal "2"
|
||||
int_literal "3"
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "copied"
|
||||
value: unsupported_node "copy original"
|
||||
@@ -0,0 +1,2 @@
|
||||
let original = [1, 2, 3]
|
||||
let copied = copy original
|
||||
@@ -0,0 +1,56 @@
|
||||
let numbers = Array<Int>()
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
functionCallExpr
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
arguments:
|
||||
additionalTrailingClosures:
|
||||
calledExpression:
|
||||
genericSpecializationExpr
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "Array"
|
||||
genericArgumentClause:
|
||||
genericArgumentClause
|
||||
arguments:
|
||||
genericArgument
|
||||
argument:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
leftAngle: <
|
||||
rightAngle: >
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "numbers"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "numbers"
|
||||
value:
|
||||
call_expr
|
||||
callee: unsupported_node "Array<Int>"
|
||||
@@ -0,0 +1 @@
|
||||
let numbers = Array<Int>()
|
||||
@@ -0,0 +1,48 @@
|
||||
let keyPath = \String.count
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
keyPathExpr
|
||||
backslash: \
|
||||
components:
|
||||
keyPathComponent
|
||||
period: .
|
||||
component:
|
||||
keyPathPropertyComponent
|
||||
declName:
|
||||
declReferenceExpr
|
||||
baseName: identifier "count"
|
||||
root:
|
||||
identifierType
|
||||
name: identifier "String"
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "keyPath"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "keyPath"
|
||||
value: unsupported_node "\\String.count"
|
||||
@@ -0,0 +1 @@
|
||||
let keyPath = \String.count
|
||||
@@ -0,0 +1,51 @@
|
||||
func doWork() {}
|
||||
unsafe doWork()
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
functionDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
name: identifier "doWork"
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
funcKeyword: func
|
||||
codeBlockItem
|
||||
item:
|
||||
unsafeExpr
|
||||
expression:
|
||||
functionCallExpr
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
arguments:
|
||||
additionalTrailingClosures:
|
||||
calledExpression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "doWork"
|
||||
unsafeKeyword: unsafe
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
function_declaration
|
||||
name: identifier "doWork"
|
||||
body: block "func doWork() {}"
|
||||
unsupported_node "unsafe doWork()"
|
||||
@@ -0,0 +1,2 @@
|
||||
func doWork() {}
|
||||
unsafe doWork()
|
||||
@@ -0,0 +1,96 @@
|
||||
var a = 1
|
||||
var b = 2
|
||||
swap(&a, &b)
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: var
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "1"
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "a"
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: var
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "2"
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "b"
|
||||
codeBlockItem
|
||||
item:
|
||||
functionCallExpr
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
arguments:
|
||||
labeledExpr
|
||||
expression:
|
||||
inOutExpr
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "a"
|
||||
ampersand: &
|
||||
trailingComma: ,
|
||||
labeledExpr
|
||||
expression:
|
||||
inOutExpr
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "b"
|
||||
ampersand: &
|
||||
additionalTrailingClosures:
|
||||
calledExpression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "swap"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "var"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "a"
|
||||
value: int_literal "1"
|
||||
variable_declaration
|
||||
modifier: modifier "var"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "b"
|
||||
value: int_literal "2"
|
||||
call_expr
|
||||
callee:
|
||||
name_expr
|
||||
identifier: identifier "swap"
|
||||
argument:
|
||||
argument
|
||||
value: unsupported_node "&a"
|
||||
argument
|
||||
value: unsupported_node "&b"
|
||||
@@ -0,0 +1,3 @@
|
||||
var a = 1
|
||||
var b = 2
|
||||
swap(&a, &b)
|
||||
@@ -0,0 +1,81 @@
|
||||
func increment(_ x: inout Int) {
|
||||
x += 1
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
functionDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
infixOperatorExpr
|
||||
operator:
|
||||
binaryOperatorExpr
|
||||
operator: binaryOperator "+="
|
||||
leftOperand:
|
||||
declReferenceExpr
|
||||
baseName: identifier "x"
|
||||
rightOperand:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "1"
|
||||
name: identifier "increment"
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
type:
|
||||
attributedType
|
||||
attributes:
|
||||
baseType:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
lateSpecifiers:
|
||||
specifiers:
|
||||
simpleTypeSpecifier
|
||||
specifier: inout
|
||||
firstName: _
|
||||
secondName: identifier "x"
|
||||
funcKeyword: func
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
function_declaration
|
||||
name: identifier "increment"
|
||||
parameter:
|
||||
parameter
|
||||
external_name: identifier "_"
|
||||
type: unsupported_node "inout Int"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "x"
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
compound_assign_expr
|
||||
target:
|
||||
name_expr
|
||||
identifier: identifier "x"
|
||||
operator: infix_operator "+="
|
||||
value: int_literal "1"
|
||||
@@ -0,0 +1,3 @@
|
||||
func increment(_ x: inout Int) {
|
||||
x += 1
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
let currentLine = #line
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
macroExpansionExpr
|
||||
arguments:
|
||||
additionalTrailingClosures:
|
||||
macroName: identifier "line"
|
||||
pound: #
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "currentLine"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "currentLine"
|
||||
value: unsupported_node "#line"
|
||||
@@ -0,0 +1 @@
|
||||
let currentLine = #line
|
||||
@@ -0,0 +1,48 @@
|
||||
postfix operator ^^
|
||||
let squared = 3^^
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
operatorDecl
|
||||
name: binaryOperator "^^"
|
||||
fixitySpecifier: postfix
|
||||
operatorKeyword: operator
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
postfixOperatorExpr
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "3"
|
||||
operator: postfixOperator "^^"
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "squared"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
unsupported_node "postfix operator ^^"
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "squared"
|
||||
value: unsupported_node "3^^"
|
||||
@@ -0,0 +1,2 @@
|
||||
postfix operator ^^
|
||||
let squared = 3^^
|
||||
@@ -0,0 +1,40 @@
|
||||
let range = 3...
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
postfixOperatorExpr
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "3"
|
||||
operator: postfixOperator "..."
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "range"
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "range"
|
||||
value: unsupported_node "3..."
|
||||
@@ -0,0 +1 @@
|
||||
let range = 3...
|
||||
@@ -0,0 +1,100 @@
|
||||
func combine(_ a: Int, _ b: Int) {
|
||||
_ = a .& b
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
functionDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
sequenceExpr
|
||||
elements:
|
||||
discardAssignmentExpr
|
||||
wildcard: _
|
||||
assignmentExpr
|
||||
equal: =
|
||||
declReferenceExpr
|
||||
baseName: identifier "a"
|
||||
binaryOperatorExpr
|
||||
operator: binaryOperator ".&"
|
||||
declReferenceExpr
|
||||
baseName: identifier "b"
|
||||
name: identifier "combine"
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
trailingComma: ,
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
firstName: _
|
||||
secondName: identifier "a"
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
firstName: _
|
||||
secondName: identifier "b"
|
||||
funcKeyword: func
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
function_declaration
|
||||
name: identifier "combine"
|
||||
parameter:
|
||||
parameter
|
||||
external_name: identifier "_"
|
||||
type:
|
||||
named_type_expr
|
||||
name: identifier "Int"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "a"
|
||||
parameter
|
||||
external_name: identifier "_"
|
||||
type:
|
||||
named_type_expr
|
||||
name: identifier "Int"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "b"
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
unresolved_operator_sequence
|
||||
element:
|
||||
name_expr
|
||||
identifier: identifier "_"
|
||||
unsupported_node "="
|
||||
name_expr
|
||||
identifier: identifier "a"
|
||||
infix_operator ".&"
|
||||
name_expr
|
||||
identifier: identifier "b"
|
||||
@@ -0,0 +1,3 @@
|
||||
func combine(_ a: Int, _ b: Int) {
|
||||
_ = a .& b
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
actor Counter {
|
||||
var value = 0
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
actorDecl
|
||||
attributes:
|
||||
name: identifier "Counter"
|
||||
actorKeyword: actor
|
||||
memberBlock:
|
||||
memberBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
members:
|
||||
memberBlockItem
|
||||
decl:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: var
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "0"
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "value"
|
||||
modifiers:
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt: unsupported_node "actor Counter {\n var value = 0\n}"
|
||||
@@ -0,0 +1,3 @@
|
||||
actor Counter {
|
||||
var value = 0
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// Conditional compilation is not yet supported: swift-syntax reports a
|
||||
// structured `ifConfigDecl` (whose branches hold ordinary member items), but
|
||||
// the mapping has no rule for it, so the whole block becomes one
|
||||
// `unsupported_node` and its members are not extracted.
|
||||
class C {
|
||||
#if DEBUG
|
||||
init(x: Int) {}
|
||||
deinit {}
|
||||
#endif
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
classDecl
|
||||
attributes:
|
||||
name: identifier "C"
|
||||
memberBlock:
|
||||
memberBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
members:
|
||||
memberBlockItem
|
||||
decl:
|
||||
ifConfigDecl
|
||||
clauses:
|
||||
ifConfigClause
|
||||
elements:
|
||||
memberBlockItem
|
||||
decl:
|
||||
initializerDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
modifiers:
|
||||
signature:
|
||||
functionSignature
|
||||
parameterClause:
|
||||
functionParameterClause
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
functionParameter
|
||||
colon: :
|
||||
attributes:
|
||||
modifiers:
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
firstName: identifier "x"
|
||||
initKeyword: init
|
||||
memberBlockItem
|
||||
decl:
|
||||
deinitializerDecl
|
||||
attributes:
|
||||
body:
|
||||
codeBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
modifiers:
|
||||
deinitKeyword: deinit
|
||||
condition:
|
||||
declReferenceExpr
|
||||
baseName: identifier "DEBUG"
|
||||
poundKeyword: #if
|
||||
poundEndif: #endif
|
||||
modifiers:
|
||||
classKeyword: class
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
class_like_declaration
|
||||
modifier: modifier "class"
|
||||
name: identifier "C"
|
||||
member: unsupported_node "#if DEBUG\n init(x: Int) {}\n deinit {}\n#endif"
|
||||
@@ -0,0 +1,10 @@
|
||||
// Conditional compilation is not yet supported: swift-syntax reports a
|
||||
// structured `ifConfigDecl` (whose branches hold ordinary member items), but
|
||||
// the mapping has no rule for it, so the whole block becomes one
|
||||
// `unsupported_node` and its members are not extracted.
|
||||
class C {
|
||||
#if DEBUG
|
||||
init(x: Int) {}
|
||||
deinit {}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
let callback: @convention(c) () -> Void = {}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
closureExpr
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "callback"
|
||||
typeAnnotation:
|
||||
typeAnnotation
|
||||
colon: :
|
||||
type:
|
||||
attributedType
|
||||
attributes:
|
||||
attribute
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
arguments:
|
||||
labeledExpr
|
||||
expression:
|
||||
declReferenceExpr
|
||||
baseName: identifier "c"
|
||||
atSign: @
|
||||
attributeName:
|
||||
identifierType
|
||||
name: identifier "convention"
|
||||
baseType:
|
||||
functionType
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
returnClause:
|
||||
returnClause
|
||||
arrow: ->
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Void"
|
||||
lateSpecifiers:
|
||||
specifiers:
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "callback"
|
||||
type: unsupported_node "@convention(c) () -> Void"
|
||||
value:
|
||||
function_expr
|
||||
body: block "{}"
|
||||
@@ -0,0 +1 @@
|
||||
let callback: @convention(c) () -> Void = {}
|
||||
@@ -0,0 +1,66 @@
|
||||
let handler: @Sendable () -> Void = {}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
closureExpr
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
statements:
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "handler"
|
||||
typeAnnotation:
|
||||
typeAnnotation
|
||||
colon: :
|
||||
type:
|
||||
attributedType
|
||||
attributes:
|
||||
attribute
|
||||
atSign: @
|
||||
attributeName:
|
||||
identifierType
|
||||
name: identifier "Sendable"
|
||||
baseType:
|
||||
functionType
|
||||
leftParen: (
|
||||
rightParen: )
|
||||
parameters:
|
||||
returnClause:
|
||||
returnClause
|
||||
arrow: ->
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Void"
|
||||
lateSpecifiers:
|
||||
specifiers:
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "handler"
|
||||
type: unsupported_node "@Sendable () -> Void"
|
||||
value:
|
||||
function_expr
|
||||
body: block "{}"
|
||||
@@ -0,0 +1 @@
|
||||
let handler: @Sendable () -> Void = {}
|
||||
@@ -0,0 +1,77 @@
|
||||
let triple: [3 of Int] = [1, 2, 3]
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
initializer:
|
||||
initializerClause
|
||||
equal: =
|
||||
value:
|
||||
arrayExpr
|
||||
elements:
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "1"
|
||||
trailingComma: ,
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "2"
|
||||
trailingComma: ,
|
||||
arrayElement
|
||||
expression:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "3"
|
||||
leftSquare: [
|
||||
rightSquare: ]
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "triple"
|
||||
typeAnnotation:
|
||||
typeAnnotation
|
||||
colon: :
|
||||
type:
|
||||
inlineArrayType
|
||||
leftSquare: [
|
||||
rightSquare: ]
|
||||
element:
|
||||
genericArgument
|
||||
argument:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
count:
|
||||
genericArgument
|
||||
argument:
|
||||
integerLiteralExpr
|
||||
literal: integerLiteral "3"
|
||||
separator: of
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "triple"
|
||||
type: unsupported_node "[3 of Int]"
|
||||
value:
|
||||
array_literal
|
||||
element:
|
||||
int_literal "1"
|
||||
int_literal "2"
|
||||
int_literal "3"
|
||||
@@ -0,0 +1 @@
|
||||
let triple: [3 of Int] = [1, 2, 3]
|
||||
@@ -0,0 +1,71 @@
|
||||
struct FileHandle: ~Copyable {
|
||||
let descriptor: Int
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
sourceFile
|
||||
endOfFileToken: endOfFile
|
||||
statements:
|
||||
codeBlockItem
|
||||
item:
|
||||
structDecl
|
||||
attributes:
|
||||
name: identifier "FileHandle"
|
||||
inheritanceClause:
|
||||
inheritanceClause
|
||||
colon: :
|
||||
inheritedTypes:
|
||||
inheritedType
|
||||
type:
|
||||
suppressedType
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Copyable"
|
||||
withoutTilde: prefixOperator "~"
|
||||
memberBlock:
|
||||
memberBlock
|
||||
leftBrace: {
|
||||
rightBrace: }
|
||||
members:
|
||||
memberBlockItem
|
||||
decl:
|
||||
variableDecl
|
||||
attributes:
|
||||
modifiers:
|
||||
bindingSpecifier: let
|
||||
bindings:
|
||||
patternBinding
|
||||
pattern:
|
||||
identifierPattern
|
||||
identifier: identifier "descriptor"
|
||||
typeAnnotation:
|
||||
typeAnnotation
|
||||
colon: :
|
||||
type:
|
||||
identifierType
|
||||
name: identifier "Int"
|
||||
modifiers:
|
||||
structKeyword: struct
|
||||
|
||||
---
|
||||
|
||||
top_level
|
||||
body:
|
||||
block
|
||||
stmt:
|
||||
class_like_declaration
|
||||
modifier: modifier "struct"
|
||||
name: identifier "FileHandle"
|
||||
base_type:
|
||||
base_type
|
||||
type: unsupported_node "~Copyable"
|
||||
member:
|
||||
variable_declaration
|
||||
modifier: modifier "let"
|
||||
pattern:
|
||||
name_pattern
|
||||
identifier: identifier "descriptor"
|
||||
type:
|
||||
named_type_expr
|
||||
name: identifier "Int"
|
||||
@@ -0,0 +1,3 @@
|
||||
struct FileHandle: ~Copyable {
|
||||
let descriptor: Int
|
||||
}
|
||||
Reference in New Issue
Block a user