Skip to content

Commit e1e0ad3

Browse files
committed
Rust: Add Callable.getBody()
1 parent 1047c3e commit e1e0ad3

File tree

21 files changed

+86
-62
lines changed

21 files changed

+86
-62
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/Scope.qll

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ final class CallableScope extends CfgScopeImpl, Callable {
4040
this instanceof ClosureExpr
4141
}
4242

43-
/** Gets the body of this callable. */
44-
AstNode getBody() {
45-
result = this.(Function).getBody()
46-
or
47-
result = this.(ClosureExpr).getBody()
48-
}
49-
5043
override predicate scopeFirst(AstNode first) {
5144
first(this.(CallableScopeTree).getFirstChildTree(), first)
5245
}

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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ module Impl {
309309
private predicate parameterDeclInScope(Variable v, VariableScope scope) {
310310
exists(Callable f |
311311
v.getParameter() = f.getParamList().getAParamBase() and
312-
scope = [f.(Function).getBody(), f.(ClosureExpr).getBody()]
312+
scope = f.getBody()
313313
)
314314
}
315315

0 commit comments

Comments
 (0)