Ejemplo n.º 1
0
        public TacticReplaceStatus ExpandTacticByMember(out string expandedTactic)
        {
            expandedTactic = "";
            var l = Microsoft.Dafny.Tacny.TacnyDriver.GetTacticResultList();
            var x = _member as Method;

            if (x == null)
            {
                return(TacticReplaceStatus.NoTactic);
            }
            var sr        = new StringWriter();
            var printer   = new Printer(sr);
            var hasTactic = false;

            foreach (var stmt in x.Body.SubStatements)
            {
                var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, stmt.Tok));
                if (result.Key == null)
                {
                    printer.PrintStatement(stmt, 0);
                }
                else
                {
                    hasTactic = true;
                    result.Value.ForEach(foundStmt => printer.PrintStatement(foundStmt, 0));
                }
                sr.Write("\n");
            }
            expandedTactic = hasTactic ? sr.ToString() : "";
            return(TacticReplaceStatus.Success);
        }
Ejemplo n.º 2
0
 public static string GuardToString(bool isExistentialGuard, Expression expr) {
   Contract.Requires(!isExistentialGuard || (expr is ExistsExpr && ((ExistsExpr)expr).Range == null));
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintGuard(isExistentialGuard, expr);
     return wr.ToString();
   }
 }
Ejemplo n.º 3
0
 public static string ExtendedExprToString(Expression expr) {
   Contract.Requires(expr != null);
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintExtendedExpr(expr, 0, true, false);
     return wr.ToString();
   }
 }
Ejemplo n.º 4
0
 public static string FrameExprListToString(List<FrameExpression> fexprs) {
   Contract.Requires(fexprs != null);
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintFrameExpressionList(fexprs);
     return wr.ToString();
   }
 }
Ejemplo n.º 5
0
 public static string StatementToString(Statement stmt) {
   Contract.Requires(stmt != null);
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintStatement(stmt, 0);
     return ToStringWithoutNewline(wr);
   }
 }
Ejemplo n.º 6
0
 public static string IteratorClassToString(IteratorDecl iter) {
   Contract.Requires(iter != null);
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintIteratorClass(iter, 0, null);
     return ToStringWithoutNewline(wr);
   }
 }
Ejemplo n.º 7
0
 public static string FunctionSignatureToString(Function f)
 {
     Contract.Requires(f != null);
       using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintFunction(f, 0, true);
     return ToStringWithoutNewline(wr);
       }
 }
Ejemplo n.º 8
0
        new public void PrintProgram(Program prog)
        {
            Contract.Requires(prog != null);
            wr = new StreamWriter(prog.FullName + ".dfy");
            var printer = new Microsoft.Dafny.Printer(wr, DafnyOptions.PrintModes.Everything);

            printer.PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, prog.FullName);
            //printer.PrintProgram(prog);// PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, Path.GetFullPath(prog.FullName));
            wr.Flush();
        }
Ejemplo n.º 9
0
        private TacticReplaceStatus ExpandSingleTacticCall(UpdateStmt us, out string expanded)
        {
            expanded = "";
            var l      = Interpreter.GetTacnyResultList();
            var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, us.Tok));

            if (result.Value == null)
            {
                return(TacticReplaceStatus.NoTactic);
            }
            var sr      = new StringWriter();
            var printer = new Printer(sr);

            result.Value.ForEach(stmt => printer.PrintStatement(stmt, 4));
            expanded = sr.ToString();
            return(!string.IsNullOrEmpty(expanded) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoTactic);
        }
Ejemplo n.º 10
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="program"></param>
    /// <param name="target"></param>
    /// <param name="erd"></param>
    ///  only used this to report error, local errors which are genereaed during searching should not use this

    /// <param name="r"></param>
    /// <returns></returns>
    public static MemberDecl FindAndApplyTactic(Program program, MemberDecl target, ErrorReporterDelegate erd, Resolver r = null) {
      Contract.Requires(program != null);
      Contract.Requires(target != null);
      Stopwatch watch = new Stopwatch();
      watch.Start();
      _i = new Interpreter(program);
      _errorReporterDelegate = erd;

      var result = _i.EvalTacticApplication(target, r);

      var p = new Printer(Console.Out);
      p.PrintMembers(new List<MemberDecl>() { result }, 0, "");

      watch.Stop();
      Console.WriteLine("Time Used: " + watch.Elapsed.TotalSeconds.ToString());

      _errorReporterDelegate = null;
      return result;
    }
