@@ -843,17 +843,20 @@ private module CaptureInput implements VariableCapture::InputSig {
843
843
BasicBlock getABasicBlockSuccessor ( BasicBlock bb ) { result = bb .( B:: BasicBlock ) .getASuccessor ( ) }
844
844
845
845
//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
+
847
852
string toString ( ) { result = super .toString ( ) }
848
853
849
- Callable getCallable ( ) { result = super .getScope ( ) }
854
+ Callable getCallable ( ) { result = super .getEnclosingCallable ( ) }
850
855
851
856
Location getLocation ( ) { result = super .getLocation ( ) }
852
857
}
853
858
854
- class CapturedParameter extends CapturedVariable {
855
- CapturedParameter ( ) { this .( S:: CapturedDecl ) .getDecl ( ) instanceof S:: ParamDecl }
856
- }
859
+ class CapturedParameter extends CapturedVariable instanceof S:: ParamDecl { }
857
860
858
861
class Expr instanceof S:: AstNode {
859
862
string toString ( ) { result = super .toString ( ) }
@@ -870,23 +873,16 @@ private module CaptureInput implements VariableCapture::InputSig {
870
873
Expr source ;
871
874
872
875
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 ( )
889
884
)
885
+ // TODO: support multiple variables in LHS of =, in both of above cases.
890
886
}
891
887
892
888
CapturedVariable getVariable ( ) { result = variable }
@@ -897,7 +893,7 @@ private module CaptureInput implements VariableCapture::InputSig {
897
893
class VariableRead extends Expr instanceof S:: DeclRefExpr {
898
894
CapturedVariable v ;
899
895
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. */ }
901
897
902
898
CapturedVariable getVariable ( ) { result = v }
903
899
}
@@ -926,7 +922,7 @@ private CaptureFlow::ClosureNode asClosureNode(Node n) {
926
922
result .( CaptureFlow:: ExprNode ) .getExpr ( ) = n .asExpr ( ) or
927
923
result .( CaptureFlow:: ExprPostUpdateNode ) .getExpr ( ) =
928
924
n .( PostUpdateNode ) .getPreUpdateNode ( ) .asExpr ( ) or
929
- result .( CaptureFlow:: ParameterNode ) .getParameter ( ) . ( CapturedDecl ) . getDecl ( ) = n .getParameter ( ) or
925
+ result .( CaptureFlow:: ParameterNode ) .getParameter ( ) = n .getParameter ( ) or
930
926
result .( CaptureFlow:: ThisParameterNode ) .getCallable ( ) .getSelfParam ( ) = n .getParameter ( ) or
931
927
result .( CaptureFlow:: MallocNode ) .getClosureExpr ( ) = n .getCfgNode ( ) .getNode ( ) .asAstNode ( ) // TODO: figure out why the java version had PostUpdateNode logic here
932
928
}
0 commit comments