Apply review suggestions: use ArgumentNode.argumentOf, and change more uses of ValuePreservingCallable -> ValuePreservingMethod

This commit is contained in:
Chris Smowton
2021-03-05 13:34:13 +00:00
parent eed357dc93
commit 012058a866
3 changed files with 7 additions and 13 deletions

View File

@@ -46,14 +46,14 @@ abstract class ValuePreservingMethod extends Method {
* These steps will be visible for all global data-flow purposes, as well as via
* `DataFlow::Node.getASuccessor` and other related functions exposing intraprocedural dataflow.
*/
abstract class FluentMethod extends ValuePreservingCallable {
abstract class FluentMethod extends ValuePreservingMethod {
override predicate returnsValue(int arg) { arg = -1 }
}
private class StandardLibraryValuePreservingMethod extends ValuePreservingMethod {
int returnsArgNo;
StandardLibraryValuePreservingCallable() {
StandardLibraryValuePreservingMethod() {
this.getDeclaringType().hasQualifiedName("java.util", "Objects") and
(
this.hasName(["requireNonNull", "requireNonNullElseGet"]) and returnsArgNo = 0
@@ -63,9 +63,7 @@ private class StandardLibraryValuePreservingMethod extends ValuePreservingMethod
this.hasName("toString") and returnsArgNo = 1
)
or
this.getDeclaringType()
.getASourceSupertype*()
.hasQualifiedName("java.util", "Stack") and
this.getDeclaringType().getASourceSupertype*().hasQualifiedName("java.util", "Stack") and
this.hasName("push") and
returnsArgNo = 0
}

View File

@@ -409,15 +409,11 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
or
summaryStep(node1, node2, "value")
or
exists(MethodAccess ma, ValuePreservingCallable c, int argNo |
ma.getCallee().getSourceDeclaration() = c and c.returnsValue(argNo)
exists(MethodAccess ma, ValuePreservingMethod m, int argNo |
ma.getCallee().getSourceDeclaration() = m and m.returnsValue(argNo)
|
node2.asExpr() = ma and
(
node1.asExpr() = ma.getArgument(argNo)
or
argNo = -1 and node1.asExpr() = ma.getQualifier()
)
node1.(ArgumentNode).argumentOf(ma, argNo)
)
}

View File

@@ -19,7 +19,7 @@ class Model extends FluentMethod {
Model() { this.getName() = "modelledFluentMethod" }
}
class IdentityModel extends ValuePreservingCallable {
class IdentityModel extends ValuePreservingMethod {
IdentityModel() { this.getName() = "modelledIdentity" }
override predicate returnsValue(int arg) { arg = 0 }