Ejemplo n.º 1
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var ghosts = context.GetRValueGhosts();
            var val    = $"({ghosts}).{name}";

            return(new ArmadaRValue(val));
        }
Ejemplo n.º 2
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var s     = context.GetRValueState();
            var addrs = AH.MakeExprDotName(s, "addrs", "Armada_Addrs");
            var addr  = AH.MakeExprDotName(addrs, name, new PointerType(ty));

            var h = context.GetRValueHeap();

            var valid = AH.GetInvocationOfValidPointer(h, addr, ty);

            if (valid == null)
            {
                context.Fail(tok, "Type {ty} is currently not supported in the heap");
                return(null);
            }
            var crashAvoidance = new UndefinedBehaviorAvoidanceConstraint(valid);

            var val = AH.GetInvocationOfDereferencePointer(h, addr, ty);

            if (val == null)
            {
                context.Fail(tok, "Type {ty} is currently not supported in the heap");
            }
            return(new ArmadaRValue(crashAvoidance, val));
        }
Ejemplo n.º 3
0
        public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
        {
            var crashAvoidance = new UndefinedBehaviorAvoidanceConstraint();
            var addr           = $"({context.GetLValueTopStackFrame()}).{methodName}.AddrOf'{name}";

            return(new AddressableArmadaLValue(tok, ty, new ArmadaRValue(crashAvoidance, addr)));
        }
Ejemplo n.º 4
0
        public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
        {
            var crashAvoidance = new UndefinedBehaviorAvoidanceConstraint();
            var varsVal        = new TopStackVarsArmadaLValue(crashAvoidance, methodName);

            return(new UnaddressableFieldArmadaLValue(tok, ty, varsVal, new UndefinedBehaviorAvoidanceConstraint(), name, 0, true));
        }
Ejemplo n.º 5
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var val            = $"({context.GetRValueTopStackFrame()}).{methodName}.{name}";
            var crashAvoidance = new UndefinedBehaviorAvoidanceConstraint();

            return(new ArmadaRValue(crashAvoidance, val));
        }
Ejemplo n.º 6
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type indexType, Type exprType)
        {
            if (!(type is SizedArrayType))
            {
                context.Fail(i_tok, "Attempt to obtain element of non-array type");
                return(null);
            }
            SizedArrayType st = (SizedArrayType)type;

            if (!AH.TypesMatch(st.Range, exprType))
            {
                context.Fail(i_tok, $"Element of type {st.Range} used as type {exprType}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance + idx1.UndefinedBehaviorAvoidance;

            var s           = context.GetLValueState();
            var h           = $"({s}).mem.heap";
            var idx1_as_int = AH.ConvertToIntIfNotInt(idx1.Val, indexType);

            crashAvoidance.Add($"{address.Val} in {h}.tree");
            crashAvoidance.Add($"0 <= {idx1_as_int} < |{h}.tree[{address.Val}].children|");

            var child = $"{h}.tree[{address.Val}].children[{idx1_as_int}]";

            return(new AddressableArmadaLValue(i_tok, st.Range, new ArmadaRValue(crashAvoidance, child)));
        }
Ejemplo n.º 7
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var globals = context.GetRValueGlobals();
            var val     = AH.MakeExprDotName(globals, name, ty);

            return(new ArmadaRValue(val));
        }
 public RefinementToken(IToken tok, ModuleDefinition m)
     : base(tok)
 {
     Contract.Requires(tok != null);
       Contract.Requires(m != null);
       this.InheritingModule = m;
 }
Ejemplo n.º 9
0
 public UnaddressableIndexArmadaLValue(IToken i_tok, Type i_type, UnaddressableArmadaLValue i_parent,
                                       UndefinedBehaviorAvoidanceConstraint i_crashAvoidance, Expression i_index)
     : base(i_tok, i_type, i_crashAvoidance)
 {
     parent = i_parent;
     index  = i_index;
 }
Ejemplo n.º 10
0
        public override ArmadaLValue ApplyExprDotName(IToken i_tok, ResolutionContext context, string fieldName, Type ty)
        {
            if (!(type is UserDefinedType))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non-struct, non-datatype type {type}");
                return(null);
            }

            UserDefinedType ut = (UserDefinedType)type;

            if (context.symbols.DoesStructExist(ut.Name))
            {
                Type fieldType = context.symbols.GetStructFieldType(ut.Name, fieldName);
                if (fieldType == null)
                {
                    context.Fail(i_tok, $"Attempt to take non-existent field ({fieldName}) in struct type {ut.Name}");
                    return(null);
                }
                if (!AH.TypesMatch(fieldType, ty))
                {
                    context.Fail(i_tok, $"Field {fieldName} of type {fieldType} used as type {ty}");
                    return(null);
                }
            }

            return(new UnaddressableFieldArmadaLValue(i_tok, ty, this, crashAvoidance, fieldName, false));
        }
