@@ -116,10 +116,11 @@ private module Cached {
116116 TReturningNode ( CfgNodes:: ReturningCfgNode n ) or
117117 TSsaDefinitionNode ( Ssa:: Definition def ) or
118118 TNormalParameterNode ( Parameter p ) { not p instanceof BlockParameter } or
119+ TSelfParameterNode ( MethodBase m ) or
119120 TBlockParameterNode ( MethodBase m ) or
120121 TExprPostUpdateNode ( CfgNodes:: ExprCfgNode n ) { n .getNode ( ) instanceof Argument }
121122
122- class TParameterNode = TNormalParameterNode or TBlockParameterNode ;
123+ class TParameterNode = TNormalParameterNode or TBlockParameterNode or TSelfParameterNode ;
123124
124125 /**
125126 * This is the local flow predicate that is used as a building block in global
@@ -137,6 +138,9 @@ private module Cached {
137138 nodeTo .( ParameterNode ) .getParameter ( ) .( KeywordParameter ) .getDefaultValue ( ) =
138139 nodeFrom .asExpr ( ) .getExpr ( )
139140 or
141+ nodeFrom .( SelfParameterNode ) .getMethod ( ) = nodeTo .asExpr ( ) .getExpr ( ) .getEnclosingMethod ( ) and
142+ nodeTo .asExpr ( ) .getExpr ( ) instanceof Self
143+ or
140144 nodeFrom .asExpr ( ) = nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: AssignExprCfgNode ) .getRhs ( )
141145 or
142146 nodeFrom .asExpr ( ) = nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: BlockArgumentCfgNode ) .getValue ( )
@@ -242,6 +246,26 @@ private module ParameterNodes {
242246 override string toStringImpl ( ) { result = parameter .toString ( ) }
243247 }
244248
249+ /**
250+ * The value of the `self` parameter at function entry, viewed as a node in a data
251+ * flow graph.
252+ */
253+ class SelfParameterNode extends ParameterNodeImpl , TSelfParameterNode {
254+ private MethodBase method ;
255+
256+ SelfParameterNode ( ) { this = TSelfParameterNode ( method ) }
257+
258+ final MethodBase getMethod ( ) { result = method }
259+
260+ override predicate isParameterOf ( Callable c , int i ) { method = c and i = - 1 }
261+
262+ override CfgScope getCfgScope ( ) { result = method }
263+
264+ override Location getLocationImpl ( ) { result = method .getLocation ( ) }
265+
266+ override string toStringImpl ( ) { result = "self in " + method .toString ( ) }
267+ }
268+
245269 /**
246270 * The value of a block parameter at function entry, viewed as a node in a data
247271 * flow graph.
@@ -295,11 +319,18 @@ private module ArgumentNodes {
295319 not this .asExpr ( ) .getExpr ( ) instanceof BlockArgument
296320 }
297321
322+ override predicate argumentOf ( DataFlowCall call , int pos ) {
323+ this .asExpr ( ) = call .getArgument ( pos )
324+ }
325+ }
326+
327+ /** A data-flow node that represents the `self` argument of a call. */
328+ class SelfArgumentNode extends ArgumentNode {
329+ SelfArgumentNode ( ) { this .asExpr ( ) = any ( CfgNodes:: ExprNodes:: CallCfgNode call ) .getReceiver ( ) }
330+
298331 override predicate argumentOf ( DataFlowCall call , int pos ) {
299332 this .asExpr ( ) = call .getReceiver ( ) and
300333 pos = - 1
301- or
302- this .asExpr ( ) = call .getArgument ( pos )
303334 }
304335 }
305336
0 commit comments