@@ -843,17 +843,20 @@ private module CaptureInput implements VariableCapture::InputSig {
843843 BasicBlock getABasicBlockSuccessor ( BasicBlock bb ) { result = bb .( B:: BasicBlock ) .getASuccessor ( ) }
844844
845845 //TODO: support capture of `this` in lambdas
846- class CapturedVariable instanceof S:: CapturedDecl {
846+ class CapturedVariable instanceof S:: VarDecl {
847+ CapturedVariable ( ) {
848+ any ( S:: CapturedDecl capturedDecl ) .getDecl ( ) = this and
849+ exists ( this .getEnclosingCallable ( ) )
850+ }
851+
847852 string toString ( ) { result = super .toString ( ) }
848853
849- Callable getCallable ( ) { result = super .getScope ( ) }
854+ Callable getCallable ( ) { result = super .getEnclosingCallable ( ) }
850855
851856 Location getLocation ( ) { result = super .getLocation ( ) }
852857 }
853858
854- class CapturedParameter extends CapturedVariable {
855- CapturedParameter ( ) { this .( S:: CapturedDecl ) .getDecl ( ) instanceof S:: ParamDecl }
856- }
859+ class CapturedParameter extends CapturedVariable instanceof S:: ParamDecl { }
857860
858861 class Expr instanceof S:: AstNode {
859862 string toString ( ) { result = super .toString ( ) }
@@ -870,23 +873,16 @@ private module CaptureInput implements VariableCapture::InputSig {
870873 Expr source ;
871874
872875 VariableWrite ( ) {
873- exists ( S:: VarDecl varDecl |
874- variable .( S:: CapturedDecl ) .getDecl ( ) = varDecl and
875- variable .getCallable ( ) = this .( S:: AstNode ) .getEnclosingCallable ( )
876- |
877- exists ( S:: Assignment a | this = a |
878- a .getDest ( ) .( DeclRefExpr ) .getDecl ( ) = varDecl and
879- source = a .getSource ( )
880- )
881- or
882- exists ( S:: PatternBindingDecl pbd , S:: NamedPattern np |
883- this = pbd and pbd .getAPattern ( ) = np
884- |
885- np .getVarDecl ( ) = varDecl and
886- source = np .getMatchingExpr ( )
887- )
888- // TODO: support multiple variables in LHS of =, in both of above cases.
876+ exists ( S:: Assignment a | this = a |
877+ a .getDest ( ) .( DeclRefExpr ) .getDecl ( ) = variable and
878+ source = a .getSource ( )
879+ )
880+ or
881+ exists ( S:: PatternBindingDecl pbd , S:: NamedPattern np | this = pbd and pbd .getAPattern ( ) = np |
882+ np .getVarDecl ( ) = variable and
883+ source = np .getMatchingExpr ( )
889884 )
885+ // TODO: support multiple variables in LHS of =, in both of above cases.
890886 }
891887
892888 CapturedVariable getVariable ( ) { result = variable }
@@ -897,7 +893,7 @@ private module CaptureInput implements VariableCapture::InputSig {
897893 class VariableRead extends Expr instanceof S:: DeclRefExpr {
898894 CapturedVariable v ;
899895
900- VariableRead ( ) { this .getCapturedDecl ( ) = v /* TODO: this should be an R-value only. */ }
896+ VariableRead ( ) { this .getDecl ( ) = v /* TODO: this should be an R-value only. */ }
901897
902898 CapturedVariable getVariable ( ) { result = v }
903899 }
@@ -926,7 +922,7 @@ private CaptureFlow::ClosureNode asClosureNode(Node n) {
926922 result .( CaptureFlow:: ExprNode ) .getExpr ( ) = n .asExpr ( ) or
927923 result .( CaptureFlow:: ExprPostUpdateNode ) .getExpr ( ) =
928924 n .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) or
929- result .( CaptureFlow:: ParameterNode ) .getParameter ( ) . ( CapturedDecl ) . getDecl ( ) = n .getParameter ( ) or
925+ result .( CaptureFlow:: ParameterNode ) .getParameter ( ) = n .getParameter ( ) or
930926 result .( CaptureFlow:: ThisParameterNode ) .getCallable ( ) .getSelfParam ( ) = n .getParameter ( ) or
931927 result .( CaptureFlow:: MallocNode ) .getClosureExpr ( ) = n .getCfgNode ( ) .getNode ( ) .asAstNode ( ) // TODO: figure out why the java version had PostUpdateNode logic here
932928}
0 commit comments