Ejemplo n.º 11
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type ty)
        {
            if (!(type is SizedArrayType))
            {
                context.Fail(i_tok, "Attempt to obtain element of non-array type");
                return(null);
            }
            SizedArrayType st = (SizedArrayType)type;

            if (!AH.TypesMatch(st.Range, ty))
            {
                context.Fail(i_tok, $"Element of type {st.Range} used as type {ty}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance + idx1.UndefinedBehaviorAvoidance;

            var s    = context.GetLValueState();
            var mem  = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var h    = AH.MakeExprDotName(mem, "heap", "Armada_Heap");
            var tree = AH.MakeExprDotName(h, "tree", "Armada_Tree");

            crashAvoidance.Add(AH.MakeInExpr(address.Val, tree));

            var node        = AH.MakeSeqSelectExpr(tree, address.Val, "Armada_Node");
            var children    = AH.MakeExprDotName(node, "children", AH.MakeChildrenType());
            var idx1_as_int = AH.ConvertToIntIfNotInt(idx1.Val);
            var field       = AH.MakeApply1("Armada_FieldArrayIndex", idx1_as_int, "Armada_Field");
            var child       = AH.MakeSeqSelectExpr(children, field, new PointerType(st.Range));

            crashAvoidance.Add(AH.MakeInExpr(field, children));

            return(new AddressableArmadaLValue(i_tok, st.Range, new ArmadaRValue(crashAvoidance, child)));
        }
Ejemplo n.º 12
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var top = context.GetRValueTopStackFrame();
            var correct_frame_type = AH.MakeExprDotName(top, $"Armada_StackFrame_{methodName}?", new BoolType());
            var crashAvoidance     = new UndefinedBehaviorAvoidanceConstraint(correct_frame_type);

            var addr = AH.MakeExprDotName(top, $"{methodName}'AddrOf'{name}", new PointerType(ty));

            var h = context.GetRValueHeap();

            var valid = AH.GetInvocationOfValidPointer(h, addr, ty);

            if (valid == null)
            {
                context.Fail(tok, "Type {ty} is not supported on the heap, and thus not for addressable stack variables either");
                return(null);
            }
            crashAvoidance.Add(valid);

            var val = AH.GetInvocationOfDereferencePointer(h, addr, ty);

            if (val == null)
            {
                context.Fail(tok, "Type {ty} is not supported on the heap, and thus not for addressable stack variables either");
            }
            return(new ArmadaRValue(crashAvoidance, val));
        }
Ejemplo n.º 13
0
 public UnaddressableFieldArmadaLValue(IToken i_tok, Type i_type, UnaddressableArmadaLValue i_parent,
                                       UndefinedBehaviorAvoidanceConstraint i_crashAvoidance, string i_fieldName, bool i_noTSO)
     : base(i_tok, i_type, i_crashAvoidance)
 {
     parent    = i_parent;
     fieldName = i_fieldName;
     noTSO     = i_noTSO;
 }
Ejemplo n.º 14
0
        public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
        {
            var top = context.GetLValueTopStackFrame();
            var correct_frame_type = AH.MakeExprDotName(top, $"Armada_StackFrame_{methodName}?", new BoolType());
            var crashAvoidance     = new UndefinedBehaviorAvoidanceConstraint(correct_frame_type);

            return(new UnaddressableFieldArmadaLValue(tok, ty, new TopStackFrameArmadaLValue(crashAvoidance), crashAvoidance, $"{methodName}'{name}", true));
        }
Ejemplo n.º 15
0
 public void Fail(IToken tok, string reason)
 {
     valid = false;
     if (reason != null)
     {
         AH.PrintError(prog, tok, reason);
     }
 }
Ejemplo n.º 16
0
        public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
        {
            var s     = context.GetLValueState();
            var addrs = AH.MakeExprDotName(s, "addrs", "Armada_Addrs");
            var addr  = AH.MakeExprDotName(addrs, name, new PointerType(ty));

            return(new AddressableArmadaLValue(tok, ty, new ArmadaRValue(addr)));
        }
Ejemplo n.º 17
0
        private TokenNode ToTokenNode(IToken tok)
        {
            var pathRaw = tok.filename.Split('[')[0];

            return(new TokenNode {
                Path = pathRaw.Split(Path.DirectorySeparatorChar),
                Line = tok.line,
                Column = tok.col,
            });
        }
Ejemplo n.º 18
0
 public static bool IsInherited(IToken tok, ModuleDefinition m) {
   while (tok is NestedToken) {
     var n = (NestedToken)tok;
     // check Outer
     var r = n.Outer as RefinementToken;
     if (r == null || r.InheritingModule != m) {
       return false;
     }
     // continue to check Inner
     tok = n.Inner;
   }
   var rtok = tok as RefinementToken;
   return rtok != null && rtok.InheritingModule == m;
 }
Ejemplo n.º 19
0
        public override ArmadaLValue ApplyExprDotName(IToken i_tok, ResolutionContext context, string fieldName, Type ty)
        {
            if (!(type is UserDefinedType))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non-struct type {type}");
                return(null);
            }
            UserDefinedType ut = (UserDefinedType)type;

            if (!context.symbols.DoesStructExist(ut.Name))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non struct type {ut.Name}");
                return(null);
            }
            Type fieldType = context.symbols.GetStructFieldType(ut.Name, fieldName);

            if (fieldType == null)
            {
                context.Fail(i_tok, $"Attempt to take non-existent field ({fieldName}) in struct type {ut.Name}");
                return(null);
            }
            if (!AH.TypesMatch(fieldType, ty))
            {
                context.Fail(i_tok, $"Field {fieldName} of type {fieldType} used as type {ty}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance;

            var s    = context.GetLValueState();
            var mem  = AH.MakeExprDotName(s, "mem", "Armada_SharedMemory");
            var h    = AH.MakeExprDotName(mem, "heap", "Armada_Heap");
            var tree = AH.MakeExprDotName(h, "tree", "Armada_Tree");

            crashAvoidance.Add(AH.MakeInExpr(address.Val, tree));

            var node     = AH.MakeSeqSelectExpr(tree, address.Val, "Armada_Node");
            var children = AH.MakeExprDotName(node, "children", AH.MakeChildrenType());
            var field    = AH.MakeApply1("Armada_FieldStruct",
                                         AH.MakeNameSegment($"Armada_FieldType_{ut.Name}'{fieldName}", "Armada_FieldType"),
                                         "Armada_Field");
            var child = AH.MakeSeqSelectExpr(children, field, new PointerType(fieldType));

            crashAvoidance.Add(AH.MakeInExpr(field, children));

            return(new AddressableArmadaLValue(i_tok, fieldType, new ArmadaRValue(crashAvoidance, child)));
        }
Ejemplo n.º 20
0
        private bool LookupLevel(IToken levelDescriptor, string kind, out LiteralModuleDecl m)
        {
            ModuleDecl md = null;

            m = null;

            if (!bindings.TryLookup(levelDescriptor, out md))
            {
                AH.PrintError(prog, $"Could not find {kind} level {levelDescriptor} referred to in proof module {mProof.Name}");
                return(false);
            }
            if (!(md is LiteralModuleDecl))
            {
                AH.PrintError(prog, $"Low-level {levelDescriptor} referred to in proof module {mProof.Name} isn't a code level");
                return(false);
            }
            m = (LiteralModuleDecl)md;
            return(true);
        }
Ejemplo n.º 21
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var addr  = $"({context.GetRValueState()}).addrs.{name}";
            var h     = context.GetRValueHeap();
            var valid = AH.GetInvocationOfValidPointer(h, addr, ty);

            if (valid == null)
            {
                context.Fail(tok, $"Type {ty} is currently not supported in the heap");
                return(null);
            }
            var crashAvoidance = new UndefinedBehaviorAvoidanceConstraint(valid);

            var val = AH.GetInvocationOfDereferencePointer(h, addr, ty);

            if (val == null)
            {
                context.Fail(tok, $"Type {ty} is currently not supported in the heap");
            }
            return(new ArmadaRValue(crashAvoidance, val));
        }
