Skip to content

Commit 6ff7419

Browse files
authored
Remove use of deprecated Applicable interface (#93)
Signed-off-by: Calvin Loncaric <calvin.loncaric@oracle.com>
1 parent c48eb7c commit 6ff7419

File tree

7 files changed

+46
-84
lines changed

7 files changed

+46
-84
lines changed

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<javac srcdir="${src}" destdir="${build}/modules" classpath="${tlc}/tla2tools.jar:${lib}/gson-2.8.6.jar:${lib}/jgrapht-core-1.5.1.jar:${lib}/jungrapht-layout-1.4-SNAPSHOT.jar:${lib}/slf4j-api-1.7.30.jar:${lib}/slf4j-nop-1.7.30.jar:${lib}/commons-lang3-3.12.0.jar:${lib}/commons-math3-3.6.1.jar"
3232
source="1.8"
3333
target="1.8"
34+
deprecation="true"
3435
includeantruntime="false"/>
3536
</target>
3637

modules/tlc2/overrides/BagsExt.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*******************************************************************************
22
* Copyright (c) 2022 Inria. All rights reserved.
3+
* Copyright (c) 2023, Oracle and/or its affiliates.
34
*
45
* The MIT License (MIT)
56
*
@@ -64,7 +65,7 @@ public static Value foldBag(final OpValue op, final Value base, final Value bag)
6465
+ Values.ppr(domain[i].toString()) + ":>" + Values.ppr(values[i].toString()) + ")" });
6566
}
6667
for (int j = 0; j < ((IntValue) values[i]).val; j++) {
67-
acc[0] = op.apply(acc, EvalControl.Clear);
68+
acc[0] = op.eval(acc, EvalControl.Clear);
6869
}
6970
}
7071

modules/tlc2/overrides/FiniteSetsExt.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*******************************************************************************
22
* Copyright (c) 2020 Microsoft Research. All rights reserved.
3+
* Copyright (c) 2023, Oracle and/or its affiliates.
34
*
45
* The MIT License (MIT)
56
*
@@ -30,7 +31,6 @@
3031
import tlc2.tool.EvalException;
3132
import tlc2.value.IBoolValue;
3233
import tlc2.value.Values;
33-
import tlc2.value.impl.Applicable;
3434
import tlc2.value.impl.BoolValue;
3535
import tlc2.value.impl.Enumerable;
3636
import tlc2.value.impl.EnumerableValue;
@@ -49,25 +49,19 @@ private FiniteSetsExt() {
4949
}
5050

5151
@TLAPlusOperator(identifier = "Quantify", module = "FiniteSetsExt", warn = false)
52-
public static Value quantify(final Value set, final Value pred) {
52+
public static Value quantify(final Value set, final OpValue test) {
5353
if (!(set instanceof EnumerableValue)) {
5454
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
5555
new String[] { "first", "Quantify", "set", Values.ppr(set.toString()) });
5656
}
57-
if (!(pred instanceof Applicable)) {
58-
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
59-
new String[] { "second", "Quantify", "boolean-valued operator", Values.ppr(pred.toString()) });
60-
}
61-
6257

