Skip to content

Commit a89505b

Browse files
committed
C#: Simplify DataFlow::Node::getType()
1 parent 7b7a1ec commit a89505b

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,17 @@ module DataFlowPrivateCached {
221221
)
222222
}
223223

224-
private DotNet::Type getDotNetType(Node node) {
224+
cached
225+
DotNet::Type getType(Node node) {
225226
result = node.(ExprNode).getExpr().getType()
226227
or
227228
result = node.(SsaDefinitionNode).getDefinition().getSourceVariable().getType()
228229
or
229230
exists(CIL::Parameter p | node = TCilParameterNode(p) | result = p.getType())
230231
or
231-
result = getDotNetType(node.(TaintedParameterNode).getUnderlyingNode())
232+
result = getType(node.(TaintedParameterNode).getUnderlyingNode())
232233
or
233-
result = getDotNetType(node.(TaintedReturnNode).getUnderlyingNode())
234+
result = getType(node.(TaintedReturnNode).getUnderlyingNode())
234235
or
235236
exists(LocalScopeVariable v | node = TImplicitCapturedArgumentNode(_, v) | result = v.getType())
236237
or
@@ -239,15 +240,6 @@ module DataFlowPrivateCached {
239240
)
240241
}
241242

242-
cached
243-
Type getType(Node node) {
244-
exists(DotNet::Type t | t = getDotNetType(node) |
245-
result = t
246-
or
247-
t.matchesHandle(result)
248-
)
249-
}
250-
251243
cached
252244
Location getLocation(Node node) {
253245
result = node.(ExprNode).getExpr().getLocation()
@@ -1006,19 +998,19 @@ predicate readStep(Node node1, Content f, Node node2) {
1006998
none() // stub implementation
1007999
}
10081000

1009-
private predicate suppressUnusedType(Type t) { any() }
1001+
private predicate suppressUnusedType(DotNet::Type t) { any() }
10101002

10111003
/**
10121004
* Gets a representative type for `t` for the purpose of pruning possible flow.
10131005
*
10141006
* Type-based pruning is disabled for now, so this is a stub implementation.
10151007
*/
10161008
bindingset[t]
1017-
Type getErasedRepr(Type t) { suppressUnusedType(t) and result instanceof ObjectType } // stub implementation
1009+
Type getErasedRepr(DotNet::Type t) { suppressUnusedType(t) and result instanceof ObjectType } // stub implementation
10181010

10191011
/** Gets a string representation of a type returned by `getErasedRepr`. */
10201012
bindingset[t]
1021-
string ppReprType(Type t) { suppressUnusedType(t) and result = "" } // stub implementation
1013+
string ppReprType(DotNet::Type t) { suppressUnusedType(t) and result = "" } // stub implementation
10221014

10231015
/**
10241016
* 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
10271019
* Type-based pruning is disabled for now, so this is a stub implementation.
10281020
*/
10291021
bindingset[t1, t2]
1030-
predicate compatibleTypes(Type t1, Type t2) {
1022+
predicate compatibleTypes(DotNet::Type t1, DotNet::Type t2) {
10311023
any() // stub implementation
10321024
}
10331025

@@ -1055,6 +1047,6 @@ class DataFlowCallable = DotNet::Callable;
10551047

10561048
class DataFlowExpr = DotNet::Expr;
10571049

1058-
class DataFlowType = Type;
1050+
class DataFlowType = DotNet::Type;
10591051

10601052
class DataFlowLocation = Location;

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowPublic.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class Node extends C::TNode {
2525
DotNet::Parameter asParameter() { result = this.(ParameterNode).getParameter() }
2626

2727
/** Gets the type of this node. */
28-
final Type getType() { result = C::getType(this) }
28+
final DotNet::Type getType() { result = C::getType(this) }
2929

3030
/** Gets an upper bound on the type of this node. */
31-
Type getTypeBound() { result = this.getType() } // stub implementation
31+
DotNet::Type getTypeBound() { result = this.getType() } // stub implementation
3232

3333
/** Gets the enclosing callable of this node. */
3434
final DotNet::Callable getEnclosingCallable() { result = C::getEnclosingCallable(this) }

0 commit comments

Comments
 (0)