Skip to content

Commit ef1778a

Browse files
authored
Merge pull request #2212 from yh-semmle/java13-ql
Java: support JDK 13
2 parents 426565a + e232f53 commit ef1778a

File tree

7 files changed

+50
-49
lines changed

7 files changed

+50
-49
lines changed

java/ql/src/config/semmlecode.dbscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ case @stmt.kind of
494494
| 20 = @superconstructorinvocationstmt
495495
| 21 = @case
496496
| 22 = @catchclause
497+
| 23 = @yieldstmt
497498
;
498499

499500
#keyset[parent,idx]

java/ql/src/config/semmlecode.dbscheme.stats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@
189189
<v>28672</v>
190190
</e>
191191
<e>
192+
<k>@yieldstmt</k>
193+
<v>100</v>
194+
</e>
195+
<e>
192196
<k>@arrayaccess</k>
193197
<v>53561</v>
194198
</e>

java/ql/src/semmle/code/java/Completion.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ newtype Completion =
5252
(innerValue = true or innerValue = false)
5353
} or
5454
/**
55-
* The expression or statement completes via a `break` statement without a value.
55+
* The expression or statement completes via a `break` statement.
5656
*/
5757
BreakCompletion(MaybeLabel l) or
5858
/**
59-
* The expression or statement completes via a value `break` statement.
59+
* The expression or statement completes via a `yield` statement.
6060
*/
61-
ValueBreakCompletion(NormalOrBooleanCompletion c) or
61+
YieldCompletion(NormalOrBooleanCompletion c) or
6262
/**
6363
* The expression or statement completes via a `continue` statement.
6464
*/