6358
int size = 0;
64-
final Applicable test = (Applicable) pred;
6559
final ValueEnumeration enumSet = ((SetEnumValue) set.toSetEnum()).elements();
6660
Value elem;
6761
final Value[] args = new Value[1];
6862
while ((elem = enumSet.nextElement()) != null) {
6963
args[0] = elem;
70-
Value val = test.apply(args, EvalControl.Clear);
64+
Value val = test.eval(args, EvalControl.Clear);
7165
if (val instanceof IBoolValue) {
7266
if (((BoolValue) val).val) {
7367
size++;
@@ -112,10 +106,10 @@ public static Value foldSet(final OpValue op, final Value base, final Enumerable
112106

113107
final ValueEnumeration ve = set.elements();
114108

115-
Value v = null;
109+
Value v;
116110
while ((v = ve.nextElement()) != null) {
117111
args[0] = v;
118-
args[1] = op.apply(args, EvalControl.Clear);
112+
args[1] = op.eval(args, EvalControl.Clear);
119113
}
120114

121115
return args[1];

modules/tlc2/overrides/Functions.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*******************************************************************************
22
* Copyright (c) 2019 Microsoft Research. All rights reserved.
3+
* Copyright (c) 2023, Oracle and/or its affiliates.
34
*
45
* The MIT License (MIT)
56
*
@@ -31,10 +32,10 @@
3132
import tlc2.tool.EvalControl;
3233
import tlc2.tool.EvalException;
3334
import tlc2.value.Values;
34-
import tlc2.value.impl.Applicable;
3535
import tlc2.value.impl.BoolValue;
3636
import tlc2.value.impl.Enumerable;
3737
import tlc2.value.impl.FcnRcdValue;
38+
import tlc2.value.impl.FunctionValue;
3839
import tlc2.value.impl.OpValue;
3940
import tlc2.value.impl.SetOfRcdsValue;
4041
import tlc2.value.impl.TupleValue;
@@ -123,23 +124,23 @@ public static Value foldFunction(final OpValue op, final Value base, final Value
123124
// Can assume type of OpValue because tla2sany.semantic.Generator.java will
124125
// make sure that the first parameter is a binary operator.
125126

126-
if (!(fun instanceof Applicable)) {
127+
if (!(fun instanceof FunctionValue)) {
127128
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
128129
new String[] { "third", "FoldFunction", "function", Values.ppr(fun.toString()) });
129130
}
130-
return foldFunctionOnSet(op, base, fun, ((Applicable) fun).getDomain());
131+
return foldFunctionOnSet(op, base, fun, ((FunctionValue) fun).getDomain());
131132
}
132133

133134
@TLAPlusOperator(identifier = "FoldFunctionOnSet", module = "Functions", warn = false)
134135
public static Value foldFunctionOnSet(final OpValue op, final Value base, final Value v3, final Value v4) {
135136
// Can assume type of OpValue because tla2sany.semantic.Generator.java will
136137
// make sure that the first parameter is a binary operator.
137138

138-
if (!(v3 instanceof Applicable)) {
139+
if (!(v3 instanceof FunctionValue)) {
139140
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
140141
new String[] { "third", "FoldFunctionOnSet", "function", Values.ppr(v3.toString()) });
141142
}
142-
final Applicable fun = (Applicable) v3;
143+
final FunctionValue fun = (FunctionValue) v3;
143144
if (!(v4 instanceof Enumerable)) {
144145
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
145146
new String[] { "fourth", "FoldFunctionOnSet", "set", Values.ppr(v4.toString()) });
@@ -152,10 +153,10 @@ public static Value foldFunctionOnSet(final OpValue op, final Value base, final
152153

153154
final ValueEnumeration ve = subdomain.elements();
154155

155-
Value v = null;
156+
Value v;
156157
while ((v = ve.nextElement()) != null) {
157-
args[0] = fun.select(v);
158-
args[1] = op.apply(args, EvalControl.Clear);
158+
args[0] = fun.apply(v, EvalControl.Clear);
159+
args[1] = op.eval(args, EvalControl.Clear);
159160
}
160161

161162
return args[1];

modules/tlc2/overrides/GraphViz.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*******************************************************************************
22
* Copyright (c) 2023 Microsoft Research. All rights reserved.
3+
* Copyright (c) 2023, Oracle and/or its affiliates.
34
*
45
* The MIT License (MIT)
56
*
@@ -27,7 +28,7 @@
2728

2829
import tlc2.tool.EvalControl;
2930
import tlc2.util.FP64;
30-
import tlc2.value.impl.Applicable;
31+
import tlc2.value.impl.OpValue;
3132
import tlc2.value.impl.RecordValue;
3233
import tlc2.value.impl.SetEnumValue;
3334
import tlc2.value.impl.StringValue;
@@ -38,24 +39,12 @@
3839
public class GraphViz {
3940

4041
@TLAPlusOperator(identifier = "DotDiGraph", module = "GraphViz", warn = false)
41-
public static Value dotDiGraph(final Value v1, final Value v2, final Value v3) throws Exception {
42+
public static Value dotDiGraph(final Value v1, final OpValue vl, final OpValue el) throws Exception {
4243
if (!(v1 instanceof RecordValue) || v1.toRcd() == null) {
4344
throw new Exception("An DiGraph must be a record. Value given is of type: " + v1.getClass().getName());
4445
}
4546
final RecordValue g = (RecordValue) v1.toRcd();
4647

47-
if (!(v2 instanceof Applicable)) {
48-
throw new Exception(
49-
"Second parameter must be an Applicable. Value given is of type: " + v2.getClass().getName());
50-
}
51-
final Applicable vl = (Applicable) v2;
52-
53-
if (!(v3 instanceof Applicable)) {
54-
throw new Exception(
55-
"Third parameter must be an Applicable. Value given is of type: " + v2.getClass().getName());
56-
}
57-
final Applicable el = (Applicable) v3;
58-
5948
String dotString = "digraph MyGraph {";
6049

6150
// Nodes
@@ -65,7 +54,7 @@ public static Value dotDiGraph(final Value v1, final Value v2, final Value v3) t
6554
Value val = null;
6655
while ((val = elements.nextElement()) != null) {
6756
dotString += String.format("%s[label=%s];", val.fingerPrint(FP64.New()),
68-
vl.apply(new Value[] { val }, EvalControl.Clear));
57+
vl.eval(new Value[] { val }, EvalControl.Clear));
6958
}
7059

7160
// Edges
@@ -75,7 +64,7 @@ public static Value dotDiGraph(final Value v1, final Value v2, final Value v3) t
7564
while ((val = elements.nextElement()) != null) {
7665
TupleValue tv = (TupleValue) val.toTuple();
7766
dotString += String.format("%s->%s[label=%s];", tv.elems[0].fingerPrint(FP64.New()),
78-
tv.elems[1].fingerPrint(FP64.New()), el.apply(new Value[] { tv }, EvalControl.Clear));
67+
tv.elems[1].fingerPrint(FP64.New()), el.eval(new Value[] { tv }, EvalControl.Clear));
7968
}
8069

8170
dotString += "}";

modules/tlc2/overrides/SequencesExt.java

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tlc2.overrides;
22
/*******************************************************************************
33
* Copyright (c) 2019 Microsoft Research. All rights reserved.
4+
* Copyright (c) 2023, Oracle and/or its affiliates.
45
*
56
* The MIT License (MIT)
67
*
@@ -40,7 +41,6 @@
4041
import tlc2.value.IBoolValue;
4142
import tlc2.value.IValue;
4243
import tlc2.value.Values;
43-
import tlc2.value.impl.Applicable;
4444
import tlc2.value.impl.BoolValue;
4545
import tlc2.value.impl.FcnRcdValue;
4646
import tlc2.value.impl.IntValue;
@@ -275,7 +275,7 @@ public static Value foldLeft(final OpValue op, final Value base, final Value val
275275
final Value[] elems = tv.elems;
276276
for (int i = 0; i < elems.length; i++) {
277277
args[1] = elems[i];
278-
args[0] = op.apply(args, EvalControl.Clear);
278+
args[0] = op.eval(args, EvalControl.Clear);
279279
}
280280

281281
return args[0];
@@ -299,7 +299,7 @@ public static Value foldRight(final OpValue op, final Value val, final Value bas
299299
final Value[] elems = tv.elems;
300300
for (int i = elems.length - 1; i >= 0; i--) {
301301
args[0] = elems[i];
302-
args[1] = op.apply(args, EvalControl.Clear);
302+
args[1] = op.eval(args, EvalControl.Clear);
303303
}
304304

305305
return args[1];
@@ -381,25 +381,20 @@ public static Value isPrefix(final Value v1, final Value v2) {
381381
}
382382

383383
@TLAPlusOperator(identifier = "SelectInSeq", module = "SequencesExt", warn = false)
384-
public static Value selectInSeq(final Value s, final Value test) {
384+
public static Value selectInSeq(final Value s, final OpValue test) {
385385
final TupleValue seq = (TupleValue) s.toTuple();
386386
if (seq == null) {
387387
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
388388
new String[] { "first", "SelectInSeq", "sequence", Values.ppr(s.toString()) });
389389
}
390-
if (!(test instanceof Applicable)) {
391-
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
392-
new String[] { "third", "SelectInSeq", "function", Values.ppr(test.toString()) });
393-
}
394390
final int len = seq.size();
395-
final Applicable ftest = (Applicable) test;
396391
final Value[] args = new Value[1];
397392
for (int i = 0; i < len; i++) {
398393
args[0] = seq.elems[i];
399-
final Value val = ftest.apply(args, EvalControl.Clear);
394+
final Value val = test.eval(args, EvalControl.Clear);
400395
if (!(val instanceof IBoolValue)) {
401396
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR, new String[] { "third", "SelectInSeq",
402-
"boolean-valued function", Values.ppr(test.toString()) });
397+
"boolean-valued operator", Values.ppr(test.toString()) });
403398
}
404399
if (((BoolValue) val).val) {
405400
return IntValue.gen(i + 1);
@@ -409,7 +404,7 @@ public static Value selectInSeq(final Value s, final Value test) {
409404
}
410405

411406
@TLAPlusOperator(identifier = "SelectInSubSeq", module = "SequencesExt", warn = false)
412-
public static Value SelectInSubSeq(final Value s, final Value f, final Value t, final Value test) {
407+
public static Value SelectInSubSeq(final Value s, final Value f, final Value t, final OpValue test) {
413408
final TupleValue seq = (TupleValue) s.toTuple();
414409
if (seq == null) {
415410
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
@@ -423,10 +418,6 @@ public static Value SelectInSubSeq(final Value s, final Value f, final Value t,
423418
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
424419
new String[] { "third", "SelectInSubSeq", "natural", Values.ppr(t.toString()) });
425420
}
426-
if (!(test instanceof Applicable)) {
427-
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
428-
new String[] { "fourth", "SelectInSubSeq", "function", Values.ppr(test.toString()) });
429-
}
430421

431422
int from = ((IntValue) f).val;
432423
final int to = ((IntValue) t).val;
@@ -442,15 +433,14 @@ public static Value SelectInSubSeq(final Value s, final Value f, final Value t,
442433
throw new EvalException(EC.TLC_MODULE_ARGUMENT_NOT_IN_DOMAIN,
443434
new String[] { "third", "SelectInSubSeq", "first", Values.ppr(s.toString()), Values.ppr(t.toString()) });
444435
}
445-
446-
final Applicable ftest = (Applicable) test;
436+
447437
final Value[] args = new Value[1];
448438
for (; from <= to; from++) {
449439
args[0] = seq.elems[from - 1];
450-
final Value val = ftest.apply(args, EvalControl.Clear);
440+
final Value val = test.eval(args, EvalControl.Clear);
451441
if (!(val instanceof IBoolValue)) {
452442
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR, new String[] { "fourth", "SelectInSubSeq",
453-
"boolean-valued function", Values.ppr(test.toString()) });
443+
"boolean-valued operator", Values.ppr(test.toString()) });
454444
}
455445
if (((BoolValue) val).val) {
456446
return IntValue.gen(from);
@@ -460,22 +450,17 @@ public static Value SelectInSubSeq(final Value s, final Value f, final Value t,
460450
}
461451

462452
@TLAPlusOperator(identifier = "SelectLastInSeq", module = "SequencesExt", warn = false)
463-
public static Value selectLastInSeq(final Value s, final Value test) {
453+
public static Value selectLastInSeq(final Value s, final OpValue test) {
464454
final TupleValue seq = (TupleValue) s.toTuple();
465455
if (seq == null) {
466456
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
467457
new String[] { "first", "SelectLastInSeq", "sequence", Values.ppr(s.toString()) });
468458
}
469-
if (!(test instanceof Applicable)) {
470-
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
471-
new String[] { "third", "SelectLastInSeq", "function", Values.ppr(test.toString()) });
472-
}
473459
int i = seq.size() - 1;
474-
final Applicable ftest = (Applicable) test;
475460
final Value[] args = new Value[1];
476461
for (; i >= 0; i--) {
477462
args[0] = seq.elems[i];
478-
final Value val = ftest.apply(args, EvalControl.Clear);
463+
final Value val = test.eval(args, EvalControl.Clear);
479464
if (!(val instanceof IBoolValue)) {
480465
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR, new String[] { "third", "SelectLastInSeq",
481466
"boolean-valued function", Values.ppr(test.toString()) });
@@ -488,7 +473,7 @@ public static Value selectLastInSeq(final Value s, final Value test) {
488473
}
489474

490475
@TLAPlusOperator(identifier = "SelectLastInSubSeq", module = "SequencesExt", warn = false)
491-
public static Value SelectLastInSubSeq(final Value s, final Value f, final Value t, final Value test) {
476+
public static Value SelectLastInSubSeq(final Value s, final Value f, final Value t, final OpValue test) {
492477
final TupleValue seq = (TupleValue) s.toTuple();
493478
if (seq == null) {
494479
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
@@ -502,10 +487,6 @@ public static Value SelectLastInSubSeq(final Value s, final Value f, final Value
502487
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
503488
new String[] { "third", "SelectLastInSubSeq", "natural", Values.ppr(t.toString()) });
504489
}
505-
if (!(test instanceof Applicable)) {
506-
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
507-
new String[] { "fourth", "SelectLastInSubSeq", "function", Values.ppr(test.toString()) });
508-
}
509490

510491
final int from = ((IntValue) f).val;
511492
int to = ((IntValue) t).val;
@@ -521,12 +502,11 @@ public static Value SelectLastInSubSeq(final Value s, final Value f, final Value
521502
throw new EvalException(EC.TLC_MODULE_ARGUMENT_NOT_IN_DOMAIN,
522503
new String[] { "third", "SelectLastInSubSeq", "first", Values.ppr(s.toString()), Values.ppr(t.toString()) });
523504
}
524-
525-
final Applicable ftest = (Applicable) test;
505+
526506
final Value[] args = new Value[1];
527507
for (; to >= from; to--) {
528508
args[0] = seq.elems[to - 1];
529-
final Value val = ftest.apply(args, EvalControl.Clear);
509+
final Value val = test.eval(args, EvalControl.Clear);
530510
if (!(val instanceof IBoolValue)) {
531511
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR, new String[] { "fourth", "SelectLastInSubSeq",
532512
"boolean-valued function", Values.ppr(test.toString()) });
@@ -561,17 +541,12 @@ public static Value removeFirst(final Value s, final Value e) {
561541
}
562542

563543
@TLAPlusOperator(identifier = "RemoveFirstMatch", module = "SequencesExt", warn = false)
564-
public static Value removeFirstMatch(final Value s, final Value test) {
544+
public static Value removeFirstMatch(final Value s, final OpValue test) {
565545
final TupleValue seq = (TupleValue) s.toTuple();
566546
if (seq == null) {
567547
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
568548
new String[] { "first", "RemoveFirstMatch", "sequence", Values.ppr(s.toString()) });
569549
}
570-
if (!(test instanceof Applicable)) {
571-
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR,
572-
new String[] { "second", "RemoveFirstMatch", "function", Values.ppr(test.toString()) });
573-
}
574-
final Applicable ftest = (Applicable) test;
575550
final Value[] args = new Value[1];
576551

577552
final ArrayList<Value> val = new ArrayList<>(seq.elems.length);
@@ -580,7 +555,7 @@ public static Value removeFirstMatch(final Value s, final Value test) {
580555
for (int i = 0; i < seq.elems.length; i++) {
581556
if (!found) {
582557
args[0] = seq.elems[i];
583-
final Value bval = ftest.apply(args, EvalControl.Clear);
558+
final Value bval = test.eval(args, EvalControl.Clear);
584559
if (!(bval instanceof IBoolValue)) {
585560
throw new EvalException(EC.TLC_MODULE_ARGUMENT_ERROR, new String[] { "second", "RemoveFirstMatch",
586561
"boolean-valued function", Values.ppr(test.toString()) });

0 commit comments

Comments
 (0)