|
10 | 10 |
|
11 | 11 | import static com.google.common.base.Preconditions.checkNotNull; |
12 | 12 |
|
| 13 | +import com.google.common.collect.FluentIterable; |
13 | 14 | import de.uni_freiburg.informatik.ultimate.logic.Annotation; |
14 | 15 | import de.uni_freiburg.informatik.ultimate.logic.ApplicationTerm; |
15 | 16 | import de.uni_freiburg.informatik.ultimate.logic.Assignments; |
|
28 | 29 | import java.math.BigDecimal; |
29 | 30 | import java.math.BigInteger; |
30 | 31 | import java.util.ArrayList; |
| 32 | +import java.util.Arrays; |
31 | 33 | import java.util.Collections; |
32 | 34 | import java.util.List; |
33 | 35 | import java.util.Map; |
@@ -70,41 +72,40 @@ public LBool assertTerm(Term pTerm) throws SMTLIBException { |
70 | 72 |
|
71 | 73 | @Override |
72 | 74 | public void declareFun(String fun, Sort[] paramSorts, Sort resultSort) throws SMTLIBException { |
73 | | - FunctionSymbol fsym = null; |
74 | | - try { |
75 | | - fsym = theory.getFunction(fun, paramSorts); |
76 | | - } catch (SMTLIBException e) { |
77 | | - // fsym = null |
78 | | - } |
79 | | - if (fsym == null) { |
| 75 | + var functions = theory.getDeclaredFunctions(); |
| 76 | + if (!functions.containsKey(fun)) { |
| 77 | + // There is no function with that name yet: create a new symbol |
80 | 78 | script.declareFun(fun, paramSorts, resultSort); |
81 | 79 | } else { |
82 | | - if (!fsym.getReturnSort().equals(resultSort)) { |
| 80 | + // A symbol with the same name already exists: Check if the signature matches and throw an |
| 81 | + // exception otherwise |
| 82 | + var decl = functions.get(fun); |
| 83 | + if (!Arrays.equals(decl.getParameterSorts(), paramSorts) |
| 84 | + || !decl.getReturnSort().equals(resultSort)) { |
83 | 85 | throw new SMTLIBException( |
84 | | - "Function " + fun + " is already declared with different definition"); |
| 86 | + "Function '%s' already declared with a different sort".formatted(fun)); |
85 | 87 | } |
86 | 88 | } |
87 | 89 | } |
88 | 90 |
|
89 | 91 | @Override |
90 | 92 | public void defineFun(String fun, TermVariable[] params, Sort resultSort, Term definition) |
91 | 93 | throws SMTLIBException { |
92 | | - Sort[] paramSorts = new Sort[params.length]; |
93 | | - for (int i = 0; i < paramSorts.length; i++) { |
94 | | - paramSorts[i] = params[i].getSort(); |
95 | | - } |
96 | | - FunctionSymbol fsym = null; |
97 | | - try { |
98 | | - fsym = theory.getFunction(fun, paramSorts); |
99 | | - } catch (SMTLIBException e) { |
100 | | - // fsym = null |
101 | | - } |
102 | | - if (fsym == null) { |
| 94 | + var functions = theory.getDeclaredFunctions(); |
| 95 | + if (!functions.containsKey(fun)) { |
| 96 | + // There is no function with that name yet: create a new symbol |
103 | 97 | script.defineFun(fun, params, resultSort, definition); |
104 | 98 | } else { |
105 | | - if (!fsym.getDefinition().equals(definition) || !fsym.getReturnSort().equals(resultSort)) { |
| 99 | + // A symbol with the same name already exists: Check if the signature and the definition |
| 100 | + // match and throw an exception otherwise |
| 101 | + var decl = functions.get(fun); |
| 102 | + if (!Arrays.equals( |
| 103 | + decl.getParameterSorts(), |
| 104 | + FluentIterable.from(params).transform(TermVariable::getSort).toArray(Sort.class)) |
| 105 | + || !decl.getReturnSort().equals(resultSort) |
| 106 | + || !decl.getDefinition().equals(definition)) { |
106 | 107 | throw new SMTLIBException( |
107 | | - "Function " + fun + " is already defined with different definition"); |
| 108 | + "Function '%s' already declared with a different sort".formatted(fun)); |
108 | 109 | } |
109 | 110 | } |
110 | 111 | } |
|
0 commit comments