Skip to content

Commit 85233b3

Browse files
committed
Swift: add new children to VarDecl
1 parent 313f600 commit 85233b3

16 files changed

+650
-2
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,39 @@ private module Impl {
680680
}
681681

682682
private Element getImmediateChildOfVarDecl(VarDecl e, int index, string partialPredicateCall) {
683-
exists(int b, int bAbstractStorageDecl, int n |
683+
exists(
684+
int b, int bAbstractStorageDecl, int n, int nPropertyWrapperBackingVarBinding,
685+
int nPropertyWrapperBackingVar, int nPropertyWrapperProjectionVarBinding,
686+
int nPropertyWrapperProjectionVar
687+
|
684688
b = 0 and
685689
bAbstractStorageDecl =
686690
b + 1 + max(int i | i = -1 or exists(getImmediateChildOfAbstractStorageDecl(e, i, _)) | i) and
687691
n = bAbstractStorageDecl and
692+
nPropertyWrapperBackingVarBinding = n + 1 and
693+
nPropertyWrapperBackingVar = nPropertyWrapperBackingVarBinding + 1 and
694+
nPropertyWrapperProjectionVarBinding = nPropertyWrapperBackingVar + 1 and
695+
nPropertyWrapperProjectionVar = nPropertyWrapperProjectionVarBinding + 1 and
688696
(
689697
none()
690698
or
691699
result = getImmediateChildOfAbstractStorageDecl(e, index - b, partialPredicateCall)
700+
or
701+
index = n and
702+
result = e.getImmediatePropertyWrapperBackingVarBinding() and
703+
partialPredicateCall = "PropertyWrapperBackingVarBinding()"
704+
or
705+
index = nPropertyWrapperBackingVarBinding and
706+
result = e.getImmediatePropertyWrapperBackingVar() and
707+
partialPredicateCall = "PropertyWrapperBackingVar()"
708+
or
709+
index = nPropertyWrapperBackingVar and
710+
result = e.getImmediatePropertyWrapperProjectionVarBinding() and
711+
partialPredicateCall = "PropertyWrapperProjectionVarBinding()"
712+
or
713+
index = nPropertyWrapperProjectionVarBinding and
714+
result = e.getImmediatePropertyWrapperProjectionVar() and
715+
partialPredicateCall = "PropertyWrapperProjectionVar()"
692716
)
693717
)
694718
}
@@ -809,14 +833,27 @@ private module Impl {
809833
}
810834

811835
private Element getImmediateChildOfParamDecl(ParamDecl e, int index, string partialPredicateCall) {
812-
exists(int b, int bVarDecl, int n |
836+
exists(
837+
int b, int bVarDecl, int n, int nPropertyWrapperLocalWrappedVarBinding,
838+
int nPropertyWrapperLocalWrappedVar
839+
|
813840
b = 0 and
814841
bVarDecl = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfVarDecl(e, i, _)) | i) and
815842
n = bVarDecl and
843+
nPropertyWrapperLocalWrappedVarBinding = n + 1 and
844+
nPropertyWrapperLocalWrappedVar = nPropertyWrapperLocalWrappedVarBinding + 1 and
816845
(
817846
none()
818847
or
819848
result = getImmediateChildOfVarDecl(e, index - b, partialPredicateCall)
849+
or
850+
index = n and
851+
result = e.getImmediatePropertyWrapperLocalWrappedVarBinding() and
852+
partialPredicateCall = "PropertyWrapperLocalWrappedVarBinding()"
853+
or
854+
index = nPropertyWrapperLocalWrappedVarBinding and
855+
result = e.getImmediatePropertyWrapperLocalWrappedVar() and
856+
partialPredicateCall = "PropertyWrapperLocalWrappedVar()"
820857
)
821858
)
822859
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ module Raw {
235235
Pattern getParentPattern() { var_decl_parent_patterns(this, result) }
236236

237237
Expr getParentInitializer() { var_decl_parent_initializers(this, result) }
238+
239+
PatternBindingDecl getPropertyWrapperBackingVarBinding() {
240+
var_decl_property_wrapper_backing_var_bindings(this, result)
241+
}
242+
243+
VarDecl getPropertyWrapperBackingVar() { var_decl_property_wrapper_backing_vars(this, result) }
244+
245+
PatternBindingDecl getPropertyWrapperProjectionVarBinding() {
246+
var_decl_property_wrapper_projection_var_bindings(this, result)
247+
}
248+
249+
VarDecl getPropertyWrapperProjectionVar() {
250+
var_decl_property_wrapper_projection_vars(this, result)
251+
}
238252
}
239253

240254
class AccessorDecl extends @accessor_decl, FuncDecl {
@@ -285,6 +299,14 @@ module Raw {
285299
override string toString() { result = "ParamDecl" }
286300

287301
predicate isInout() { param_decl_is_inout(this) }
302+
303+
PatternBindingDecl getPropertyWrapperLocalWrappedVarBinding() {
304+
param_decl_property_wrapper_local_wrapped_var_bindings(this, result)
305+
}
306+
307+
VarDecl getPropertyWrapperLocalWrappedVar() {
308+
param_decl_property_wrapper_local_wrapped_vars(this, result)
309+
}
288310
}
289311

290312
class TypeAliasDecl extends @type_alias_decl, GenericTypeDecl {

swift/ql/lib/codeql/swift/generated/decl/ParamDecl.qll

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// generated by codegen/codegen.py
22
private import codeql.swift.generated.Synth
33
private import codeql.swift.generated.Raw
4+
import codeql.swift.elements.decl.PatternBindingDecl
45
import codeql.swift.elements.decl.VarDecl
56

67
module Generated {
@@ -11,5 +12,65 @@ module Generated {
1112
* Holds if this is an `inout` parameter.
1213
*/
1314
predicate isInout() { Synth::convertParamDeclToRaw(this).(Raw::ParamDecl).isInout() }
15+
16+
/**
17+
* Gets the property wrapper local wrapped var binding of this parameter declaration, if it exists.
18+
*
19+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
20+
* behavior of both the `Immediate` and non-`Immediate` versions.
21+
*/
22+
PatternBindingDecl getImmediatePropertyWrapperLocalWrappedVarBinding() {
23+
result =
24+
Synth::convertPatternBindingDeclFromRaw(Synth::convertParamDeclToRaw(this)
25+
.(Raw::ParamDecl)
26+
.getPropertyWrapperLocalWrappedVarBinding())
27+
}
28+
29+
/**
30+
* Gets the property wrapper local wrapped var binding of this parameter declaration, if it exists.
31+
*
32+
* This is the synthesized binding introducing the property wrapper local wrapped projection
33+
* variable for this variable, if any.
34+
*/
35+
final PatternBindingDecl getPropertyWrapperLocalWrappedVarBinding() {
36+
result = getImmediatePropertyWrapperLocalWrappedVarBinding().resolve()
37+
}
38+
39+
/**
40+
* Holds if `getPropertyWrapperLocalWrappedVarBinding()` exists.
41+
*/
42+
final predicate hasPropertyWrapperLocalWrappedVarBinding() {
43+
exists(getPropertyWrapperLocalWrappedVarBinding())
44+
}
45+
46+
/**
47+
* Gets the property wrapper local wrapped var of this parameter declaration, if it exists.
48+
*
49+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
50+
* behavior of both the `Immediate` and non-`Immediate` versions.
51+
*/
52+
VarDecl getImmediatePropertyWrapperLocalWrappedVar() {
53+
result =
54+
Synth::convertVarDeclFromRaw(Synth::convertParamDeclToRaw(this)
55+
.(Raw::ParamDecl)
56+
.getPropertyWrapperLocalWrappedVar())
57+
}
58+
59+
/**
60+
* Gets the property wrapper local wrapped var of this parameter declaration, if it exists.
61+
*
62+
* This is the synthesized local wrapped value, shadowing this parameter declaration in case it
63+
* has a property wrapper.
64+
*/
65+
final VarDecl getPropertyWrapperLocalWrappedVar() {
66+
result = getImmediatePropertyWrapperLocalWrappedVar().resolve()
67+
}
68+
69+
/**
70+
* Holds if `getPropertyWrapperLocalWrappedVar()` exists.
71+
*/
72+
final predicate hasPropertyWrapperLocalWrappedVar() {
73+
exists(getPropertyWrapperLocalWrappedVar())
74+
}
1475
}
1576
}

swift/ql/lib/codeql/swift/generated/decl/VarDecl.qll

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ private import codeql.swift.generated.Raw
44
import codeql.swift.elements.decl.AbstractStorageDecl
55
import codeql.swift.elements.expr.Expr
66
import codeql.swift.elements.pattern.Pattern
7+
import codeql.swift.elements.decl.PatternBindingDecl
78
import codeql.swift.elements.type.Type
89

910
module Generated {
@@ -98,5 +99,121 @@ module Generated {
9899
* Holds if `getParentInitializer()` exists.
99100
*/
100101
final predicate hasParentInitializer() { exists(getParentInitializer()) }
102+
103+
/**
104+
* Gets the property wrapper backing var binding of this var declaration, if it exists.
105+
*
106+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
107+
* behavior of both the `Immediate` and non-`Immediate` versions.
108+
*/
109+
PatternBindingDecl getImmediatePropertyWrapperBackingVarBinding() {
110+
result =
111+
Synth::convertPatternBindingDeclFromRaw(Synth::convertVarDeclToRaw(this)
112+
.(Raw::VarDecl)
113+
.getPropertyWrapperBackingVarBinding())
114+
}
115+
116+
/**
117+
* Gets the property wrapper backing var binding of this var declaration, if it exists.
118+
*
119+
* This is the synthesized binding introducing the property wrapper backing variable for this
120+
* variable, if any.
121+
*/
122+
final PatternBindingDecl getPropertyWrapperBackingVarBinding() {
123+
result = getImmediatePropertyWrapperBackingVarBinding().resolve()
124+
}
125+
126+
/**
127+
* Holds if `getPropertyWrapperBackingVarBinding()` exists.
128+
*/
129+
final predicate hasPropertyWrapperBackingVarBinding() {
130+
exists(getPropertyWrapperBackingVarBinding())
131+
}
132+
133+
/**
134+
* Gets the property wrapper backing var of this var declaration, if it exists.
135+
*
136+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
137+
* behavior of both the `Immediate` and non-`Immediate` versions.
138+
*/
139+
VarDecl getImmediatePropertyWrapperBackingVar() {
140+
result =
141+
Synth::convertVarDeclFromRaw(Synth::convertVarDeclToRaw(this)
142+
.(Raw::VarDecl)
143+
.getPropertyWrapperBackingVar())
144+
}
145+
146+
/**
147+
* Gets the property wrapper backing var of this var declaration, if it exists.
148+
*
149+
* This is the synthesized variable holding the property wrapper for this variable, if any.
150+
*/
151+
final VarDecl getPropertyWrapperBackingVar() {
152+
result = getImmediatePropertyWrapperBackingVar().resolve()
153+
}
154+
155+
/**
156+
* Holds if `getPropertyWrapperBackingVar()` exists.
157+
*/
158+
final predicate hasPropertyWrapperBackingVar() { exists(getPropertyWrapperBackingVar()) }
159+
160+
/**
161+
* Gets the property wrapper projection var binding of this var declaration, if it exists.
162+
*
163+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
164+
* behavior of both the `Immediate` and non-`Immediate` versions.
165+
*/
166+
PatternBindingDecl getImmediatePropertyWrapperProjectionVarBinding() {
167+
result =
168+
Synth::convertPatternBindingDeclFromRaw(Synth::convertVarDeclToRaw(this)
169+
.(Raw::VarDecl)
170+
.getPropertyWrapperProjectionVarBinding())
171+
}
172+
173+
/**
174+
* Gets the property wrapper projection var binding of this var declaration, if it exists.
175+
*
176+
* This is the synthesized binding introducing the property wrapper projection variable for this
177+
* variable, if any.
178+
*/
179+
final PatternBindingDecl getPropertyWrapperProjectionVarBinding() {
180+
result = getImmediatePropertyWrapperProjectionVarBinding().resolve()
181+
}
182+
183+
/**
184+
* Holds if `getPropertyWrapperProjectionVarBinding()` exists.
185+
*/
186+
final predicate hasPropertyWrapperProjectionVarBinding() {
187+
exists(getPropertyWrapperProjectionVarBinding())
188+
}
189+
190+
/**
191+
* Gets the property wrapper projection var of this var declaration, if it exists.
192+
*
193+
* This includes nodes from the "hidden" AST. It can be overridden in subclasses to change the
194+
* behavior of both the `Immediate` and non-`Immediate` versions.
195+
*/
196+
VarDecl getImmediatePropertyWrapperProjectionVar() {
197+
result =
198+
Synth::convertVarDeclFromRaw(Synth::convertVarDeclToRaw(this)
199+
.(Raw::VarDecl)
200+
.getPropertyWrapperProjectionVar())
201+
}
202+
203+
/**
204+
* Gets the property wrapper projection var of this var declaration, if it exists.
205+
*
206+
* If this variable has a property wrapper with a projected value, this is the corresponding
207+
* synthesized variable holding that projected value, accessible with this variable's name
208+
* prefixed with `$`.
209+
*/
210+
final VarDecl getPropertyWrapperProjectionVar() {
211+
result = getImmediatePropertyWrapperProjectionVar().resolve()
212+
}
213+
214+
/**
215+
* Holds if `getPropertyWrapperProjectionVar()` exists.
216+
*/
217+
final predicate hasPropertyWrapperProjectionVar() { exists(getPropertyWrapperProjectionVar()) }
101218
}
102219
}

swift/ql/lib/swift.dbscheme

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,30 @@ var_decl_parent_initializers( //dir=decl
483483
int parent_initializer: @expr_or_none ref
484484
);
485485

486+
#keyset[id]
487+
var_decl_property_wrapper_backing_var_bindings( //dir=decl
488+
int id: @var_decl ref,
489+
int property_wrapper_backing_var_binding: @pattern_binding_decl_or_none ref
490+
);
491+
492+
#keyset[id]
493+
var_decl_property_wrapper_backing_vars( //dir=decl
494+
int id: @var_decl ref,
495+
int property_wrapper_backing_var: @var_decl_or_none ref
496+
);
497+
498+
#keyset[id]
499+
var_decl_property_wrapper_projection_var_bindings( //dir=decl
500+
int id: @var_decl ref,
501+
int property_wrapper_projection_var_binding: @pattern_binding_decl_or_none ref
502+
);
503+
504+
#keyset[id]
505+
var_decl_property_wrapper_projection_vars( //dir=decl
506+
int id: @var_decl ref,
507+
int property_wrapper_projection_var: @var_decl_or_none ref
508+
);
509+
486510
accessor_decls( //dir=decl
487511
unique int id: @accessor_decl
488512
);
@@ -558,6 +582,18 @@ param_decl_is_inout( //dir=decl
558582
int id: @param_decl ref
559583
);
560584

585+
#keyset[id]
586+
param_decl_property_wrapper_local_wrapped_var_bindings( //dir=decl
587+
int id: @param_decl ref,
588+
int property_wrapper_local_wrapped_var_binding: @pattern_binding_decl_or_none ref
589+
);
590+
591+
#keyset[id]
592+
param_decl_property_wrapper_local_wrapped_vars( //dir=decl
593+
int id: @param_decl ref,
594+
int property_wrapper_local_wrapped_var: @var_decl_or_none ref
595+
);
596+
561597
type_alias_decls( //dir=decl
562598
unique int id: @type_alias_decl
563599
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from ConcreteVarDecl x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getPropertyWrapperBackingVar()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from ConcreteVarDecl x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getPropertyWrapperBackingVarBinding()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from ConcreteVarDecl x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getPropertyWrapperProjectionVar()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from ConcreteVarDecl x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getPropertyWrapperProjectionVarBinding()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from ParamDecl x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getPropertyWrapperBackingVar()

0 commit comments

Comments
 (0)