コード例 #1
0
 public static void renameBody(AssignmentRhs Expr, Dictionary <string, string> rename)
 {
     if (Expr is ExprRhs)
     {
         renameBody(((ExprRhs)Expr).Expr, rename);
     }
 }
コード例 #2
0
 public static AssignmentRhs renameB(AssignmentRhs a, Dictionary <string, string> rename)
 {
     if (!(a is ExprRhs))
     {
         return(null);
     }
     return(new ExprRhs(renameB(((ExprRhs)a).Expr, rename)));
 }
コード例 #3
0
ファイル: RemovableTypeFinder.cs プロジェクト: ggrov/dafny
        private bool IsAssignmentLemmaCall(AssignmentRhs expr, ClassDecl classDecl)
        {
            var exprRhs = expr as ExprRhs;

            if (exprRhs == null)
            {
                return(false);
            }
            if (!(exprRhs.Expr is ApplySuffix))
            {
                return(false);
            }
            return(IsCallToGhost((ApplySuffix)exprRhs.Expr, classDecl));
        }
コード例 #4
0
        public virtual void Visit(AssignmentRhs assignmentRhs)
        {
            switch (assignmentRhs)
            {
            case ExprRhs expressionRhs:
                Visit(expressionRhs);
                break;

            case TypeRhs typeRhs:
                Visit(typeRhs);
                break;

            default:
                VisitUnknown(assignmentRhs, assignmentRhs.Tok);
                break;
            }
        }
コード例 #5
0
        public override void Visit(AssignmentRhs o)
        {
            var declaration = FindDeclaration(o.Tok.val, SurroundingScope);

            CreateSymbol(
                name: o.Tok.val,
                kind: Kind.Variable,

                positionAsToken: o.Tok,
                bodyStartPosAsToken: null,
                bodyEndPosAsToken: null,

                isDeclaration: false,
                declarationSymbol: declaration,
                addUsageAtDeclaration: true,

                canHaveChildren: false,
                canBeUsed: false
                );
        }
コード例 #6
0
ファイル: Kremlin.cs プロジェクト: Chris-Hawblitzel/dafny
        // Invoked typically as TrRhs(variable, null, RhsExpr)   <- UpdateStmt with multi-assignment
        //                   or TrRhs(null, LhsExpr, RhsExpr)    <- AssignStmt
        void TrRhs(BoundVar target, Expression targetExpr, AssignmentRhs rhs)
        {
            Contract.Requires((target == null) != (targetExpr == null));
              var tRhs = rhs as TypeRhs;
              if (rhs is HavocRhs) {
            // do nothing
              }
              else {
            using (WriteArray()) {
              j.WriteValue(KremlinAst.ESequence);
              using (WriteArray()) {
            WriteEUnit();

            // For C#, Dafny calls TrExpr(targetExpr), emits "=" then TrAssignmentRhs(rhs),
            // For Kremlin, we may generate EAssign or EBufWrite depending on the
            // targetExpr type.  The ELet has already been generated by the caller and
            // we are inside an ESequence, about to generate the RHS expression code.
            if (target != null) {
              TrAssignmentRhs(rhs);
            }
            else {
              if (targetExpr is SeqSelectExpr) {
                SeqSelectExpr e = (SeqSelectExpr)targetExpr;
                Contract.Assert(e.Seq.Type != null);
                if (!e.SelectOne) {
                  WriteEAbort("BUGBUG: TrRhs is a SeqSelectExpr with SelectMany"); // bugbug: is this valid Dafny?
                }
                else {
                  using (WriteArray()) {
                    j.WriteValue(KremlinAst.EBufWrite);
                    using (WriteArray()) { // of (expr * expr * expr)
                      TrExpr(e.Seq, false);    // expr1 - the buffer identifier
                      TrBufferIndexSizeExpr(e.E0, false); // expr2 - the buffer offset
                      TrAssignmentRhs(rhs);    // expr3 - the value to write
                    }
                  }
                }
              }
              else if (targetExpr is IdentifierExpr) {
                using (WriteArray()) {
                  j.WriteValue(KremlinAst.EAssign);
                  using (WriteArray()) {
                    var e = (IdentifierExpr)targetExpr;
                    WriteEBound(e.Var);
                    TrAssignmentRhs(rhs);
                  }
                }
              }
              else if (targetExpr is MemberSelectExpr) {
                MemberSelectExpr e = (MemberSelectExpr)targetExpr;
                SpecialField sf = e.Member as SpecialField;
                if (sf != null) {
                  WriteEAbort("BUGBUG MemberSelectExpr TrRhs if SpecialField not supported"); // bugbug: implement
                }
                else {
                  // EAssign of
                  //   EField(lident, EBufRead( EBound(var), 0), FieldName)
                  using (WriteArray()) {
                    j.WriteValue(KremlinAst.EAssign);
                    using (WriteArray()) { // of (expr * expr)

                      // EAssign expr1
                      using (WriteArray()) {
                        j.WriteValue(KremlinAst.EField);
                        using (WriteArray()) { // of (lident * expr * ident)
                          WriteLident(e.Obj.Type);
                          using (WriteArray()) {
                            j.WriteValue(KremlinAst.EBufRead);
                            using (WriteArray()) { // of (expr * expr)
                              TrExpr(e.Obj, false); // This will generate an EBound reference to the variable
                              WriteConstant(0u);    // expr2 is the offset (always 0)
                            }
                          }
                          j.WriteValue(e.Member.Name);
                        }
                      }
                      TrAssignmentRhs(rhs); // right-hand-side expression
                    }
                  }
                }
              }
              else {
                WriteEAbort("BUGBUG TrRhs of unsupported targetExpr type " + targetExpr.ToString());
              }
            }
            if (tRhs != null && tRhs.InitCall != null) {
              // We have now generated: var target = Default value;
              // Generate statement:    target.ctor();
              var oldEnclosingThis = enclosingThis;
              if (target != null) {
                j.WriteComment("TrRhs of InitCall to target");
                enclosingThis = target;
                TrCallStmt(tRhs.InitCall); // expr2
              }
              else {
                // targetExpr should be turned into the enclosingThis
                using (WriteArray()) {
                  string nw = idGenerator.FreshId("_nw");
                  enclosingThis = new BoundVar(targetExpr.tok, nw, targetExpr.Type);
                  j.WriteValue(KremlinAst.ELet);
                  using (WriteArray()) { // of (binder * expr * expr)
                    WriteBinder(enclosingThis, nw, true);
                    TrExpr(targetExpr, false);
                    VarTracker.Push(enclosingThis);
                    TrCallStmt(tRhs.InitCall);
                  }
                  VarTracker.Pop(enclosingThis);
                }
              }
              enclosingThis = oldEnclosingThis;
            }
              }
            }
              }
        }