Ejemplo n.º 22
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type indexType, Type exprType)
        {
            var me = GetValueInLValueState(context);
            var sz = $"|{me}|";

            var newUndefinedBehaviorAvoidance = GetUndefinedBehaviorAvoidanceConstraint() + idx1.UndefinedBehaviorAvoidance;

            var idx1val = AH.ConvertToIntIfNotInt(idx1.Val, indexType);

            if (type is SizedArrayType)
            {
                SizedArrayType st = (SizedArrayType)type;
                if (!AH.TypesMatch(st.Range, exprType))
                {
                    context.Fail(i_tok, $"Element of type {st.Range} used as type {exprType}");
                    return(null);
                }

                newUndefinedBehaviorAvoidance.Add($"0 <= {idx1val} < {sz}");
            }
            else if (type is SeqType)
            {
                newUndefinedBehaviorAvoidance.Add($"0 <= {idx1val} < {sz}");
            }
            else if (type is MapType)
            {
                // There's no need to consider it undefined behavior if idx1.Val isn't in this map, since we're just
                // using it as an lvalue.  It's fine to update an element of a map that isn't yet in its domain.
                // So we don't need to do:
                //   newUndefinedBehaviorAvoidance.Add($"({idx1.Val}) in ({me})");
                return(new UnaddressableIndexArmadaLValue(i_tok, exprType, this, newUndefinedBehaviorAvoidance, idx1.Val));
            }
            else
            {
                context.Fail(i_tok, $"Attempt to index into something that isn't an array, seq, or map");
                return(null);
            }

            return(new UnaddressableIndexArmadaLValue(i_tok, exprType, this, newUndefinedBehaviorAvoidance, idx1val));
        }
