Skip to content

Commit 166f891

Browse files
committed
Rust: Remove Format.getArgument
1 parent 0dccbb9 commit 166f891

16 files changed

+102
-52
lines changed

rust/ql/.generated.list

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll

+3-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ final class FormatArgsExprCfgNode extends Nodes::FormatArgsExprCfgNode {
195195

196196
/** Gets a format argument of the `i`th format of this format arguments expression (0-based). */
197197
FormatTemplateVariableAccessCfgNode getFormatTemplateVariableAccess(int i) {
198-
exists(FormatTemplateVariableAccess v |
199-
v.getArgument() = node.getFormat(i).getArgument(_) and
198+
exists(FormatTemplateVariableAccess v, Format f |
199+
f = node.getFormat(i) and
200+
v.getArgument() = [f.getArgumentRef(), f.getWidthArgument(), f.getPrecisionArgument()] and
200201
result.getFormatTemplateVariableAccess() = v and
201202
any(ChildMapping mapping).hasCfgChild(node, v, this, result)
202203
)

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

-10
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ module Impl {
4040

4141
override Format getParent() { result = Synth::TFormat(parent, index, _, _) }
4242

43-
/** Gets the position of this argument. */
44-
int getPosition() {
45-
this =
46-
rank[result + 1](FormatArgument f, int offs |
47-
f = Synth::TFormatArgument(parent, index, _, _, _, offs)
48-
|
49-
f order by offs
50-
)
51-
}
52-
5343
override FormatTemplateVariableAccess getVariable() { result.getArgument() = this }
5444
}
5545

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ module Impl {
4242

4343
override int getIndex() { result = index }
4444

45-
override FormatArgument getArgument(int i) {
46-
result.getParent() = this and i = result.getPosition()
47-
}
48-
4945
/**
5046
* Gets the name or position reference of this format, if any. For example `name` and `0` in:
5147
* ```rust
@@ -54,7 +50,7 @@ module Impl {
5450
* println!("{0} in wonderland", name);
5551
* ```
5652
*/
57-
FormatArgument getArgumentRef() {
53+
override FormatArgument getArgumentRef() {
5854
result.getParent() = this and result = Synth::TFormatArgument(_, _, 0, _, _, _)
5955
}
6056

@@ -66,7 +62,7 @@ module Impl {
6662
* println!("{:1$}", PI, width);
6763
* ```
6864
*/
69-
FormatArgument getWidthArgument() {
65+
override FormatArgument getWidthArgument() {
7066
result.getParent() = this and result = Synth::TFormatArgument(_, _, 1, _, _, _)
7167
}
7268

@@ -78,7 +74,7 @@ module Impl {
7874
* println!("{:.1$}", PI, prec);
7975
* ```
8076
*/
81-
FormatArgument getPrecisionArgument() {
77+
override FormatArgument getPrecisionArgument() {
8278
result.getParent() = this and result = Synth::TFormatArgument(_, _, 2, _, _, _)
8379
}
8480
}

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

+21-6
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

+15-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
| gen_format.rs:5:21:5:22 | {} | getParent: | gen_format.rs:5:14:5:32 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 0 |
2-
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | getParent: | gen_format.rs:7:14:7:47 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 3 |
3-
| gen_format_args_arg.rs:5:26:5:27 | {} | getParent: | gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 0 |
4-
| gen_format_args_expr.rs:6:19:6:20 | {} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 0 |
5-
| gen_format_args_expr.rs:6:26:6:29 | {:?} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 3 | getNumberOfArguments: | 0 |
6-
| gen_format_args_expr.rs:7:19:7:21 | {b} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 1 |
7-
| gen_format_args_expr.rs:7:27:7:31 | {a:?} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 3 | getNumberOfArguments: | 1 |
8-
| gen_format_args_expr.rs:9:19:9:21 | {x} | getParent: | gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 1 |
9-
| gen_format_args_expr.rs:9:24:9:26 | {y} | getParent: | gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getIndex: | 3 | getNumberOfArguments: | 1 |
10-
| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | getParent: | gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 3 |
11-
| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | getParent: | gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | getIndex: | 1 | getNumberOfArguments: | 3 |
1+
| gen_format.rs:5:21:5:22 | {} | getParent: | gen_format.rs:5:14:5:32 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | no | hasWidthArgument: | no | hasPrecisionArgument: | no |
2+
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | getParent: | gen_format.rs:7:14:7:47 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | yes | hasWidthArgument: | yes | hasPrecisionArgument: | yes |
3+
| gen_format_args_arg.rs:5:26:5:27 | {} | getParent: | gen_format_args_arg.rs:5:17:5:39 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | no | hasWidthArgument: | no | hasPrecisionArgument: | no |
4+
| gen_format_args_expr.rs:6:19:6:20 | {} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | no | hasWidthArgument: | no | hasPrecisionArgument: | no |
5+
| gen_format_args_expr.rs:6:26:6:29 | {:?} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 3 | hasArgumentRef: | no | hasWidthArgument: | no | hasPrecisionArgument: | no |
6+
| gen_format_args_expr.rs:7:19:7:21 | {b} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | yes | hasWidthArgument: | no | hasPrecisionArgument: | no |
7+
| gen_format_args_expr.rs:7:27:7:31 | {a:?} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 3 | hasArgumentRef: | yes | hasWidthArgument: | no | hasPrecisionArgument: | no |
8+
| gen_format_args_expr.rs:9:19:9:21 | {x} | getParent: | gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | yes | hasWidthArgument: | no | hasPrecisionArgument: | no |
9+
| gen_format_args_expr.rs:9:24:9:26 | {y} | getParent: | gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getIndex: | 3 | hasArgumentRef: | yes | hasWidthArgument: | no | hasPrecisionArgument: | no |
10+
| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | getParent: | gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | yes | hasWidthArgument: | yes | hasPrecisionArgument: | yes |
11+
| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | getParent: | gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | getIndex: | 1 | hasArgumentRef: | yes | hasWidthArgument: | yes | hasPrecisionArgument: | yes |

rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.ql

+8-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | gen_format.rs:7:22:7:26 | value |
2+
| gen_format_args_expr.rs:7:19:7:21 | {b} | gen_format_args_expr.rs:7:20:7:20 | b |
3+
| gen_format_args_expr.rs:7:27:7:31 | {a:?} | gen_format_args_expr.rs:7:28:7:28 | a |
4+
| gen_format_args_expr.rs:9:19:9:21 | {x} | gen_format_args_expr.rs:9:20:9:20 | x |
5+
| gen_format_args_expr.rs:9:24:9:26 | {y} | gen_format_args_expr.rs:9:25:9:25 | y |
6+
| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | gen_format_argument.rs:5:22:5:26 | value |
7+
| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | gen_format_argument.rs:7:22:7:22 | 0 |

rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql renamed to rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgumentRef.ql

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | gen_format.rs:7:36:7:44 | precision |
2+
| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | gen_format_argument.rs:5:36:5:44 | precision |
3+
| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | gen_format_argument.rs:7:28:7:28 | 2 |

rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getPrecisionArgument.ql

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| gen_format.rs:7:21:7:46 | {value:#width$.precision$} | gen_format.rs:7:29:7:33 | width |
2+
| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | gen_format_argument.rs:5:29:5:33 | width |
3+
| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | gen_format_argument.rs:7:25:7:25 | 1 |

rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getWidthArgument.ql

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/schema/annotations.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,9 @@ class Format(Locatable):
18781878
"""
18791879
parent: FormatArgsExpr
18801880
index: int
1881-
argument: list["FormatArgument"] | child
1881+
argument_ref: optional["FormatArgument"] | child
1882+
width_argument: optional["FormatArgument"] | child
1883+
precision_argument: optional["FormatArgument"] | child
18821884

18831885

18841886
@synth.on_arguments(parent=FormatArgsExpr, index=int, kind=int, name=string, positional=boolean, offset=int)

0 commit comments

Comments
 (0)