コード例 #7
0
ファイル: Kremlin.cs プロジェクト: Chris-Hawblitzel/dafny
        /// <summary>
        /// Before calling TrAssignmentRhs(rhs), the caller must have spilled the let variables declared in "rhs".
        /// </summary>
        void TrAssignmentRhs(AssignmentRhs rhs)
        {
            Contract.Requires(rhs != null);
              Contract.Requires(!(rhs is HavocRhs));
              if (rhs is ExprRhs) {
            ExprRhs e = (ExprRhs)rhs;
            TrExpr(e.Expr, false);

              } else {

            TypeRhs tp = (TypeRhs)rhs;
            if (tp.ArrayDimensions == null) {
              if (tp.EType is UserDefinedType) {
            var udt = tp.EType as UserDefinedType;
            WriteClassAllocation(udt);
              }
              else {
            WriteDefaultValue(tp.EType);
              }
            }
            else {
              if (tp.EType.IsIntegerType || tp.EType.IsTypeParameter) {
            WriteEAbort("BUGBUG: TypeRhs with IntegerType or TypeParameter is unsupported"); // bugbug: implement
              }
              else if (tp.ArrayDimensions.Count == 1) {
            // Dafny: var W := new uint32[64];
            // C#:    new TypeName[ (int)ParenExpr, ... ];
            using (WriteArray()) {
              j.WriteValue(KremlinAst.EBufCreate);
              using (WriteArray()) { // of (expr * expr)
                WriteDefaultValue(tp.EType);
                TrBufferIndexSizeExpr(tp.ArrayDimensions[0], false);
              }
            }
              }
              else {
            WriteEAbort("BUGBUG: TypeRhs with multi-dimensional array is unsupported"); // bugbug: implement
              }
            }

              }
        }
コード例 #8
0
ファイル: Parser.cs プロジェクト: dbremner/dafny
 // the real work
 public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors, ModuleDecl module, BuiltIns builtIns, bool verifyThisFile=true)
     : this(scanner, errors)
 {
     // initialize readonly fields
       dummyExpr = new LiteralExpr(Token.NoToken);
       dummyRhs = new ExprRhs(dummyExpr, null);
       dummyFrameExpr = new FrameExpression(dummyExpr.tok, dummyExpr, null);
       dummyStmt = new ReturnStmt(Token.NoToken, Token.NoToken, null);
       theModule = module;
       theBuiltIns = builtIns;
       theVerifyThisFile = verifyThisFile;
 }