Ejemplo n.º 11
0
        private TacticReplaceStatus ExpandSingleTacticCall(Statement us, out string expanded)
        {
            expanded = "";
            var l      = Microsoft.Dafny.Tacny.TacnyDriver.GetTacticResultList();
            var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, us.Tok));

            if (result.Value == null)
            {
                return(TacticReplaceStatus.NoTactic);
            }
            var sr      = new StringWriter();
            var printer = new Printer(sr);

            foreach (var stmt in result.Value)
            {
                printer.PrintStatement(stmt, 4);
                sr.Write("\n");
            }
            expanded = sr.ToString();
            return(!string.IsNullOrEmpty(expanded) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoTactic);
        }
Ejemplo n.º 12
0
 new public void PrintProgram(Program prog) {
     Contract.Requires(prog != null);
     wr = new StreamWriter(prog.FullName + ".dfy");
     var printer = new Microsoft.Dafny.Printer(wr, DafnyOptions.PrintModes.Everything);
     printer.PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, prog.FullName);
     //printer.PrintProgram(prog);// PrintTopLevelDecls(prog.DefaultModuleDef.TopLevelDecls, 0, Path.GetFullPath(prog.FullName));
     wr.Flush();
 }
Ejemplo n.º 13
0
Archivo: Dare.cs Proyecto: ggrov/tacny
 private static int GetExpressionLength(Expression expr)
 {
     var sw = new StringWriter();
     var printer = new Printer(sw);
     printer.PrintExpression(expr, false);
     return sw.ToString().Length;
 }
Ejemplo n.º 14
0
 public static bool SameStatement(Statement a, Statement b)
 {
   if (a == null || b == null) return false;
   var sr = new StringWriter();
   var printer = new Printer(sr);
   printer.PrintStatement(a, 0);
   var sa = sr.ToString();
   sr.Flush();
   printer.PrintStatement(b, 0);
   var sb = sr.ToString();
   return sa == sb;
 }
Ejemplo n.º 15
0
    private TacticReplaceStatus ExpandSingleTacticCall(UpdateStmt us, out string expanded)
    {
      expanded = "";
      var status = TacticReplaceStatus.Success;
      var newStmts = Tacny.Interpreter.FindSingleTactic(_program, _member, us,
        errorInfo => { status = TacticReplaceStatus.TranslatorFail; }, _unresolvedProgram);
      if (status != TacticReplaceStatus.Success) return status;
      if (newStmts == null) return TacticReplaceStatus.NoTactic;

      var sr = new StringWriter();
      var pr = new Printer(sr);
      for(var i = 0; i < newStmts.Count-1; i++)
      {
        pr.PrintStatement(newStmts[i], 4);
        sr.WriteLine();
      }
      pr.PrintStatement(newStmts[newStmts.Count-1], 4);
      expanded += sr;
      return TacticReplaceStatus.Success;
    }
Ejemplo n.º 16
0
    public TacticReplaceStatus ExpandTactic(out string expandedTactic)
    {
      expandedTactic = null;
      if (!MemberReady) return TacticReplaceStatus.NoTactic;

      var status = TacticReplaceStatus.Success;
      var evaluatedMember = Tacny.Interpreter.FindAndApplyTactic(_program, _member, errorInfo => { status = TacticReplaceStatus.TranslatorFail; }, _unresolvedProgram);
      if (evaluatedMember == null || status != TacticReplaceStatus.Success) return TacticReplaceStatus.TranslatorFail;

      var sr = new StringWriter();
      var printer = new Printer(sr);
      printer.PrintMembers(new List<MemberDecl> { evaluatedMember }, 0, _program.FullName);
      expandedTactic = Util.StripExtraContentFromExpanded(sr.ToString());
      return !string.IsNullOrEmpty(expandedTactic) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoTactic;
    }
Ejemplo n.º 17
0
 public static string OneAttributeToString(Attributes a, string nameSubstitution = null) {
   Contract.Requires(a != null);
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintOneAttribute(a, nameSubstitution);
     return ToStringWithoutNewline(wr);
   }
 }
Ejemplo n.º 18
0
 public static string MethodSignatureToString(Method m) {
   Contract.Requires(m != null);
   using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintMethod(m, 0, true);
     return ToStringWithoutNewline(wr);
   }
 }
Ejemplo n.º 19
0
 public TacticReplaceStatus ExpandTacticByMember(out string expandedTactic) {
   expandedTactic = "";
   var l = Interpreter.GetTacnyResultList();
   var x = _member as Method;
   if (x == null) return TacticReplaceStatus.NoTactic;
   var sr = new StringWriter();
   var printer = new Printer(sr);
   var hasTactic = false;
   foreach (var stmt in x.Body.SubStatements)
   {
     var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key, stmt.Tok));
     if (result.Key==null)
     {
       printer.PrintStatement(stmt,0);
     }
     else
     {
       hasTactic = true;
       result.Value.ForEach(foundStmt => printer.PrintStatement(foundStmt, 0));
     }
     sr.Write("\n");
   }
   expandedTactic = hasTactic ? sr.ToString() : "";
   return TacticReplaceStatus.Success;
 }
