Example #1
0
File: Util.cs Project: ggrov/dafny
 /// <summary>
 /// Add "fe" to "mod", if "performThisDeprecationCheck" is "false".
 /// Otherwise, first strip "fe" of certain easy occurrences of "this", and for each one giving a warning about
 /// that "this" is deprecated in modifies clauses of constructors.
 /// This method may modify "fe" and the subexpressions contained within "fe".
 /// </summary>
 public static void AddFrameExpression(List <FrameExpression> mod, FrameExpression fe, bool performThisDeprecationCheck, Errors errors)
 {
     Contract.Requires(mod != null);
     Contract.Requires(fe != null);
     Contract.Requires(errors != null);
     if (performThisDeprecationCheck)
     {
         if (fe.E is ThisExpr)
         {
             errors.Deprecated(fe.E.tok, "Dafny's constructors no longer need 'this' to be listed in modifies clauses");
             return;
         }
         else if (fe.E is SetDisplayExpr)
         {
             var s          = (SetDisplayExpr)fe.E;
             var deprecated = s.Elements.FindAll(e => e is ThisExpr);
             if (deprecated.Count != 0)
             {
                 foreach (var e in deprecated)
                 {
                     errors.Deprecated(e.tok, "Dafny's constructors no longer need 'this' to be listed in modifies clauses");
                 }
                 s.Elements.RemoveAll(e => e is ThisExpr);
                 if (s.Elements.Count == 0)
                 {
                     return;
                 }
             }
         }
     }
     mod.Add(fe);
 }
Example #2
0
 private SpecNode ToSpecNode(FrameExpression expr, string kind, TokenNode token)
 {
     Console.WriteLine("Specification (" + kind + ")");
     return(new SpecNode {
         Kind = kind,
         Clause = Printer.ExprToString(expr.E),
         UserDoc = null,
         Token = token,
     });
 }
Example #3
0
 static void FrameExprRegions(FrameExpression fe, List <IdRegion> regions, bool descendIntoExpressions, ModuleDefinition module)
 {
     Contract.Requires(fe != null);
     Contract.Requires(regions != null);
     if (descendIntoExpressions)
     {
         ExprRegions(fe.E, regions, module);
     }
     if (fe.Field != null)
     {
         Microsoft.Dafny.Type showType = null; // TODO: if we had the instantiated type of this field, that would have been nice to use here (but the Resolver currently does not compute or store the instantiated type for a FrameExpression)
         IdRegion.Add(regions, fe.tok, fe.Field, showType, "field", false, module);
     }
 }
Example #4
0
 void FrameExprRegions(FrameExpression fe, List <IdRegion> regions, bool descendIntoExpressions, Microsoft.Dafny.Program prog, ModuleDefinition module)
 {
     Contract.Requires(fe != null);
     Contract.Requires(regions != null);
     Contract.Requires(prog != null);
     if (descendIntoExpressions)
     {
         ExprRegions(fe.E, regions, prog, module);
     }
     if (fe.Field != null)
     {
         Microsoft.Dafny.Type showType = null; // TODO: if we had the instantiated type of this field, that would have been nice to use here (but the Resolver currently does not compute or store the instantiated type for a FrameExpression)
         var kind = !(fe.Field is ConstantField) ? "field" : fe.Field.IsStatic && !(fe.Field.EnclosingClass is DefaultClassDecl) ? "static const" : "const";
         IdRegion.Add(regions, prog, fe.tok, fe.Field, showType, kind, false, module);
         RecordUseAndDef(prog, fe.tok, fe.Field.Name.Length, fe.Field.tok);
     }
 }
 public virtual void Visit(FrameExpression frameExpression)
 {
 }
Example #6
0
 // 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;
 }
Example #7
0
 void PossiblyWildFrameExpression(out FrameExpression fe, bool allowSemi)
 {
     Contract.Ensures(Contract.ValueAtReturn(out fe) != null); fe = dummyFrameExpr;
     if (la.kind == 57) {
     Get();
     fe = new FrameExpression(t, new WildcardExpr(t), null);
     } else if (StartOf(18)) {
     FrameExpression(out fe, allowSemi, false);
     } else SynErr(174);
 }
Example #8
0
        void FrameExpression(out FrameExpression fe, bool allowSemi, bool allowLambda)
        {
            Contract.Ensures(Contract.ValueAtReturn(out fe) != null);
            Expression/*!*/ e;
            IToken/*!*/ id;
            string fieldName = null;  IToken feTok = null;
            fe = null;

            if (StartOf(7)) {
            Expression(out e, allowSemi, allowLambda);
            feTok = e.tok;
            if (la.kind == 91) {
                Get();
                Ident(out id);
                fieldName = id.val;  feTok = id;
            }
            fe = new FrameExpression(feTok, e, fieldName);
            } else if (la.kind == 91) {
            Get();
            Ident(out id);
            fieldName = id.val;
            fe = new FrameExpression(id, new ImplicitThisExpr(id), fieldName);
            } else SynErr(171);
        }
Example #9
0
 public FrameExpression CloneFrameExpr(FrameExpression frame) {
   return new FrameExpression(Tok(frame.tok), CloneExpr(frame.E), frame.FieldName);
 }
Example #10
0
 public override void Visit(FrameExpression frameExpression)
 {
     _cancellationToken.ThrowIfCancellationRequested();
     RegisterDesignator(_currentScope, frameExpression, frameExpression.tok, frameExpression.FieldName);
 }
 public static FrameExpression renameB(FrameExpression v, Dictionary <string, string> rename)
 {
     return(new FrameExpression(null, renameB(v.E, rename), v.FieldName));
 }