コード例 #9
0
ファイル: Parser.cs プロジェクト: dbremner/dafny
        void Rhs(out AssignmentRhs r)
        {
            Contract.Ensures(Contract.ValueAtReturn<AssignmentRhs>(out r) != null);
            IToken/*!*/ x, newToken;  Expression/*!*/ e;
            Type ty = null;
            List<Expression> ee = null;
            List<Expression> args = null;
            r = dummyRhs;  // to please compiler
            Attributes attrs = null;

            if (la.kind == 97) {
            Get();
            newToken = t;
            TypeAndToken(out x, out ty);
            if (la.kind == 48 || la.kind == 50) {
                if (la.kind == 48) {
                    Get();
                    ee = new List<Expression>();
                    Expressions(ee);
                    Expect(49);
                    var tmp = theBuiltIns.ArrayType(ee.Count, new IntType(), true);

                } else {
                    x = null; args = new List<Expression/*!*/>();
                    Get();
                    if (StartOf(7)) {
                        Expressions(args);
                    }
                    Expect(51);
                }
            }
            if (ee != null) {
             r = new TypeRhs(newToken, ty, ee);
            } else if (args != null) {
             r = new TypeRhs(newToken, ty, args, false);
            } else {
             r = new TypeRhs(newToken, ty);
            }

            } else if (la.kind == 57) {
            Get();
            r = new HavocRhs(t);
            } else if (StartOf(7)) {
            Expression(out e, false, true);
            r = new ExprRhs(e);
            } else SynErr(197);
            while (la.kind == 46) {
            Attribute(ref attrs);
            }
            r.Attributes = attrs;
        }
コード例 #10
0
ファイル: Printer.cs プロジェクト: ggrov/tacny
    void PrintRhs(AssignmentRhs rhs) {
      Contract.Requires(rhs != null);
      if (rhs is ExprRhs) {
        PrintExpression(((ExprRhs)rhs).Expr, true);
      } else if (rhs is HavocRhs) {
        wr.Write("*");
      } else if (rhs is TypeRhs) {
        TypeRhs t = (TypeRhs)rhs;
        wr.Write("new ");
        if (t.ArrayDimensions != null) {
          PrintType(t.EType);
          string s = "[";
          foreach (Expression dim in t.ArrayDimensions) {
            Contract.Assume(dim != null);
            wr.Write(s);
            PrintExpression(dim, false);
            s = ", ";
          }
          wr.Write("]");
        } else if (t.Arguments == null) {
          PrintType(t.EType);
        } else {
          PrintType(t.Path);
          wr.Write("(");
          PrintExpressionList(t.Arguments, false);
          wr.Write(")");
        }
      } else {
        Contract.Assert(false); throw new cce.UnreachableException();  // unexpected RHS
      }

      if (rhs.HasAttributes())
      {
        PrintAttributes(rhs.Attributes);
      }
    }
コード例 #11
0
 public override void Visit(AssignmentRhs o)
 {
 }
コード例 #12
0
ファイル: Cloner.cs プロジェクト: ggrov/tacny
 public override AssignmentRhs CloneRHS(AssignmentRhs rhs) {
   var r = rhs as ExprRhs;
   if (r != null && r.Expr is ApplySuffix) {
     var apply = (ApplySuffix)r.Expr;
     var mse = apply.Lhs.Resolved as MemberSelectExpr;
     if (mse != null && mse.Member is FixpointLemma && ModuleDefinition.InSameSCC(context, (FixpointLemma)mse.Member)) {
       // we're looking at a recursive call to a fixpoint lemma
       Contract.Assert(apply.Lhs is NameSegment || apply.Lhs is ExprDotName);  // this is the only way a call statement can have been parsed
       // clone "apply.Lhs", changing the inductive/co lemma to the prefix lemma; then clone "apply", adding in the extra argument
       Expression lhsClone;
       if (apply.Lhs is NameSegment) {
         var lhs = (NameSegment)apply.Lhs;
         lhsClone = new NameSegment(Tok(lhs.tok), lhs.Name + "#", lhs.OptTypeArguments == null ? null : lhs.OptTypeArguments.ConvertAll(CloneType));
       } else {
         var lhs = (ExprDotName)apply.Lhs;
         lhsClone = new ExprDotName(Tok(lhs.tok), CloneExpr(lhs.Lhs), lhs.SuffixName + "#", lhs.OptTypeArguments == null ? null : lhs.OptTypeArguments.ConvertAll(CloneType));
       }
       var args = new List<Expression>();
       args.Add(k);
       apply.Args.ForEach(arg => args.Add(CloneExpr(arg)));
       var applyClone = new ApplySuffix(Tok(apply.tok), lhsClone, args);
       var c = new ExprRhs(applyClone);
       reporter.Info(MessageSource.Cloner, apply.Lhs.tok, mse.Member.Name + suffix);
       return c;
     }
   }
   return base.CloneRHS(rhs);
 }
