mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
python: add support for lower bound position
This commit is contained in:
@@ -57,6 +57,9 @@ newtype TParameterPosition =
|
||||
// parameter positions available.
|
||||
FlowSummaryImpl::ParsePositions::isParsedPositionalArgumentPosition(_, index)
|
||||
} or
|
||||
TPositionalParameterLowerBoundPosition(int pos) {
|
||||
FlowSummaryImpl::ParsePositions::isParsedArgumentLowerBoundPosition(_, pos)
|
||||
} or
|
||||
TKeywordParameterPosition(string name) {
|
||||
name = any(Parameter p).getName()
|
||||
or
|
||||
@@ -91,6 +94,9 @@ class ParameterPosition extends TParameterPosition {
|
||||
/** Holds if this position represents a positional parameter at (0-based) `index`. */
|
||||
predicate isPositional(int index) { this = TPositionalParameterPosition(index) }
|
||||
|
||||
/** Holds if this position represents any positional parameter starting from position `pos`. */
|
||||
predicate isPositionalLowerBound(int pos) { this = TPositionalParameterLowerBoundPosition(pos) }
|
||||
|
||||
/** Holds if this position represents a keyword parameter named `name`. */
|
||||
predicate isKeyword(string name) { this = TKeywordParameterPosition(name) }
|
||||
|
||||
@@ -123,6 +129,8 @@ class ParameterPosition extends TParameterPosition {
|
||||
or
|
||||
exists(int index | this.isPositional(index) and result = "position " + index)
|
||||
or
|
||||
exists(int pos | this.isPositionalLowerBound(pos) and result = "position " + pos + "..")
|
||||
or
|
||||
exists(string name | this.isKeyword(name) and result = "keyword " + name)
|
||||
or
|
||||
exists(int index | this.isStarArgs(index) and result = "*args at " + index)
|
||||
@@ -211,6 +219,10 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
|
||||
or
|
||||
exists(int index | ppos.isPositional(index) and apos.isPositional(index))
|
||||
or
|
||||
exists(int index1, int index2 |
|
||||
ppos.isPositionalLowerBound(index1) and apos.isPositional(index2) and index2 >= index1
|
||||
)
|
||||
or
|
||||
exists(string name | ppos.isKeyword(name) and apos.isKeyword(name))
|
||||
or
|
||||
exists(int index | ppos.isStarArgs(index) and apos.isStarArgs(index))
|
||||
@@ -360,6 +372,10 @@ abstract class DataFlowFunction extends DataFlowCallable, TFunction {
|
||||
result.getParameter() = func.getArg(index + this.positionalOffset())
|
||||
)
|
||||
or
|
||||
exists(int index1, int index2 | ppos.isPositionalLowerBound(index1) and index2 >= index1 |
|
||||
result.getParameter() = func.getArg(index2 + this.positionalOffset())
|
||||
)
|
||||
or
|
||||
exists(string name | ppos.isKeyword(name) | result.getParameter() = func.getArgByName(name))
|
||||
or
|
||||
// `*args`
|
||||
|
||||
@@ -195,6 +195,11 @@ module ParsePositions {
|
||||
i = AccessPath::parseInt(c)
|
||||
}
|
||||
|
||||
predicate isParsedArgumentLowerBoundPosition(string c, int i) {
|
||||
isArgBody(c) and
|
||||
i = AccessPath::parseLowerBound(c)
|
||||
}
|
||||
|
||||
predicate isParsedKeywordArgumentPosition(string c, string argName) {
|
||||
isArgBody(c) and
|
||||
c = argName + ":"
|
||||
|
||||
Reference in New Issue
Block a user