Search in sources :

Example 1 with ArrayFormulaType

use of org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType in project java-smt by sosy-lab.

the class PrincessFormulaCreator method getFormulaType.

@SuppressWarnings("unchecked")
@Override
public <T extends Formula> FormulaType<T> getFormulaType(final T pFormula) {
    if (pFormula instanceof BitvectorFormula) {
        ITerm input = (ITerm) extractInfo(pFormula);
        Sort sort = Sort$.MODULE$.sortOf(input);
        scala.Option<Object> bitWidth = PrincessEnvironment.getBitWidth(sort);
        checkArgument(bitWidth.isDefined(), "BitvectorFormula with actual type %s: %s", sort, pFormula);
        return (FormulaType<T>) FormulaType.getBitvectorTypeWithSize((Integer) bitWidth.get());
    } else if (pFormula instanceof ArrayFormula<?, ?>) {
        final FormulaType<?> arrayIndexType = getArrayFormulaIndexType((ArrayFormula<?, ?>) pFormula);
        final FormulaType<?> arrayElementType = getArrayFormulaElementType((ArrayFormula<?, ?>) pFormula);
        return (FormulaType<T>) new ArrayFormulaType<>(arrayIndexType, arrayElementType);
    }
    return super.getFormulaType(pFormula);
}
Also used : BitvectorFormula(org.sosy_lab.java_smt.api.BitvectorFormula) ArrayFormula(org.sosy_lab.java_smt.api.ArrayFormula) ITerm(ap.parser.ITerm) Sort(ap.types.Sort) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)

Example 2 with ArrayFormulaType

use of org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType in project java-smt by sosy-lab.

the class PrincessEnvironment method getFormulaTypeFromSort.

private static FormulaType<?> getFormulaTypeFromSort(final Sort sort) {
    if (sort == PrincessEnvironment.BOOL_SORT) {
        return FormulaType.BooleanType;
    } else if (sort == PrincessEnvironment.INTEGER_SORT) {
        return FormulaType.IntegerType;
    } else if (sort instanceof ExtArray.ArraySort) {
        Seq<Sort> indexSorts = ((ExtArray.ArraySort) sort).theory().indexSorts();
        Sort elementSort = ((ExtArray.ArraySort) sort).theory().objSort();
        assert indexSorts.iterator().size() == 1 : "unexpected index type in Array type:" + sort;
        // assert indexSorts.size() == 1; // TODO Eclipse does not like simpler code.
        return new ArrayFormulaType<>(// get single index-sort
        getFormulaTypeFromSort(indexSorts.iterator().next()), getFormulaTypeFromSort(elementSort));
    } else if (sort instanceof MultipleValueBool$) {
        return FormulaType.BooleanType;
    } else {
        scala.Option<Object> bitWidth = getBitWidth(sort);
        if (bitWidth.isDefined()) {
            return FormulaType.getBitvectorTypeWithSize((Integer) bitWidth.get());
        }
    }
    throw new IllegalArgumentException(String.format("Unknown formula type '%s' for sort '%s'.", sort.getClass(), sort));
}
Also used : ExtArray(ap.theories.ExtArray) MultipleValueBool$(ap.types.Sort.MultipleValueBool$) Sort(ap.types.Sort) Option(org.sosy_lab.common.configuration.Option) FileOption(org.sosy_lab.common.configuration.FileOption) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)

Example 3 with ArrayFormulaType

use of org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType in project java-smt by sosy-lab.

the class AbstractFormulaManager method makeVariable.

@Override
public <T extends Formula> T makeVariable(FormulaType<T> formulaType, String name) {
    checkVariableName(name);
    Formula t;
    if (formulaType.isBooleanType()) {
        t = booleanManager.makeVariable(name);
    } else if (formulaType.isIntegerType()) {
        assert integerManager != null;
        t = integerManager.makeVariable(name);
    } else if (formulaType.isRationalType()) {
        assert rationalManager != null;
        t = rationalManager.makeVariable(name);
    } else if (formulaType.isStringType()) {
        assert strManager != null;
        t = strManager.makeVariable(name);
    } else if (formulaType.isBitvectorType()) {
        assert bitvectorManager != null;
        t = bitvectorManager.makeVariable((BitvectorType) formulaType, name);
    } else if (formulaType.isFloatingPointType()) {
        assert floatingPointManager != null;
        t = floatingPointManager.makeVariable(name, (FloatingPointType) formulaType);
    } else if (formulaType.isArrayType()) {
        assert arrayManager != null;
        t = arrayManager.makeArray(name, (ArrayFormulaType<?, ?>) formulaType);
    } else {
        throw new IllegalArgumentException("Unknown formula type");
    }
    @SuppressWarnings("unchecked") T out = (T) t;
    return out;
}
Also used : BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Formula(org.sosy_lab.java_smt.api.Formula) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)

Example 4 with ArrayFormulaType

use of org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType in project java-smt by sosy-lab.

the class CVC4ArrayFormulaManager method internalMakeArray.

@Override
@SuppressWarnings("MethodTypeParameterName")
protected <TI extends Formula, TE extends Formula> Expr internalMakeArray(String pName, FormulaType<TI> pIndexType, FormulaType<TE> pElementType) {
    final ArrayFormulaType<TI, TE> arrayFormulaType = FormulaType.getArrayType(pIndexType, pElementType);
    final Type cvc4ArrayType = toSolverType(arrayFormulaType);
    return getFormulaCreator().makeVariable(cvc4ArrayType, pName);
}
Also used : Type(edu.stanford.CVC4.Type) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)

Aggregations

ArrayFormulaType (org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)4 Sort (ap.types.Sort)2 FormulaType (org.sosy_lab.java_smt.api.FormulaType)2 ITerm (ap.parser.ITerm)1 ExtArray (ap.theories.ExtArray)1 MultipleValueBool$ (ap.types.Sort.MultipleValueBool$)1 Type (edu.stanford.CVC4.Type)1 FileOption (org.sosy_lab.common.configuration.FileOption)1 Option (org.sosy_lab.common.configuration.Option)1 ArrayFormula (org.sosy_lab.java_smt.api.ArrayFormula)1 BitvectorFormula (org.sosy_lab.java_smt.api.BitvectorFormula)1 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)1 Formula (org.sosy_lab.java_smt.api.Formula)1 BitvectorType (org.sosy_lab.java_smt.api.FormulaType.BitvectorType)1