Skip to content

Commit 34e8ea1

Browse files
authored
Merge pull request github#17898 from paldepind/rust-cfg-refactor
Rust: CFG classes are in expression module iff they correspond to exp…
2 parents fb26f78 + 633bac6 commit 34e8ea1

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

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

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,8 @@ class ParamTree extends StandardPostOrderTree, Param {
9393
override AstNode getChildNode(int i) { i = 0 and result = this.getPat() }
9494
}
9595

96-
class FormatArgsExprTree extends StandardPostOrderTree, FormatArgsExpr {
97-
override AstNode getChildNode(int i) {
98-
i = -1 and result = this.getTemplate()
99-
or
100-
result = this.getArg(i).getExpr()
101-
or
102-
result =
103-
any(FormatTemplateVariableAccess v, Format f, int index, int kind |
104-
f = this.getFormat(index) and
105-
(
106-
v.getArgument() = f.getArgumentRef() and kind = 0
107-
or
108-
v.getArgument() = f.getWidthArgument() and kind = 1
109-
or
110-
v.getArgument() = f.getPrecisionArgument() and kind = 2
111-
) and
112-
i = this.getNumberOfArgs() + index * 3 + kind
113-
|
114-
v
115-
)
116-
}
96+
class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
97+
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
11798
}
11899

119100
class FormatTemplateVariableAccessTree extends LeafTree, FormatTemplateVariableAccess { }
@@ -219,22 +200,6 @@ class NameTree extends LeafTree, Name { }
219200

220201
class NameRefTree extends LeafTree, NameRef { }
221202

222-
class OffsetOfExprTree extends LeafTree instanceof OffsetOfExpr { }
223-
224-
class ParenExprTree extends ControlFlowTree, ParenExpr {
225-
private ControlFlowTree expr;
226-
227-
ParenExprTree() { expr = super.getExpr() }
228-
229-
override predicate propagatesAbnormal(AstNode child) { expr.propagatesAbnormal(child) }
230-
231-
override predicate first(AstNode first) { expr.first(first) }
232-
233-
override predicate last(AstNode last, Completion c) { expr.last(last, c) }
234-
235-
override predicate succ(AstNode pred, AstNode succ, Completion c) { none() }
236-
}
237-
238203
class TypeRefTree extends LeafTree instanceof TypeRef { }
239204

240205
/**
@@ -360,10 +325,6 @@ module ExprTrees {
360325
}
361326
}
362327

363-
class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
364-
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
365-
}
366-
367328
class FieldExprTree extends StandardPostOrderTree instanceof FieldExpr {
368329
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
369330
}
@@ -409,6 +370,21 @@ module ExprTrees {
409370
i = -1 and result = this.getTemplate()
410371
or
411372
result = this.getArg(i).getExpr()
373+
or
374+
result =
375+
any(FormatTemplateVariableAccess v, Format f, int index, int kind |
376+
f = this.getFormat(index) and
377+
(
378+
v.getArgument() = f.getArgumentRef() and kind = 0
379+
or
380+
v.getArgument() = f.getWidthArgument() and kind = 1
381+
or
382+
v.getArgument() = f.getPrecisionArgument() and kind = 2
383+
) and
384+
i = this.getNumberOfArgs() + index * 3 + kind
385+
|
386+
v
387+
)
412388
}
413389
}
414390

@@ -566,6 +542,22 @@ module ExprTrees {
566542
}
567543
}
568544

545+
class OffsetOfExprTree extends LeafTree instanceof OffsetOfExpr { }
546+
547+
class ParenExprTree extends ControlFlowTree, ParenExpr {
548+
private ControlFlowTree expr;
549+
550+
ParenExprTree() { expr = super.getExpr() }
551+
552+
override predicate propagatesAbnormal(AstNode child) { expr.propagatesAbnormal(child) }
553+
554+
override predicate first(AstNode first) { expr.first(first) }
555+
556+
override predicate last(AstNode last, Completion c) { expr.last(last, c) }
557+
558+
override predicate succ(AstNode pred, AstNode succ, Completion c) { none() }
559+
}
560+
569561
class PathExprTree extends LeafTree instanceof PathExpr { }
570562

571563
class PrefixExprTree extends StandardPostOrderTree instanceof PrefixExpr {

0 commit comments

Comments
 (0)