@@ -21,9 +21,11 @@ private import semmle.code.csharp.frameworks.system.threading.Tasks
2121
2222abstract class NodeImpl extends Node {
2323 /** Do not call: use `getEnclosingCallable()` instead. */
24+ cached
2425 abstract DataFlowCallable getEnclosingCallableImpl ( ) ;
2526
2627 /** Do not call: use `getType()` instead. */
28+ cached
2729 abstract DotNet:: Type getTypeImpl ( ) ;
2830
2931 /** Gets the type of this node used for type pruning. */
@@ -39,27 +41,39 @@ abstract class NodeImpl extends Node {
3941 }
4042
4143 /** Do not call: use `getControlFlowNode()` instead. */
44+ cached
4245 abstract ControlFlow:: Node getControlFlowNodeImpl ( ) ;
4346
4447 /** Do not call: use `getLocation()` instead. */
48+ cached
4549 abstract Location getLocationImpl ( ) ;
4650
4751 /** Do not call: use `toString()` instead. */
52+ cached
4853 abstract string toStringImpl ( ) ;
4954}
5055
5156private class ExprNodeImpl extends ExprNode , NodeImpl {
5257 override DataFlowCallable getEnclosingCallableImpl ( ) {
58+ Stages:: DataFlowStage:: forceCachingInSameStage ( ) and
5359 result = this .getExpr ( ) .getEnclosingCallable ( )
5460 }
5561
56- override DotNet:: Type getTypeImpl ( ) { result = this .getExpr ( ) .getType ( ) }
62+ override DotNet:: Type getTypeImpl ( ) {
63+ Stages:: DataFlowStage:: forceCachingInSameStage ( ) and
64+ result = this .getExpr ( ) .getType ( )
65+ }
5766
58- override ControlFlow:: Nodes:: ElementNode getControlFlowNodeImpl ( ) { this = TExprNode ( result ) }
67+ override ControlFlow:: Nodes:: ElementNode getControlFlowNodeImpl ( ) {
68+ Stages:: DataFlowStage:: forceCachingInSameStage ( ) and this = TExprNode ( result )
69+ }
5970
60- override Location getLocationImpl ( ) { result = this .getExpr ( ) .getLocation ( ) }
71+ override Location getLocationImpl ( ) {
72+ Stages:: DataFlowStage:: forceCachingInSameStage ( ) and result = this .getExpr ( ) .getLocation ( )
73+ }
6174
6275 override string toStringImpl ( ) {
76+ Stages:: DataFlowStage:: forceCachingInSameStage ( ) and
6377 result = this .getControlFlowNode ( ) .toString ( )
6478 or
6579 exists ( CIL:: Expr e |
@@ -967,6 +981,16 @@ private module Cached {
967981 or
968982 n .asExpr ( ) = any ( WithExpr we ) .getInitializer ( )
969983 }
984+
985+ cached
986+ predicate parameterNode ( Node n , DataFlowCallable c , int i ) {
987+ n .( ParameterNodeImpl ) .isParameterOf ( c , i )
988+ }
989+
990+ cached
991+ predicate argumentNode ( Node n , DataFlowCall call , int pos ) {
992+ n .( ArgumentNodeImpl ) .argumentOf ( call , pos )
993+ }
970994}
971995
972996import Cached
@@ -992,8 +1016,6 @@ class SsaDefinitionNode extends NodeImpl, TSsaDefinitionNode {
9921016}
9931017
9941018abstract class ParameterNodeImpl extends NodeImpl {
995- abstract DotNet:: Parameter getParameter ( ) ;
996-
9971019 abstract predicate isParameterOf ( DataFlowCallable c , int i ) ;
9981020}
9991021
@@ -1010,11 +1032,9 @@ private module ParameterNodes {
10101032 /** Gets the SSA definition corresponding to this parameter, if any. */
10111033 Ssa:: ExplicitDefinition getSsaDefinition ( ) {
10121034 result .getADefinition ( ) .( AssignableDefinitions:: ImplicitParameterDefinition ) .getParameter ( ) =
1013- this . getParameter ( )
1035+ parameter
10141036 }
10151037
1016- override DotNet:: Parameter getParameter ( ) { result = parameter }
1017-
10181038 override predicate isParameterOf ( DataFlowCallable c , int i ) { c .getParameter ( i ) = parameter }
10191039
10201040 override DataFlowCallable getEnclosingCallableImpl ( ) { result = parameter .getCallable ( ) }
@@ -1037,8 +1057,6 @@ private module ParameterNodes {
10371057 /** Gets the callable containing this implicit instance parameter. */
10381058 Callable getCallable ( ) { result = callable }
10391059
1040- override DotNet:: Parameter getParameter ( ) { none ( ) }
1041-
10421060 override predicate isParameterOf ( DataFlowCallable c , int pos ) { callable = c and pos = - 1 }
10431061
10441062 override DataFlowCallable getEnclosingCallableImpl ( ) { result = callable }
@@ -1113,8 +1131,6 @@ private module ParameterNodes {
11131131 /** Gets the captured variable that this implicit parameter models. */
11141132 LocalScopeVariable getVariable ( ) { result = def .getVariable ( ) }
11151133
1116- override DotNet:: Parameter getParameter ( ) { none ( ) }
1117-
11181134 override predicate isParameterOf ( DataFlowCallable c , int i ) {
11191135 i = getParameterPosition ( def ) and
11201136 c = this .getEnclosingCallable ( )
@@ -1125,13 +1141,15 @@ private module ParameterNodes {
11251141import ParameterNodes
11261142
11271143/** A data-flow node that represents a call argument. */
1128- abstract class ArgumentNode extends Node {
1144+ class ArgumentNode extends Node {
1145+ ArgumentNode ( ) { argumentNode ( this , _, _) }
1146+
11291147 /** Holds if this argument occurs at the given position in the given call. */
1130- cached
1131- abstract predicate argumentOf ( DataFlowCall call , int pos ) ;
1148+ final predicate argumentOf ( DataFlowCall call , int pos ) { argumentNode ( this , call , pos ) }
1149+ }
11321150
1133- /** Gets the call in which this node is an argument. */
1134- final DataFlowCall getCall ( ) { this . argumentOf ( result , _ ) }
1151+ abstract private class ArgumentNodeImpl extends Node {
1152+ abstract predicate argumentOf ( DataFlowCall call , int pos ) ;
11351153}
11361154
11371155private module ArgumentNodes {
@@ -1149,15 +1167,14 @@ private module ArgumentNodes {
11491167 }
11501168
11511169 /** A data-flow node that represents an explicit call argument. */
1152- class ExplicitArgumentNode extends ArgumentNode {
1170+ class ExplicitArgumentNode extends ArgumentNodeImpl {
11531171 ExplicitArgumentNode ( ) {
11541172 this .asExpr ( ) instanceof Argument
11551173 or
11561174 this .asExpr ( ) = any ( CIL:: Call call ) .getAnArgument ( )
11571175 }
11581176
11591177 override predicate argumentOf ( DataFlowCall call , int pos ) {
1160- Stages:: DataFlowStage:: forceCachingInSameStage ( ) and
11611178 exists ( ArgumentConfiguration x , Expr c , Argument arg |
11621179 arg = this .asExpr ( ) and
11631180 c = call .getExpr ( ) and
@@ -1189,7 +1206,8 @@ private module ArgumentNodes {
11891206 * } }
11901207 * ```
11911208 */
1192- class ImplicitCapturedArgumentNode extends ArgumentNode , NodeImpl , TImplicitCapturedArgumentNode {
1209+ class ImplicitCapturedArgumentNode extends ArgumentNodeImpl , NodeImpl ,
1210+ TImplicitCapturedArgumentNode {
11931211 private LocalScopeVariable v ;
11941212 private ControlFlow:: Nodes:: ElementNode cfn ;
11951213
@@ -1231,7 +1249,7 @@ private module ArgumentNodes {
12311249 * A node that corresponds to the value of an object creation (`new C()`) before
12321250 * the constructor has run.
12331251 */
1234- class MallocNode extends ArgumentNode , NodeImpl , TMallocNode {
1252+ class MallocNode extends ArgumentNodeImpl , NodeImpl , TMallocNode {
12351253 private ControlFlow:: Nodes:: ElementNode cfn ;
12361254
12371255 MallocNode ( ) { this = TMallocNode ( cfn ) }
@@ -1266,7 +1284,7 @@ private module ArgumentNodes {
12661284 * and that argument is itself a compatible array, for example
12671285 * `Foo(new[] { "a", "b", "c" })`.
12681286 */
1269- class ParamsArgumentNode extends ArgumentNode , NodeImpl , TParamsArgumentNode {
1287+ class ParamsArgumentNode extends ArgumentNodeImpl , NodeImpl , TParamsArgumentNode {
12701288 private ControlFlow:: Node callCfn ;
12711289
12721290 ParamsArgumentNode ( ) { this = TParamsArgumentNode ( callCfn ) }
@@ -1291,7 +1309,7 @@ private module ArgumentNodes {
12911309 override string toStringImpl ( ) { result = "[implicit array creation] " + callCfn }
12921310 }
12931311
1294- private class SummaryArgumentNode extends SummaryNode , ArgumentNode {
1312+ private class SummaryArgumentNode extends SummaryNode , ArgumentNodeImpl {
12951313 private DataFlowCall c ;
12961314 private int i ;
12971315
@@ -1324,10 +1342,7 @@ private module ReturnNodes {
13241342 )
13251343 }
13261344
1327- override NormalReturnKind getKind ( ) {
1328- any ( DotNet:: Callable c ) .canReturn ( this .getExpr ( ) ) and
1329- exists ( result )
1330- }
1345+ override NormalReturnKind getKind ( ) { exists ( result ) }
13311346 }
13321347
13331348 /**
@@ -1744,7 +1759,10 @@ class DataFlowType extends Gvn::GvnType {
17441759}
17451760
17461761/** Gets the type of `n` used for type pruning. */
1747- DataFlowType getNodeType ( NodeImpl n ) { result = n .getDataFlowType ( ) }
1762+ pragma [ inline]
1763+ Gvn:: GvnType getNodeType ( NodeImpl n ) {
1764+ pragma [ only_bind_into ] ( result ) = pragma [ only_bind_out ] ( n ) .getDataFlowType ( )
1765+ }
17481766
17491767/** Gets a string representation of a `DataFlowType`. */
17501768string ppReprType ( DataFlowType t ) { result = t .toString ( ) }
@@ -1819,7 +1837,8 @@ private module PostUpdateNodes {
18191837 * Such a node acts as both a post-update node for the `MallocNode`, as well as
18201838 * a pre-update node for the `ObjectCreationNode`.
18211839 */
1822- class ObjectInitializerNode extends PostUpdateNode , NodeImpl , ArgumentNode , TObjectInitializerNode {
1840+ class ObjectInitializerNode extends PostUpdateNode , NodeImpl , ArgumentNodeImpl ,
1841+ TObjectInitializerNode {
18231842 private ObjectCreation oc ;
18241843 private ControlFlow:: Nodes:: ElementNode cfn ;
18251844
0 commit comments