Skip to content

Commit e7fdf66

Browse files
Print error messages for unsupported SMTLIB commands during parsing
1 parent aff1b96 commit e7fdf66

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,21 @@ private String sanitize(String formulaStr) {
287287
// We could keep track of the state of the stack and only consider the formulas that remain
288288
// on the stack at the end of the script. However, this does not seem worth it at the
289289
// moment. If needed, this feature can still be added later.
290-
throw new IllegalArgumentException();
290+
String message;
291+
if (Tokenizer.isPushToken(token)) {
292+
message = "(push ...)";
293+
} else if (Tokenizer.isPopToken(token)) {
294+
message = "(pop ...)";
295+
} else if (Tokenizer.isResetAssertionsToken(token)) {
296+
message = "(reset-assertions)";
297+
} else if (Tokenizer.isResetToken(token)) {
298+
message = "(reset)";
299+
} else {
300+
// Should be unreachable
301+
throw new UnsupportedOperationException();
302+
}
303+
throw new IllegalArgumentException(
304+
String.format("SMTLIB command '%s' is not supported when parsing formulas.", message));
291305

292306
} else {
293307
// Remove everything else

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

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ private static boolean matchesOneOf(String token, String... regexp) {
137137
return token.matches("\\(\\s*(" + String.join("|", regexp) + ")[\\S\\s]*");
138138
}
139139

140+
/**
141+
* Check if the token is <code>(set-logic ..)</code>.
142+
*
143+
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
144+
*/
145+
public static boolean isSetLogicToken(String token) {
146+
return matchesOneOf(token, "set-logic");
147+
}
148+
140149
/**
141150
* Check if the token is a function or variable declaration.
142151
*
@@ -165,16 +174,43 @@ public static boolean isAssertToken(String token) {
165174
}
166175

167176
/**
168-
* Check if the token is <code>(set-logic ..)</code>.
177+
* Check if the token is an <code>(push ...)</code>.
169178
*
170179
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
171180
*/
172-
public static boolean isSetLogicToken(String token) {
173-
return matchesOneOf(token, "set-logic");
181+
public static boolean isPushToken(String token) {
182+
return matchesOneOf(token, "push");
183+
}
184+
185+
/**
186+
* Check if the token is an <code>(pop ...)</code>.
187+
*
188+
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
189+
*/
190+
public static boolean isPopToken(String token) {
191+
return matchesOneOf(token, "pop");
192+
}
193+
194+
/**
195+
* Check if the token is an <code>(reset-assertions ...)</code>.
196+
*
197+
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
198+
*/
199+
public static boolean isResetAssertionsToken(String token) {
200+
return matchesOneOf(token, "reset-assertions");
201+
}
202+
203+
/**
204+
* Check if the token is an <code>(reset)</code>.
205+
*
206+
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
207+
*/
208+
public static boolean isResetToken(String token) {
209+
return matchesOneOf(token, "reset");
174210
}
175211

176212
/**
177-
* Check if the token is <code>(exit ...)</code>.
213+
* Check if the token is <code>(exit)</code>.
178214
*
179215
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
180216
*/
@@ -197,6 +233,9 @@ public static boolean isExitToken(String token) {
197233
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
198234
*/
199235
public static boolean isUnsupportedToken(String token) {
200-
return matchesOneOf(token, "push", "pop", "reset-assertions", "reset");
236+
return isPushToken(token)
237+
| isPopToken(token)
238+
| isResetAssertionsToken(token)
239+
| isResetToken(token);
201240
}
202241
}

0 commit comments

Comments
 (0)