Skip to content

Commit

Permalink
Rust: implement Format and FormatArgument classes
Browse files Browse the repository at this point in the history
  • Loading branch information
aibaars committed Oct 22, 2024
1 parent ffee937 commit 61a74d3
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 277 deletions.
4 changes: 0 additions & 4 deletions rust/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions rust/ql/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

248 changes: 0 additions & 248 deletions rust/ql/lib/codeql/rust/elements/FormatTemplate.qll

This file was deleted.

7 changes: 7 additions & 0 deletions rust/ql/lib/codeql/rust/elements/NamedFormatArgument.qll
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 rust/ql/lib/codeql/rust/elements/PositionalFormatArgument.qll
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;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

private import codeql.rust.elements.internal.generated.FormatArgsExpr
private import codeql.rust.elements.FormatTemplate
private import codeql.rust.elements.Format

/**
* INTERNAL: This module contains the customizable definition of `FormatArgsExpr` and should not
Expand Down
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
)
}
Loading

0 comments on commit 61a74d3

Please sign in to comment.