Skip to content

Commit f85767f

Browse files
committed
PS: add a super class for all loop-related CFG nodes.
1 parent 19454a5 commit f85767f

File tree

1 file changed

+29
-25
lines changed
  • powershell/ql/lib/semmle/code/powershell/controlflow

1 file changed

+29
-25
lines changed

powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,40 +1078,50 @@ module StmtNodes {
10781078
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
10791079
}
10801080

1081-
class DoUntilStmtChildMapping extends NonExprChildMapping, DoUntilStmt {
1081+
private class LoopStmtChildMapping extends NonExprChildMapping, LoopStmt {
1082+
override predicate relevantChild(Ast child) { child = this.getBody() }
1083+
}
1084+
1085+
class LoopStmtCfgNode extends StmtCfgNode {
1086+
override string getAPrimaryQlClass() { result = "LoopStmtCfgNode" }
1087+
1088+
override LoopStmtChildMapping s;
1089+
1090+
override LoopStmt getStmt() { result = s }
1091+
1092+
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
1093+
}
1094+
1095+
private class DoUntilStmtChildMapping extends LoopStmtChildMapping, DoUntilStmt {
10821096
override predicate relevantChild(Ast child) {
1083-
child = this.getCondition() or child = this.getBody()
1097+
child = this.getCondition() or super.relevantChild(child)
10841098
}
10851099
}
10861100

1087-
class DoUntilStmtCfgNode extends StmtCfgNode {
1101+
class DoUntilStmtCfgNode extends LoopStmtCfgNode {
10881102
override string getAPrimaryQlClass() { result = "DoUntilStmtCfgNode" }
10891103

10901104
override DoUntilStmtChildMapping s;
10911105

10921106
override DoUntilStmt getStmt() { result = s }
10931107

10941108
ExprCfgNode getCondition() { s.hasCfgChild(s.getCondition(), this, result) }
1095-
1096-
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
10971109
}
10981110

1099-
private class DoWhileStmtChildMapping extends NonExprChildMapping, DoWhileStmt {
1111+
private class DoWhileStmtChildMapping extends LoopStmtChildMapping, DoWhileStmt {
11001112
override predicate relevantChild(Ast child) {
1101-
child = this.getCondition() or child = this.getBody()
1113+
child = this.getCondition() or super.relevantChild(child)
11021114
}
11031115
}
11041116

1105-
class DoWhileStmtCfgNode extends StmtCfgNode {
1117+
class DoWhileStmtCfgNode extends LoopStmtCfgNode {
11061118
override string getAPrimaryQlClass() { result = "DoWhileStmtCfgNode" }
11071119

11081120
override DoWhileStmtChildMapping s;
11091121

11101122
override DoWhileStmt getStmt() { result = s }
11111123

11121124
ExprCfgNode getCondition() { s.hasCfgChild(s.getCondition(), this, result) }
1113-
1114-
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
11151125
}
11161126

11171127
private class ErrorStmtChildMapping extends NonExprChildMapping, ErrorStmt {
@@ -1160,13 +1170,13 @@ module StmtNodes {
11601170
ExprCfgNode getHashTableExpr() { s.hasCfgChild(s.getHashTableExpr(), this, result) }
11611171
}
11621172

1163-
private class ForEachStmtChildMapping extends NonExprChildMapping, ForEachStmt {
1173+
private class ForEachStmtChildMapping extends LoopStmtChildMapping, ForEachStmt {
11641174
override predicate relevantChild(Ast child) {
1165-
child = this.getVarAccess() or child = this.getIterableExpr() or child = this.getBody()
1175+
child = this.getVarAccess() or child = this.getIterableExpr() or super.relevantChild(child)
11661176
}
11671177
}
11681178

1169-
class ForEachStmtCfgNode extends StmtCfgNode {
1179+
class ForEachStmtCfgNode extends LoopStmtCfgNode {
11701180
override string getAPrimaryQlClass() { result = "ForEachStmtCfgNode" }
11711181

11721182
override ForEachStmtChildMapping s;
@@ -1176,20 +1186,18 @@ module StmtNodes {
11761186
ExprCfgNode getVarAccess() { s.hasCfgChild(s.getVarAccess(), this, result) }
11771187

11781188
ExprCfgNode getIterableExpr() { s.hasCfgChild(s.getIterableExpr(), this, result) }
1179-
1180-
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
11811189
}
11821190

1183-
private class ForStmtChildMapping extends NonExprChildMapping, ForStmt {
1191+
private class ForStmtChildMapping extends LoopStmtChildMapping, ForStmt {
11841192
override predicate relevantChild(Ast child) {
11851193
child = this.getInitializer() or
11861194
child = this.getCondition() or
11871195
child = this.getIterator() or
1188-
child = this.getBody()
1196+
super.relevantChild(child)
11891197
}
11901198
}
11911199

1192-
class ForStmtCfgNode extends StmtCfgNode {
1200+
class ForStmtCfgNode extends LoopStmtCfgNode {
11931201
override string getAPrimaryQlClass() { result = "ForStmtCfgNode" }
11941202

11951203
override ForStmtChildMapping s;
@@ -1201,8 +1209,6 @@ module StmtNodes {
12011209
ExprCfgNode getCondition() { s.hasCfgChild(s.getCondition(), this, result) }
12021210

12031211
AstCfgNode getIterator() { s.hasCfgChild(s.getIterator(), this, result) }
1204-
1205-
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
12061212
}
12071213

12081214
private class GotoStmtChildMapping extends NonExprChildMapping, GotoStmt {
@@ -1340,23 +1346,21 @@ module StmtNodes {
13401346
override UsingStmt getStmt() { result = s }
13411347
}
13421348

1343-
private class WhileStmtChildMapping extends NonExprChildMapping, WhileStmt {
1349+
private class WhileStmtChildMapping extends LoopStmtChildMapping, WhileStmt {
13441350
override predicate relevantChild(Ast child) {
13451351
child = this.getCondition() or
1346-
child = this.getBody()
1352+
super.relevantChild(child)
13471353
}
13481354
}
13491355

1350-
class WhileStmtCfgNode extends StmtCfgNode {
1356+
class WhileStmtCfgNode extends LoopStmtCfgNode {
13511357
override string getAPrimaryQlClass() { result = "WhileStmtCfgNode" }
13521358

13531359
override WhileStmtChildMapping s;
13541360

13551361
override WhileStmt getStmt() { result = s }
13561362

13571363
ExprCfgNode getCondition() { s.hasCfgChild(s.getCondition(), this, result) }
1358-
1359-
StmtCfgNode getBody() { s.hasCfgChild(s.getBody(), this, result) }
13601364
}
13611365

13621366
private class ConfigurationChildMapping extends NonExprChildMapping, Configuration {

0 commit comments

Comments
 (0)