Skip to content

Commit f14f937

Browse files
authored
Merge pull request #10210 from github/redsun82/swift-fix-double-parent
Swift: fix double parent
2 parents 27bc698 + 7b50c95 commit f14f937

File tree

7 files changed

+23
-26
lines changed

7 files changed

+23
-26
lines changed

swift/codegen/schema.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ AstNode:
8080

8181
Callable:
8282
_children:
83-
params: ParamDecl*
8483
self_param: ParamDecl?
84+
params: ParamDecl*
8585
body: BraceStmt?
8686

8787
ConditionElement:
@@ -545,7 +545,7 @@ RebindSelfInConstructorExpr:
545545
_extends: Expr
546546
_children:
547547
sub_expr: Expr
548-
self: VarDecl
548+
self: VarDecl
549549

550550
SequenceExpr:
551551
_extends: Expr

swift/ql/lib/codeql/swift/generated/Callable.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ import codeql.swift.elements.Element
66
import codeql.swift.elements.decl.ParamDecl
77

88
class CallableBase extends Synth::TCallable, Element {
9-
ParamDecl getImmediateParam(int index) {
9+
ParamDecl getImmediateSelfParam() {
1010
result =
1111
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
1212
.(Raw::Callable)
13-
.getParam(index))
13+
.getSelfParam())
1414
}
1515

16-
final ParamDecl getParam(int index) { result = getImmediateParam(index).resolve() }
17-
18-
final ParamDecl getAParam() { result = getParam(_) }
16+
final ParamDecl getSelfParam() { result = getImmediateSelfParam().resolve() }
1917

20-
final int getNumberOfParams() { result = count(getAParam()) }
18+
final predicate hasSelfParam() { exists(getSelfParam()) }
2119

22-
ParamDecl getImmediateSelfParam() {
20+
ParamDecl getImmediateParam(int index) {
2321
result =
2422
Synth::convertParamDeclFromRaw(Synth::convertCallableToRaw(this)
2523
.(Raw::Callable)
26-
.getSelfParam())
24+
.getParam(index))
2725
}
2826

29-
final ParamDecl getSelfParam() { result = getImmediateSelfParam().resolve() }
27+
final ParamDecl getParam(int index) { result = getImmediateParam(index).resolve() }
3028

31-
final predicate hasSelfParam() { exists(getSelfParam()) }
29+
final ParamDecl getAParam() { result = getParam(_) }
30+
31+
final int getNumberOfParams() { result = count(getAParam()) }
3232

3333
BraceStmt getImmediateBody() {
3434
result =

swift/ql/lib/codeql/swift/generated/GetImmediateParent.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Element getAnImmediateChild(Element e) {
1313
// * none() simplifies generation, as we can append `or ...` without a special case for the first item
1414
none()
1515
or
16-
result = e.(Callable).getImmediateParam(_)
17-
or
1816
result = e.(Callable).getImmediateSelfParam()
1917
or
18+
result = e.(Callable).getImmediateParam(_)
19+
or
2020
result = e.(Callable).getImmediateBody()
2121
or
2222
result = e.(AbstractStorageDecl).getImmediateAccessorDecl(_)
@@ -123,8 +123,6 @@ Element getAnImmediateChild(Element e) {
123123
or
124124
result = e.(RebindSelfInConstructorExpr).getImmediateSubExpr()
125125
or
126-
result = e.(RebindSelfInConstructorExpr).getImmediateSelf()
127-
or
128126
result = e.(SelfApplyExpr).getImmediateBase()
129127
or
130128
result = e.(SequenceExpr).getImmediateElement(_)

swift/ql/lib/codeql/swift/generated/Raw.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Raw {
66
}
77

88
class Callable extends @callable, Element {
9-
ParamDecl getParam(int index) { callable_params(this, index, result) }
10-
119
ParamDecl getSelfParam() { callable_self_params(this, result) }
1210

11+
ParamDecl getParam(int index) { callable_params(this, index, result) }
12+
1313
BraceStmt getBody() { callable_bodies(this, result) }
1414
}
1515

swift/ql/lib/swift.dbscheme

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,19 @@ nominal_type_decls( //dir=decl
166166
| @abstract_function_decl
167167
;
168168

169+
#keyset[id]
170+
callable_self_params(
171+
int id: @callable ref,
172+
int self_param: @param_decl ref
173+
);
174+
169175
#keyset[id, index]
170176
callable_params(
171177
int id: @callable ref,
172178
int index: int ref,
173179
int param: @param_decl ref
174180
);
175181

176-
#keyset[id]
177-
callable_self_params(
178-
int id: @callable ref,
179-
int self_param: @param_decl ref
180-
);
181-
182182
#keyset[id]
183183
callable_bodies(
184184
int id: @callable ref,
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
| ConstructorDecl | RebindSelfInConstructorExpr | ParamDecl |
2-
| RebindSelfInConstructorExpr | ConstructorDecl | ParamDecl |

swift/ql/test/library-tests/parent/parent.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@
623623
| expressions.swift:77:21:77:21 | init | ConstructorDecl | expressions.swift:77:21:77:21 | self | ParamDecl |
624624
| expressions.swift:77:21:77:21 | init | ConstructorDecl | file://:0:0:0:0 | x | ParamDecl |
625625
| expressions.swift:77:21:77:21 | init | ConstructorDecl | file://:0:0:0:0 | { ... } | BraceStmt |
626+
| expressions.swift:78:3:80:3 | init | ConstructorDecl | expressions.swift:78:3:78:3 | self | ParamDecl |
626627
| expressions.swift:78:3:80:3 | init | ConstructorDecl | expressions.swift:78:10:80:3 | { ... } | BraceStmt |
627628
| expressions.swift:78:10:80:3 | { ... } | BraceStmt | expressions.swift:79:5:79:21 | self = ... | RebindSelfInConstructorExpr |
628629
| expressions.swift:78:10:80:3 | { ... } | BraceStmt | expressions.swift:80:3:80:3 | return | ReturnStmt |

0 commit comments

Comments
 (0)