java/ql/src/semmle/code/java/ControlFlowGraph.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -804,23 +804,23 @@ private module ControlFlowGraphImpl {
804804
or
805805
// handle `switch` expression
806806
exists(SwitchExpr switch | switch = n |
807-
// value `break` terminates the `switch`
808-
last(switch.getAStmt(), last, ValueBreakCompletion(completion))
807+
// `yield` terminates the `switch`
808+
last(switch.getAStmt(), last, YieldCompletion(completion))
809809
or
810810
// any other abnormal completion is propagated
811811
last(switch.getAStmt(), last, completion) and
812-
not completion instanceof ValueBreakCompletion and
812+
not completion instanceof YieldCompletion and
813813
completion != NormalCompletion()
814814
)
815815
or
816816
// the last node in a case rule is the last node in the right-hand side
817817
last(n.(SwitchCase).getRuleStatement(), last, completion)
818818
or
819-
// ...and if the rhs is an expression we wrap the completion as a value break
819+
// ...and if the rhs is an expression we wrap the completion as a yield
820820
exists(Completion caseCompletion |
821821
last(n.(SwitchCase).getRuleExpression(), last, caseCompletion) and
822822
if caseCompletion instanceof NormalOrBooleanCompletion
823-
then completion = ValueBreakCompletion(caseCompletion)
823+
then completion = YieldCompletion(caseCompletion)
824824
else completion = caseCompletion
825825
)
826826
or
@@ -833,18 +833,18 @@ private module ControlFlowGraphImpl {
833833
// `throw` statements or throwing calls give rise to ` Throw` completion
834834
exists(ThrowableType tt | mayThrow(n, tt) | last = n and completion = ThrowCompletion(tt))
835835
or
836-
// `break` statements without value give rise to a `Break` completion
837-
exists(BreakStmt break | break = n and last = n and not break.hasValue() |
836+
// `break` statements give rise to a `Break` completion
837+
exists(BreakStmt break | break = n and last = n |
838838
completion = labelledBreakCompletion(MkLabel(break.getLabel()))
839839
or
840840
not exists(break.getLabel()) and completion = anonymousBreakCompletion()
841841
)
842842
or
843-
// value break statements get their completion wrapped as a value break
843+
// yield statements get their completion wrapped as a yield
844844
exists(Completion caseCompletion |
845-
last(n.(BreakStmt).getValue(), last, caseCompletion) and
845+
last(n.(YieldStmt).getValue(), last, caseCompletion) and
846846
if caseCompletion instanceof NormalOrBooleanCompletion
847-
then completion = ValueBreakCompletion(caseCompletion)
847+
then completion = YieldCompletion(caseCompletion)
848848
else completion = caseCompletion
849849
)
850850
or
@@ -1112,9 +1112,9 @@ private module ControlFlowGraphImpl {
11121112
n = case and result = first(case.getRuleStatement())
11131113
)
11141114
or
1115-
// Value break
1116-
exists(BreakStmt break | completion = NormalCompletion() |
1117-
n = break and result = first(break.getValue())
1115+
// Yield
1116+
exists(YieldStmt yield | completion = NormalCompletion() |
1117+
n = yield and result = first(yield.getValue())
11181118
)
11191119
or
11201120
// Synchronized statements execute their expression _before_ synchronization, so the CFG reflects that.

java/ql/src/semmle/code/java/Expr.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ class ConditionalExpr extends Expr, @conditionalexpr {
10841084
}
10851085

10861086
/**
1087-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
1087+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
10881088
*
10891089
* A `switch` expression.
10901090
*/
@@ -1117,7 +1117,7 @@ class SwitchExpr extends Expr, @switchexpr {
11171117
Expr getAResult() {
11181118
result = getACase().getRuleExpression()
11191119
or
1120-
exists(BreakStmt break | break.(JumpStmt).getTarget() = this and result = break.getValue())
1120+
exists(YieldStmt yield | yield.(JumpStmt).getTarget() = this and result = yield.getValue())
11211121
}
11221122

11231123
/** Gets a printable representation of this expression. */

java/ql/src/semmle/code/java/Statement.qll

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class SwitchCase extends Stmt, @case {
417417
SwitchStmt getSwitch() { result.getACase() = this }
418418

419419
/**
420-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
420+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
421421
*
422422
* Gets the switch expression to which this case belongs, if any.
423423
*/
@@ -432,7 +432,7 @@ class SwitchCase extends Stmt, @case {
432432
}
433433

434434
/**
435-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
435+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
436436
*
437437
* Holds if this `case` is a switch labeled rule of the form `... -> ...`.
438438
*/
@@ -443,14 +443,14 @@ class SwitchCase extends Stmt, @case {
443443
}
444444

445445
/**
446-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
446+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
447447
*
448448
* Gets the expression on the right-hand side of the arrow, if any.
449449
*/
450450
Expr getRuleExpression() { result.getParent() = this and result.getIndex() = -1 }
451451

452452
/**
453-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
453+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
454454
*
455455
* Gets the statement on the right-hand side of the arrow, if any.
456456
*/
@@ -465,7 +465,7 @@ class ConstCase extends SwitchCase {
465465
Expr getValue() { result.getParent() = this and result.getIndex() = 0 }
466466

467467
/**
468-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
468+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
469469
*
470470
* Gets the `case` constant at the specified index.
471471
*/
@@ -558,10 +558,11 @@ class ThrowStmt extends Stmt, @throwstmt {
558558
}
559559
}
560560

561-
/** A `break` or `continue` statement. */
561+
/** A `break`, `yield` or `continue` statement. */
562562
class JumpStmt extends Stmt {
563563
JumpStmt() {
564564
this instanceof BreakStmt or
565+
this instanceof YieldStmt or
565566
this instanceof ContinueStmt
566567
}
567568

@@ -585,9 +586,7 @@ class JumpStmt extends Stmt {
585586
)
586587
}
587588

588-
private SwitchExpr getSwitchExprTarget() {
589-
this.(BreakStmt).hasValue() and result = this.getParent+()
590-
}
589+
private SwitchExpr getSwitchExprTarget() { result = this.(YieldStmt).getParent+() }
591590

592591
private StmtParent getEnclosingTarget() {
593592
result = getSwitchExprTarget()
@@ -598,7 +597,7 @@ class JumpStmt extends Stmt {
598597
}
599598

600599
/**
601-
* Gets the statement or `switch` expression that this `break` or `continue` jumps to.
600+
* Gets the statement or `switch` expression that this `break`, `yield` or `continue` jumps to.
602601
*/
603602
StmtParent getTarget() {
604603
result = getLabelTarget()
@@ -615,34 +614,31 @@ class BreakStmt extends Stmt, @breakstmt {
615614
/** Holds if this `break` statement has an explicit label. */
616615
predicate hasLabel() { exists(string s | s = this.getLabel()) }
617616

618-
/**
619-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
620-
*
621-
* Gets the value of this `break` statement, if any.
622-
*/
623-
Expr getValue() { result.getParent() = this }
624-
625-
/**
626-
* PREVIEW FEATURE in Java 12. Subject to removal in a future release.
627-
*
628-
* Holds if this `break` statement has a value.
629-
*/
630-
predicate hasValue() { exists(Expr e | e.getParent() = this) }
631-
632617
/** Gets a printable representation of this statement. May include more detail than `toString()`. */
633618
override string pp() {
634-
if this.hasLabel()
635-
then result = "break " + this.getLabel()
636-
else
637-
if this.hasValue()
638-
then result = "break ..."
639-
else result = "break"
619+
if this.hasLabel() then result = "break " + this.getLabel() else result = "break"
640620
}
641621

642622
/** This statement's Halstead ID (used to compute Halstead metrics). */
643623
override string getHalsteadID() { result = "BreakStmt" }
644624
}
645625

626+
/**
627+
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
628+
*
629+
* A `yield` statement.
630+
*/
631+
class YieldStmt extends Stmt, @yieldstmt {
632+
/**
633+
* Gets the value of this `yield` statement.
634+
*/
635+
Expr getValue() { result.getParent() = this }
636+
637+
override string pp() { result = "yield ..." }
638+
639+
override string getHalsteadID() { result = "YieldStmt" }
640+
}
641+
646642
/** A `continue` statement. */
647643
class ContinueStmt extends Stmt, @continuestmt {
648644
/** Gets the label targeted by this `continue` statement, if any. */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//semmle-extractor-options: --javac-args --enable-preview -source 12 -target 12
1+
//semmle-extractor-options: --javac-args --enable-preview -source 13 -target 13

0 commit comments

Comments
 (0)