Skip to content

Commit

Permalink
Fix dependence on Id sort
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltoli committed Oct 10, 2022
1 parent 9f9c1fa commit 260aa4c
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ private Object unwrap(String token, String hook) {
}
}

private K wrap(Object result, Sort sort) {
private K wrap(Object result, Sort sort, Module module) {
String resultHookName = module.sortAttributesFor().apply(sort.head()).getOptional(Att.HOOK()).orElse("");
boolean hasStringHook = resultHookName.equals("STRING.String") || resultHookName.equals("BYTES.Bytes");

if (result instanceof Boolean) {
return KToken(result.toString(), sort);
} else if (result instanceof FloatBuiltin) {
return KToken(((FloatBuiltin)result).value(), sort);
} else if (result instanceof BigInteger) {
return KToken(result.toString(), sort);
} else if (result instanceof String && !Objects.equals(sort.name(), "Id")) {
} else if (result instanceof String && hasStringHook) {
return KToken(StringUtil.enquoteKString((String)result), sort);
} else {
return KToken(result.toString(), sort);
Expand All @@ -142,7 +145,7 @@ private K doFolding(String hook, List<K> args, Sort resultSort, Module module) t
try {
Method m = ConstantFolding.class.getDeclaredMethod(renamedHook, paramTypes.toArray(new Class<?>[args.size()]));
Object result = m.invoke(this, unwrappedArgs.toArray(new Object[args.size()]));
return wrap(result, resultSort);
return wrap(result, resultSort, module);
} catch (IllegalAccessException e) {
throw KEMException.internalError("Error invoking constant folding function", e);
} catch (InvocationTargetException e) {
Expand Down

0 comments on commit 260aa4c

Please sign in to comment.