Skip to content

Commit b19194b

Browse files
committed
Swift: make only Expr, Pattern and Type hideable
1 parent a087fef commit b19194b

File tree

100 files changed

+453
-1470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+453
-1470
lines changed

swift/ql/.generated.list

Lines changed: 87 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/.gitattributes

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/lib/codeql/swift/controlflow/internal/Completion.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private predicate isBooleanConstant(ControlFlowElement n, boolean value) {
9898
// Boolean constants hidden inside conversions are also
9999
// constants that resolve to the same value.
100100
exists(ControlFlowElement parent |
101-
parent.asAstNode() = n.asAstNode().getResolveStep() and
101+
parent.asAstNode() = n.asAstNode().(HideableElement).getResolveStep() and
102102
isBooleanConstant(parent, value)
103103
)
104104
}
@@ -122,9 +122,9 @@ private predicate inBooleanContext(ControlFlowElement n) {
122122
private predicate astInBooleanContext(AstNode n) {
123123
n = any(ConditionElement condElem).getBoolean().getFullyUnresolved()
124124
or
125-
n = any(ConditionElement condElem).getAvailability().getFullyUnresolved()
125+
n = any(ConditionElement condElem).getAvailability()
126126
or
127-
n = any(StmtCondition stmtCond).getFullyUnresolved()
127+
n = any(StmtCondition stmtCond)
128128
or
129129
exists(RepeatWhileStmt repeat | n = repeat.getCondition().getFullyConverted())
130130
or

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ module Stmts {
264264
or
265265
child.asAstNode() = ast.getAnElement().getBoolean().getFullyConverted()
266266
or
267-
child.asAstNode() = ast.getAnElement().getAvailability().getFullyUnresolved()
267+
child.asAstNode() = ast.getAnElement().getAvailability()
268268
}
269269

270270
predicate firstElement(int i, ControlFlowElement first) {
@@ -278,7 +278,7 @@ module Stmts {
278278
astFirst(ast.getElement(i).getBoolean().getFullyConverted(), first)
279279
or
280280
// ... or an availability check.
281-
astFirst(ast.getElement(i).getAvailability().getFullyUnresolved(), first)
281+
astFirst(ast.getElement(i).getAvailability(), first)
282282
)
283283
}
284284

@@ -296,7 +296,7 @@ module Stmts {
296296
astLast(ast.getElement(i).getBoolean().getFullyConverted(), pred, c)
297297
or
298298
// ... or the availability check ...
299-
astLast(ast.getElement(i).getAvailability().getFullyUnresolved(), pred, c)
299+
astLast(ast.getElement(i).getAvailability(), pred, c)
300300
) and
301301
// We evaluate the next element
302302
c instanceof NormalCompletion and
@@ -313,7 +313,7 @@ module Stmts {
313313
not c.(MatchingCompletion).isMatch()
314314
or
315315
// Stop if an availability check failed
316-
astLast(ast.getAnElement().getAvailability().getFullyUnresolved(), last, c) and
316+
astLast(ast.getAnElement().getAvailability(), last, c) and
317317
c instanceof FalseCompletion
318318
or
319319
// Stop if we successfully evaluated all the conditionals
@@ -322,7 +322,7 @@ module Stmts {
322322
or
323323
astLast(ast.getLastElement().getPattern().getFullyUnresolved(), last, c)
324324
or
325-
astLast(ast.getLastElement().getAvailability().getFullyUnresolved(), last, c)
325+
astLast(ast.getLastElement().getAvailability(), last, c)
326326
) and
327327
c instanceof NormalCompletion
328328
}
@@ -342,14 +342,14 @@ module Stmts {
342342
override IfStmt ast;
343343

344344
final override predicate propagatesAbnormal(ControlFlowElement child) {
345-
child.asAstNode() = ast.getCondition().getFullyUnresolved() or
345+
child.asAstNode() = ast.getCondition() or
346346
child.asAstNode() = ast.getThen() or
347347
child.asAstNode() = ast.getElse()
348348
}
349349

350350
final override predicate last(ControlFlowElement last, Completion c) {
351351
// Condition exits with a false completion and there is no `else` branch
352-
astLast(ast.getCondition().getFullyUnresolved(), last, c) and
352+
astLast(ast.getCondition(), last, c) and
353353
c instanceof FalseOrNonMatchCompletion and
354354
not exists(ast.getElse())
355355
or
@@ -360,10 +360,10 @@ module Stmts {
360360
final override predicate succ(ControlFlowElement pred, ControlFlowElement succ, Completion c) {
361361
// Pre-order: flow from statement itself to first element of condition
362362
pred.asAstNode() = ast and
363-
astFirst(ast.getCondition().getFullyUnresolved(), succ) and
363+
astFirst(ast.getCondition(), succ) and
364364
c instanceof SimpleCompletion
365365
or
366-
astLast(ast.getCondition().getFullyUnresolved(), pred, c) and
366+
astLast(ast.getCondition(), pred, c) and
367367
(
368368
// Flow from last element of condition to first element of then branch
369369
c instanceof TrueOrMatchCompletion and
@@ -380,7 +380,7 @@ module Stmts {
380380
override GuardStmt ast;
381381

382382
final override predicate propagatesAbnormal(ControlFlowElement child) {
383-
child.asAstNode() = ast.getCondition().getFullyUnresolved() or
383+
child.asAstNode() = ast.getCondition() or
384384
child.asAstNode() = ast.getBody()
385385
}
386386

@@ -390,18 +390,18 @@ module Stmts {
390390
c instanceof NormalCompletion
391391
or
392392
// Exit when a condition is true
393-
astLast(ast.getCondition().getFullyUnresolved(), last, c) and
393+
astLast(ast.getCondition(), last, c) and
394394
c instanceof TrueOrMatchCompletion
395395
}
396396

397397
final override predicate succ(ControlFlowElement pred, ControlFlowElement succ, Completion c) {
398398
// Pre-order: flow from statement itself to first element of condition
399399
pred.asAstNode() = ast and
400-
astFirst(ast.getCondition().getFullyUnresolved(), succ) and
400+
astFirst(ast.getCondition(), succ) and
401401
c instanceof SimpleCompletion
402402
or
403403
// Flow to the body when the condition is false
404-
astLast(ast.getCondition().getFullyUnresolved(), pred, c) and
404+
astLast(ast.getCondition(), pred, c) and
405405
c instanceof FalseOrNonMatchCompletion and
406406
astFirst(ast.getBody(), succ)
407407
}
@@ -458,9 +458,7 @@ module Stmts {
458458
private class WhileTree extends LoopTree {
459459
override WhileStmt ast;
460460

461-
final override ControlFlowElement getCondition() {
462-
result.asAstNode() = ast.getCondition().getFullyUnresolved()
463-
}
461+
final override ControlFlowElement getCondition() { result.asAstNode() = ast.getCondition() }
464462

465463
final override ControlFlowElement getBody() { result.asAstNode() = ast.getBody() }
466464

@@ -674,7 +672,7 @@ module Stmts {
674672

675673
final override predicate last(ControlFlowElement last, Completion c) {
676674
// Case pattern exits with a non-match
677-
astLast(ast.getLastLabel().getFullyUnresolved(), last, c) and
675+
astLast(ast.getLastLabel(), last, c) and
678676
not c.(MatchingCompletion).isMatch()
679677
or
680678
// Case body exits with any completion
@@ -684,18 +682,18 @@ module Stmts {
684682
override predicate succ(ControlFlowElement pred, ControlFlowElement succ, Completion c) {
685683
// Pre-order: Flow from the case statement itself to the first label
686684
pred.asAstNode() = ast and
687-
astFirst(ast.getFirstLabel().getFullyUnresolved(), succ) and
685+
astFirst(ast.getFirstLabel(), succ) and
688686
c instanceof SimpleCompletion
689687
or
690688
// Left-to-right evaluation of labels until we find a match
691689
exists(int i |
692-
astLast(ast.getLabel(i).getFullyUnresolved(), pred, c) and
693-
astFirst(ast.getLabel(i + 1).getFullyUnresolved(), succ) and
690+
astLast(ast.getLabel(i), pred, c) and
691+
astFirst(ast.getLabel(i + 1), succ) and
694692
c.(MatchingCompletion).isNonMatch()
695693
)
696694
or
697695
// Flow from last element of pattern to first element of body
698-
astLast(ast.getALabel().getFullyUnresolved(), pred, c) and
696+
astLast(ast.getALabel(), pred, c) and
699697
astFirst(ast.getBody(), succ) and
700698
c.(MatchingCompletion).isMatch()
701699
}
@@ -1164,7 +1162,7 @@ module Exprs {
11641162
override CaptureListExpr ast;
11651163

11661164
final override ControlFlowElement getChildElement(int i) {
1167-
result.asAstNode() = ast.getBindingDecl(i).getFullyUnresolved()
1165+
result.asAstNode() = ast.getBindingDecl(i)
11681166
or
11691167
i = ast.getNumberOfBindingDecls() and
11701168
result.asAstNode() = ast.getClosureBody().getFullyConverted()
@@ -1796,9 +1794,7 @@ module AvailabilityInfo {
17961794
private class AvailabilityInfoTree extends AstStandardPostOrderTree {
17971795
override AvailabilityInfo ast;
17981796

1799-
final override ControlFlowElement getChildElement(int i) {
1800-
result.asAstNode() = ast.getSpec(i).getFullyUnresolved()
1801-
}
1797+
final override ControlFlowElement getChildElement(int i) { result.asAstNode() = ast.getSpec(i) }
18021798
}
18031799

18041800
private class AvailabilitySpecTree extends AstLeafTree {

swift/ql/lib/codeql/swift/elements.qll

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/lib/codeql/swift/elements/Element.qll

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
private import codeql.swift.generated.Element
22

33
class Element extends Generated::Element {
4-
private predicate resolvesFrom(Element e) { e.getResolveStep() = this }
5-
64
override string toString() { result = this.getPrimaryQlClasses() }
7-
8-
Element getFullyUnresolved() {
9-
not this.resolvesFrom(_) and result = this
10-
or
11-
exists(Element e |
12-
this.resolvesFrom(e) and
13-
result = e.getFullyUnresolved()
14-
)
15-
}
165
}
176

187
class UnknownElement extends Element {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
private import codeql.swift.generated.HideableElement
2+
3+
class HideableElement extends Generated::HideableElement {
4+
private predicate resolvesFrom(HideableElement e) { e.getResolveStep() = this }
5+
6+
HideableElement getFullyUnresolved() {
7+
not this.resolvesFrom(_) and result = this
8+
or
9+
exists(HideableElement e |
10+
this.resolvesFrom(e) and
11+
result = e.getFullyUnresolved()
12+
)
13+
}
14+
}

swift/ql/lib/codeql/swift/elements/Locatable.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ private import codeql.swift.elements.UnknownLocation
44

55
class Locatable extends Generated::Locatable {
66
pragma[nomagic]
7-
override Location getImmediateLocation() {
8-
result = Generated::Locatable.super.getImmediateLocation()
7+
override Location getLocation() {
8+
result = Generated::Locatable.super.getLocation()
99
or
10-
not exists(Generated::Locatable.super.getImmediateLocation()) and
10+
not exists(Generated::Locatable.super.getLocation()) and
1111
result instanceof UnknownLocation
1212
}
1313

swift/ql/lib/codeql/swift/elements/UnknownLocation.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private import codeql.swift.elements.File
66
* A `Location` that is given to something that is not associated with any position in the source code.
77
*/
88
class UnknownLocation extends Generated::UnknownLocation {
9-
override File getImmediateFile() { result instanceof UnknownFile }
9+
override File getFile() { result instanceof UnknownFile }
1010

1111
override int getStartLine() { result = 0 }
1212

swift/ql/lib/codeql/swift/elements/UnspecifiedElement.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ class UnspecifiedElement extends Generated::UnspecifiedElement {
1919
)
2020
}
2121

22-
override Location getImmediateLocation() { result = this.getParent().(Locatable).getLocation() }
22+
override Location getLocation() { result = this.getParent().(Locatable).getLocation() }
2323
}

0 commit comments

Comments
 (0)