count both named and positional arguments in the WithArity filter

This commit is contained in:
Erik Krogh Kristensen
2022-05-03 21:21:57 +02:00
parent c0eca0d09a
commit 8ffc05c84b
4 changed files with 11 additions and 4 deletions

View File

@@ -349,8 +349,8 @@ module API {
result.getAnImmediateUse() = this
}
/** Gets the number of arguments of this call. */
int getNumArgument() { result = count(this.getArg(_)) }
/** Gets the number of arguments of this call. Both positional and named arguments are counted. */
int getNumArgument() { result = count([this.getArg(_), this.getArgByName(_)]) }
}
/**

View File

@@ -46,6 +46,8 @@ isSink
| test.py:85:8:85:53 | ControlFlowNode for Attribute() | test-sink |
| test.py:86:8:86:60 | ControlFlowNode for Attribute() | test-sink |
| test.py:87:8:87:67 | ControlFlowNode for Attribute() | test-sink |
| test.py:89:21:89:23 | ControlFlowNode for one | test-source |
| test.py:90:25:90:27 | ControlFlowNode for one | test-source |
isSource
| test.py:3:5:3:15 | ControlFlowNode for getSource() | test-source |
| test.py:9:8:9:14 | ControlFlowNode for alias() | test-source |

View File

@@ -84,4 +84,9 @@ mySink(Steps.preserveArgZeroAndTwo("foo", "bar", getSource())) # FLOW
mySink(Steps.preserveAllButFirstArgument(getSource())) # NO FLOW
mySink(Steps.preserveAllButFirstArgument("foo", getSource())) # FLOW
mySink(Steps.preserveAllButFirstArgument("foo", "bar", getSource())) # FLOW
mySink(Steps.preserveAllButFirstArgument("foo", "bar", getSource())) # FLOW
CallFilter.arityOne(one) # match
CallFilter.arityOne(one=one) # match
CallFilter.arityOne(one, two=two) # NO match
CallFilter.arityOne(one=one, two=two) # NO match

View File

@@ -41,7 +41,7 @@ class Sinks extends ModelInput::SinkModelCsv {
"testlib;;Member[Args].Member[lastarg].Argument[N-1];test-source", //
"testlib;;Member[Args].Member[nonFist].Argument[1..];test-source", //
// callsite filter.
"testlib;;Member[CallFilter].Member[arityOne].WithArity[1].Argument[0..];test-source", //
"testlib;;Member[CallFilter].Member[arityOne].WithArity[1].Argument[any];test-source", //
"testlib;;Member[CallFilter].Member[twoOrMore].WithArity[2..].Argument[0..];test-source", //
// testing non-positional arguments
"testlib;;Member[ArgPos].Member[selfThing].Argument[self];test-source", //