mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
Rust: Include index in Format.getArgument
This commit is contained in:
@@ -196,7 +196,7 @@ final class FormatArgsExprCfgNode extends Nodes::FormatArgsExprCfgNode {
|
||||
/** Gets a format argument of the `i`th format of this format arguments expression (0-based). */
|
||||
FormatTemplateVariableAccessCfgNode getFormatTemplateVariableAccess(int i) {
|
||||
exists(FormatTemplateVariableAccess v |
|
||||
v.getArgument() = node.getFormat(i).getArgument() and
|
||||
v.getArgument() = node.getFormat(i).getArgument(_) and
|
||||
result.getFormatTemplateVariableAccess() = v and
|
||||
any(ChildMapping mapping).hasCfgChild(node, v, this, result)
|
||||
)
|
||||
|
||||
@@ -40,6 +40,16 @@ module Impl {
|
||||
|
||||
override Format getParent() { result = Synth::TFormat(parent, index, _, _) }
|
||||
|
||||
/** Gets the position of this argument. */
|
||||
int getPosition() {
|
||||
this =
|
||||
rank[result + 1](FormatArgument f, int offs |
|
||||
f = Synth::TFormatArgument(parent, index, _, _, _, offs)
|
||||
|
|
||||
f order by offs
|
||||
)
|
||||
}
|
||||
|
||||
override FormatTemplateVariableAccess getVariable() { result.getArgument() = this }
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ module Impl {
|
||||
|
||||
override int getIndex() { result = index }
|
||||
|
||||
override FormatArgument getArgument() { result.getParent() = this }
|
||||
override FormatArgument getArgument(int i) {
|
||||
result.getParent() = this and i = result.getPosition()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name or position reference of this format, if any. For example `name` and `0` in:
|
||||
|
||||
@@ -41,13 +41,18 @@ module Generated {
|
||||
int getIndex() { none() }
|
||||
|
||||
/**
|
||||
* Gets the argument of this format, if it exists.
|
||||
* Gets the `index`th argument of this format (0-based).
|
||||
*/
|
||||
FormatArgument getArgument() { none() }
|
||||
FormatArgument getArgument(int index) { none() }
|
||||
|
||||
/**
|
||||
* Holds if `getArgument()` exists.
|
||||
* Gets any of the arguments of this format.
|
||||
*/
|
||||
final predicate hasArgument() { exists(this.getArgument()) }
|
||||
final FormatArgument getAnArgument() { result = this.getArgument(_) }
|
||||
|
||||
/**
|
||||
* Gets the number of arguments of this format.
|
||||
*/
|
||||
final int getNumberOfArguments() { result = count(int i | exists(this.getArgument(i))) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,13 +73,14 @@ private module Impl {
|
||||
b = 0 and
|
||||
bLocatable = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocatable(e, i, _)) | i) and
|
||||
n = bLocatable and
|
||||
nArgument = n + 1 and
|
||||
nArgument = n + 1 + max(int i | i = -1 or exists(e.getArgument(i)) | i) and
|
||||
(
|
||||
none()
|
||||
or
|
||||
result = getImmediateChildOfLocatable(e, index - b, partialPredicateCall)
|
||||
or
|
||||
index = n and result = e.getArgument() and partialPredicateCall = "Argument()"
|
||||
result = e.getArgument(index - n) and
|
||||
partialPredicateCall = "Argument(" + (index - n).toString() + ")"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user