Ejemplo n.º 23
0
        public override ArmadaLValue ApplyExprDotName(IToken i_tok, ResolutionContext context, string fieldName, Type targetType)
        {
            if (!(type is UserDefinedType))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non-struct type {type}");
                return(null);
            }
            UserDefinedType ut = (UserDefinedType)type;

            if (!context.symbols.DoesStructExist(ut.Name))
            {
                context.Fail(i_tok, $"Attempt to take a field ({fieldName}) of non struct type {ut.Name}");
                return(null);
            }
            Type fieldType = context.symbols.GetStructFieldType(ut.Name, fieldName);

            if (fieldType == null)
            {
                context.Fail(i_tok, $"Attempt to take non-existent field ({fieldName}) in struct type {ut.Name}");
                return(null);
            }
            if (!AH.TypesMatch(fieldType, targetType))
            {
                context.Fail(i_tok, $"Field {fieldName} of type {fieldType} used as type {targetType}");
                return(null);
            }

            var crashAvoidance = address.UndefinedBehaviorAvoidance;

            var s        = context.GetLValueState();
            var h        = $"({s}).mem.heap";
            int fieldPos = context.symbols.GetStructFieldPos(ut.Name, fieldName);

            crashAvoidance.Add($"{address.Val} in {h}.tree");
            crashAvoidance.Add($"0 <= {fieldPos} < |{h}.tree[{address.Val}].children|");

            var child = $"{h}.tree[{address.Val}].children[{fieldPos}]";

            return(new AddressableArmadaLValue(i_tok, fieldType, new ArmadaRValue(crashAvoidance, child)));
        }
