public IEnumerable <LemmaDecl> GetHints(Expr e) { _hintLemmas = new List <LemmaDecl>(); tyVarTranslation = variableFactory.CreateTranslation().TypeVarTranslation; Visit(e); return(_hintLemmas); }
public PassificationLemmaManager( CFGRepr cfg, IDictionary <Block, Block> origToPassiveBlock, IProgramAccessor programAccessor, IProgramAccessor passiveProgramAccessor, Tuple <string, string> varContextNonPassivePassive, StateRelationData oldStateRelationData, PassiveRelationGen relationGen, IVariableTranslationFactory varTranslationFactory, IVariableTranslationFactory passiveTranslationFactory) { this.cfg = cfg; this.origToPassiveBlock = origToPassiveBlock; this.programAccessor = programAccessor; this.passiveProgramAccessor = passiveProgramAccessor; _oldStateRelationData = oldStateRelationData; _relationGen = relationGen; initState = IsaBoogieTerm.Normal(normalInitState); varTranslation = varTranslationFactory.CreateTranslation().VarTranslation; passiveVarTranslation = passiveTranslationFactory.CreateTranslation().VarTranslation; //separate unique namer for function interpretations (since they already have a name in uniqueNamer): possible clashes boogieContext = new BoogieContextIsa( IsaCommonTerms.TermIdentFromName("A"), IsaCommonTerms.TermIdentFromName("M"), IsaCommonTerms.TermIdentFromName(varContextNonPassivePassive.Item1), IsaCommonTerms.TermIdentFromName("\\<Gamma>"), IsaCommonTerms.TermIdentFromName("\\<Omega>") ); passiveVarContext = IsaCommonTerms.TermIdentFromName(varContextNonPassivePassive.Item2); }
public BasicCmdIsaVisitor(IVariableTranslationFactory variableFactory) { this.variableFactory = variableFactory; boogieVarTranslation = variableFactory.CreateTranslation(); //by sharing TypeVarTranslation, changes in the bound variables will be visible in the type visitor typeIsaVisitor = new TypeIsaVisitor(boogieVarTranslation.TypeVarTranslation); }
/// <summary> /// Initializes a new instance of the <see cref="MembershipLemmaManager"/> class. /// Generated instance only has information about global data. /// </summary> public MembershipLemmaManager( IsaGlobalProgramRepr globalProgRepr, int globalsMax, IVariableTranslationFactory factory, string theoryName) { containsLocalInformation = false; this.factory = factory; this.theoryName = theoryName; typeIsaVisitor = new TypeIsaVisitor(factory.CreateTranslation().TypeVarTranslation); basicCmdIsaVisitor = new BasicCmdIsaVisitor(factory); isaProgramRepr = new IsaProgramRepr(globalProgRepr, null, null, null, null, null, null); config = new IsaProgramGeneratorConfig(null, true, true, true, false, SpecsConfig.None, false); consts = QualifyAccessName(isaProgramRepr.GlobalProgramRepr.constantsDeclDef); globals = QualifyAccessName(isaProgramRepr.GlobalProgramRepr.globalsDeclDef); constsAndGlobalsDefs = new[] { consts + "_def", globals + "_def" }; constsAndGlobalsList = IsaCommonTerms.AppendList(IsaCommonTerms.TermIdentFromName(consts), IsaCommonTerms.TermIdentFromName(globals)); AddMinOrMaxLemma(true, globalsMax, VariableNames(constsAndGlobalsList)); AddWellFormednessLemmas(); }
public ContextElem Context() { return(new ContextElem( ContextHelper.GlobalFixedVariables(boogieContext, methodData.Functions, methodData.Constants, normalInitState, funToInterpMapping, uniqueNamer), assmManager.AllAssumptions(funToInterpMapping, declToVCMapping, normalInitState, boogieContext, variableFactory.CreateTranslation().VarTranslation), assmManager.AllAssumptionLabels() )); }
public MembershipLemmaManager( IsaProgramGeneratorConfig config, IsaProgramRepr isaProgramRepr, IsaBlockInfo isaBlockInfo, Tuple <int, int> GlobalsMaxLocalsMin, IVariableTranslationFactory factory, string theoryName ) { parent = config.parentAccessor; this.isaProgramRepr = isaProgramRepr; this.factory = factory; this.theoryName = theoryName; this.config = config; this.isaBlockInfo = isaBlockInfo; typeIsaVisitor = new TypeIsaVisitor(factory.CreateTranslation().TypeVarTranslation); basicCmdIsaVisitor = new BasicCmdIsaVisitor(factory); paramsAndLocalsDefs = new[] { isaProgramRepr.paramsDeclDef + "_def", isaProgramRepr.localVarsDeclDef + "_def" }; parameters = config.generateParamsAndLocals ? QualifyAccessName(isaProgramRepr.paramsDeclDef) : parent.ParamsDecl(); locals = config.generateParamsAndLocals ? QualifyAccessName(isaProgramRepr.localVarsDeclDef) : parent.LocalsDecl(); paramsAndLocalsList = IsaCommonTerms.AppendList(IsaCommonTerms.TermIdentFromName(parameters), IsaCommonTerms.TermIdentFromName(locals)); consts = config.generateGlobalsAndConstants ? QualifyAccessName(isaProgramRepr.GlobalProgramRepr.constantsDeclDef) : parent.ConstsDecl(); globals = config.generateGlobalsAndConstants ? QualifyAccessName(isaProgramRepr.GlobalProgramRepr.globalsDeclDef) : parent.GlobalsDecl(); constsAndGlobalsDefs = new[] { consts + "_def", globals + "_def" }; constsAndGlobalsList = IsaCommonTerms.AppendList(IsaCommonTerms.TermIdentFromName(consts), IsaCommonTerms.TermIdentFromName(globals)); AddDisjointnessLemmas(GlobalsMaxLocalsMin.Item1, GlobalsMaxLocalsMin.Item2); AddWellFormednessLemmas(); }
public BoogieVariableTranslation VariableTranslation() { return(factory.CreateTranslation()); }
public static Theory PassificationProof( string theoryName, string boogieToVcTheoryName, bool generateEndToEndLemma, LemmaDecl boogieToVcLemma, Term vcAssm, CFGRepr beforePassificationCfg, IDictionary <Block, Block> nonPassiveToPassiveBlock, PassiveRelationGen relationGen, IProgramAccessor beforePassiveProgAccess, IProgramAccessor passiveProgAccess, BoogieMethodData beforePassiveData, IVariableTranslationFactory beforePassiveFactory, IVariableTranslationFactory passiveFactory) { var varContextName = "\\<Lambda>1"; var passiveVarContextName = "\\<Lambda>2"; var varContextNonPassivePassive = Tuple.Create(varContextName, passiveVarContextName); var oldGlobalVars = GetOldGlobalVariables(beforePassificationCfg); var oldRelationData = OldRelation( oldGlobalVars, beforePassiveFactory.CreateTranslation().VarTranslation, out var oldRelListDecl); var passificationProofDecls = new List <OuterDecl>(); passificationProofDecls.AddRange(oldRelListDecl); passificationProofDecls.AddRange(oldRelationData.VarToLookupLemma.Values); if (oldRelationData.VarToLookupLemma.Any()) { passificationProofDecls.Add(new LemmasDecl(allOldLookupLemmasName, oldRelationData.VarToLookupLemma.Values.Select(lemma => lemma.Name).ToList())); } var beforePassiveLemmaManager = new PassificationLemmaManager( beforePassificationCfg, nonPassiveToPassiveBlock, beforePassiveProgAccess, passiveProgAccess, varContextNonPassivePassive, oldRelationData, relationGen, beforePassiveFactory, passiveFactory ); var lemmaNamer = new IsaUniqueNamer(); var varContextAbbrev = new AbbreviationDecl( varContextName, new Tuple <IList <Term>, Term>(new List <Term>(), beforePassiveProgAccess.VarContext()) ); var passiveVarContextAbbrev = new AbbreviationDecl( passiveVarContextName, new Tuple <IList <Term>, Term>(new List <Term>(), passiveProgAccess.VarContext()) ); passificationProofDecls.Add(varContextAbbrev); passificationProofDecls.Add(passiveVarContextAbbrev); passificationProofDecls.AddRange(beforePassiveLemmaManager.Prelude()); var cfgLemmas = new List <OuterDecl>(); foreach (var block in beforePassificationCfg.GetBlocksBackwards()) { var localAndCfgLemma = beforePassiveLemmaManager.GenerateBlockLemma( block, GetLemmaName(block, lemmaNamer), b => GetCfgLemmaName(b, lemmaNamer)); passificationProofDecls.Add(localAndCfgLemma.Item1); cfgLemmas.Add(localAndCfgLemma.Item2); } //add cfg lemmas at the end passificationProofDecls.AddRange(cfgLemmas); if (generateEndToEndLemma) { var endToEnd = new PassificationEndToEnd(); passificationProofDecls.AddRange(endToEnd.EndToEndProof( GetCfgLemmaName(beforePassificationCfg.entry, lemmaNamer), boogieToVcTheoryName + "." + boogieToVcLemma.Name, vcAssm, beforePassiveProgAccess, passiveProgAccess, varContextNonPassivePassive, oldRelationData, beforePassificationCfg, relationGen.LiveVarsBeforeBlock(beforePassificationCfg.entry), passiveFactory.CreateTranslation().VarTranslation )); } var imports = new List <string> { "Boogie_Lang.Semantics", "Boogie_Lang.Util", beforePassiveProgAccess.TheoryName(), passiveProgAccess.TheoryName(), "Boogie_Lang.PassificationML", boogieToVcTheoryName }; if (generateEndToEndLemma) { imports.Add("Boogie_Lang.PassificationEndToEnd"); } return(new Theory(theoryName, imports, passificationProofDecls)); }
public IProgramAccessor GetIsaProgram( string theoryName, string procName, BoogieMethodData methodData, IsaProgramGeneratorConfig config, IVariableTranslationFactory varTranslationFactory, CFGRepr cfg, out IList <OuterDecl> decls, bool generateMembershipLemmas = true, bool onlyGlobalData = false ) { this.varTranslationFactory = varTranslationFactory; varTranslation = varTranslationFactory.CreateTranslation(); cmdIsaVisitor = new MultiCmdIsaVisitor(varTranslationFactory); /* * Term program = IsaBoogieTerm.Program(IsaCommonTerms.TermIdentFromName(funcs.name), * new TermList(new List<Term>()), * new TermList(new List<Term>()), * IsaCommonTerms.TermIdentFromName(axiomsDecl.name), * new List<Term>() { method }); * * var list = new List<Tuple<IList<Term>, Term>> * { * new Tuple<IList<Term>, Term>(new List<Term>(), program) * }; */ //OuterDecl programDefinition = new DefDecl("ProgramM", new Tuple<IList<Term>, Term>(new List<Term>(), program)); decls = new List <OuterDecl>(); var isaGlobalProgramRepr = new IsaGlobalProgramRepr( FunctionDeclarationsName(), AxiomDeclarationsName(), VariableDeclarationsName("globals"), VariableDeclarationsName("constants") ); var globalsMax = methodData.Constants.Count() + methodData.GlobalVars.Count() - 1; // assume single versioning and order on constants, globals, params, locals var localsMin = globalsMax + 1; if (globalsMax < 0) { globalsMax = 0; } MembershipLemmaManager membershipLemmaManager; if (onlyGlobalData) { membershipLemmaManager = new MembershipLemmaManager( isaGlobalProgramRepr, globalsMax, varTranslationFactory, theoryName); } else { var outEdges = GetOutEdgesIsa(procName, cfg, out var edgeLemmas); var blockInfo = BlockToInfo(theoryName, procName, cfg, edgeLemmas); var isaProgramRepr = new IsaProgramRepr( isaGlobalProgramRepr, PreconditionDeclarationName(), PostconditionDeclarationName(), VariableDeclarationsName("params"), VariableDeclarationsName("locals"), cfgName, procDefName); membershipLemmaManager = new MembershipLemmaManager(config, isaProgramRepr, blockInfo, Tuple.Create(globalsMax, localsMin), varTranslationFactory, theoryName); var nodesToBlocks = GetNodeToBlocksIsa(cfg, blockInfo.BlockCmdsDefs); decls.AddRange(blockInfo.BlockCmdsDefs.Values); Term entry = new IntConst(BigNum.FromInt(cfg.GetUniqueIntLabel(cfg.entry))); var methodBodyCFG = IsaBoogieTerm.MethodCFGBody( entry, IsaCommonTerms.TermIdentFromName(outEdges.Name), IsaCommonTerms.TermIdentFromName(nodesToBlocks.Name) ); var methodBodyDecl = GetMethodBodyCFGDecl(procName, methodBodyCFG); decls.AddRange( new List <OuterDecl> { outEdges, nodesToBlocks, methodBodyDecl }); decls.AddRange(blockInfo.BlockCmdsLemmas.Values); decls.AddRange(blockInfo.BlockOutEdgesLemmas.Values); if (config.specsConfig != SpecsConfig.None) { OuterDecl preconditions; OuterDecl postconditions; if (config.specsConfig == SpecsConfig.AllPreCheckedPost) { preconditions = GetExprListIsa(PreconditionDeclarationName(), methodData.Preconditions.Select(pre => pre.Item1)); postconditions = GetExprListIsa(PostconditionDeclarationName(), methodData.Postconditions.Where(post => !post.Item2).Select(post => post.Item1)); } else { preconditions = GetExprListIsa(PreconditionDeclarationName(), methodData.Preconditions); postconditions = GetExprListIsa(PostconditionDeclarationName(), methodData.Postconditions); } decls.Add(preconditions); decls.Add(postconditions); } if (config.generateParamsAndLocals) { decls.Add(GetVariableDeclarationsIsa("params", methodData.InParams)); decls.Add(GetVariableDeclarationsIsa("locals", methodData.Locals)); } /* membership lemmas might still be added even if the parameter and local variable definitions are not generated * at this point (since the variable context may still be different, which requires other lookup lemmas) */ if (generateMembershipLemmas) { membershipLemmaManager.AddVariableMembershipLemmas(methodData.InParams, VarKind.ParamOrLocal); membershipLemmaManager.AddVariableMembershipLemmas(methodData.Locals, VarKind.ParamOrLocal); } } if (config.generateAxioms) { decls.Add(GetAxioms(methodData.Axioms)); if (generateMembershipLemmas) { membershipLemmaManager.AddAxiomMembershipLemmas(methodData.Axioms); } } if (config.generateFunctions) { decls.Add(GetFunctionDeclarationsIsa(methodData.Functions)); if (generateMembershipLemmas) { membershipLemmaManager.AddFunctionMembershipLemmas(methodData.Functions); } } if (config.generateGlobalsAndConstants) { decls.Add(GetVariableDeclarationsIsa("globals", methodData.GlobalVars)); decls.Add(GetVariableDeclarationsIsa("constants", methodData.Constants)); } if (generateMembershipLemmas) { membershipLemmaManager.AddVariableMembershipLemmas(methodData.GlobalVars, VarKind.Global); membershipLemmaManager.AddVariableMembershipLemmas(methodData.Constants, VarKind.Constant); decls.AddRange(membershipLemmaManager.OuterDecls()); } if (config.specsConfig != SpecsConfig.None) { DefDecl methodDef = MethodDefinition(membershipLemmaManager, methodData, config.specsConfig); decls.Add(methodDef); } return(membershipLemmaManager); }