Ejemplo n.º 1
0
        public static Solution CreateSolution(Atomic atomic, MatchStmt ms)
        {
            Atomic ac = atomic.Copy();

            ac.AddUpdated(ms, ms);
            return(new Solution(ac, true, null));
        }
Ejemplo n.º 2
0
        public static IEnumerable <Solution> SearchBlockStmt(BlockStmt body, Atomic atomic)
        {
            Atomic ac = atomic.Copy();

            ac.DynamicContext.tacticBody = body.Body;
            ac.DynamicContext.ResetCounter();
            Stack <IEnumerator <Solution> > solutionStack = new Stack <IEnumerator <Solution> >();

            solutionStack.Push(Atomic.ResolveStatement(new Solution(ac)).GetEnumerator());

            while (true)
            {
                if (solutionStack.Count == 0)
                {
                    yield break;
                }

                var solutionEnum = solutionStack.Pop();

                // if the solution is fully resolved skip resolution
                if (!solutionEnum.MoveNext())
                {
                    continue;
                }
                var solution = solutionEnum.Current;

                solutionStack.Push(solutionEnum);
                if (solution.State.DynamicContext.isPartialyResolved)
                {
                    solutionStack.Push(Atomic.ResolveStatement(solution).GetEnumerator());
                    yield return(solution);
                }
                else if (solution.State.DynamicContext.GetCurrentStatement() == null)
                {
                    yield return(solution);
                }
                else
                {
                    solutionStack.Push(Atomic.ResolveStatement(solution).GetEnumerator());
                }
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable <Solution> SearchBlockStmt(BlockStmt body, Atomic atomic)
        {
            Atomic ac = atomic.Copy();

            ac.DynamicContext.tacticBody = body.Body;
            ac.DynamicContext.ResetCounter();
            List <Solution> result = new List <Solution> {
                new Solution(ac)
            };

            // search strategy for body goes here
            while (true)
            {
                List <Solution> interm = new List <Solution>();
                if (result.Count == 0)
                {
                    break;
                }
                foreach (var solution in result)
                {
                    foreach (var item in Atomic.ResolveStatement(solution))
                    {
                        if (item.State.DynamicContext.isPartialyResolved)
                        {
                            { interm.Add(item); }
                            yield return(item);
                        }
                        else if (item.State.DynamicContext.GetCurrentStatement() == null)
                        {
                            yield return(item);
                        }
                        else
                        {
                            interm.Add(item);
                        }
                    }
                }

                result.Clear();
                result.AddRange(interm);
            }
        }
Ejemplo n.º 4
0
        public string GenerateProgram(ref Program prog, bool isFinal = false)
        {
            Debug.WriteLine("Generating Dafny program");
            var        ac = State.Copy();
            MemberDecl newMemberDecl;

            ac.Fin();
            if (!ac.IsFunction)
            {
                var method = Tacny.Program.FindMember(prog, ac.DynamicContext.md.Name) as Method;
                if (method == null)
                {
                    throw new Exception("Method not found");
                }
                UpdateStmt       tacCall = ac.GetTacticCall();
                List <Statement> body    = method.Body.Body;
                body = InsertSolution(body, tacCall, ac.GetResolved());
                if (body == null)
                {
                    return(null);
                }
                if (!isFinal)
                {
                    for (int i = 0; i < body.Count; i++)
                    {
                        var us = body[i] as UpdateStmt;
                        if (us == null)
                        {
                            continue;
                        }
                        if (State.StaticContext.program.IsTacticCall(us))
                        {
                            body.RemoveAt(i);
                        }
                    }
                }

                newMemberDecl = GenerateMethod(method, body, ac.DynamicContext.newTarget as Method);
            }
            else
            {
                newMemberDecl = ac.GetNewTarget();
            }
            for (int i = 0; i < prog.DefaultModuleDef.TopLevelDecls.Count; i++)
            {
                var curDecl = prog.DefaultModuleDef.TopLevelDecls[i] as ClassDecl;
                if (curDecl != null)
                {
                    // scan each member for tactic calls and resolve if found
                    for (int j = 0; j < curDecl.Members.Count; j++)
                    {
                        if (curDecl.Members[j].Name == newMemberDecl.Name)
                        {
                            curDecl.Members[j] = newMemberDecl;
                        }
                    }

                    prog.DefaultModuleDef.TopLevelDecls[i] = Tacny.Program.RemoveTactics(curDecl);
                }
            }

            Debug.WriteLine("Dafny program generated");
            return(null);
        }
Ejemplo n.º 5
0
    public static IEnumerable<Solution> SearchBlockStmt(BlockStmt body, Atomic atomic) {
      Atomic ac = atomic.Copy();
      ac.DynamicContext.tacticBody = body.Body;
      ac.DynamicContext.ResetCounter();
      Stack<IEnumerator<Solution>> solutionStack = new Stack<IEnumerator<Solution>>();
      solutionStack.Push(Atomic.ResolveStatement(new Solution(ac)).GetEnumerator());

      while (true) {
        if (solutionStack.Count == 0) {

          yield break;
        }

        var solutionEnum = solutionStack.Pop();

        // if the solution is fully resolved skip resolution
        if (!solutionEnum.MoveNext())
          continue;
        var solution = solutionEnum.Current;

        solutionStack.Push(solutionEnum);
        if (solution.State.DynamicContext.isPartialyResolved) {
          solutionStack.Push(Atomic.ResolveStatement(solution).GetEnumerator());
          yield return solution;
        } else if (solution.State.DynamicContext.GetCurrentStatement() == null) {
          yield return solution;
        } else { solutionStack.Push(Atomic.ResolveStatement(solution).GetEnumerator()); }

      }
    }
Ejemplo n.º 6
0
    public static IEnumerable<Solution> SearchBlockStmt(BlockStmt body, Atomic atomic) {
      Atomic ac = atomic.Copy();
      ac.DynamicContext.tacticBody = body.Body;
      ac.DynamicContext.ResetCounter();
      List<Solution> result = new List<Solution> { new Solution(ac) };
      // search strategy for body goes here
      while (true) {
        List<Solution> interm = new List<Solution>();
        if (result.Count == 0)
          break;
        foreach (var solution in result) {
          foreach (var item in Atomic.ResolveStatement(solution)) {
            if (item.State.DynamicContext.isPartialyResolved) {
              { interm.Add(item); }
              yield return item;
            } else if (item.State.DynamicContext.GetCurrentStatement() == null) { yield return item; } else { interm.Add(item); }
          }
        }

        result.Clear();
        result.AddRange(interm);
      }
    }