mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: simplify synth constructors
This commit is contained in:
2
rust/ql/.generated.list
generated
2
rust/ql/.generated.list
generated
@@ -587,7 +587,7 @@ lib/codeql/rust/elements/internal/generated/Static.qll 5fbd6879858cf356d4bdaa6da
|
||||
lib/codeql/rust/elements/internal/generated/Stmt.qll 8473ff532dd5cc9d7decaddcd174b94d610f6ca0aec8e473cc051dad9f3db917 6ef7d2b5237c2dbdcacbf7d8b39109d4dc100229f2b28b5c9e3e4fbf673ba72b
|
||||
lib/codeql/rust/elements/internal/generated/StmtList.qll a667193e32341e17400867c6e359878c4e645ef9f5f4d97676afc0283a33a026 a320ed678ee359302e2fc1b70a9476705cd616fcfa44a499d32f0c7715627f73
|
||||
lib/codeql/rust/elements/internal/generated/Struct.qll 4d57f0db12dc7ad3e31e750a24172ef1505406b4dab16386af0674bd18bf8f4b 1a73c83df926b996f629316f74c61ea775be04532ab61b56af904223354f033e
|
||||
lib/codeql/rust/elements/internal/generated/Synth.qll 65bf61ce73c7d1cce98a470b292122a7a3b136804179386f4e7517e4d8f7b81e 4905af04e60fbb4ab54fee58880150a6eb71ad70fe1a5e30d9ec493b5689078d
|
||||
lib/codeql/rust/elements/internal/generated/Synth.qll 521c9180f37ae5a7d5798c4b353b9ce04a0d2ce1a83440c34955f12e3e31f0ed 880fbb1dd673c2f64e9404f79cb62691d7778faa7618f7302e566112b54f08c3
|
||||
lib/codeql/rust/elements/internal/generated/SynthConstructors.qll e929c49ea60810a2bbc19ad38110b8bbaf21db54dae90393b21a3459a54abf6f e929c49ea60810a2bbc19ad38110b8bbaf21db54dae90393b21a3459a54abf6f
|
||||
lib/codeql/rust/elements/internal/generated/Token.qll 77a91a25ca5669703cf3a4353b591cef4d72caa6b0b9db07bb9e005d69c848d1 2fdffc4882ed3a6ca9ac6d1fb5f1ac5a471ca703e2ffdc642885fa558d6e373b
|
||||
lib/codeql/rust/elements/internal/generated/TokenTree.qll 8577c2b097c1be2f0f7daa5acfcf146f78674a424d99563e08a84dd3e6d91b46 d2f30764e84dbfc0a6a5d3d8a5f935cd432413688cb32da9c94e420fbc10665c
|
||||
|
||||
@@ -12,11 +12,7 @@ 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) {
|
||||
formatArgument(parent, index, kind, _, _, _)
|
||||
}
|
||||
|
||||
predicate formatArgument(
|
||||
predicate constructFormatArgument(
|
||||
Raw::FormatArgsExpr parent, int index, int kind, string value, boolean positional, int offset
|
||||
) {
|
||||
exists(string text, int formatOffset, int group |
|
||||
|
||||
@@ -32,10 +32,7 @@ module Impl {
|
||||
string name;
|
||||
private int offset;
|
||||
|
||||
FormatArgument() {
|
||||
this = Synth::TFormatArgument(parent, index, kind) and
|
||||
formatArgument(parent, index, kind, name, _, offset)
|
||||
}
|
||||
FormatArgument() { this = Synth::TFormatArgument(parent, index, kind, name, _, offset) }
|
||||
|
||||
override string toString() { result = name }
|
||||
|
||||
@@ -53,7 +50,7 @@ module Impl {
|
||||
endcolumn = startcolumn + name.length() - 1
|
||||
}
|
||||
|
||||
override Format getParent() { result = Synth::TFormat(parent, index) }
|
||||
override Format getParent() { result = Synth::TFormat(parent, index, _, _) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,7 +61,7 @@ module Impl {
|
||||
* ```
|
||||
*/
|
||||
class PositionalFormatArgument extends FormatArgument {
|
||||
PositionalFormatArgument() { formatArgument(parent, index, kind, _, true, _) }
|
||||
PositionalFormatArgument() { this = Synth::TFormatArgument(_, _, _, _, true, _) }
|
||||
|
||||
/** Gets the index of this positional argument */
|
||||
int getIndex() { result = name.toInt() }
|
||||
@@ -78,7 +75,7 @@ module Impl {
|
||||
* ```
|
||||
*/
|
||||
class NamedFormatArgument extends FormatArgument {
|
||||
NamedFormatArgument() { formatArgument(parent, index, kind, _, false, _) }
|
||||
NamedFormatArgument() { this = Synth::TFormatArgument(_, _, _, _, false, _) }
|
||||
|
||||
/** Gets the name of this named argument */
|
||||
string getName() { result = name }
|
||||
|
||||
@@ -9,9 +9,13 @@ private import codeql.rust.elements.internal.generated.Raw
|
||||
/**
|
||||
* The characteristic predicate of `Format` synthesized instances.
|
||||
* INTERNAL: Do not use.
|
||||
*
|
||||
* Match an element of a format string, either text (`Hello`) or a format placeholder (`{}`).
|
||||
*/
|
||||
predicate constructFormat(Raw::FormatArgsExpr parent, int index) {
|
||||
formatElement(parent, index, _).regexpMatch(formatRegex())
|
||||
predicate constructFormat(Raw::FormatArgsExpr parent, int index, string text, int offset) {
|
||||
text = formatElement(parent, index, offset) and
|
||||
text.charAt(0) = "{" and
|
||||
text.charAt(1) != "{"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,9 +32,11 @@ string formatElement(Raw::FormatArgsExpr parent, int occurrenceIndex, int occurr
|
||||
}
|
||||
|
||||
/**
|
||||
* A regular expression for matching format elements in a formatting template. The
|
||||
* A regular expression for matching format elements in a formatting template. The syntax of
|
||||
* formatting templates is defined at https://doc.rust-lang.org/stable/std/fmt/#syntax . The
|
||||
* regular expression is generated from the following python code:
|
||||
*
|
||||
*
|
||||
* ```python
|
||||
* identifier = "([A-Za-z_][A-Za-z0-9_]*)"
|
||||
* integer = "([0-9]+)"
|
||||
|
||||
@@ -28,9 +28,7 @@ module Impl {
|
||||
private int index;
|
||||
private int offset;
|
||||
|
||||
Format() {
|
||||
this = Synth::TFormat(parent, index) and text = formatElement(parent, index, offset)
|
||||
}
|
||||
Format() { this = Synth::TFormat(parent, index, text, offset) }
|
||||
|
||||
override string toString() { result = text }
|
||||
|
||||
@@ -58,7 +56,7 @@ module Impl {
|
||||
* ```
|
||||
*/
|
||||
FormatArgument getArgumentRef() {
|
||||
result.getParent() = this and result = Synth::TFormatArgument(_, _, 0)
|
||||
result.getParent() = this and result = Synth::TFormatArgument(_, _, 0, _, _, _)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +68,7 @@ module Impl {
|
||||
* ```
|
||||
*/
|
||||
FormatArgument getWidthArgument() {
|
||||
result.getParent() = this and result = Synth::TFormatArgument(_, _, 1)
|
||||
result.getParent() = this and result = Synth::TFormatArgument(_, _, 1, _, _, _)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +80,7 @@ module Impl {
|
||||
* ```
|
||||
*/
|
||||
FormatArgument getPrecisionArgument() {
|
||||
result.getParent() = this and result = Synth::TFormatArgument(_, _, 2)
|
||||
result.getParent() = this and result = Synth::TFormatArgument(_, _, 2, _, _, _)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,9 @@ module Synth {
|
||||
/**
|
||||
* INTERNAL: Do not use.
|
||||
*/
|
||||
TFormat(Raw::FormatArgsExpr parent, int index) { constructFormat(parent, index) } or
|
||||
TFormat(Raw::FormatArgsExpr parent, int index, string text, int offset) {
|
||||
constructFormat(parent, index, text, offset)
|
||||
} or
|
||||
/**
|
||||
* INTERNAL: Do not use.
|
||||
*/
|
||||
@@ -165,8 +167,10 @@ module Synth {
|
||||
/**
|
||||
* INTERNAL: Do not use.
|
||||
*/
|
||||
TFormatArgument(Raw::FormatArgsExpr parent, int index, int kind) {
|
||||
constructFormatArgument(parent, index, kind)
|
||||
TFormatArgument(
|
||||
Raw::FormatArgsExpr parent, int index, int kind, string name, boolean positional, int offset
|
||||
) {
|
||||
constructFormatArgument(parent, index, kind, name, positional, offset)
|
||||
} or
|
||||
/**
|
||||
* INTERNAL: Do not use.
|
||||
|
||||
@@ -1763,7 +1763,7 @@ class FormatTemplateVariableAccess(Expr):
|
||||
|
||||
|
||||
@qltest.skip
|
||||
@synth.on_arguments(parent=FormatArgsExpr, index=int)
|
||||
@synth.on_arguments(parent=FormatArgsExpr, index=int, text=string, offset=int)
|
||||
class Format(Locatable):
|
||||
"""
|
||||
A format element in a formatting template. For example the `{}` in:
|
||||
@@ -1776,7 +1776,7 @@ class Format(Locatable):
|
||||
|
||||
|
||||
@qltest.skip
|
||||
@synth.on_arguments(parent=FormatArgsExpr, index=int, kind=int)
|
||||
@synth.on_arguments(parent=FormatArgsExpr, index=int, kind=int, name=string, positional=boolean, offset=int)
|
||||
class FormatArgument(Locatable):
|
||||
"""
|
||||
An argument in a format element in a formatting template. For example the `width`, `precision`, and `value` in:
|
||||
|
||||
Reference in New Issue
Block a user