Skip to content

Commit 84316c4

Browse files
committed
Java: Add more qldoc.
1 parent 90052a3 commit 84316c4

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,29 @@ private newtype TDataFlowCallable =
337337
TSummarizedCallable(SummarizedCallable c) or
338338
TFieldScope(Field f)
339339

340+
/**
341+
* A callable or scope enclosing some number of data flow nodes. This can either
342+
* be a source callable, a synthesized callable for which we have a summary
343+
* model, or a synthetic scope for a field value node.
344+
*/
340345
class DataFlowCallable extends TDataFlowCallable {
346+
/** Gets the source callable corresponding to this callable, if any. */
341347
Callable asCallable() { this = TSrcCallable(result) }
342348

349+
/** Gets the summary model callable corresponding to this callable, if any. */
343350
SummarizedCallable asSummarizedCallable() { this = TSummarizedCallable(result) }
344351

352+
/** Gets the field corresponding to this callable, if it is a field value scope. */
345353
Field asFieldScope() { this = TFieldScope(result) }
346354

355+
/** Gets a textual representation of this callable. */
347356
string toString() {
348357
result = this.asCallable().toString() or
349358
result = "Synthetic: " + this.asSummarizedCallable().toString() or
350359
result = "Field scope: " + this.asFieldScope().toString()
351360
}
352361

362+
/** Gets the location of this callable. */
353363
Location getLocation() {
354364
result = this.asCallable().getLocation() or
355365
result = this.asSummarizedCallable().getLocation() or

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowUtil.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ private predicate capturedVariableRead(Node n) {
139139
n.asExpr().(RValue).getVariable() instanceof CapturedVariable
140140
}
141141

142+
/**
143+
* Holds if there is a data flow step from `e1` to `e2` that only steps from
144+
* child to parent in the AST.
145+
*/
142146
predicate simpleAstFlowStep(Expr e1, Expr e2) {
143147
e2.(CastingExpr).getExpr() = e1
144148
or

shared/dataflow/codeql/dataflow/VariableCapture.qll

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,14 @@ module Flow<InputSig Input> implements OutputSig<Input> {
570570
pragma[only_bind_out](closureExprGetCallable(ce))
571571
}
572572

573-
/** Holds if we need an additional read of `v` TODO */
573+
/**
574+
* Holds if we need an additional read of `v` in the `i`th node of `bb` in
575+
* order to synchronize the value stored on `closure`.
576+
* `topScope` is true if the read is in the defining callable of `v`.
577+
*
578+
* Side-effects of potentially calling `closure` at this point will be
579+
* observed in a similarly synthesized post-update node for this read of `v`.
580+
*/
574581
private predicate synthRead(
575582
CapturedVariable v, BasicBlock bb, int i, boolean topScope, Expr closure
576583
) {
@@ -582,6 +589,10 @@ module Flow<InputSig Input> implements OutputSig<Input> {
582589
if v.getCallable() != bb.getEnclosingCallable() then topScope = false else topScope = true
583590
}
584591

592+
/**
593+
* Holds if there is an access of a captured variable inside a closure in the
594+
* `i`th node of `bb`, such that we need to synthesize a `this.` qualifier.
595+
*/
585596
private predicate synthThisQualifier(BasicBlock bb, int i) {
586597
synthRead(_, bb, i, false, _) or
587598
captureRead(_, bb, i, false, _) or
@@ -592,6 +603,11 @@ module Flow<InputSig Input> implements OutputSig<Input> {
592603
TVariable(CapturedVariable v) or
593604
TThis(Callable c) { captureAccess(_, c) }
594605

606+
/**
607+
* A storage location for a captured variable in a specific callable. This is
608+
* either the variable itself (in its defining scope) or an instance variable
609+
* `this` (in a capturing scope).
610+
*/
595611
private class CaptureContainer extends TCaptureContainer {
596612
string toString() {
597613
exists(CapturedVariable v | this = TVariable(v) and result = v.toString())
@@ -600,6 +616,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
600616
}
601617
}
602618

619+
/** Holds if `cc` needs a definition at the entry of its callable scope. */
603620
private predicate entryDef(CaptureContainer cc, BasicBlock bb, int i) {
604621
exists(Callable c |
605622
entryBlock(bb) and
@@ -681,6 +698,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
681698
TMallocNode(ClosureExpr ce) { hasConstructorCapture(ce, _) }
682699

683700
class ClosureNode extends TClosureNode {
701+
/** Gets a textual representation of this node. */
684702
string toString() {
685703
exists(CapturedVariable v | this = TSynthRead(v, _, _, _) and result = v.toString())
686704
or
@@ -705,6 +723,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
705723
result = "malloc" and this = TMallocNode(_)
706724
}
707725

726+
/** Gets the location of this node. */
708727
Location getLocation() {
709728
exists(CapturedVariable v, BasicBlock bb, int i, Expr closure |
710729
this = TSynthRead(v, bb, i, _) and
@@ -893,6 +912,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
893912
|
894913
post = true
895914
or
915+
// for a constructor call the regulare ExprNode is the post-update for the MallocNode
896916
post = false and hasConstructorCapture(closure, v)
897917
)
898918
or

0 commit comments

Comments
 (0)