C#: Simplify DataFlow::Node::getType()

This commit is contained in:
Tom Hvitved
2019-05-07 20:52:38 +02:00
parent 7b7a1ecea0
commit a89505ba32
2 changed files with 11 additions and 19 deletions

View File

@@ -221,16 +221,17 @@ module DataFlowPrivateCached {
)
}
private DotNet::Type getDotNetType(Node node) {
cached
DotNet::Type getType(Node node) {
result = node.(ExprNode).getExpr().getType()
or
result = node.(SsaDefinitionNode).getDefinition().getSourceVariable().getType()
or
exists(CIL::Parameter p | node = TCilParameterNode(p) | result = p.getType())
or
result = getDotNetType(node.(TaintedParameterNode).getUnderlyingNode())
result = getType(node.(TaintedParameterNode).getUnderlyingNode())
or
result = getDotNetType(node.(TaintedReturnNode).getUnderlyingNode())
result = getType(node.(TaintedReturnNode).getUnderlyingNode())
or
exists(LocalScopeVariable v | node = TImplicitCapturedArgumentNode(_, v) | result = v.getType())
or
@@ -239,15 +240,6 @@ module DataFlowPrivateCached {
)
}
cached
Type getType(Node node) {
exists(DotNet::Type t | t = getDotNetType(node) |
result = t
or
t.matchesHandle(result)
)
}
cached
Location getLocation(Node node) {
result = node.(ExprNode).getExpr().getLocation()
@@ -1006,7 +998,7 @@ predicate readStep(Node node1, Content f, Node node2) {
none() // stub implementation
}
private predicate suppressUnusedType(Type t) { any() }
private predicate suppressUnusedType(DotNet::Type t) { any() }
/**
* Gets a representative type for `t` for the purpose of pruning possible flow.
@@ -1014,11 +1006,11 @@ private predicate suppressUnusedType(Type t) { any() }
* Type-based pruning is disabled for now, so this is a stub implementation.
*/
bindingset[t]
Type getErasedRepr(Type t) { suppressUnusedType(t) and result instanceof ObjectType } // stub implementation
Type getErasedRepr(DotNet::Type t) { suppressUnusedType(t) and result instanceof ObjectType } // stub implementation
/** Gets a string representation of a type returned by `getErasedRepr`. */
bindingset[t]
string ppReprType(Type t) { suppressUnusedType(t) and result = "" } // stub implementation
string ppReprType(DotNet::Type t) { suppressUnusedType(t) and result = "" } // stub implementation
/**
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
@@ -1027,7 +1019,7 @@ string ppReprType(Type t) { suppressUnusedType(t) and result = "" } // stub impl
* Type-based pruning is disabled for now, so this is a stub implementation.
*/
bindingset[t1, t2]
predicate compatibleTypes(Type t1, Type t2) {
predicate compatibleTypes(DotNet::Type t1, DotNet::Type t2) {
any() // stub implementation
}
@@ -1055,6 +1047,6 @@ class DataFlowCallable = DotNet::Callable;
class DataFlowExpr = DotNet::Expr;
class DataFlowType = Type;
class DataFlowType = DotNet::Type;
class DataFlowLocation = Location;

View File

@@ -25,10 +25,10 @@ class Node extends C::TNode {
DotNet::Parameter asParameter() { result = this.(ParameterNode).getParameter() }
/** Gets the type of this node. */
final Type getType() { result = C::getType(this) }
final DotNet::Type getType() { result = C::getType(this) }
/** Gets an upper bound on the type of this node. */
Type getTypeBound() { result = this.getType() } // stub implementation
DotNet::Type getTypeBound() { result = this.getType() } // stub implementation
/** Gets the enclosing callable of this node. */
final DotNet::Callable getEnclosingCallable() { result = C::getEnclosingCallable(this) }