Skip to content

Commit 8a5fa9b

Browse files
committed
Rust: add ImplicitVariableAccess class
1 parent 8f2c7c1 commit 8a5fa9b

File tree

12 files changed

+184
-9
lines changed

12 files changed

+184
-9
lines changed

rust/ql/.generated.list

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

rust/ql/.gitattributes

Lines changed: 2 additions & 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.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/ImplicitVariableAccess.qll

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* This module defines the hook used internally to tweak the characteristic predicate of
3+
* `ImplicitVariableAccess` synthesized instances.
4+
* INTERNAL: Do not use.
5+
*/
6+
7+
private import codeql.rust.elements.internal.generated.Raw
8+
private import codeql.rust.elements.internal.generated.Synth
9+
private import codeql.rust.elements.FormatTemplate
10+
11+
/**
12+
* The characteristic predicate of `ImplicitVariableAccess` synthesized instances.
13+
* INTERNAL: Do not use.
14+
*/
15+
predicate constructImplicitVariableAccess(Raw::FormatArgsExpr parent, int index, int kind) {
16+
exists(NamedFormatArgument arg | unboundNamedFormatArgument(parent, index, kind, arg))
17+
}
18+
19+
/**
20+
* A named format argument for which no binding is found in the parent `FormatArgsExpr::getArg(_)`.
21+
* INTERNAL: Do not use.
22+
*/
23+
predicate unboundNamedFormatArgument(
24+
Raw::FormatArgsExpr parent, int index, int kind, NamedFormatArgument arg
25+
) {
26+
exists(Format format, string name |
27+
not parent.getArg(_).getName().getText() = name and
28+
name = arg.getName() and
29+
Synth::convertFormatArgsExprToRaw(format.getParent()) = parent and
30+
format.getIndex() = index
31+
|
32+
arg = format.getArgumentRef() and kind = 0
33+
or
34+
arg = format.getWidthArgument() and kind = 1
35+
or
36+
arg = format.getPrecisionArgument() and kind = 2
37+
)
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* This module provides a hand-modifiable wrapper around the generated class `ImplicitVariableAccess`.
3+
*
4+
* INTERNAL: Do not use.
5+
*/
6+
7+
private import codeql.rust.elements.internal.generated.ImplicitVariableAccess
8+
private import codeql.rust.elements.internal.ImplicitVariableAccessConstructor
9+
private import codeql.rust.elements.internal.generated.Raw
10+
private import codeql.rust.elements.internal.generated.Synth
11+
private import codeql.rust.elements.FormatTemplate
12+
13+
/**
14+
* INTERNAL: This module contains the customizable definition of `ImplicitVariableAccess` and should not
15+
* be referenced directly.
16+
*/
17+
module Impl {
18+
class ImplicitVariableAccess extends Generated::ImplicitVariableAccess {
19+
private NamedFormatArgument argument;
20+
21+
ImplicitVariableAccess() {
22+
exists(Raw::FormatArgsExpr parent, int index, int kind |
23+
this = Synth::TImplicitVariableAccess(parent, index, kind) and
24+
unboundNamedFormatArgument(parent, index, kind, argument)
25+
)
26+
}
27+
28+
/**
29+
* Holds if this element is at the specified location.
30+
* The location spans column `startcolumn` of line `startline` to
31+
* column `endcolumn` of line `endline` in file `filepath`.
32+
* For more information, see
33+
* [Providing locations in CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
34+
*/
35+
predicate hasLocationInfo(
36+
string filepath, int startline, int startcolumn, int endline, int endcolumn
37+
) {
38+
argument.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
39+
}
40+
41+
override string toString() { result = this.getName() }
42+
43+
/** Gets the name of the variable */
44+
string getName() { result = argument.getName() }
45+
46+
/** Gets the underlying `NamedFormatArgument` . */
47+
NamedFormatArgument getArgument() { result = argument }
48+
}
49+
}

rust/ql/lib/codeql/rust/elements/internal/generated/ImplicitVariableAccess.qll

Lines changed: 23 additions & 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/generated/ParentChild.qll

Lines changed: 17 additions & 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/generated/PureSynthConstructors.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/generated/Synth.qll

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

0 commit comments

Comments
 (0)