move getAnInstanceMemberAccess to ClassNode

This commit is contained in:
Erik Krogh Kristensen
2021-01-28 13:33:25 +01:00
parent e8afafca7a
commit 518bfa4d41
2 changed files with 26 additions and 21 deletions

View File

@@ -1007,6 +1007,31 @@ class ClassNode extends DataFlow::SourceNode {
result = getAnInstanceReference(DataFlow::TypeTracker::end())
}
/**
* Gets a property read that accesses the property `name` on an instance of this class.
*
* Concretely, this holds when the base is an instance of this class or a subclass thereof.
*/
pragma[nomagic]
DataFlow::PropRead getAnInstanceMemberAccess(string name, DataFlow::TypeTracker t) {
result = this.getAnInstanceReference(t.continue()).getAPropertyRead(name)
or
exists(DataFlow::ClassNode subclass |
result = subclass.getAnInstanceMemberAccess(name, t) and
not exists(subclass.getInstanceMember(name, _)) and
this = subclass.getADirectSuperClass()
)
}
/**
* Gets a property read that accesses the property `name` on an instance of this class.
*
* Concretely, this holds when the base is an instance of this class or a subclass thereof.
*/
DataFlow::PropRead getAnInstanceMemberAccess(string name) {
result = this.getAnInstanceMemberAccess(name, DataFlow::TypeTracker::end())
}
/**
* Gets an access to a static member of this class.
*/

View File

@@ -57,7 +57,7 @@ module CallGraph {
exists(DataFlow::ClassNode cls |
exists(string name |
function = cls.getInstanceMethod(name) and
getAnInstanceMemberAccess(cls, name, t.continue()).flowsTo(result)
cls.getAnInstanceMemberAccess(name, t.continue()).flowsTo(result)
or
function = cls.getStaticMethod(name) and
cls.getAClassReference(t.continue()).getAPropertyRead(name).flowsTo(result)
@@ -133,26 +133,6 @@ module CallGraph {
)
}
/**
* Gets a property read that accesses the property `name` on an instance of this class.
*
* Concretely, this holds when the base is an instance of this class or a subclass thereof.
*
* This predicate may be overridden to customize the class hierarchy analysis.
*/
pragma[nomagic]
private DataFlow::PropRead getAnInstanceMemberAccess(
DataFlow::ClassNode cls, string name, DataFlow::TypeTracker t
) {
result = cls.getAnInstanceReference(t.continue()).getAPropertyRead(name)
or
exists(DataFlow::ClassNode subclass |
result = getAnInstanceMemberAccess(subclass, name, t) and
not exists(subclass.getInstanceMember(name, _)) and
cls = subclass.getADirectSuperClass()
)
}
/**
* Gets a possible callee of `node` with the given `imprecision`.
*