-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: implement Format and FormatArgument classes
- Loading branch information
Showing
13 changed files
with
230 additions
and
277 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* This module provides the public class `NamedFormatArgument`. | ||
*/ | ||
|
||
private import internal.FormatArgumentImpl | ||
|
||
final class NamedFormatArgument = Impl::NamedFormatArgument; |
7 changes: 7 additions & 0 deletions
7
rust/ql/lib/codeql/rust/elements/PositionalFormatArgument.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* This module provides the public class `PositionalFormatArgument`. | ||
*/ | ||
|
||
private import internal.FormatArgumentImpl | ||
|
||
final class PositionalFormatArgument = Impl::PositionalFormatArgument; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
rust/ql/lib/codeql/rust/elements/internal/FormatArgumentConstructor.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
// generated by codegen, remove this comment if you wish to edit this file | ||
/** | ||
* This module defines the hook used internally to tweak the characteristic predicate of | ||
* `FormatArgument` synthesized instances. | ||
* INTERNAL: Do not use. | ||
*/ | ||
|
||
private import codeql.rust.elements.internal.generated.Raw | ||
private import codeql.rust.elements.internal.generated.Synth | ||
private import codeql.rust.elements.internal.FormatConstructor | ||
|
||
/** | ||
* The characteristic predicate of `FormatArgument` synthesized instances. | ||
* INTERNAL: Do not use. | ||
*/ | ||
predicate constructFormatArgument(Raw::FormatArgsExpr parent, int index, int kind) { none() } | ||
predicate constructFormatArgument(Raw::FormatArgsExpr parent, int index, int kind) { | ||
formatArgument(parent, index, kind, _, _, _) | ||
} | ||
|
||
predicate formatArgument( | ||
Raw::FormatArgsExpr parent, int index, int kind, string value, boolean positional, int offset | ||
) { | ||
exists(string text, int formatOffset, int group | | ||
group = [3, 4] and offset = formatOffset + 1 and kind = 0 | ||
or | ||
group = [15, 16] and | ||
offset = formatOffset + min(text.indexOf(value + "$")) and | ||
kind = 1 | ||
or | ||
group = [23, 24] and | ||
offset = formatOffset + max(text.indexOf(value + "$")) and | ||
kind = 2 | ||
| | ||
text = formatElement(parent, index, formatOffset) and | ||
value = text.regexpCapture(formatRegex(), group) and | ||
if group % 2 = 1 then positional = true else positional = false | ||
) | ||
} |
Oops, something went wrong.