Skip to content

Commit d2ac4f5

Browse files
committed
Code style: apply several smaller improvements.
1 parent 0e67ad2 commit d2ac4f5

14 files changed

+38
-91
lines changed

src/org/sosy_lab/java_smt/basicimpl/AbstractBooleanFormulaManager.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,24 +345,21 @@ public R visitFunction(
345345
Formula f, List<Formula> args, FunctionDeclaration<?> functionDeclaration) {
346346
switch (functionDeclaration.getKind()) {
347347
case AND:
348-
R out = delegate.visitAnd(getBoolArgs(args));
349-
return out;
348+
return delegate.visitAnd(getBoolArgs(args));
350349
case NOT:
351350
checkState(args.size() == 1);
352351
Formula arg = args.get(0);
353352

354353
checkArgument(arg instanceof BooleanFormula);
355354
return delegate.visitNot((BooleanFormula) arg);
356355
case OR:
357-
R out2 = delegate.visitOr(getBoolArgs(args));
358-
return out2;
356+
return delegate.visitOr(getBoolArgs(args));
359357
case IFF:
360358
checkState(args.size() == 2);
361359
Formula a = args.get(0);
362360
Formula b = args.get(1);
363361
checkState(a instanceof BooleanFormula && b instanceof BooleanFormula);
364-
R out3 = delegate.visitEquivalence((BooleanFormula) a, (BooleanFormula) b);
365-
return out3;
362+
return delegate.visitEquivalence((BooleanFormula) a, (BooleanFormula) b);
366363
case EQ:
367364
if (args.size() == 2
368365
&& args.get(0) instanceof BooleanFormula

src/org/sosy_lab/java_smt/example/SolverOverviewTable.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public static void main(String[] args) throws SolverException, InterruptedExcept
8888
* UnsatCoreWithAssumptions, Assumptions, AllSat, Interpolation
8989
*
9090
* @param context SolverContext you want to check for features.
91-
* @return String with the features of the entered solver separated by a comma. Empty if none
92-
* available.
91+
* @return supported features of the entered solver separated by a comma. Empty if none available.
9392
*/
9493
@SuppressWarnings({"CheckReturnValue", "resource"})
9594
private List<String> getFeatures(SolverContext context)
@@ -158,7 +157,7 @@ private List<String> getFeatures(SolverContext context)
158157
* as String with each theory separated by a comma.
159158
*
160159
* @param context JavaSMT SolverContext of the Solver you want to check for theories.
161-
* @return String of all supported theories except Booleans, separated by a comma. Empty if none
160+
* @return supported theories except Boolean theory, separated by a comma. Empty if none
162161
* available.
163162
*/
164163
private List<String> getTheories(SolverContext context) {
@@ -323,20 +322,20 @@ private void padLines(List<String> linesToPad, int amountOfLines) {
323322
private List<String> formatLines(String lineToSplit, int maxLength) {
324323
List<String> versionSplit = Splitter.on(" ").splitToList(lineToSplit);
325324
List<String> versionLines = new ArrayList<>();
326-
String line = versionSplit.get(0);
325+
StringBuilder line = new StringBuilder(versionSplit.get(0));
327326
int lineCounter = line.length();
328327
for (String current : Iterables.skip(versionSplit, 1)) {
329328
lineCounter += current.length() + 1;
330329

331330
if (lineCounter > maxLength) {
332331
lineCounter = current.length() + 1;
333-
versionLines.add(line);
334-
line = current;
332+
versionLines.add(line.toString());
333+
line = new StringBuilder(current);
335334
} else {
336-
line = line + " " + current;
335+
line.append(" ").append(current);
337336
}
338337
}
339-
versionLines.add(line);
338+
versionLines.add(line.toString());
340339
return versionLines;
341340
}
342341

src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private Collection<ValueAssignment> getArrayAssignments(Term pTerm, List<Object>
134134
Vector_Term children = array.children();
135135
List<Object> innerIndices = new ArrayList<>(upperIndices);
136136
String name = getArrayName(array);
137-
assert name != null;
137+
Preconditions.checkNotNull(name, "unexpected array %s without name", array);
138138
if (children.isEmpty()) {
139139
// Empty array
140140
return assignments;

src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaSolverContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
public final class BitwuzlaSolverContext extends AbstractSolverContext {
9494

9595
@org.sosy_lab.common.configuration.Options(prefix = "solver.bitwuzla")
96-
public static class BitwuzlaSettings {
96+
static class BitwuzlaSettings {
9797

9898
enum SatSolver {
9999
LINGELING,
@@ -117,11 +117,11 @@ enum SatSolver {
117117
+ "Example: \"PRODUCE_MODELS=2,SAT_SOLVER=kissat\".")
118118
private String furtherOptions = "";
119119

120-
protected SatSolver getSatSolver() {
120+
SatSolver getSatSolver() {
121121
return satSolver;
122122
}
123123

124-
protected String getFurtherOptions() {
124+
String getFurtherOptions() {
125125
return furtherOptions;
126126
}
127127

src/org/sosy_lab/java_smt/solvers/boolector/BoolectorFormulaCreator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,7 @@ protected Object transformStringToBigInt(String value) {
325325
*/
326326
private BigInteger parseBigInt(String assignment) {
327327
try {
328-
BigInteger bigInt = new BigInteger(assignment, 2);
329-
return bigInt;
328+
return new BigInteger(assignment, 2);
330329
} catch (NumberFormatException e) {
331330
char[] charArray = assignment.toCharArray();
332331
for (int i = 0; i < charArray.length; i++) {

src/org/sosy_lab/java_smt/solvers/boolector/BoolectorModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private ImmutableList<ValueAssignment> toList1(Set<String> variables) {
214214
private ValueAssignment getConstAssignment(long key, String name) {
215215
List<Object> argumentInterpretation = new ArrayList<>();
216216
Object value = creator.convertValue(key, evalImpl(key));
217-
Long valueNode = BtorJNI.boolector_get_value(btor, key);
217+
long valueNode = BtorJNI.boolector_get_value(btor, key);
218218
// Boolector might return the internal name of the variable with a leading BTOR_number@ which we
219219
// need to strip!
220220
return new ValueAssignment(
@@ -232,7 +232,7 @@ private ImmutableList<ValueAssignment> getUFAssignments(long key, String name) {
232232
// of values may differ when calling boolector_uf_assignment_helper again to get the arguments!
233233
// The "value" from boolector_get_value() is just
234234
// a plain copy of the entered node with static results!
235-
Long fun = BtorJNI.boolector_get_value(btor, key);
235+
long fun = BtorJNI.boolector_get_value(btor, key);
236236
String[][] ufAssignments = BtorJNI.boolector_uf_assignment_helper(btor, key);
237237
for (int i = 0; i < ufAssignments[0].length; i++) {
238238
ImmutableList.Builder<Object> argBuilder = ImmutableList.builder();
@@ -265,7 +265,7 @@ private ValueAssignment getArrayAssignment(long key, String name) {
265265
argumentInterpretation.add(bfCreator.transformStringToBigInt(stringArrayEntry));
266266
}
267267
Object value = creator.convertValue(key, evalImpl(key));
268-
Long valueNode = BtorJNI.boolector_get_value(btor, key);
268+
long valueNode = BtorJNI.boolector_get_value(btor, key);
269269
// Boolector might return the internal name of the variable with a leading BTOR_number@ which we
270270
// need to strip!
271271
return new ValueAssignment(

src/org/sosy_lab/java_smt/solvers/cvc5/CVC5FormulaCreator.java

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,12 @@ public Term makeVariable(Sort sort, String name) {
104104
if (existingVar != null) {
105105
return existingVar;
106106
}
107-
if (variablesCache.containsRow(name)) {
108-
throw new IllegalArgumentException(
109-
"Symbol "
110-
+ name
111-
+ " requested with type "
112-
+ sort
113-
+ ", but "
114-
+ "already "
115-
+ "used "
116-
+ "with "
117-
+ "type "
118-
+ variablesCache
119-
.rowMap()
120-
.get(name)
121-
.entrySet()
122-
.toArray((java.util.Map.Entry[]) Array.newInstance(java.util.Map.Entry.class, 0))[
123-
0]
124-
.getKey());
125-
}
107+
Preconditions.checkArgument(
108+
!variablesCache.containsRow(name),
109+
"Symbol %s requested with type %s, but already used with type %s",
110+
name,
111+
sort,
112+
Iterables.getOnlyElement(variablesCache.row(name).entrySet()));
126113
Term newVar = termManager.mkConst(sort, name);
127114
variablesCache.put(name, sort.toString(), newVar);
128115
return newVar;
@@ -860,25 +847,12 @@ private FloatingPointNumber convertFloatingPoint(Term value) throws CVC5ApiExcep
860847

861848
private Term accessVariablesCache(String name, Sort sort) {
862849
Term existingVar = variablesCache.get(name, sort.toString());
863-
if (existingVar == null) {
864-
throw new IllegalArgumentException(
865-
"Symbol "
866-
+ name
867-
+ " requested with type "
868-
+ sort
869-
+ ", but "
870-
+ "already "
871-
+ "used "
872-
+ "with "
873-
+ "type"
874-
+ variablesCache
875-
.rowMap()
876-
.get(name)
877-
.entrySet()
878-
.toArray((java.util.Map.Entry[]) Array.newInstance(java.util.Map.Entry.class, 0))[
879-
0]
880-
.getKey());
881-
}
850+
Preconditions.checkNotNull(
851+
existingVar,
852+
"Symbol %s requested with type %s, but already used with type %s",
853+
name,
854+
sort,
855+
Iterables.getOnlyElement(variablesCache.row(name).entrySet()));
882856
return existingVar;
883857
}
884858
}

src/org/sosy_lab/java_smt/solvers/cvc5/CVC5FormulaManager.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,7 @@ assert getFormulaCreator().getFormulaType(f) == FormulaType.BooleanType
105105
}
106106

107107
// now add the final assert
108-
out.append("(assert ");
109-
// Formerly in CVC4:
110-
// f.toString() does expand all nested sub-expressions and causes exponential overhead.
111-
// f.toStream() uses LET-expressions and is exactly what we want.
112-
// However, in CVC5 toStream() does no longer exists.
113-
// TODO: either toString() will do, or we may need iterator().
114-
/*
115-
try (OutputStream stream =
116-
new OutputStream() {
117-
118-
@Override
119-
public void write(int chr) throws IOException {
120-
out.append((char) chr);
121-
}
122-
}) {
123-
f.toStream(stream);
124-
}
125-
*/
126-
out.append(f.toString());
127-
out.append(')');
108+
out.append("(assert ").append(f).append(')');
128109
return out.toString();
129110
}
130111

src/org/sosy_lab/java_smt/solvers/cvc5/CVC5Model.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private ValueAssignment getAssignment(Term pKeyTerm) {
180180
}
181181
}
182182

183-
String nameStr = "";
183+
String nameStr;
184184
if (pKeyTerm.hasSymbol()) {
185185
nameStr = pKeyTerm.getSymbol();
186186
} else {

src/org/sosy_lab/java_smt/solvers/princess/PrincessRationalFormulaManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class PrincessRationalFormulaManager
2727
extends PrincessNumeralFormulaManager<NumeralFormula, RationalFormula>
2828
implements RationalFormulaManager {
2929

30-
private PrincessIntegerFormulaManager ifmgr;
30+
private final PrincessIntegerFormulaManager ifmgr;
3131

3232
PrincessRationalFormulaManager(
3333
PrincessFormulaCreator pCreator,

0 commit comments

Comments
 (0)