Ejemplo n.º 20
0
 private TacticReplaceStatus ExpandSingleTacticCall(UpdateStmt us, out string expanded) {
   expanded = "";
   var l = Interpreter.GetTacnyResultList();
   var result = l.FirstOrDefault(pair => RefactoringUtil.TokenEquals(pair.Key,us.Tok));
   if (result.Value == null) return TacticReplaceStatus.NoTactic;
   var sr = new StringWriter();
   var printer = new Printer(sr);
   result.Value.ForEach(stmt => printer.PrintStatement(stmt, 4));
   expanded = sr.ToString();
   return !string.IsNullOrEmpty(expanded) ? TacticReplaceStatus.Success : TacticReplaceStatus.NoTactic;
 }
Ejemplo n.º 21
0
 public static string ModuleDefinitionToString(ModuleDefinition m, DafnyOptions.PrintModes printMode = DafnyOptions.PrintModes.
     Everything)
 {
     Contract.Requires(m != null);
       using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr, printMode);
     pr.PrintModuleDefinition(m, m.VisibilityScope, 0, null);
     return ToStringWithoutNewline(wr);
       }
 }
Ejemplo n.º 22
0
Archivo: Dare.cs Proyecto: ggrov/tacny
 public void PrintProgram(TextWriter writer)
 {
     var dafnyPrinter = new Printer(writer);
     dafnyPrinter.PrintProgram(Program, false);
 }
Ejemplo n.º 23
0
Archivo: Match.cs Proyecto: ggrov/tacny
    public IEnumerable<ProofState> EvalInit(Statement statement, ProofState state0){
      Contract.Requires(statement != null);
      Contract.Requires(statement is TacnyCasesBlockStmt);
      var state = state0.Copy();

      var stmt = statement as TacnyCasesBlockStmt;
      var p = new Printer(Console.Out);
      NameSegment caseVar;

      //get guards
      Debug.Assert(stmt != null, "stmt != null");
      var guard = stmt.Guard as ParensExpression;

      if(guard == null)
        caseVar = stmt.Guard as NameSegment;
      else
        caseVar = guard.E as NameSegment;

      //TODO: need to check the datatype pf caseGuard, 
      // also need to consider the case that caseVar is a tac var
      var srcVar = state.GetTacnyVarValue(caseVar) as NameSegment;
      var srcVarData = state.GetDafnyVar(srcVar.Name);
      var datatype = state.GetDafnyVarType(srcVar.Name).AsDatatype;


      //generate a test program to check which cases need to apply tacny
      bool[] ctorFlags;
      int ctor; // current active match case
      InitCtorFlags(datatype, out ctorFlags);

      List<Func<int, List<Statement>>> fList = new List<Func<int, List<Statement>>>();

      int i;
      for(i = 0; i < datatype.Ctors.Count; i++) {
        fList.Add(GenerateAssumeFalseStmtAsStmtList);
      }

      //var matchStmt = GenerateMatchStmt(state.TacticApplication.Tok.line, srcVar.Copy(), datatype, fList);
      var matchStmt = GenerateMatchStmt(Interpreter.TACNY_CODE_TOK_LINE, srcVar.Copy(), datatype, fList);

      //use a dummystmt to creat a frame for match, note that this stmts is never be evaluated
      var dummystmt = new List<Statement>();
      for(i = 0; i < datatype.Ctors.Count; i++) {
        dummystmt.Add(stmt);
      }

      state.AddNewFrame(dummystmt, IsPartial, Signature);
      //add raw[0]
      state.AddStatement(matchStmt);

      //push a frame for the first case
      //TODO: add case variable to frame, so that variable () can refer to it
      state.AddNewFrame(stmt.Body.Body, IsPartial);

      foreach(var tmp in matchStmt.Cases[0].CasePatterns) {
        state.AddDafnyVar(tmp.Var.Name, new ProofState.VariableData { Variable = tmp.Var, Type = tmp.Var.Type });
      }
      //with this flag set to true, dafny will check the case brnach before evaluates any tacny code
      state.IfVerify = true;
      yield return state;
    }
Ejemplo n.º 24
0
 public static string FieldToString(Field field)
 {
     Contract.Requires(field != null);
       using (var wr = new System.IO.StringWriter()) {
     var pr = new Printer(wr);
     pr.PrintField(field, 0);
     return ToStringWithoutNewline(wr);
       }
 }