public void Arguments() { var tcDecl = new TypeCtorDecl(Token.NoToken, "fox", 1); var tc = new CtorType(Token.NoToken, tcDecl, new List <Microsoft.Boogie.Type>() { Microsoft.Boogie.Type.Bool }); var tcTypeIdent = new TypedIdent(Token.NoToken, "fox", tc); var gv = new GlobalVariable(Token.NoToken, tcTypeIdent); // FIXME: The Symbolic constructor shouldn't really need the program location gv.SetMetadata <ProgramLocation>((int)AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(gv)); var sym = new SymbolicVariable("y", gv); var builder = new SimpleExprBuilder(/*immutable=*/ true); var eq = builder.Eq(sym.Expr, sym.Expr); Assert.IsNotInstanceOf <LiteralExpr>(eq); // Check that it wasn't constant folded using (var writer = new StringWriter()) { var printer = GetPrinter(writer); printer.AddDeclarations(eq); printer.PrintSortDeclarations(); Assert.AreEqual("(declare-sort @fox)\n", writer.ToString()); } }
public override Declaration VisitTypeCtorDecl(TypeCtorDecl node) { if (DoesTypeCtorDeclNeedMonomorphization(node)) { isMonomorphic = false; } return(base.VisitTypeCtorDecl(node)); }
public static ProverInterface CreateProver(Program prog, string/*?*/ logFilePath, bool appendLogFile, int timeout, int taskID = -1) { Contract.Requires(prog != null); ProverOptions options = cce.NonNull(CommandLineOptions.Clo.TheProverFactory).BlankProverOptions(); if (logFilePath != null) { options.LogFilename = logFilePath; if (appendLogFile) options.AppendLogFile = appendLogFile; } if (timeout > 0) { options.TimeLimit = timeout * 1000; } if (taskID >= 0) { options.Parse(CommandLineOptions.Clo.Cho[taskID].ProverOptions); } else { options.Parse(CommandLineOptions.Clo.ProverOptions); } ProverContext ctx = (ProverContext)CommandLineOptions.Clo.TheProverFactory.NewProverContext(options); // set up the context foreach (Declaration decl in prog.TopLevelDeclarations) { Contract.Assert(decl != null); TypeCtorDecl t = decl as TypeCtorDecl; if (t != null) { ctx.DeclareType(t, null); } } foreach (Declaration decl in prog.TopLevelDeclarations) { Contract.Assert(decl != null); Constant c = decl as Constant; if (c != null) { ctx.DeclareConstant(c, c.Unique, null); } else { Function f = decl as Function; if (f != null) { ctx.DeclareFunction(f, null); } } } foreach (var ax in prog.Axioms) { ctx.AddAxiom(ax, null); } foreach (Declaration decl in prog.TopLevelDeclarations) { Contract.Assert(decl != null); GlobalVariable v = decl as GlobalVariable; if (v != null) { ctx.DeclareGlobalVariable(v, null); } } return (ProverInterface)CommandLineOptions.Clo.TheProverFactory.SpawnProver(options, ctx); }
private Function SelectFun(MapType m, TypeCtorDecl ctorDecl) { var ctorTypeParams = m.FreeVariables.Select(tv => (Type)tv).ToList(); var ctorType = new CtorType(Token.NoToken, ctorDecl, ctorTypeParams); var valueTypes = new List <Type> { ctorType }; valueTypes.AddRange(m.Arguments); valueTypes.Add(m.Result); List <TypeVariable> typeParams = new List <TypeVariable> (m.TypeParameters); typeParams.AddRange(m.FreeVariables); return(HelperFuns.BoogieFunction("select_" + ctorDecl.Name, typeParams, valueTypes.ToArray())); }
protected MapTypeClassRepresentation GetClassRepresentation(MapType abstractedType, MapType rawType) { MapTypeClassRepresentation res; if (!classRepresentations.TryGetValue(abstractedType, out res)) { int num = classRepresentations.Count; TypeCtorDecl /*!*/ synonym = new TypeCtorDecl(Token.NoToken, "MapType" + num, abstractedType.FreeVariables.Count); Function select, store; GenSelectStoreFunctions(abstractedType, synonym, out select, out store); res = new MapTypeClassRepresentation(synonym, select, store); classRepresentations.Add(abstractedType, res); reprToRawType.Add(synonym, rawType); } return(res); }
public void MapWithTypeConstructorTypesNoArguments() { var tcDecl = new TypeCtorDecl(Token.NoToken, "fox", 0); var tc = new CtorType(Token.NoToken, tcDecl, new List <Microsoft.Boogie.Type>()); var tcDecl2 = new TypeCtorDecl(Token.NoToken, "fox_two", 0); var tc2 = new CtorType(Token.NoToken, tcDecl2, new List <Microsoft.Boogie.Type>()); var tcDecl3 = new TypeCtorDecl(Token.NoToken, "fox_three", 0); var tc3 = new CtorType(Token.NoToken, tcDecl3, new List <Microsoft.Boogie.Type>()); var mapType = new MapType( Token.NoToken, new List <Microsoft.Boogie.TypeVariable>(), new List <Microsoft.Boogie.Type>() { tc, tc2 }, tc3); var mapTypeTypeIdent = new TypedIdent(Token.NoToken, "mapx", mapType); var gv = new GlobalVariable(Token.NoToken, mapTypeTypeIdent); // FIXME: The Symbolic constructor shouldn't really need the program location gv.SetMetadata <ProgramLocation>((int)AnnotationIndex.PROGRAM_LOCATION, new ProgramLocation(gv)); var sym = new SymbolicVariable("y", gv); var builder = new SimpleExprBuilder(/*immutable=*/ true); var eq = builder.Eq(sym.Expr, sym.Expr); Assert.IsNotInstanceOf <LiteralExpr>(eq); // Check that it wasn't constant folded using (var writer = new StringWriter()) { var printer = GetPrinter(writer); printer.AddDeclarations(eq); printer.PrintSortDeclarations(); var str = writer.ToString().Trim(); // Check we can see all the sort declarations we expect but don't depend on their order Assert.IsTrue(str.Contains("(declare-sort @fox)")); Assert.IsTrue(str.Contains("(declare-sort @fox_two)")); Assert.IsTrue(str.Contains("(declare-sort @fox_three)")); } }
public MapTypeClassRepresentation(TypeCtorDecl representingType, Function select, Function store) { RepresentingType = representingType; Select = select; Store = store; }
public override Declaration VisitTypeCtorDecl(TypeCtorDecl node) { return((Declaration)node); }
public override Declaration VisitTypeCtorDecl(TypeCtorDecl node) { add(node); return(base.VisitTypeCtorDecl(node)); }
public override void DeclareType(TypeCtorDecl t, string attributes) { base.DeclareType(t, attributes); log("(declare-sort {0})", t.Name); }
public LeftInverseAxiomInfo(TypeCtorDecl decl, int projectedIdx, VCExpr expr) : base(expr) { Decl = decl; this.projectedIdx = projectedIdx; }
public static bool DoesTypeCtorDeclNeedMonomorphization(TypeCtorDecl typeCtorDecl) { return(typeCtorDecl.Arity > 0 && typeCtorDecl.FindStringAttribute("builtin") == null); }
//////////////////////////////////////////////////////////////////////////// protected override void GenSelectStoreFunctions(MapType abstractedType, TypeCtorDecl synonym, out Function /*!*/ select, out Function /*!*/ store) { //Contract.Requires(synonym != null); //Contract.Requires(abstractedType != null); Contract.Ensures(Contract.ValueAtReturn(out select) != null); Contract.Ensures(Contract.ValueAtReturn(out store) != null); Contract.Assert(synonym.Name != null); string /*!*/ baseName = synonym.Name; int typeParamNum = abstractedType.FreeVariables.Count + abstractedType.TypeParameters.Count; int arity = typeParamNum + abstractedType.Arguments.Count; Type /*!*/[] /*!*/ selectTypes = new Type /*!*/ [arity + 2]; Type /*!*/[] /*!*/ storeTypes = new Type /*!*/ [arity + 3]; int i = 0; // Fill in the free variables and type parameters for (; i < typeParamNum; i++) { selectTypes[i] = AxBuilder.T; storeTypes[i] = AxBuilder.T; } // Fill in the map type selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; i++; // Fill in the index types foreach (Type /*!*/ type in abstractedType.Arguments) { Contract.Assert(type != null); selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; i++; } // Fill in the output type for select function which also happens // to be the type of the last argument to the store function selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; i++; // Fill in the map type which is the output of the store function storeTypes[i] = AxBuilder.U; Contract.Assert(cce.NonNullElements <Type>(selectTypes)); Contract.Assert(cce.NonNullElements <Type>(storeTypes)); select = HelperFuns.BoogieFunction(baseName + "Select", selectTypes); store = HelperFuns.BoogieFunction(baseName + "Store", storeTypes); if (CommandLineOptions.Clo.UseArrayTheory) { select.AddAttribute("builtin", "select"); store.AddAttribute("builtin", "store"); } else { AxBuilder.AddTypeAxiom(GenMapAxiom0(select, store, abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count)); AxBuilder.AddTypeAxiom(GenMapAxiom1(select, store, abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count)); } }
//////////////////////////////////////////////////////////////////////////// protected override void GenSelectStoreFunctions(MapType abstractedType, TypeCtorDecl synonym, out Function/*!*/ select, out Function/*!*/ store) { //Contract.Requires(synonym != null); //Contract.Requires(abstractedType != null); Contract.Ensures(Contract.ValueAtReturn(out select) != null); Contract.Ensures(Contract.ValueAtReturn(out store) != null); Contract.Assert(synonym.Name != null); string/*!*/ baseName = synonym.Name; int typeParamNum = abstractedType.FreeVariables.Count + abstractedType.TypeParameters.Count; int arity = typeParamNum + abstractedType.Arguments.Count; Type/*!*/[]/*!*/ selectTypes = new Type/*!*/ [arity + 2]; Type/*!*/[]/*!*/ storeTypes = new Type/*!*/ [arity + 3]; int i = 0; // Fill in the free variables and type parameters for (; i < typeParamNum; i++) { selectTypes[i] = AxBuilder.T; storeTypes[i] = AxBuilder.T; } // Fill in the map type if (CommandLineOptions.Clo.MonomorphicArrays) { selectTypes[i] = abstractedType; storeTypes[i] = abstractedType; } else { selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; } i++; // Fill in the index types foreach (Type/*!*/ type in abstractedType.Arguments) { Contract.Assert(type != null); if (CommandLineOptions.Clo.Monomorphize && AxBuilder.UnchangedType(type)) { selectTypes[i] = type; storeTypes[i] = type; } else { selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; } i++; } // Fill in the output type for select function which also happens // to be the type of the last argument to the store function if (CommandLineOptions.Clo.Monomorphize && AxBuilder.UnchangedType(abstractedType.Result)) { selectTypes[i] = abstractedType.Result; storeTypes[i] = abstractedType.Result; } else { selectTypes[i] = AxBuilder.U; storeTypes[i] = AxBuilder.U; } i++; // Fill in the map type which is the output of the store function if (CommandLineOptions.Clo.MonomorphicArrays) storeTypes[i] = abstractedType; else storeTypes[i] = AxBuilder.U; Contract.Assert(cce.NonNullElements<Type>(selectTypes)); Contract.Assert(cce.NonNullElements<Type>(storeTypes)); select = HelperFuns.BoogieFunction(baseName + "Select", selectTypes); store = HelperFuns.BoogieFunction(baseName + "Store", storeTypes); if (CommandLineOptions.Clo.UseArrayTheory) { select.AddAttribute("builtin", "select"); store.AddAttribute("builtin", "store"); } else { AxBuilder.AddTypeAxiom(GenMapAxiom0(select, store, abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count)); AxBuilder.AddTypeAxiom(GenMapAxiom1(select, store, abstractedType.TypeParameters.Count, abstractedType.FreeVariables.Count)); } }
private void GenSelectStoreFunctions(MapType abstractedType, TypeCtorDecl synonym, out Function select, out Function store) { select = SelectFun(abstractedType, synonym); store = StoreFun(abstractedType, synonym); }
public MapType RawType(TypeCtorDecl decl) { return(reprToRawType[decl]); }
public CtorDeclAxiomInfo(TypeCtorDecl decl, int ctorValue, VCExpr expr) : base(ctorValue, expr) { Decl = decl; }
public virtual void DeclareType(TypeCtorDecl t, string attributes) { Contract.Requires(t != null); ProcessDeclaration(t); }
//////////////////////////////////////////////////////////////////////////// protected override void GenSelectStoreFunctions(MapType abstractedType, TypeCtorDecl synonym, out Function/*!*/ select, out Function/*!*/ store) { //Contract.Requires(synonym != null); //Contract.Requires(abstractedType != null); Contract.Ensures(Contract.ValueAtReturn(out select) != null); Contract.Ensures(Contract.ValueAtReturn(out store) != null); Type/*!*/ mapTypeSynonym; List<TypeVariable/*!*/>/*!*/ typeParams; List<Type/*!*/>/*!*/ originalInTypes; GenTypeAxiomParams(abstractedType, synonym, out mapTypeSynonym, out typeParams, out originalInTypes); // select List<TypeVariable/*!*/>/*!*/ explicitSelectParams, implicitSelectParams; select = CreateAccessFun(typeParams, originalInTypes, abstractedType.Result, synonym.Name + "Select", out implicitSelectParams, out explicitSelectParams); // store, which gets one further argument: the assigned rhs originalInTypes.Add(abstractedType.Result); List<TypeVariable/*!*/>/*!*/ explicitStoreParams, implicitStoreParams; store = CreateAccessFun(typeParams, originalInTypes, mapTypeSynonym, synonym.Name + "Store", out implicitStoreParams, out explicitStoreParams); // the store function does not have any explicit type parameters Contract.Assert(explicitStoreParams.Count == 0); if (CommandLineOptions.Clo.UseArrayTheory) { select.AddAttribute("builtin", "select"); store.AddAttribute("builtin", "store"); } else { AxBuilder.AddTypeAxiom(GenMapAxiom0(select, store, abstractedType.Result, implicitSelectParams, explicitSelectParams, originalInTypes)); AxBuilder.AddTypeAxiom(GenMapAxiom1(select, store, abstractedType.Result, explicitSelectParams)); } }
protected void GenTypeAxiomParams(MapType/*!*/ abstractedType, TypeCtorDecl/*!*/ synonymDecl, out Type/*!*/ mapTypeSynonym, out List<TypeVariable/*!*/>/*!*/ typeParams, out List<Type/*!*/>/*!*/ originalIndexTypes) { Contract.Requires(abstractedType != null); Contract.Requires(synonymDecl != null); Contract.Ensures(Contract.ValueAtReturn(out mapTypeSynonym) != null); Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out typeParams))); Contract.Ensures(cce.NonNullElements(Contract.ValueAtReturn(out originalIndexTypes))); typeParams = new List<TypeVariable/*!*/>(); typeParams.AddRange(abstractedType.TypeParameters); typeParams.AddRange(abstractedType.FreeVariables); originalIndexTypes = new List<Type/*!*/>(abstractedType.Arguments.Count + 1); List<Type>/*!*/ mapTypeParams = new List<Type>(); foreach (TypeVariable/*!*/ var in abstractedType.FreeVariables) { Contract.Assert(var != null); mapTypeParams.Add(var); } if (CommandLineOptions.Clo.MonomorphicArrays) mapTypeSynonym = abstractedType; else mapTypeSynonym = new CtorType(Token.NoToken, synonymDecl, mapTypeParams); originalIndexTypes.Add(mapTypeSynonym); originalIndexTypes.AddRange(abstractedType.Arguments.ToList()); }
public virtual Declaration VisitTypeCtorDecl(TypeCtorDecl node) { Contract.Requires(node != null); Contract.Ensures(Contract.Result <Declaration>() != null); return(this.VisitDeclaration(node)); }