Java: Add proper types for capture nodes.

This commit is contained in:
Anders Schack-Mulligen
2023-07-27 15:22:25 +02:00
parent e2a0849a0e
commit 90052a3ca2
2 changed files with 34 additions and 5 deletions

View File

@@ -167,6 +167,12 @@ signature module OutputSig<InputSig I> {
/** Gets the enclosing callable. */
I::Callable getEnclosingCallable();
/** Holds if this node is a synthesized access of `v`. */
predicate isVariableAccess(I::CapturedVariable v);
/** Holds if this node is a synthesized instance access. */
predicate isInstanceAccess();
}
/** A data flow node for an expression. */
@@ -740,6 +746,22 @@ module Flow<InputSig Input> implements OutputSig<Input> {
this = TSynthPhi(phi) and phi.definesAt(_, bb, _, _) and result = bb.getEnclosingCallable()
)
}
predicate isVariableAccess(CapturedVariable v) {
this = TSynthRead(v, _, _, _)
or
exists(CaptureSsa::DefinitionExt phi |
this = TSynthPhi(phi) and phi.definesAt(TVariable(v), _, _, _)
)
}
predicate isInstanceAccess() {
this instanceof TSynthThisQualifier
or
exists(CaptureSsa::DefinitionExt phi |
this = TSynthPhi(phi) and phi.definesAt(TThis(_), _, _, _)
)
}
}
class ExprNode extends ClosureNode, TExprNode {