mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Python: Better API for parameters.
This commit is contained in:
@@ -81,7 +81,7 @@ class Comprehension extends Comprehension_, AstNode {
|
||||
|
||||
}
|
||||
|
||||
class BytesOrStr extends BytesOrStr_ {
|
||||
class BytesOrStr extends BytesOrStr_ {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,12 @@ class Parameter extends Parameter_ {
|
||||
Parameter() {
|
||||
/* Parameter_ is just defined as a Name or Tuple, narrow to actual parameters */
|
||||
exists(ParameterList pl | py_exprs(this, _, pl, _))
|
||||
or
|
||||
exists(Function f |
|
||||
f.getVararg() = this
|
||||
or
|
||||
f.getKwarg() = this
|
||||
)
|
||||
}
|
||||
|
||||
Location getLocation() {
|
||||
@@ -242,6 +248,7 @@ class Parameter extends Parameter_ {
|
||||
result = this
|
||||
}
|
||||
|
||||
/** Gets the expression for the default value of this parameter */
|
||||
Expr getDefault() {
|
||||
exists(Function f, int n, int c, int d, Arguments args |
|
||||
args = f.getDefinition().getArgs() |
|
||||
@@ -252,6 +259,24 @@ class Parameter extends Parameter_ {
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the annotation expression of this parameter */
|
||||
Expr getAnnotation() {
|
||||
exists(Function f, int n, Arguments args |
|
||||
args = f.getDefinition().getArgs() |
|
||||
f.getArg(n) = this and
|
||||
result = args.getAnnotation(n)
|
||||
)
|
||||
or
|
||||
exists(Function f, Arguments args |
|
||||
args = f.getDefinition().getArgs() |
|
||||
f.getKwarg() = this and
|
||||
result = args.getKwargannotation()
|
||||
or
|
||||
f.getVararg() = this and
|
||||
result = args.getVarargannotation()
|
||||
)
|
||||
}
|
||||
|
||||
Variable getVariable() {
|
||||
result.getAnAccess() = this.asName()
|
||||
}
|
||||
|
||||
@@ -275,14 +275,19 @@ class ParameterDefinition extends PyNodeDefinition {
|
||||
this.getDefiningNode().getNode().(Parameter).isSelf()
|
||||
}
|
||||
|
||||
/** Gets the control flow node for the default value of this parameter */
|
||||
ControlFlowNode getDefault() {
|
||||
exists(Function f, int n, int c, int d, Arguments args |
|
||||
args = f.getDefinition().getArgs() |
|
||||
f.getArg(n) = this.getDefiningNode().getNode() and
|
||||
c = count(f.getAnArg()) and
|
||||
d = count(args.getADefault()) and
|
||||
result.getNode() = args.getDefault(d-c+n)
|
||||
)
|
||||
result.getNode() = this.getParameter().getDefault()
|
||||
}
|
||||
|
||||
/** Gets the annotation control flow node of this parameter */
|
||||
ControlFlowNode getAnnotation() {
|
||||
result.getNode() = this.getParameter().getAnnotation()
|
||||
}
|
||||
|
||||
/** Gets the name of this parameter definition */
|
||||
string getName() {
|
||||
result = this.getParameter().asName().getId()
|
||||
}
|
||||
|
||||
predicate isVarargs() {
|
||||
|
||||
Reference in New Issue
Block a user