Skip to content

Commit 4c0384b

Browse files
committed
Swift: control flow and dataflow library renamings
1 parent 82eb002 commit 4c0384b

File tree

10 files changed

+74
-74
lines changed

10 files changed

+74
-74
lines changed

swift/ql/lib/codeql/swift/controlflow/CfgNodes.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class PropertyGetterCfgNode extends CfgNode {
136136

137137
CfgNode getBase() { result.getAst() = n.getBase() }
138138

139-
AccessorDecl getAccessorDecl() { result = n.getAccessorDecl() }
139+
Accessor getAccessor() { result = n.getAccessor() }
140140
}
141141

142142
/** A control-flow node that wraps a property setter. */
@@ -149,7 +149,7 @@ class PropertySetterCfgNode extends CfgNode {
149149

150150
CfgNode getSource() { result.getAst() = n.getAssignExpr().getSource() }
151151

152-
AccessorDecl getAccessorDecl() { result = n.getAccessorDecl() }
152+
Accessor getAccessor() { result = n.getAccessor() }
153153
}
154154

155155
class PropertyObserverCfgNode extends CfgNode {
@@ -161,7 +161,7 @@ class PropertyObserverCfgNode extends CfgNode {
161161

162162
CfgNode getSource() { result.getAst() = n.getAssignExpr().getSource() }
163163

164-
AccessorDecl getAccessorDecl() { result = n.getObserver() }
164+
Accessor getAccessor() { result = n.getObserver() }
165165
}
166166

167167
class ApplyExprCfgNode extends ExprCfgNode {
@@ -171,7 +171,7 @@ class ApplyExprCfgNode extends ExprCfgNode {
171171

172172
CfgNode getQualifier() { result.getAst() = e.getQualifier() }
173173

174-
AbstractFunctionDecl getStaticTarget() { result = e.getStaticTarget() }
174+
Callable getStaticTarget() { result = e.getStaticTarget() }
175175

176176
Expr getFunction() { result = e.getFunction() }
177177
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private predicate mayHaveThrowCompletion(ControlFlowElement n) {
309309
isThrowingType(n.asAstNode().(ApplyExpr).getFunction().getType())
310310
or
311311
// Getters are the only accessor declarators that may throw.
312-
exists(AccessorDecl accessor | isThrowingType(accessor.getInterfaceType()) |
312+
exists(Accessor accessor | isThrowingType(accessor.getInterfaceType()) |
313313
isPropertyGetterElement(n, accessor, _)
314314
)
315315
}

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ private import swift
33
cached
44
newtype TControlFlowElement =
55
TAstElement(AstNode n) or
6-
TFuncDeclElement(AbstractFunctionDecl func) { func.hasBody() } or
7-
TClosureElement(ClosureExpr clos) or
6+
TFuncDeclElement(Function func) { func.hasBody() } or
7+
TClosureElement(ExplicitClosureExpr clos) or
88
TPropertyGetterElement(Decl accessor, Expr ref) { isPropertyGetterElement(accessor, ref) } or
9-
TPropertySetterElement(AccessorDecl accessor, AssignExpr assign) {
9+
TPropertySetterElement(Accessor accessor, AssignExpr assign) {
1010
isPropertySetterElement(accessor, assign)
1111
} or
12-
TPropertyObserverElement(AccessorDecl observer, AssignExpr assign) {
12+
TPropertyObserverElement(Accessor observer, AssignExpr assign) {
1313
isPropertyObserverElement(observer, assign)
1414
} or
1515
TKeyPathElement(KeyPathExpr expr)
@@ -24,19 +24,19 @@ predicate ignoreAstElement(AstNode n) {
2424
isPropertySetterElement(_, n)
2525
}
2626

27-
private AccessorDecl getAnAccessorDecl(Decl d) {
28-
result = d.(VarDecl).getAnAccessorDecl() or
29-
result = d.(SubscriptDecl).getAnAccessorDecl()
27+
private Accessor getAnAccessor(Decl d) {
28+
result = d.(VarDecl).getAnAccessor() or
29+
result = d.(SubscriptDecl).getAnAccessor()
3030
}
3131

32-
predicate isPropertyGetterElement(AccessorDecl accessor, Expr ref) {
32+
predicate isPropertyGetterElement(Accessor accessor, Expr ref) {
3333
hasDirectToImplementationOrOrdinarySemantics(ref) and
3434
isRValue(ref) and
3535
accessor.isGetter() and
36-
accessor = getAnAccessorDecl([ref.(LookupExpr).getMember(), ref.(DeclRefExpr).getDecl()])
36+
accessor = getAnAccessor([ref.(LookupExpr).getMember(), ref.(DeclRefExpr).getDecl()])
3737
}
3838

39-
predicate isPropertyGetterElement(PropertyGetterElement pge, AccessorDecl accessor, Expr ref) {
39+
predicate isPropertyGetterElement(PropertyGetterElement pge, Accessor accessor, Expr ref) {
4040
pge = TPropertyGetterElement(accessor, ref)
4141
}
4242

@@ -60,32 +60,32 @@ private predicate hasDirectToImplementationOrOrdinarySemantics(Expr e) {
6060
hasDirectToImplementationSemantics(e) or hasOrdinarySemantics(e)
6161
}
6262

63-
private predicate isPropertySetterElement(AccessorDecl accessor, AssignExpr assign) {
63+
private predicate isPropertySetterElement(Accessor accessor, AssignExpr assign) {
6464
exists(Expr lhs | lhs = assign.getDest() |
6565
hasDirectToImplementationOrOrdinarySemantics(lhs) and
6666
accessor.isSetter() and
6767
isLValue(lhs) and
68-
accessor = getAnAccessorDecl([lhs.(LookupExpr).getMember(), lhs.(DeclRefExpr).getDecl()])
68+
accessor = getAnAccessor([lhs.(LookupExpr).getMember(), lhs.(DeclRefExpr).getDecl()])
6969
)
7070
}
7171

7272
predicate isPropertySetterElement(
73-
PropertySetterElement pse, AccessorDecl accessor, AssignExpr assign
73+
PropertySetterElement pse, Accessor accessor, AssignExpr assign
7474
) {
7575
pse = TPropertySetterElement(accessor, assign)
7676
}
7777

78-
private predicate isPropertyObserverElement(AccessorDecl observer, AssignExpr assign) {
78+
private predicate isPropertyObserverElement(Accessor observer, AssignExpr assign) {
7979
exists(Expr lhs | lhs = assign.getDest() |
8080
hasDirectToImplementationOrOrdinarySemantics(lhs) and
8181
observer.isPropertyObserver() and
8282
isLValue(lhs) and
83-
observer = getAnAccessorDecl([lhs.(LookupExpr).getMember(), lhs.(DeclRefExpr).getDecl()])
83+
observer = getAnAccessor([lhs.(LookupExpr).getMember(), lhs.(DeclRefExpr).getDecl()])
8484
)
8585
}
8686

8787
predicate isPropertyObserverElement(
88-
PropertyObserverElement poe, AccessorDecl accessor, AssignExpr assign
88+
PropertyObserverElement poe, Accessor accessor, AssignExpr assign
8989
) {
9090
poe = TPropertyObserverElement(accessor, assign)
9191
}
@@ -111,7 +111,7 @@ class AstElement extends ControlFlowElement, TAstElement {
111111
}
112112

113113
class PropertyGetterElement extends ControlFlowElement, TPropertyGetterElement {
114-
AccessorDecl accessor;
114+
Accessor accessor;
115115
Expr ref;
116116

117117
PropertyGetterElement() { this = TPropertyGetterElement(accessor, ref) }
@@ -122,13 +122,13 @@ class PropertyGetterElement extends ControlFlowElement, TPropertyGetterElement {
122122

123123
Expr getRef() { result = ref }
124124

125-
AccessorDecl getAccessorDecl() { result = accessor }
125+
Accessor getAccessor() { result = accessor }
126126

127127
Expr getBase() { result = ref.(LookupExpr).getBase() }
128128
}
129129

130130
class PropertySetterElement extends ControlFlowElement, TPropertySetterElement {
131-
AccessorDecl accessor;
131+
Accessor accessor;
132132
AssignExpr assign;
133133

134134
PropertySetterElement() { this = TPropertySetterElement(accessor, assign) }
@@ -137,15 +137,15 @@ class PropertySetterElement extends ControlFlowElement, TPropertySetterElement {
137137

138138
override Location getLocation() { result = assign.getLocation() }
139139

140-
AccessorDecl getAccessorDecl() { result = accessor }
140+
Accessor getAccessor() { result = accessor }
141141

142142
AssignExpr getAssignExpr() { result = assign }
143143

144144
Expr getBase() { result = assign.getDest().(LookupExpr).getBase() }
145145
}
146146

147147
class PropertyObserverElement extends ControlFlowElement, TPropertyObserverElement {
148-
AccessorDecl observer;
148+
Accessor observer;
149149
AssignExpr assign;
150150

151151
PropertyObserverElement() { this = TPropertyObserverElement(observer, assign) }
@@ -160,7 +160,7 @@ class PropertyObserverElement extends ControlFlowElement, TPropertyObserverEleme
160160

161161
override Location getLocation() { result = assign.getLocation() }
162162

163-
AccessorDecl getObserver() { result = observer }
163+
Accessor getObserver() { result = observer }
164164

165165
predicate isWillSet() { observer.isWillSet() }
166166

@@ -172,15 +172,15 @@ class PropertyObserverElement extends ControlFlowElement, TPropertyObserverEleme
172172
}
173173

174174
class FuncDeclElement extends ControlFlowElement, TFuncDeclElement {
175-
AbstractFunctionDecl func;
175+
Function func;
176176

177177
FuncDeclElement() { this = TFuncDeclElement(func) }
178178

179179
override string toString() { result = func.toString() }
180180

181181
override Location getLocation() { result = func.getLocation() }
182182

183-
AbstractFunctionDecl getAst() { result = func }
183+
Function getAst() { result = func }
184184
}
185185

186186
class KeyPathElement extends ControlFlowElement, TKeyPathElement {
@@ -196,13 +196,13 @@ class KeyPathElement extends ControlFlowElement, TKeyPathElement {
196196
}
197197

198198
class ClosureElement extends ControlFlowElement, TClosureElement {
199-
ClosureExpr expr;
199+
ExplicitClosureExpr expr;
200200

201201
ClosureElement() { this = TClosureElement(expr) }
202202

203203
override Location getLocation() { result = expr.getLocation() }
204204

205-
ClosureExpr getAst() { result = expr }
205+
ExplicitClosureExpr getAst() { result = expr }
206206

207207
override string toString() { result = expr.toString() }
208208
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module CfgScope {
4747
abstract predicate exit(ControlFlowElement last, Completion c);
4848
}
4949

50-
private class BodyStmtCallableScope extends Range_ instanceof AbstractFunctionDecl {
50+
private class BodyStmtCallableScope extends Range_ instanceof Function {
5151
Decls::FuncDeclTree tree;
5252

5353
BodyStmtCallableScope() { tree.getAst() = this }
@@ -67,7 +67,7 @@ module CfgScope {
6767
final override predicate exit(ControlFlowElement last, Completion c) { last(tree, last, c) }
6868
}
6969

70-
private class ClosureExprScope extends Range_ instanceof ClosureExpr {
70+
private class ClosureExprScope extends Range_ instanceof ExplicitClosureExpr {
7171
Exprs::ClosureExprTree tree;
7272

7373
ClosureExprScope() { tree.getAst() = this }
@@ -1002,17 +1002,17 @@ module Decls {
10021002
* }
10031003
* ```
10041004
*/
1005-
private class AbstractFunctionDeclTree extends AstLeafTree {
1006-
override AbstractFunctionDecl ast;
1005+
private class FunctionTree extends AstLeafTree {
1006+
override Function ast;
10071007
}
10081008

10091009
/** The control-flow of a function declaration body. */
10101010
class FuncDeclTree extends StandardPreOrderTree, TFuncDeclElement {
1011-
AbstractFunctionDecl ast;
1011+
Function ast;
10121012

10131013
FuncDeclTree() { this = TFuncDeclElement(ast) }
10141014

1015-
AbstractFunctionDecl getAst() { result = ast }
1015+
Function getAst() { result = ast }
10161016

10171017
final override ControlFlowElement getChildElement(int i) {
10181018
i = -1 and
@@ -1107,12 +1107,12 @@ module Exprs {
11071107
* direct-to-implementation-access semantics.
11081108
*/
11091109
class PropertyAssignExpr extends AssignExprTree {
1110-
AccessorDecl accessorDecl;
1110+
Accessor accessor;
11111111

1112-
PropertyAssignExpr() { isPropertySetterElement(_, accessorDecl, ast) }
1112+
PropertyAssignExpr() { isPropertySetterElement(_, accessor, ast) }
11131113

11141114
final override predicate isLast(ControlFlowElement last, Completion c) {
1115-
isPropertySetterElement(last, accessorDecl, ast) and
1115+
isPropertySetterElement(last, accessor, ast) and
11161116
completionIsValidFor(c, last)
11171117
}
11181118

@@ -1138,11 +1138,11 @@ module Exprs {
11381138
}
11391139

11401140
class ClosureExprTree extends StandardPreOrderTree, TClosureElement {
1141-
ClosureExpr expr;
1141+
ExplicitClosureExpr expr;
11421142

11431143
ClosureExprTree() { this = TClosureElement(expr) }
11441144

1145-
ClosureExpr getAst() { result = expr }
1145+
ExplicitClosureExpr getAst() { result = expr }
11461146

11471147
final override ControlFlowElement getChildElement(int i) {
11481148
result.asAstNode() = expr.getParam(i)
@@ -1175,8 +1175,8 @@ module Exprs {
11751175
class Closure = @auto_closure_expr or @closure_expr;
11761176

11771177
// TODO: Traverse the expressions in the capture list once we extract it.
1178-
private class ClosureTree extends AstLeafTree {
1179-
override ClosureExpr ast;
1178+
private class ExplicitClosureTree extends AstLeafTree {
1179+
override ExplicitClosureExpr ast;
11801180
}
11811181

11821182
/**
@@ -1308,8 +1308,8 @@ module Exprs {
13081308
}
13091309
}
13101310

1311-
private class RebindSelfInConstructorTree extends AstStandardPostOrderTree {
1312-
override RebindSelfInConstructorExpr ast;
1311+
private class RebindSelfInInitializerTree extends AstStandardPostOrderTree {
1312+
override RebindSelfInInitializerExpr ast;
13131313

13141314
final override ControlFlowElement getChildElement(int i) {
13151315
result.asAstNode() = ast.getSubExpr().getFullyConverted() and i = 0
@@ -1342,8 +1342,8 @@ module Exprs {
13421342
}
13431343
}
13441344

1345-
private class LazyInitializerTree extends AstStandardPostOrderTree {
1346-
override LazyInitializerExpr ast;
1345+
private class LazyInitializationTree extends AstStandardPostOrderTree {
1346+
override LazyInitializationExpr ast;
13471347

13481348
final override ControlFlowElement getChildElement(int i) {
13491349
result.asAstNode() = ast.getSubExpr().getFullyConverted() and i = 0
@@ -1426,8 +1426,8 @@ module Exprs {
14261426
DeclRefExprLValueTree() { isLValue(ast) }
14271427
}
14281428

1429-
class OtherConstructorDeclRefTree extends AstLeafTree {
1430-
override OtherConstructorDeclRefExpr ast;
1429+
class OtherInitializerRefTree extends AstLeafTree {
1430+
override OtherInitializerRefExpr ast;
14311431
}
14321432

14331433
abstract class DeclRefExprRValueTree extends AstControlFlowTree {
@@ -1443,7 +1443,7 @@ module Exprs {
14431443
}
14441444

14451445
private class PropertyDeclRefRValueTree extends DeclRefExprRValueTree {
1446-
AccessorDecl accessor;
1446+
Accessor accessor;
14471447

14481448
PropertyDeclRefRValueTree() { isPropertyGetterElement(_, accessor, ast) }
14491449

@@ -1550,7 +1550,7 @@ module Exprs {
15501550
* or ordinary semantics that includes a getter.
15511551
*/
15521552
private class PropertyMemberRefRValue extends MemberRefRValueTree {
1553-
AccessorDecl accessor;
1553+
Accessor accessor;
15541554

15551555
PropertyMemberRefRValue() { isPropertyGetterElement(_, accessor, ast) }
15561556

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ private import codeql.swift.generated.ParentChild
33
private import codeql.swift.generated.Synth
44

55
module CallableBase {
6-
class TypeRange = Synth::TAbstractFunctionDecl or Synth::TKeyPathExpr or Synth::TClosureExpr;
6+
class TypeRange = Synth::TFunction or Synth::TKeyPathExpr or Synth::TClosureExpr;
77

88
class Range extends Scope::Range, TypeRange { }
99
}

swift/ql/lib/codeql/swift/dataflow/ExternalFlow.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private predicate elementSpec(
378378
summaryModel(namespace, type, subtypes, name, signature, ext, _, _, _, _)
379379
}
380380

381-
private string paramsStringPart(AbstractFunctionDecl c, int i) {
381+
private string paramsStringPart(Function c, int i) {
382382
i = -1 and result = "(" and exists(c)
383383
or
384384
exists(int n, string p | c.getParam(n).getType().toString() = p |
@@ -397,12 +397,12 @@ private string paramsStringPart(AbstractFunctionDecl c, int i) {
397397
* Parameter types are represented by their type erasure.
398398
*/
399399
cached
400-
string paramsString(AbstractFunctionDecl c) {
400+
string paramsString(Function c) {
401401
result = concat(int i | | paramsStringPart(c, i) order by i)
402402
}
403403

404404
bindingset[func]
405-
predicate matchesSignature(AbstractFunctionDecl func, string signature) {
405+
predicate matchesSignature(Function func, string signature) {
406406
signature = "" or
407407
paramsString(func) = signature
408408
}
@@ -425,17 +425,17 @@ private Element interpretElement0(
425425
namespace = "" and // TODO: Fill out when we properly extract modules.
426426
(
427427
// Non-member functions
428-
exists(AbstractFunctionDecl func |
428+
exists(Function func |
429429
func.getName() = name and
430430
type = "" and
431431
matchesSignature(func, signature) and
432432
subtypes = false and
433-
not result instanceof MethodDecl and
433+
not result instanceof Method and
434434
result = func
435435
)
436436
or
437437
// Member functions
438-
exists(NominalTypeDecl namedTypeDecl, Decl declWithMethod, MethodDecl method |
438+
exists(NominalTypeDecl namedTypeDecl, Decl declWithMethod, Method method |
439439
method.getName() = name and
440440
method = declWithMethod.getAMember() and
441441
namedTypeDecl.getFullName() = type and

0 commit comments

Comments
 (0)