Ejemplo n.º 24
0
        public override ArmadaLValue ApplySeqSelect(IToken i_tok, ResolutionContext context, ArmadaRValue idx1, Type ty)
        {
            var me = GetValueInLValueState(context);
            var sz = AH.MakeCardinalityExpr(me);

            var newUndefinedBehaviorAvoidance = GetUndefinedBehaviorAvoidanceConstraint() + idx1.UndefinedBehaviorAvoidance;

            var idx1val = AH.ConvertToIntIfNotInt(idx1.Val);

            if (type is SizedArrayType)
            {
                SizedArrayType st = (SizedArrayType)type;
                if (!AH.TypesMatch(st.Range, ty))
                {
                    context.Fail(i_tok, $"Element of type {st.Range} used as type {ty}");
                    return(null);
                }

                newUndefinedBehaviorAvoidance.Add(AH.MakeLeExpr(AH.MakeZero(), idx1val));
                newUndefinedBehaviorAvoidance.Add(AH.MakeLtExpr(idx1val, sz));
            }
            else if (type is SeqType)
            {
                newUndefinedBehaviorAvoidance.Add(AH.MakeLeExpr(AH.MakeZero(), idx1val));
                newUndefinedBehaviorAvoidance.Add(AH.MakeLtExpr(idx1val, sz));
            }
            else if (type is MapType)
            {
                newUndefinedBehaviorAvoidance.Add(AH.MakeInExpr(idx1val, me));
            }
            else
            {
                context.Fail(i_tok, $"Attempt to index into something that isn't an array, seq, or map");
                return(null);
            }

            return(new UnaddressableIndexArmadaLValue(i_tok, ty, this, newUndefinedBehaviorAvoidance, idx1val));
        }
Ejemplo n.º 25
0
        public override ArmadaRValue GetRValue(IToken tok, ResolutionContext context)
        {
            var crashAvoidance = new UndefinedBehaviorAvoidanceConstraint();
            var addr           = $"({context.GetRValueTopStackFrame()}).{methodName}.AddrOf'{name}";
            var h = context.GetRValueHeap();

            var valid = AH.GetInvocationOfValidPointer(h, addr, ty);

            if (valid == null)
            {
                context.Fail(tok, $"Type {ty} is not supported on the heap, and thus not for addressable stack variables either");
                return(null);
            }
            crashAvoidance.Add(valid);

            var val = AH.GetInvocationOfDereferencePointer(h, addr, ty);

            if (val == null)
            {
                context.Fail(tok, $"Type {ty} is not supported on the heap, and thus not for addressable stack variables either");
            }
            return(new ArmadaRValue(crashAvoidance, val));
        }
