@@ -115,9 +115,12 @@ private module Cached {
115115 TExprNode ( CfgNodes:: ExprCfgNode n ) or
116116 TReturningNode ( CfgNodes:: ReturningCfgNode n ) or
117117 TSsaDefinitionNode ( Ssa:: Definition def ) or
118- TParameterNode ( Parameter p ) or
118+ TNormalParameterNode ( Parameter p ) { not p instanceof BlockParameter } or
119+ TBlockParameterNode ( MethodBase m ) or
119120 TExprPostUpdateNode ( CfgNodes:: ExprCfgNode n ) { n .getNode ( ) instanceof Argument }
120121
122+ class TParameterNode = TNormalParameterNode or TBlockParameterNode ;
123+
121124 /**
122125 * This is the local flow predicate that is used as a building block in global
123126 * data flow. It excludes SSA flow through instance fields, as flow through fields
@@ -136,6 +139,8 @@ private module Cached {
136139 or
137140 nodeFrom .asExpr ( ) = nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: AssignExprCfgNode ) .getRhs ( )
138141 or
142+ nodeFrom .asExpr ( ) = nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: BlockArgumentCfgNode ) .getValue ( )
143+ or
139144 nodeFrom .asExpr ( ) = nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: StmtSequenceCfgNode ) .getLastStmt ( )
140145 or
141146 nodeFrom .asExpr ( ) = nodeTo .asExpr ( ) .( CfgNodes:: ExprNodes:: ConditionalExprCfgNode ) .getBranch ( _)
@@ -221,10 +226,10 @@ private module ParameterNodes {
221226 * The value of an explicit parameter at function entry, viewed as a node in a data
222227 * flow graph.
223228 */
224- class ExplicitParameterNode extends ParameterNodeImpl , TParameterNode {
229+ class ExplicitParameterNode extends ParameterNodeImpl , TNormalParameterNode {
225230 private Parameter parameter ;
226231
227- ExplicitParameterNode ( ) { this = TParameterNode ( parameter ) }
232+ ExplicitParameterNode ( ) { this = TNormalParameterNode ( parameter ) }
228233
229234 override Parameter getParameter ( ) { result = parameter }
230235
@@ -236,6 +241,38 @@ private module ParameterNodes {
236241
237242 override string toStringImpl ( ) { result = parameter .toString ( ) }
238243 }
244+
245+ /**
246+ * The value of a block parameter at function entry, viewed as a node in a data
247+ * flow graph.
248+ */
249+ class BlockParameterNode extends ParameterNodeImpl , TBlockParameterNode {
250+ private MethodBase method ;
251+
252+ BlockParameterNode ( ) { this = TBlockParameterNode ( method ) }
253+
254+ final MethodBase getMethod ( ) { result = method }
255+
256+ override Parameter getParameter ( ) {
257+ result = method .getAParameter ( ) and result instanceof BlockParameter
258+ }
259+
260+ override predicate isParameterOf ( Callable c , int i ) { c = method and i = - 2 }
261+
262+ override CfgScope getCfgScope ( ) { result = method }
263+
264+ override Location getLocationImpl ( ) {
265+ result = getParameter ( ) .getLocation ( )
266+ or
267+ not exists ( getParameter ( ) ) and result = method .getLocation ( )
268+ }
269+
270+ override string toStringImpl ( ) {
271+ result = getParameter ( ) .toString ( )
272+ or
273+ not exists ( getParameter ( ) ) and result = "&block"
274+ }
275+ }
239276}
240277
241278import ParameterNodes
@@ -253,7 +290,10 @@ abstract class ArgumentNode extends Node {
253290private module ArgumentNodes {
254291 /** A data-flow node that represents an explicit call argument. */
255292 class ExplicitArgumentNode extends ArgumentNode {
256- ExplicitArgumentNode ( ) { this .asExpr ( ) .getExpr ( ) instanceof Argument }
293+ ExplicitArgumentNode ( ) {
294+ this .asExpr ( ) .getExpr ( ) instanceof Argument and
295+ not this .asExpr ( ) .getExpr ( ) instanceof BlockArgument
296+ }
257297
258298 override predicate argumentOf ( DataFlowCall call , int pos ) {
259299 this .asExpr ( ) = call .getReceiver ( ) and
@@ -262,6 +302,27 @@ private module ArgumentNodes {
262302 this .asExpr ( ) = call .getArgument ( pos )
263303 }
264304 }
305+
306+ /** A data-flow node that represents a block argument. */
307+ class BlockArgumentNode extends ArgumentNode {
308+ BlockArgumentNode ( ) {
309+ this .asExpr ( ) .getExpr ( ) instanceof BlockArgument or
310+ exists ( CfgNodes:: ExprNodes:: CallCfgNode c | c .getBlock ( ) = this .asExpr ( ) )
311+ }
312+
313+ override predicate argumentOf ( DataFlowCall call , int pos ) {
314+ pos = - 2 and
315+ (
316+ this .asExpr ( ) = call .getBlock ( )
317+ or
318+ exists ( CfgNodes:: ExprCfgNode arg , int n |
319+ arg = call .getArgument ( n ) and
320+ this .asExpr ( ) = arg and
321+ arg .getExpr ( ) instanceof BlockArgument
322+ )
323+ )
324+ }
325+ }
265326}
266327
267328import ArgumentNodes
0 commit comments