Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf63139

Browse files
committed
Java: Autoformat semmle.code.java.controlflow.
1 parent 291fb11 commit bf63139

7 files changed

Lines changed: 254 additions & 178 deletions

File tree

java/ql/src/semmle/code/java/controlflow/BasicBlocks.qll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ import semmle.code.java.ControlFlowGraph
1414
*/
1515
class BasicBlock extends ControlFlowNode {
1616
BasicBlock() {
17-
not exists(this.getAPredecessor()) and exists(this.getASuccessor()) or
18-
strictcount(this.getAPredecessor()) > 1 or
19-
exists(ControlFlowNode pred | pred = this.getAPredecessor() | strictcount(pred.getASuccessor()) > 1)
17+
not exists(this.getAPredecessor()) and exists(this.getASuccessor())
18+
or
19+
strictcount(this.getAPredecessor()) > 1
20+
or
21+
exists(ControlFlowNode pred | pred = this.getAPredecessor() |
22+
strictcount(pred.getASuccessor()) > 1
23+
)
2024
}
2125

2226
/** Gets an immediate successor of this basic block. */
2327
cached
24-
BasicBlock getABBSuccessor() {
25-
result = getLastNode().getASuccessor()
26-
}
28+
BasicBlock getABBSuccessor() { result = getLastNode().getASuccessor() }
2729

2830
/** Gets an immediate predecessor of this basic block. */
29-
BasicBlock getABBPredecessor() {
30-
result.getABBSuccessor() = this
31-
}
31+
BasicBlock getABBPredecessor() { result.getABBSuccessor() = this }
3232

3333
/** Gets a control-flow node contained in this basic block. */
3434
ControlFlowNode getANode() { result = getNode(_) }
@@ -49,7 +49,7 @@ class BasicBlock extends ControlFlowNode {
4949
ControlFlowNode getFirstNode() { result = this }
5050

5151
/** Gets the last control-flow node in this basic block. */
52-
ControlFlowNode getLastNode() { result = getNode(length()-1) }
52+
ControlFlowNode getLastNode() { result = getNode(length() - 1) }
5353

5454
/** Gets the number of control-flow nodes contained in this basic block. */
5555
cached

java/ql/src/semmle/code/java/controlflow/Dominance.qll

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Provides classes and predicates for control-flow graph dominance.
33
*/
4+
45
import java
56
private import semmle.code.java.ControlFlowGraph
67

7-
88
/*
99
* Predicates for basic-block-level dominance.
1010
*/
@@ -20,47 +20,47 @@ private predicate flowEntry(Stmt entry) {
2020
}
2121

2222
/** The successor relation for basic blocks. */
23-
private predicate bbSucc(BasicBlock pre, BasicBlock post) {
24-
post = pre.getABBSuccessor()
25-
}
23+
private predicate bbSucc(BasicBlock pre, BasicBlock post) { post = pre.getABBSuccessor() }
2624

2725
/** The immediate dominance relation for basic blocks. */
28-
cached predicate bbIDominates(BasicBlock dom, BasicBlock node) = idominance(flowEntry/1, bbSucc/2)(_, dom, node)
26+
cached
27+
predicate bbIDominates(BasicBlock dom, BasicBlock node) =
28+
idominance(flowEntry/1, bbSucc/2)(_, dom, node)
2929

3030
/** Holds if the dominance relation is calculated for `bb`. */
3131
predicate hasDominanceInformation(BasicBlock bb) {
3232
exists(BasicBlock entry | flowEntry(entry) and bbSucc*(entry, bb))
3333
}
3434

3535
/** Exit points for control-flow. */
36-
private predicate flowExit(Callable exit) {
37-
exists(ControlFlowNode s | s.getASuccessor() = exit)
38-
}
36+
private predicate flowExit(Callable exit) { exists(ControlFlowNode s | s.getASuccessor() = exit) }
3937

4038
/** Exit points for basic-block control-flow. */
41-
private predicate bbSink(BasicBlock exit) {
42-
flowExit(exit.getLastNode())
43-
}
39+
private predicate bbSink(BasicBlock exit) { flowExit(exit.getLastNode()) }
4440

4541
/** Reversed `bbSucc`. */
46-
private predicate bbPred(BasicBlock post, BasicBlock pre) {
47-
post = pre.getABBSuccessor()
48-
}
42+
private predicate bbPred(BasicBlock post, BasicBlock pre) { post = pre.getABBSuccessor() }
4943

5044
/** The immediate post-dominance relation on basic blocks. */
51-
cached predicate bbIPostDominates(BasicBlock dominator, BasicBlock node) = idominance(bbSink/1,bbPred/2)(_, dominator, node)
45+
cached
46+
predicate bbIPostDominates(BasicBlock dominator, BasicBlock node) =
47+
idominance(bbSink/1, bbPred/2)(_, dominator, node)
5248

5349
/** Holds if `dom` strictly dominates `node`. */
5450
predicate bbStrictlyDominates(BasicBlock dom, BasicBlock node) { bbIDominates+(dom, node) }
5551

5652
/** Holds if `dom` dominates `node`. (This is reflexive.) */
57-
predicate bbDominates(BasicBlock dom, BasicBlock node) { bbStrictlyDominates(dom, node) or dom = node }
53+
predicate bbDominates(BasicBlock dom, BasicBlock node) {
54+
bbStrictlyDominates(dom, node) or dom = node
55+
}
5856

5957
/** Holds if `dom` strictly post-dominates `node`. */
6058
predicate bbStrictlyPostDominates(BasicBlock dom, BasicBlock node) { bbIPostDominates+(dom, node) }
6159

6260
/** Holds if `dom` post-dominates `node`. (This is reflexive.) */
63-
predicate bbPostDominates(BasicBlock dom, BasicBlock node) { bbStrictlyPostDominates(dom, node) or dom = node }
61+
predicate bbPostDominates(BasicBlock dom, BasicBlock node) {
62+
bbStrictlyPostDominates(dom, node) or dom = node
63+
}
6464

6565
/**
6666
* The dominance frontier relation for basic blocks.
@@ -86,7 +86,8 @@ predicate dominanceFrontier(BasicBlock x, BasicBlock w) {
8686

8787
/** Immediate dominance relation on control-flow graph nodes. */
8888
predicate iDominates(ControlFlowNode dominator, ControlFlowNode node) {
89-
exists(BasicBlock bb, int i | dominator = bb.getNode(i) and node = bb.getNode(i+1)) or
89+
exists(BasicBlock bb, int i | dominator = bb.getNode(i) and node = bb.getNode(i + 1))
90+
or
9091
exists(BasicBlock dom, BasicBlock bb |
9192
bbIDominates(dom, bb) and
9293
dominator = dom.getLastNode() and
@@ -100,9 +101,7 @@ predicate strictlyDominates(ControlFlowNode dom, ControlFlowNode node) {
100101
// This predicate is gigantic, so it must be inlined.
101102
bbStrictlyDominates(dom.getBasicBlock(), node.getBasicBlock())
102103
or
103-
exists(BasicBlock b, int i, int j |
104-
dom = b.getNode(i) and node = b.getNode(j) and i < j
105-
)
104+
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i < j)
106105
}
107106

108107
/** Holds if `dom` dominates `node`. (This is reflexive.) */
@@ -111,9 +110,7 @@ predicate dominates(ControlFlowNode dom, ControlFlowNode node) {
111110
// This predicate is gigantic, so it must be inlined.
112111
bbStrictlyDominates(dom.getBasicBlock(), node.getBasicBlock())
113112
or
114-
exists(BasicBlock b, int i, int j |
115-
dom = b.getNode(i) and node = b.getNode(j) and i <= j
116-
)
113+
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i <= j)
117114
}
118115

119116
/** Holds if `dom` strictly post-dominates `node`. */
@@ -122,9 +119,7 @@ predicate strictlyPostDominates(ControlFlowNode dom, ControlFlowNode node) {
122119
// This predicate is gigantic, so it must be inlined.
123120
bbStrictlyPostDominates(dom.getBasicBlock(), node.getBasicBlock())
124121
or
125-
exists(BasicBlock b, int i, int j |
126-
dom = b.getNode(i) and node = b.getNode(j) and i > j
127-
)
122+
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i > j)
128123
}
129124

130125
/** Holds if `dom` post-dominates `node`. (This is reflexive.) */
@@ -133,7 +128,5 @@ predicate postDominates(ControlFlowNode dom, ControlFlowNode node) {
133128
// This predicate is gigantic, so it must be inlined.
134129
bbStrictlyPostDominates(dom.getBasicBlock(), node.getBasicBlock())
135130
or
136-
exists(BasicBlock b, int i, int j |
137-
dom = b.getNode(i) and node = b.getNode(j) and i >= j
138-
)
131+
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i >= j)
139132
}