コード例 #13
0
ファイル: Cloner.cs プロジェクト: ggrov/tacny
 public virtual AssignmentRhs CloneRHS(AssignmentRhs rhs) {
   AssignmentRhs c;
   if (rhs is ExprRhs) {
     var r = (ExprRhs)rhs;
     c = new ExprRhs(CloneExpr(r.Expr));
   } else if (rhs is HavocRhs) {
     c = new HavocRhs(Tok(rhs.Tok));
   } else {
     var r = (TypeRhs)rhs;
     if (r.ArrayDimensions != null) {
       c = new TypeRhs(Tok(r.Tok), CloneType(r.EType), r.ArrayDimensions.ConvertAll(CloneExpr));
     } else if (r.Arguments == null) {
       c = new TypeRhs(Tok(r.Tok), CloneType(r.EType));
     } else {
       c = new TypeRhs(Tok(r.Tok), CloneType(r.Path), r.Arguments.ConvertAll(CloneExpr), false);
     }
   }
   c.Attributes = CloneAttributes(rhs.Attributes);
   return c;
 }
コード例 #14
0
ファイル: RemovableTypeFinder.cs プロジェクト: ggrov/tacny
 private bool IsAssignmentLemmaCall(AssignmentRhs expr, ClassDecl classDecl)
 {
     var exprRhs = expr as ExprRhs;
     if (exprRhs == null) return false;
     if (!(exprRhs.Expr is ApplySuffix)) return false;
     return IsCallToGhost((ApplySuffix) exprRhs.Expr, classDecl);
 }
コード例 #15
0
ファイル: Compiler.cs プロジェクト: ggrov/tacny
 void TrRhs(string target, Expression targetExpr, AssignmentRhs rhs, int indent, TextWriter wr) {
   Contract.Requires((target == null) != (targetExpr == null));
   var tRhs = rhs as TypeRhs;
   if (tRhs != null && tRhs.InitCall != null) {
     string nw = idGenerator.FreshId("_nw");
     Indent(indent, wr);
     wr.Write("var {0} = ", nw);
     TrAssignmentRhs(rhs, wr);  // in this case, this call will not require us to spill any let variables first
     wr.WriteLine(";");
     wr.Write(TrCallStmt(tRhs.InitCall, nw, indent).ToString());
     Indent(indent, wr);
     if (target != null) {
       wr.Write(target);
     } else {
       TrExpr(targetExpr, wr, false);
     }
     wr.WriteLine(" = {0};", nw);
   } else if (rhs is HavocRhs) {
     // do nothing
   } else {
     if (rhs is ExprRhs) {
     } else if (tRhs != null && tRhs.ArrayDimensions != null) {
       foreach (Expression dim in tRhs.ArrayDimensions) {
       }
     }
     Indent(indent, wr);
     if (target != null) {
       wr.Write(target);
     } else {
       TrExpr(targetExpr, wr, false);
     }
     wr.Write(" = ");
     TrAssignmentRhs(rhs, wr);
     wr.WriteLine(";");
   }
 }
コード例 #16
0
ファイル: Compiler.cs プロジェクト: ggrov/tacny
    /// <summary>
    /// Before calling TrAssignmentRhs(rhs), the caller must have spilled the let variables declared in "rhs".
    /// </summary>
    void TrAssignmentRhs(AssignmentRhs rhs, TextWriter wr) {
      Contract.Requires(rhs != null);
      Contract.Requires(!(rhs is HavocRhs));
      if (rhs is ExprRhs) {
        ExprRhs e = (ExprRhs)rhs;
        TrExpr(e.Expr, wr, false);

      } else {
        TypeRhs tp = (TypeRhs)rhs;
        if (tp.ArrayDimensions == null) {
          wr.Write("new {0}()", TypeName(tp.EType, wr));
        } else {
          if (tp.EType.IsIntegerType || tp.EType.IsTypeParameter) {
            // Because the default constructor for BigInteger does not generate a valid BigInteger, we have
            // to excplicitly initialize the elements of an integer array.  This is all done in a helper routine.
            wr.Write("Dafny.Helpers.InitNewArray{0}<{1}>", tp.ArrayDimensions.Count, TypeName(tp.EType, wr));
            string prefix = "(";
            foreach (Expression dim in tp.ArrayDimensions) {
              wr.Write(prefix);
              TrParenExpr(dim, wr, false);
              prefix = ", ";
            }
            wr.Write(")");
          } else {
            wr.Write("new {0}", TypeName(tp.EType, wr));
            string prefix = "[";
            foreach (Expression dim in tp.ArrayDimensions) {
              wr.Write("{0}(int)", prefix);
              TrParenExpr(dim, wr, false);
              prefix = ", ";
            }
            wr.Write("]");
          }
        }
      }
    }
コード例 #17
0
 public override void Leave(AssignmentRhs o)
 {
 }