public VarInfo(Constant varOcc, Sort sort, VarType varType) { this.varKey = getVarKey(varOcc); this.sort = sort; this.loc = varOcc.location().orElse(null); this.varType = varType; }
private Either<Set<ParseFailedException>, Term> wrapTermWithCast(Constant c, Sort declared) { Production cast; if (addCast) { cast = productions.apply(KLabel("#SemanticCastTo" + declared.toString())).head(); } else if (inferCasts && !hasCastAlready && productions.contains(KLabel("#SyntacticCast"))) { cast = stream(productions.apply(KLabel("#SyntacticCast"))).filter(p -> p.sort().equals(declared)).findAny().get(); } else { cast = null; } if (cast == null) { return Right.apply(c); } else { return Right.apply(TermCons.apply(ConsPStack.singleton(c), cast, c.location(), c.source())); } }
public Either<java.util.Set<ParseFailedException>, Term> apply(Constant c) { if (c.production().sort().equals(Sorts.KVariable())) { Sort declared = decl.get(getVarKey(c)); if (declared != null && !(declared.equals(Sorts.K()) && subsorts.lessThanEq(sort, Sorts.KList()))) { // if the declared/inferred sort is K, make sure it can fit in the context (ex. is not a KLabel) if ((!strictSortEquality && !subsorts.lessThanEq(declared, sort)) || (strictSortEquality && !declared.equals(sort))) { String msg = "Unexpected sort " + declared + " for term " + c.value() + ". Expected " + sort + "."; KException kex = new KException(KException.ExceptionType.ERROR, KException.KExceptionGroup.CRITICAL, msg, c.source().orElse(null), c.location().orElse(null)); return Left.apply(Sets.newHashSet(new VariableTypeClashException(kex))); } return wrapTermWithCast(c, declared); } } return Right.apply(c); }