Ejemplo n.º 26
0
 public override ArmadaLValue GetLValue(IToken tok, ResolutionContext context)
 {
     return(new UnaddressableFieldArmadaLValue(tok, ty, new GlobalsArmadaLValue(), new UndefinedBehaviorAvoidanceConstraint(), name, false));
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Checks if the given token is part of the entrypoint document.
 /// </summary>
 /// <param name="program">The dafny program to check the token against.</param>
 /// <param name="token">The token to check.</param>
 /// <returns><c>true</c> if the given token is part of the entrypoint document of the given program.</returns>
 public static bool IsPartOfEntryDocument(this Microsoft.Dafny.Program program, Microsoft.Boogie.IToken token)
 {
     // TODO Cleanup this check. It requires that DafnyLangParser sets the program's name to the entrypoint filename.
     // TODO the token filename happens to be null if it's representing a default module or class.
     return(token.filename == null || token.filename == program.FullName);
 }
Ejemplo n.º 28
0
 public static string TokenToString(IToken tok)
 {
     return($"line {tok.line}, col {tok.col}");
 }
Ejemplo n.º 29
0
 public static void PrintWarning(Program prog, IToken tok, string s)
 {
     prog.reporter.Warning(MessageSource.Rewriter, tok, s);
 }
Ejemplo n.º 30
0
 public static void PrintError(Program prog, IToken tok, string s)
 {
     prog.reporter.Error(MessageSource.Rewriter, tok, s);
     throw new Exception(s);
 }
Ejemplo n.º 31
0
 public static bool TokenEquals(Microsoft.Boogie.IToken t, Microsoft.Boogie.IToken u)
 {
     return(t.IsValid == u.IsValid && t.col == u.col && t.filename == u.filename &&
            t.kind == u.kind && t.line == u.line && t.pos == u.pos && t.val == u.val);
 }
Ejemplo n.º 32
0
        Function CloneFunction(IToken tok, Function f, bool isGhost, List<Expression> moreEnsures, Expression moreBody, Expression replacementBody, bool checkPrevPostconditions, Attributes moreAttributes)
        {
            Contract.Requires(tok != null);
              Contract.Requires(moreBody == null || f is Predicate);
              Contract.Requires(moreBody == null || replacementBody == null);

              var tps = f.TypeArgs.ConvertAll(refinementCloner.CloneTypeParam);
              var formals = f.Formals.ConvertAll(refinementCloner.CloneFormal);
              var req = f.Req.ConvertAll(refinementCloner.CloneExpr);
              var reads = f.Reads.ConvertAll(refinementCloner.CloneFrameExpr);
              var decreases = refinementCloner.CloneSpecExpr(f.Decreases);

              List<Expression> ens;
              if (checkPrevPostconditions)  // note, if a postcondition includes something that changes in the module, the translator will notice this and still re-check the postcondition
            ens = f.Ens.ConvertAll(rawCloner.CloneExpr);
              else
            ens = f.Ens.ConvertAll(refinementCloner.CloneExpr);
              if (moreEnsures != null) {
            ens.AddRange(moreEnsures);
              }

              Expression body;
              Predicate.BodyOriginKind bodyOrigin;
              if (replacementBody != null) {
            body = replacementBody;
            bodyOrigin = Predicate.BodyOriginKind.DelayedDefinition;
              } else if (moreBody != null) {
            if (f.Body == null) {
              body = moreBody;
              bodyOrigin = Predicate.BodyOriginKind.DelayedDefinition;
            } else {
              body = new BinaryExpr(f.tok, BinaryExpr.Opcode.And, refinementCloner.CloneExpr(f.Body), moreBody);
              bodyOrigin = Predicate.BodyOriginKind.Extension;
            }
              } else {
            body = refinementCloner.CloneExpr(f.Body);
            bodyOrigin = Predicate.BodyOriginKind.OriginalOrInherited;
              }

              if (f is Predicate) {
            return new Predicate(tok, f.Name, f.HasStaticKeyword, f.IsProtected, isGhost, tps, formals,
              req, reads, ens, decreases, body, bodyOrigin, refinementCloner.MergeAttributes(f.Attributes, moreAttributes), null, f);
              } else if (f is InductivePredicate) {
            return new InductivePredicate(tok, f.Name, f.HasStaticKeyword, f.IsProtected, tps, formals,
              req, reads, ens, body, refinementCloner.MergeAttributes(f.Attributes, moreAttributes), null, f);
              } else if (f is CoPredicate) {
            return new CoPredicate(tok, f.Name, f.HasStaticKeyword, f.IsProtected, tps, formals,
              req, reads, ens, body, refinementCloner.MergeAttributes(f.Attributes, moreAttributes), null, f);
              } else if (f is TwoStatePredicate) {
            return new TwoStatePredicate(tok, f.Name, f.HasStaticKeyword, tps, formals,
              req, reads, ens, decreases, body, refinementCloner.MergeAttributes(f.Attributes, moreAttributes), null, f);
              } else if (f is TwoStateFunction) {
            return new TwoStateFunction(tok, f.Name, f.HasStaticKeyword, tps, formals, refinementCloner.CloneType(f.ResultType),
              req, reads, ens, decreases, body, refinementCloner.MergeAttributes(f.Attributes, moreAttributes), null, f);
              } else {
            return new Function(tok, f.Name, f.HasStaticKeyword, f.IsProtected, isGhost, tps, formals, refinementCloner.CloneType(f.ResultType),
              req, reads, ens, decreases, body, refinementCloner.MergeAttributes(f.Attributes, moreAttributes), null, f);
              }
        }
Ejemplo n.º 33
0
 void CheckAgreement_TypeParameters(IToken tok, List<TypeParameter> old, List<TypeParameter> nw, string name, string thing, bool checkNames = true)
 {
     Contract.Requires(tok != null);
       Contract.Requires(old != null);
       Contract.Requires(nw != null);
       Contract.Requires(name != null);
       Contract.Requires(thing != null);
       if (old.Count != nw.Count) {
     reporter.Error(MessageSource.RefinementTransformer, tok, "{0} '{1}' is declared with a different number of type parameters ({2} instead of {3}) than the corresponding {0} in the module it refines", thing, name, nw.Count, old.Count);
       } else {
     for (int i = 0; i < old.Count; i++) {
       var o = old[i];
       var n = nw[i];
       if (o.Name != n.Name && checkNames) { // if checkNames is false, then just treat the parameters positionally.
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "type parameters are not allowed to be renamed from the names given in the {0} in the module being refined (expected '{1}', found '{2}')", thing, o.Name, n.Name);
       } else {
     // This explains what we want to do and why:
     // switch (o.EqualitySupport) {
     //   case TypeParameter.EqualitySupportValue.Required:
     //     // here, we will insist that the new type-parameter also explicitly requires equality support (because we don't want
     //     // to wait for the inference to run on the new module)
     //     good = n.EqualitySupport == TypeParameter.EqualitySupportValue.Required;
     //     break;
     //   case TypeParameter.EqualitySupportValue.InferredRequired:
     //     // here, we can allow anything, because even with an Unspecified value, the inference will come up with InferredRequired, like before
     //     good = true;
     //     break;
     //   case TypeParameter.EqualitySupportValue.Unspecified:
     //     // inference didn't come up with anything on the previous module, so the only value we'll allow here is Unspecified as well
     //     good = n.EqualitySupport == TypeParameter.EqualitySupportValue.Unspecified;
     //     break;
     // }
     // Here's how we actually compute it:
     if (o.EqualitySupport != TypeParameter.EqualitySupportValue.InferredRequired && o.EqualitySupport != n.EqualitySupport) {
       reporter.Error(MessageSource.RefinementTransformer, n.tok, "type parameter '{0}' is not allowed to change the requirement of supporting equality", n.Name);
     }
       }
     }
       }
 }
