Skip to content

Commit 944ebc5

Browse files
committed
Rust: Add Callable.getBody()
1 parent 7d0509b commit 944ebc5

File tree

25 files changed

+135
-105
lines changed

25 files changed

+135
-105
lines changed

rust/ast-generator/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ fn property_name(type_name: &str, field_name: &str) -> String {
4444
("StructField", "expr") => "default",
4545
("UseTree", "is_star") => "is_glob",
4646
(_, "ty") => "type_repr",
47+
("Function", "body") => "function_body",
48+
("ClosureExpr", "body") => "closure_body",
4749
_ if field_name.contains("record") => &field_name.replacen("record", "struct", 1),
4850
_ => field_name,
4951
};

rust/extractor/src/generated/.generated.list

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

rust/extractor/src/generated/top.rs

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

rust/extractor/src/translate/generated.rs

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

rust/ql/.generated.list

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ query predicate scopeNoFirst(CfgScope scope) {
3636
Consistency::scopeNoFirst(scope) and
3737
not scope =
3838
[
39-
any(AstNode f | not f.(Function).hasBody()),
40-
any(ClosureExpr c | not c.hasBody()),
39+
any(AstNode f | not f.(Callable).hasBody()),
4140
any(AsyncBlockExpr b | not b.hasStmtList())
4241
]
4342
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ final class CallableScope extends CfgScopeImpl, Callable {
3535
CallableScope() {
3636
// A function without a body corresponds to a trait method signature and
3737
// should not have a CFG scope.
38-
this.(Function).hasBody()
39-
or
40-
this instanceof ClosureExpr
41-
}
42-
43-
/** Gets the body of this callable. */
44-
AstNode getBody() {
45-
result = this.(Function).getBody()
46-
or
47-
result = this.(ClosureExpr).getBody()
38+
this.hasBody()
4839
}
4940

5041
override predicate scopeFirst(AstNode first) {

rust/ql/lib/codeql/rust/elements/Callable.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.

rust/ql/lib/codeql/rust/elements/internal/ClosureExprImpl.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ module Impl {
2929
*/
3030
class ClosureExpr extends Generated::ClosureExpr {
3131
override string toStringImpl() { result = "|...| " + this.getBody().toAbbreviatedString() }
32+
33+
override Expr getBody() { result = this.getClosureBody() }
3234
}
3335
}

rust/ql/lib/codeql/rust/elements/internal/FunctionImpl.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,7 @@ module Impl {
6969
this.getLocation().getStartLine() <= result.getLocation().getStartLine() and
7070
result.getLocation().getStartLine() <= this.getName().getLocation().getStartLine()
7171
}
72+
73+
override BlockExpr getBody() { result = this.getFunctionBody() }
7274
}
7375
}

0 commit comments

Comments
 (0)