java/ql/src/semmle/code/java/controlflow/Guards.qll

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ private import semmle.code.java.controlflow.internal.GuardsLogic
66
* A basic block that terminates in a condition, splitting the subsequent control flow.
77
*/
88
class ConditionBlock extends BasicBlock {
9-
ConditionBlock() {
10-
this.getLastNode() instanceof ConditionNode
11-
}
9+
ConditionBlock() { this.getLastNode() instanceof ConditionNode }
1210

1311
/** Gets the last node of this basic block. */
14-
ConditionNode getConditionNode() {
15-
result = this.getLastNode()
16-
}
12+
ConditionNode getConditionNode() { result = this.getLastNode() }
1713

1814
/** Gets the condition of the last node of this basic block. */
19-
Expr getCondition() {
20-
result = this.getConditionNode().getCondition()
21-
}
15+
Expr getCondition() { result = this.getConditionNode().getCondition() }
2216

2317
/** Gets a `true`- or `false`-successor of the last node of this basic block. */
2418
BasicBlock getTestSuccessor(boolean testIsTrue) {
@@ -63,6 +57,7 @@ class ConditionBlock extends BasicBlock {
6357
* that `this` strictly dominates `controlled` so that isn't necessary to check
6458
* directly.
6559
*/
60+
6661
exists(BasicBlock succ |
6762
succ = this.getTestSuccessor(testIsTrue) and
6863
succ.bbDominates(controlled) and
@@ -83,7 +78,8 @@ class ConditionBlock extends BasicBlock {
8378
*/
8479
class Guard extends ExprParent {
8580
Guard() {
86-
this.(Expr).getType() instanceof BooleanType and not this instanceof BooleanLiteral or
81+
this.(Expr).getType() instanceof BooleanType and not this instanceof BooleanLiteral
82+
or
8783
this instanceof SwitchCase
8884
}
8985

@@ -106,10 +102,9 @@ class Guard extends ExprParent {
106102
* true.
107103
*/
108104
predicate isEquality(Expr e1, Expr e2, boolean polarity) {
109-
exists(Expr exp1, Expr exp2 |
110-
equalityGuard(this, exp1, exp2, polarity)
111-
|
112-
e1 = exp1.getProperExpr() and e2 = exp2.getProperExpr() or
105+
exists(Expr exp1, Expr exp2 | equalityGuard(this, exp1, exp2, polarity) |
106+
e1 = exp1.getProperExpr() and e2 = exp2.getProperExpr()
107+
or
113108
e2 = exp1.getProperExpr() and e1 = exp2.getProperExpr()
114109
)
115110
}
@@ -123,7 +118,8 @@ class Guard extends ExprParent {
123118
cb = bb1 and
124119
cb.getCondition() = this and
125120
bb2 = cb.getTestSuccessor(branch)
126-
) or
121+
)
122+
or
127123
exists(SwitchCase sc, ControlFlowNode pred |
128124
sc = this and
129125
branch = true and
@@ -143,7 +139,8 @@ class Guard extends ExprParent {
143139
exists(ConditionBlock cb |
144140
cb.getCondition() = this and
145141
cb.controls(controlled, branch)
146-
) or
142+
)
143+
or
147144
switchCaseControls(this, controlled) and branch = true
148145
}
149146

@@ -175,7 +172,8 @@ private predicate switchCaseControls(SwitchCase sc, BasicBlock bb) {
175172
* BaseSSA-based reasoning.
176173
*/
177174
predicate guardControls_v1(Guard guard, BasicBlock controlled, boolean branch) {
178-
guard.directlyControls(controlled, branch) or
175+
guard.directlyControls(controlled, branch)
176+
or
179177
exists(Guard g, boolean b |
180178
guardControls_v1(g, controlled, b) and
181179
implies_v1(g, b, guard, branch)
@@ -189,15 +187,17 @@ predicate guardControls_v1(Guard guard, BasicBlock controlled, boolean branch) {
189187
* RangeAnalysis.
190188
*/
191189
predicate guardControls_v2(Guard guard, BasicBlock controlled, boolean branch) {
192-
guard.directlyControls(controlled, branch) or
190+
guard.directlyControls(controlled, branch)
191+
or
193192
exists(Guard g, boolean b |
194193
guardControls_v2(g, controlled, b) and
195194
implies_v2(g, b, guard, branch)
196195
)
197196
}
198197

199198
private predicate guardControls_v3(Guard guard, BasicBlock controlled, boolean branch) {
200-
guard.directlyControls(controlled, branch) or
199+
guard.directlyControls(controlled, branch)
200+
or
201201
exists(Guard g, boolean b |
202202
guardControls_v3(g, controlled, b) and
203203
implies_v3(g, b, guard, branch)
@@ -209,25 +209,31 @@ private predicate equalityGuard(Guard g, Expr e1, Expr e2, boolean polarity) {
209209
eqtest = g and
210210
polarity = eqtest.polarity() and
211211
eqtest.hasOperands(e1, e2)
212-
) or
212+
)
213+
or
213214
exists(MethodAccess ma |
214215
ma = g and
215216
ma.getMethod() instanceof EqualsMethod and
216217
polarity = true and
217-
ma.getAnArgument() = e1 and ma.getQualifier() = e2
218-
) or
218+
ma.getAnArgument() = e1 and
219+
ma.getQualifier() = e2
220+
)
221+
or
219222
exists(MethodAccess ma, Method equals |
220223
ma = g and
221224
ma.getMethod() = equals and
222225
polarity = true and
223226
equals.hasName("equals") and
224227
equals.getNumberOfParameters() = 2 and
225228
equals.getDeclaringType().hasQualifiedName("java.util", "Objects") and
226-
ma.getArgument(0) = e1 and ma.getArgument(1) = e2
227-
) or
229+
ma.getArgument(0) = e1 and
230+
ma.getArgument(1) = e2
231+
)
232+
or
228233
exists(ConstCase cc |
229234
cc = g and
230235
polarity = true and
231-
cc.getSwitch().getExpr().getProperExpr() = e1 and cc.getValue() = e2
236+
cc.getSwitch().getExpr().getProperExpr() = e1 and
237+
cc.getValue() = e2
232238
)
233239
}

java/ql/src/semmle/code/java/controlflow/Paths.qll

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ abstract class ActionConfiguration extends string {
2525
}
2626

2727
/** Holds if every path through `call` goes through at least one action node. */
28-
final predicate callAlwaysPerformsAction(Call call) {
29-
callAlwaysPerformsAction(call, this)
30-
}
28+
final predicate callAlwaysPerformsAction(Call call) { callAlwaysPerformsAction(call, this) }
3129
}
3230

3331
/** Gets a `BasicBlock` that contains an action. */
@@ -40,7 +38,9 @@ private BasicBlock actionBlock(ActionConfiguration conf) {
4038

4139
/** Holds if every path through `call` goes through at least one action node. */
4240
private predicate callAlwaysPerformsAction(Call call, ActionConfiguration conf) {
43-
forex(Callable callable | callable = viableCallable(call) | callableAlwaysPerformsAction(callable, conf))
41+
forex(Callable callable | callable = viableCallable(call) |
42+
callableAlwaysPerformsAction(callable, conf)
43+
)
4444
}
4545

4646
/** Holds if an action dominates the exit of the callable. */
@@ -60,18 +60,20 @@ private BasicBlock nonDominatingActionBlock(ActionConfiguration conf) {
6060
)
6161
}
6262

63-
private class JoinBlock extends BasicBlock { JoinBlock() { 2 <= strictcount(this.getABBPredecessor()) } }
63+
private class JoinBlock extends BasicBlock {
64+
JoinBlock() { 2 <= strictcount(this.getABBPredecessor()) }
65+
}
6466

6567
/**
6668
* Holds if `bb` is a block that is collectively dominated by a set of one or
6769
* more actions that individually does not dominate the exit.
6870
*/
6971
private predicate postActionBlock(BasicBlock bb, ActionConfiguration conf) {
70-
bb = nonDominatingActionBlock(conf) or
71-
if bb instanceof JoinBlock then
72-
forall(BasicBlock pred | pred = bb.getABBPredecessor() | postActionBlock(pred, conf))
73-
else
74-
postActionBlock(bb.getABBPredecessor(), conf)
72+
bb = nonDominatingActionBlock(conf)
73+
or
74+
if bb instanceof JoinBlock
75+
then forall(BasicBlock pred | pred = bb.getABBPredecessor() | postActionBlock(pred, conf))
76+
else postActionBlock(bb.getABBPredecessor(), conf)
7577
}
7678

7779
/** Holds if every path through `callable` goes through at least one action node. */

0 commit comments

Comments
 (0)