Skip to content

Commit 0207229

Browse files
authored
Merge pull request #617 from sosy-lab/revert-formulatype-to-interface
Revert: API change: convert the abstract class "FormulaType" to interface. #615
2 parents ce1b181 + 98b4355 commit 0207229

1 file changed

Lines changed: 59 additions & 61 deletions

File tree

src/org/sosy_lab/java_smt/api/FormulaType.java

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// an API wrapper for a collection of SMT solvers:
33
// https://github.com/sosy-lab/java-smt
44
//
5-
// SPDX-FileCopyrightText: 2026 Dirk Beyer <https://www.sosy-lab.org>
5+
// SPDX-FileCopyrightText: 2020 Dirk Beyer <https://www.sosy-lab.org>
66
//
77
// SPDX-License-Identifier: Apache-2.0
88

@@ -25,77 +25,72 @@
2525
import org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula;
2626

2727
/**
28-
* Subclasses of this interface represent the different types of formulas supported by SMT solvers,
29-
* typically including boolean, integer, bitvector, and more. Each type corresponds to a specific
30-
* class of formulas that can be created and manipulated using the SMT solver's API.
31-
*
32-
* <p>Subclasses of this interface must be immutable, as they are used as keys in maps and sets, and
33-
* their immutability ensures that they can be safely shared and used without unintended side
34-
* effects.
28+
* Type of a formula.
3529
*
3630
* @param <T> Formula class corresponding to the given formula type.
3731
*/
3832
@SuppressWarnings("checkstyle:constantname")
3933
@Immutable
40-
public interface FormulaType<T extends Formula> {
34+
public abstract class FormulaType<T extends Formula> {
35+
36+
private FormulaType() {}
4137

42-
default boolean isArrayType() {
38+
public boolean isArrayType() {
4339
return false;
4440
}
4541

46-
default boolean isBitvectorType() {
42+
public boolean isBitvectorType() {
4743
return false;
4844
}
4945

50-
default boolean isBooleanType() {
46+
public boolean isBooleanType() {
5147
return false;
5248
}
5349

54-
default boolean isFloatingPointType() {
50+
public boolean isFloatingPointType() {
5551
return false;
5652
}
5753

58-
default boolean isFloatingPointRoundingModeType() {
54+
public boolean isFloatingPointRoundingModeType() {
5955
return false;
6056
}
6157

62-
default boolean isNumeralType() {
58+
public boolean isNumeralType() {
6359
return false;
6460
}
6561

66-
default boolean isRationalType() {
62+
public boolean isRationalType() {
6763
return false;
6864
}
6965

70-
default boolean isIntegerType() {
66+
public boolean isIntegerType() {
7167
return false;
7268
}
7369

74-
default boolean isSLType() {
70+
public boolean isSLType() {
7571
return false;
7672
}
7773

78-
default boolean isStringType() {
74+
public boolean isStringType() {
7975
return false;
8076
}
8177

82-
default boolean isRegexType() {
78+
public boolean isRegexType() {
8379
return false;
8480
}
8581

86-
default boolean isEnumerationType() {
82+
public boolean isEnumerationType() {
8783
return false;
8884
}
8985

90-
/** returns a human-readable representation of the formula type. */
9186
@Override
92-
String toString();
87+
public abstract String toString();
9388

94-
/** returns a correctly formatted string that can be used in SMTLIB2 declarations. */
95-
String toSMTLIBString();
89+
/** return the correctly formatted SMTLIB2 type declaration. */
90+
public abstract String toSMTLIBString();
9691

9792
@Immutable
98-
abstract class NumeralType<T extends NumeralFormula> implements FormulaType<T> {
93+
public abstract static class NumeralType<T extends NumeralFormula> extends FormulaType<T> {
9994

10095
@Override
10196
public final boolean isNumeralType() {
@@ -104,7 +99,7 @@ public final boolean isNumeralType() {
10499
}
105100

106101
@SuppressWarnings("ClassInitializationDeadlock")
107-
FormulaType<RationalFormula> RationalType =
102+
public static final FormulaType<RationalFormula> RationalType =
108103
new NumeralType<>() {
109104

110105
@Override
@@ -124,7 +119,7 @@ public String toSMTLIBString() {
124119
};
125120

126121
@SuppressWarnings("ClassInitializationDeadlock")
127-
FormulaType<IntegerFormula> IntegerType =
122+
public static final FormulaType<IntegerFormula> IntegerType =
128123
new NumeralType<>() {
129124

130125
@Override
@@ -143,7 +138,7 @@ public String toSMTLIBString() {
143138
}
144139
};
145140

146-
FormulaType<BooleanFormula> BooleanType =
141+
public static final FormulaType<BooleanFormula> BooleanType =
147142
new FormulaType<>() {
148143

149144
@Override
@@ -162,12 +157,12 @@ public String toSMTLIBString() {
162157
}
163158
};
164159

165-
static BitvectorType getBitvectorTypeWithSize(int size) {
160+
public static BitvectorType getBitvectorTypeWithSize(int size) {
166161
return new BitvectorType(size);
167162
}
168163

169164
@Immutable
170-
final class BitvectorType implements FormulaType<BitvectorFormula> {
165+
public static final class BitvectorType extends FormulaType<BitvectorFormula> {
171166
private final int size;
172167

173168
private BitvectorType(int size) {
@@ -225,7 +220,7 @@ public String toSMTLIBString() {
225220
*/
226221
@Deprecated(since = "6.0", forRemoval = true)
227222
@SuppressWarnings("InlineMeSuggester")
228-
static FloatingPointType getFloatingPointType(
223+
public static FloatingPointType getFloatingPointType(
229224
int exponentSize, int mantissaSizeWithoutHiddenBit) {
230225
return getFloatingPointTypeFromSizesWithoutHiddenBit(
231226
exponentSize, mantissaSizeWithoutHiddenBit);
@@ -248,7 +243,7 @@ static FloatingPointType getFloatingPointType(
248243
* significand), excluding the hidden bit.
249244
* @return the newly constructed {@link FloatingPointType}.
250245
*/
251-
static FloatingPointType getFloatingPointTypeFromSizesWithoutHiddenBit(
246+
public static FloatingPointType getFloatingPointTypeFromSizesWithoutHiddenBit(
252247
int exponentSize, int mantissaSizeWithoutHiddenBit) {
253248
checkArgument(exponentSize > 1, "Exponent size must be greater than 1");
254249
checkArgument(
@@ -274,7 +269,7 @@ static FloatingPointType getFloatingPointTypeFromSizesWithoutHiddenBit(
274269
* significand), including the hidden bit.
275270
* @return the newly constructed {@link FloatingPointType}.
276271
*/
277-
static FloatingPointType getFloatingPointTypeFromSizesWithHiddenBit(
272+
public static FloatingPointType getFloatingPointTypeFromSizesWithHiddenBit(
278273
int exponentSize, int mantissaSizeWithHiddenBit) {
279274
checkArgument(
280275
mantissaSizeWithHiddenBit > 1,
@@ -288,7 +283,7 @@ static FloatingPointType getFloatingPointTypeFromSizesWithHiddenBit(
288283
* of the sign bit, an exponent sized 8 bits, and a mantissa sized 23 bits (excluding the
289284
* hidden bit).
290285
*/
291-
static FloatingPointType getSinglePrecisionFloatingPointType() {
286+
public static FloatingPointType getSinglePrecisionFloatingPointType() {
292287
return FloatingPointType.SINGLE_PRECISION_FP_TYPE;
293288
}
294289

@@ -297,12 +292,12 @@ static FloatingPointType getSinglePrecisionFloatingPointType() {
297292
* of the sign bit, an exponent sized 11 bits, and a mantissa sized 52 bits (excluding the
298293
* hidden bit).
299294
*/
300-
static FloatingPointType getDoublePrecisionFloatingPointType() {
295+
public static FloatingPointType getDoublePrecisionFloatingPointType() {
301296
return FloatingPointType.DOUBLE_PRECISION_FP_TYPE;
302297
}
303298

304299
@Immutable
305-
final class FloatingPointType implements FormulaType<FloatingPointFormula> {
300+
public static final class FloatingPointType extends FormulaType<FloatingPointFormula> {
306301

307302
@SuppressWarnings("removal")
308303
private static final FloatingPointType SINGLE_PRECISION_FP_TYPE =
@@ -405,35 +400,38 @@ public String toSMTLIBString() {
405400
}
406401
}
407402

408-
FormulaType<FloatingPointRoundingModeFormula> FloatingPointRoundingModeType =
409-
new FormulaType<>() {
403+
public static final FormulaType<FloatingPointRoundingModeFormula> FloatingPointRoundingModeType =
404+
new FloatingPointRoundingModeType();
410405

411-
@Override
412-
public boolean isFloatingPointRoundingModeType() {
413-
return true;
414-
}
406+
private static final class FloatingPointRoundingModeType
407+
extends FormulaType<FloatingPointRoundingModeFormula> {
415408

416-
@Override
417-
public String toString() {
418-
return "FloatingPointRoundingMode";
419-
}
409+
@Override
410+
public boolean isFloatingPointRoundingModeType() {
411+
return true;
412+
}
420413

421-
@Override
422-
public String toSMTLIBString() {
423-
throw new UnsupportedOperationException(
424-
"rounding mode is not expected in symbol declarations");
425-
}
426-
};
414+
@Override
415+
public String toString() {
416+
return "FloatingPointRoundingMode";
417+
}
418+
419+
@Override
420+
public String toSMTLIBString() {
421+
throw new UnsupportedOperationException(
422+
"rounding mode is not expected in symbol declarations");
423+
}
424+
}
427425

428426
@SuppressWarnings("MethodTypeParameterName")
429-
static <TD extends Formula, TR extends Formula> ArrayFormulaType<TD, TR> getArrayType(
427+
public static <TD extends Formula, TR extends Formula> ArrayFormulaType<TD, TR> getArrayType(
430428
FormulaType<TD> pDomainSort, FormulaType<TR> pRangeSort) {
431429
return new ArrayFormulaType<>(pDomainSort, pRangeSort);
432430
}
433431

434432
@SuppressWarnings("ClassTypeParameterName")
435-
final class ArrayFormulaType<TI extends Formula, TE extends Formula>
436-
implements FormulaType<ArrayFormula<TI, TE>> {
433+
public static final class ArrayFormulaType<TI extends Formula, TE extends Formula>
434+
extends FormulaType<ArrayFormula<TI, TE>> {
437435

438436
private final FormulaType<TE> elementType;
439437
private final FormulaType<TI> indexType;
@@ -482,11 +480,11 @@ public String toSMTLIBString() {
482480
}
483481
}
484482

485-
static EnumerationFormulaType getEnumerationType(String pName, Set<String> pElements) {
483+
public static EnumerationFormulaType getEnumerationType(String pName, Set<String> pElements) {
486484
return new EnumerationFormulaType(pName, pElements);
487485
}
488486

489-
final class EnumerationFormulaType implements FormulaType<EnumerationFormula> {
487+
public static final class EnumerationFormulaType extends FormulaType<EnumerationFormula> {
490488

491489
private final String name;
492490
private final ImmutableSet<String> elements;
@@ -539,7 +537,7 @@ public String toSMTLIBString() {
539537
}
540538
}
541539

542-
FormulaType<StringFormula> StringType =
540+
public static final FormulaType<StringFormula> StringType =
543541
new FormulaType<>() {
544542

545543
@Override
@@ -558,7 +556,7 @@ public String toSMTLIBString() {
558556
}
559557
};
560558

561-
FormulaType<RegexFormula> RegexType =
559+
public static final FormulaType<RegexFormula> RegexType =
562560
new FormulaType<>() {
563561

564562
@Override
@@ -581,7 +579,7 @@ public String toSMTLIBString() {
581579
* Parse a string and return the corresponding type. This method is the counterpart of {@link
582580
* #toString()}.
583581
*/
584-
static FormulaType<?> fromString(String t) {
582+
public static FormulaType<?> fromString(String t) {
585583
if (BooleanType.toString().equals(t)) {
586584
return BooleanType;
587585
} else if (IntegerType.toString().equals(t)) {

0 commit comments

Comments
 (0)