Skip to content

Commit d89d9e2

Browse files
committed
Unified: Extract init keywords
1 parent e258ded commit d89d9e2

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,15 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
12741274
// nest under `signature` (as for `functionDecl`).
12751275
rule!(
12761276
(initializerDecl
1277+
initKeyword: @initK
12771278
modifiers: _* @mods
12781279
signature: (functionSignature
12791280
parameterClause: (functionParameterClause parameters: _* @params))
12801281
body: (codeBlock statements: _* @body_stmts)?)
12811282
=>
12821283
(constructor_declaration
12831284
modifier: {mods}
1285+
name_node: (identifier #{initK})
12841286
parameter: {params}
12851287
body: (block stmt: {body_stmts}))
12861288
),

‎unified/extractor/tests/corpus/swift/types/class-with-initializer.output‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ top_level source="⟨body⟩"
9898
modifier: modifier "var" source="var"
9999
pattern: identifier "x" source="x"
100100
type: identifier "Int" source="Int"
101-
constructor_declaration source="⟨body⟩⟨parameter⟩"
101+
constructor_declaration source="⟨name_node⟩⟨body⟩⟨parameter⟩"
102+
name_node: identifier "init" source="init"
102103
parameter:
103104
parameter source="⟨pattern⟩: ⟨type⟩"
104105
type: identifier "Int" source="Int"

‎unified/extractor/tests/corpus/swift/types/constructor-with-parameters.output‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ top_level source="⟨body⟩"
6767
modifier: modifier "struct" source="struct"
6868
name_node: identifier "Size" source="Size"
6969
member:
70-
constructor_declaration source="⟨body⟩⟨parameter⟩⟨parameter⟩"
70+
constructor_declaration source="⟨name_node⟩⟨body⟩⟨parameter⟩⟨parameter⟩"
71+
name_node: identifier "init" source="init"
7172
parameter:
7273
parameter source="⟨external_name_node⟩ ⟨pattern⟩: ⟨type⟩,"
7374
external_name_node: identifier "width" source="width"

‎unified/ql/test/library-tests/controlflow/cfg.expected‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ noCfg
153153
| cfg.swift:358:6:358:28 | loop_with_identity_expr |
154154
| cfg.swift:371:8:371:18 | getOptional |
155155
| cfg.swift:380:45:380:47 | Int |
156+
| cfg.swift:391:3:391:6 | init |
157+
| cfg.swift:408:3:408:6 | init |
156158
| cfg.swift:421:6:421:22 | localDeclarations |
159+
| cfg.swift:424:5:424:8 | init |
160+
| cfg.swift:431:5:431:8 | init |
157161
| cfg.swift:468:6:468:17 | testIfConfig |
158162
| cfg.swift:497:6:497:18 | testAvailable |
159163
| cfg.swift:524:6:524:17 | testAsyncFor |

‎unified/ql/test/library-tests/controlflow/cfg.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func testTupleElement(t : (a: Int, Int, c: Int)) -> Int {
388388
}
389389

390390
class Derived : C { // $ nonSimple='ClassLikeDeclaration -V Derived -^ BaseType -V C'
391-
init() {
391+
init() { // $ noCfg
392392
super.init(n: 0)
393393
}
394394
}
@@ -405,7 +405,7 @@ func doWithoutCatch(x : Int) throws -> Int {
405405

406406
class Structors {
407407
var field: Int
408-
init() {
408+
init() { // $ noCfg
409409
field = 10
410410
}
411411

@@ -421,14 +421,14 @@ func dictionaryLiteral(x: Int, y: Int) -> [String: Int] {
421421
func localDeclarations() -> Int { // $ noCfg
422422
class MyLocalClass {
423423
var x: Int
424-
init() {
424+
init() { // $ noCfg
425425
x = 10
426426
}
427427
}
428428

429429
struct MyLocalStruct {
430430
var x: Int
431-
init() {
431+
init() { // $ noCfg
432432
x = 10
433433
}
434434
}

0 commit comments

Comments
 (0)