Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions unified/extractor/src/languages/swift/swift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
// an empty `block`.
rule!(
(functionDecl
attributes: _* @attrs
modifiers: _* @mods
name: @@name
genericParameterClause: (genericParameterClause parameters: _* @type_params)?
Expand All @@ -647,6 +648,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
body: (codeBlock) @body)
=>
(function_declaration
modifier: {attrs}
modifier: {mods}
name_node: (identifier #{name})
type_parameter: {type_params}
Expand All @@ -656,6 +658,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
),
rule!(
(functionDecl
attributes: _* @attrs
modifiers: _* @mods
name: @@name
genericParameterClause: (genericParameterClause parameters: _* @type_params)?
Expand All @@ -664,6 +667,7 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
returnClause: (returnClause type: @ret)?))
=>
(function_declaration
modifier: {attrs}
modifier: {mods}
name_node: (identifier #{name})
type_parameter: {type_params}
Expand Down Expand Up @@ -1456,12 +1460,14 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
rule!(
(initializerDecl
initKeyword: @@initK
attributes: _* @attrs
modifiers: _* @mods
signature: (functionSignature
parameterClause: (functionParameterClause parameters: _* @params))
body: (codeBlock) @body)
=>
(constructor_declaration
modifier: {attrs}
modifier: {mods}
name_node: (identifier #{initK})
parameter: {params}
Expand All @@ -1470,11 +1476,13 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
rule!(
(initializerDecl
initKeyword: @@initK
attributes: _* @attrs
modifiers: _* @mods
signature: (functionSignature
parameterClause: (functionParameterClause parameters: _* @params)))
=>
(constructor_declaration
modifier: {attrs}
modifier: {mods}
name_node: (identifier #{initK})
parameter: {params}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
class C {
@discardableResult public func f() -> Int { return 0 }
@available(*, unavailable) public init(x: Int) {}
}

---

sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
classDecl
attributes:
name: identifier "C"
memberBlock:
memberBlock
leftBrace: {
rightBrace: }
members:
memberBlockItem
decl:
functionDecl
attributes:
attribute
atSign: @
attributeName:
identifierType
name: identifier "discardableResult"
body:
codeBlock
leftBrace: {
rightBrace: }
statements:
codeBlockItem
item:
returnStmt
expression:
integerLiteralExpr
literal: integerLiteral "0"
returnKeyword: return
name: identifier "f"
modifiers:
declModifier
name: public
signature:
functionSignature
parameterClause:
functionParameterClause
leftParen: (
rightParen: )
parameters:
returnClause:
returnClause
arrow: ->
type:
identifierType
name: identifier "Int"
funcKeyword: func
memberBlockItem
decl:
initializerDecl
attributes:
attribute
leftParen: (
rightParen: )
arguments:
availabilityArgument
trailingComma: ,
argument: binaryOperator "*"
availabilityArgument
argument: unavailable
atSign: @
attributeName:
identifierType
name: identifier "available"
body:
codeBlock
leftBrace: {
rightBrace: }
statements:
modifiers:
declModifier
name: public
signature:
functionSignature
parameterClause:
functionParameterClause
leftParen: (
rightParen: )
parameters:
functionParameter
colon: :
attributes:
modifiers:
type:
identifierType
name: identifier "Int"
firstName: identifier "x"
initKeyword: init
modifiers:
classKeyword: class

---

top_level source="⟨body⟩"
body:
block source="⟨stmt⟩"
stmt:
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n ⟨member⟩\n ⟨member⟩\n}"
modifier: modifier "class" source="class"
name_node: identifier "C" source="C"
member:
function_declaration source="⟨modifier⟩ ⟨modifier⟩ func ⟨name_node⟩() -> ⟨return_type⟩ ⟨body⟩"
modifier:
modifier "@discardableResult" source="@discardableResult"
modifier "public" source="public"
name_node: identifier "f" source="f"
return_type: identifier "Int" source="Int"
body:
block source="{ ⟨stmt⟩ }"
stmt:
return_expr source="return ⟨value⟩"
value: int_literal "0" source="0"
constructor_declaration source="⟨modifier⟩ ⟨modifier⟩ ⟨name_node⟩(⟨parameter⟩) ⟨body⟩"
modifier:
modifier "@available(*, unavailable)" source="@available(*, unavailable)"
modifier "public" source="public"
name_node: identifier "init" source="init"
parameter:
parameter source="⟨external_name_node⟩⟨pattern⟩: ⟨type⟩"
external_name_node: identifier "x" source="x"
type: identifier "Int" source="Int"
pattern: identifier "x" source="x"
body: block "{}" source="{}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class C {
@discardableResult public func f() -> Int { return 0 }
@available(*, unavailable) public init(x: Int) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
class C {
public static var shared: C { get }
@objc public var name: String { get set }
private var count: Int { return 0 }
}

---

sourceFile
endOfFileToken: endOfFile
statements:
codeBlockItem
item:
classDecl
attributes:
name: identifier "C"
memberBlock:
memberBlock
leftBrace: {
rightBrace: }
members:
memberBlockItem
decl:
variableDecl
attributes:
modifiers:
declModifier
name: public
declModifier
name: static
bindingSpecifier: var
bindings:
patternBinding
pattern:
identifierPattern
identifier: identifier "shared"
typeAnnotation:
typeAnnotation
colon: :
type:
identifierType
name: identifier "C"
accessorBlock:
accessorBlock
accessors:
accessorDecl
accessorSpecifier: get
attributes:
leftBrace: {
rightBrace: }
memberBlockItem
decl:
variableDecl
attributes:
attribute
atSign: @
attributeName:
identifierType
name: identifier "objc"
modifiers:
declModifier
name: public
bindingSpecifier: var
bindings:
patternBinding
pattern:
identifierPattern
identifier: identifier "name"
typeAnnotation:
typeAnnotation
colon: :
type:
identifierType
name: identifier "String"
accessorBlock:
accessorBlock
accessors:
accessorDecl
accessorSpecifier: get
attributes:
accessorDecl
accessorSpecifier: set
attributes:
leftBrace: {
rightBrace: }
memberBlockItem
decl:
variableDecl
attributes:
modifiers:
declModifier
name: private
bindingSpecifier: var
bindings:
patternBinding
pattern:
identifierPattern
identifier: identifier "count"
typeAnnotation:
typeAnnotation
colon: :
type:
identifierType
name: identifier "Int"
accessorBlock:
accessorBlock
accessors:
codeBlockItem
item:
returnStmt
expression:
integerLiteralExpr
literal: integerLiteral "0"
returnKeyword: return
leftBrace: {
rightBrace: }
modifiers:
classKeyword: class

---

top_level source="⟨body⟩"
body:
block source="⟨stmt⟩"
stmt:
class_like_declaration source="⟨modifier⟩ ⟨name_node⟩ {\n public static var shared: C { ⟨member⟩ }\n @objc public var name: String { ⟨member⟩ ⟨member⟩ }\n ⟨member⟩\n}"
modifier: modifier "class" source="class"
name_node: identifier "C" source="C"
member:
accessor_declaration source="⟨accessor_kind⟩"
modifier:
modifier "var" source="var" (external)
modifier "public" source="public" (external)
modifier "static" source="static" (external)
name_node: identifier "shared" source="shared" (external)
accessor_kind: accessor_kind "get" source="get"
return_type: identifier "C" source="C" (external)
accessor_declaration source="⟨accessor_kind⟩"
modifier:
modifier "var" source="var" (external)
modifier "@objc" source="@objc" (external)
modifier "public" source="public" (external)
name_node: identifier "name" source="name" (external)
accessor_kind: accessor_kind "get" source="get"
return_type: identifier "String" source="String" (external)
accessor_declaration source="⟨accessor_kind⟩⟨parameter⟩"
modifier:
modifier "var" source="var" (external)
modifier "@objc" source="@objc" (external)
modifier "public" source="public" (external)
modifier "chained_declaration" source=""
name_node: identifier "name" source="name" (external)
accessor_kind: accessor_kind "set" source="set"
parameter:
parameter source="⟨pattern⟩"
modifier: modifier "generated" source=""
type: identifier "String" source="String" (external)
pattern: identifier "newValue" source="set"
accessor_declaration source="⟨modifier⟩ ⟨modifier⟩ ⟨name_node⟩: ⟨return_type⟩ ⟨body⟩"
modifier:
modifier "var" source="var"
modifier "private" source="private"
name_node: identifier "count" source="count"
accessor_kind: accessor_kind "get" source=""
return_type: identifier "Int" source="Int"
body:
block source="{ ⟨stmt⟩ }"
stmt:
return_expr source="return ⟨value⟩"
value: int_literal "0" source="0"
constructor_declaration source=""
modifier: modifier "generated" source=""
name_node: identifier "init" source=""
body: block source=""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class C {
public static var shared: C { get }
@objc public var name: String { get set }
private var count: Int { return 0 }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: majorAnalysis
---
* Library models now use the dynamic models-as-data format (`sourceModel`, `sinkModel`, `summaryModel`, and `typeModel` rows identified by a `(type, path)` pair), which does not require type information. This replaces the models previously imported from the Swift analysis. Type models describing how to obtain instances of library types can be generated from `.swiftinterface` files using `unified/scripts/generate-type-models.sh`.
Loading
Loading