Ejemplo n.º 34
0
 void CheckAgreement_Parameters(IToken tok, List<Formal> old, List<Formal> nw, string name, string thing, string parameterKind)
 {
     Contract.Requires(tok != null);
       Contract.Requires(old != null);
       Contract.Requires(nw != null);
       Contract.Requires(name != null);
       Contract.Requires(thing != null);
       Contract.Requires(parameterKind != null);
       if (old.Count != nw.Count) {
     reporter.Error(MessageSource.RefinementTransformer, tok, "{0} '{1}' is declared with a different number of {2} ({3} instead of {4}) than the corresponding {0} in the module it refines", thing, name, parameterKind, nw.Count, old.Count);
       } else {
     for (int i = 0; i < old.Count; i++) {
       var o = old[i];
       var n = nw[i];
       if (o.Name != n.Name) {
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "there is a difference in name of {0} {1} ('{2}' versus '{3}') of {4} {5} compared to corresponding {4} in the module it refines", parameterKind, i, n.Name, o.Name, thing, name);
       } else if (!o.IsGhost && n.IsGhost) {
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it refines, from non-ghost to ghost", parameterKind, n.Name, thing, name);
       } else if (o.IsGhost && !n.IsGhost) {
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it refines, from ghost to non-ghost", parameterKind, n.Name, thing, name);
       } else if (!o.IsOld && n.IsOld) {
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it refines, from non-new to new", parameterKind, n.Name, thing, name);
       } else if (o.IsOld && !n.IsOld) {
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it refines, from new to non-new", parameterKind, n.Name, thing, name);
       } else if (!TypesAreSyntacticallyEqual(o.Type, n.Type)) {
     reporter.Error(MessageSource.RefinementTransformer, n.tok, "the type of {0} '{1}' is different from the type of the same {0} in the corresponding {2} in the module it refines ('{3}' instead of '{4}')", parameterKind, n.Name, thing, n.Type, o.Type);
       }
     }
       }
 }
