Skip to content

Commit fc4ac9b

Browse files
committed
Rust: implement Format and FormatArgument classes
1 parent 58dfe6c commit fc4ac9b

13 files changed

+230
-277
lines changed

rust/ql/.generated.list

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

rust/ql/.gitattributes

Lines changed: 0 additions & 4 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/FormatTemplate.qll

Lines changed: 0 additions & 248 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This module provides the public class `NamedFormatArgument`.
3+
*/
4+
5+
private import internal.FormatArgumentImpl
6+
7+
final class NamedFormatArgument = Impl::NamedFormatArgument;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This module provides the public class `PositionalFormatArgument`.
3+
*/
4+
5+
private import internal.FormatArgumentImpl
6+
7+
final class PositionalFormatArgument = Impl::PositionalFormatArgument;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
private import codeql.rust.elements.internal.generated.FormatArgsExpr
8-
private import codeql.rust.elements.FormatTemplate
8+
private import codeql.rust.elements.Format
99

1010
/**
1111
* INTERNAL: This module contains the customizable definition of `FormatArgsExpr` and should not
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module defines the hook used internally to tweak the characteristic predicate of
43
* `FormatArgument` synthesized instances.
54
* INTERNAL: Do not use.
65
*/
76

87
private import codeql.rust.elements.internal.generated.Raw
8+
private import codeql.rust.elements.internal.generated.Synth
9+
private import codeql.rust.elements.internal.FormatConstructor
910

1011
/**
1112
* The characteristic predicate of `FormatArgument` synthesized instances.
1213
* INTERNAL: Do not use.
1314
*/
14-
predicate constructFormatArgument(Raw::FormatArgsExpr parent, int index, int kind) { none() }
15+
predicate constructFormatArgument(Raw::FormatArgsExpr parent, int index, int kind) {
16+
formatArgument(parent, index, kind, _, _, _)
17+
}
18+
19+
predicate formatArgument(
20+
Raw::FormatArgsExpr parent, int index, int kind, string value, boolean positional, int offset
21+
) {
22+
exists(string text, int formatOffset, int group |
23+
group = [3, 4] and offset = formatOffset + 1 and kind = 0
24+
or
25+
group = [15, 16] and
26+
offset = formatOffset + min(text.indexOf(value + "$")) and
27+
kind = 1
28+
or
29+
group = [23, 24] and
30+
offset = formatOffset + max(text.indexOf(value + "$")) and
31+
kind = 2
32+
|
33+
text = formatElement(parent, index, formatOffset) and
34+
value = text.regexpCapture(formatRegex(), group) and
35+
if group % 2 = 1 then positional = true else positional = false
36+
)
37+
}

0 commit comments

Comments
 (0)