Ejemplo n.º 35
0
 public abstract ArmadaRValue GetRValue(IToken tok, ResolutionContext context);
Ejemplo n.º 36
0
 public void CheckOverride_TypeParameters(IToken tok, List<TypeParameter> old, List<TypeParameter> nw, string name, string thing, bool checkNames = true)
 {
     Contract.Requires(tok != null);
     Contract.Requires(old != null);
     Contract.Requires(nw != null);
     Contract.Requires(name != null);
     Contract.Requires(thing != null);
     if (old.Count != nw.Count)
     {
     reporter.Error(MessageSource.RefinementTransformer, tok, "{0} '{1}' is declared with a different number of type parameters ({2} instead of {3}) than the corresponding {0} in the module it overrides", thing, name, nw.Count, old.Count);
     }
     else
     {
     for (int i = 0; i < old.Count; i++)
     {
         var o = old[i];
         var n = nw[i];
         if (o.Name != n.Name && checkNames)
         { // if checkNames is false, then just treat the parameters positionally.
             reporter.Error(MessageSource.RefinementTransformer, n.tok, "type parameters are not allowed to be renamed from the names given in the {0} in the module being overriden (expected '{1}', found '{2}')", thing, o.Name, n.Name);
         }
         else
         {
             // Here's how we actually compute it:
             if (o.EqualitySupport != TypeParameter.EqualitySupportValue.InferredRequired && o.EqualitySupport != n.EqualitySupport)
             {
                 reporter.Error(MessageSource.RefinementTransformer, n.tok, "type parameter '{0}' is not allowed to change the requirement of supporting equality", n.Name);
             }
         }
     }
     }
 }
Ejemplo n.º 37
0
 public override IToken Tok(IToken tok)
 {
     return new RefinementToken(tok, moduleUnderConstruction);
 }
Ejemplo n.º 38
0
 public void CheckOverrideResolvedParameters(IToken tok, List<Formal> old, List<Formal> nw, string name, string thing, string parameterKind)
 {
     Contract.Requires(tok != null);
     Contract.Requires(old != null);
     Contract.Requires(nw != null);
     Contract.Requires(name != null);
     Contract.Requires(thing != null);
     Contract.Requires(parameterKind != null);
     if (old.Count != nw.Count)
     {
         reporter.Error(MessageSource.RefinementTransformer, tok, "{0} '{1}' is declared with a different number of {2} ({3} instead of {4}) than the corresponding {0} in the module it overrides", thing, name, parameterKind, nw.Count, old.Count);
     }
     else
     {
         for (int i = 0; i < old.Count; i++)
         {
             var o = old[i];
             var n = nw[i];
             if (!o.IsGhost && n.IsGhost)
             {
                 reporter.Error(MessageSource.RefinementTransformer, n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it overrides, from non-ghost to ghost", parameterKind, n.Name, thing, name);
             }
             else if (o.IsGhost && !n.IsGhost)
             {
                 reporter.Error(MessageSource.RefinementTransformer, n.tok, "{0} '{1}' of {2} {3} cannot be changed, compared to the corresponding {2} in the module it overrides, from ghost to non-ghost", parameterKind, n.Name, thing, name);
             }
             else if (!ResolvedTypesAreTheSame(o.Type, n.Type))
             {
                 reporter.Error(MessageSource.RefinementTransformer, n.tok, "the type of {0} '{1}' is different from the type of the same {0} in the corresponding {2} in the module it overrides ('{3}' instead of '{4}')", parameterKind, n.Name, thing, n.Type, o.Type);
             }
         }
     }
 }
Ejemplo n.º 39
0
 public virtual IToken Tok(IToken tok) {
   return tok;
 }