Example #1
0
        protected void InsertPreConditionEdges(BlockWithLabels <Label> previousBlock, BlockWithLabels <Label> newBlock)
        {
            var methodCallBlock = newBlock as MethodCallBlock <Label>;

            if (methodCallBlock == null || CurrentSubroutine.IsContract || CurrentSubroutine.IsOldValue)
            {
                return;
            }

            if (CurrentSubroutine.IsMethod)
            {
                var      methodInfo = CurrentSubroutine as IMethodInfo;
                Property property;
                if (methodInfo != null && MetaDataProvider.IsConstructor(methodInfo.Method) &&
                    MetaDataProvider.IsPropertySetter(methodCallBlock.CalledMethod, out property) &&
                    MetaDataProvider.IsAutoPropertyMember(methodCallBlock.CalledMethod))
                {
                    return;
                }
            }

            EdgeTag    callTag  = methodCallBlock.IsNewObj ? EdgeTag.BeforeNewObj : EdgeTag.BeforeCall;
            Subroutine requires = this.SubroutineFacade.GetRequires(methodCallBlock.CalledMethod);

            CurrentSubroutine.AddEdgeSubroutine(previousBlock, newBlock, requires, callTag);
        }
Example #2
0
        protected void InsertPostConditionEdges(BlockWithLabels <Label> previousBlock, BlockWithLabels <Label> newBlock)
        {
            var methodCallBlock = previousBlock as MethodCallBlock <Label>;

            if (methodCallBlock == null)
            {
                return;
            }

            if (CurrentSubroutine.IsMethod)
            {
                var      methodInfo = CurrentSubroutine as IMethodInfo;
                Property property;
                if (methodInfo != null && MetaDataProvider.IsConstructor(methodInfo.Method) &&
                    MetaDataProvider.IsPropertyGetter(methodCallBlock.CalledMethod, out property) &&
                    MetaDataProvider.IsAutoPropertyMember(methodCallBlock.CalledMethod))
                {
                    return;
                }
            }

            EdgeTag    callTag = methodCallBlock.IsNewObj ? EdgeTag.AfterNewObj : EdgeTag.AfterCall;
            Subroutine ensures = this.SubroutineFacade.GetEnsures(methodCallBlock.CalledMethod);

            CurrentSubroutine.AddEdgeSubroutine(previousBlock, newBlock, ensures, callTag);
        }
Example #3
0
 public AssertionObligation(APC pc, EdgeTag tag, TVariable cond, bool isAssume)
 {
     this.Apc       = pc;
     this.Tag       = tag;
     this.Condition = cond;
     this.IsAssume  = isAssume;
 }
Example #4
0
                public override bool Assume(APC pc, EdgeTag tag, TVariable condition, bool data)
                {
                    if (!pc.InsideRequiresAtCallInsideContract && tag == EdgeTag.Assume)
                    {
                        this.Obligations.Add(new AssertionObligation(pc, tag, condition, true));
                    }

                    return(data);
                }
        public Result Assume(APC pc, EdgeTag tag, Dummy condition, Data data)
        {
            if (tag == EdgeTag.Requires && pc.InsideRequiresAtCall || tag == EdgeTag.Invariant && pc.InsideInvariantOnExit)
            {
                return(this.visitor.Assert(pc, tag, condition, data));
            }

            return(this.visitor.Assume(pc, tag, condition, data));
        }
        public Result Assert(APC pc, EdgeTag tag, Dummy condition, Data data)
        {
            if (pc.InsideEnsuresAtCall)
            {
                return(this.visitor.Assume(pc, tag, condition, data));
            }

            return(this.visitor.Assert(pc, tag, condition, data));
        }
Example #7
0
                public override bool Assert(APC pc, EdgeTag tag, TVariable condition, bool data)
                {
                    if (pc.InsideRequiresAtCallInsideContract)
                    {
                        return(data);
                    }

                    this.Obligations.Add(new AssertionObligation(pc, tag, condition));
                    return(data);
                }
Example #8
0
        public override ExprDomain <TSymValue> Assert(APC pc, EdgeTag tag, TSymValue condition, ExprDomain <TSymValue> data)
        {
            FlatDomain <Expr <TSymValue> > expression = data [condition];

            if (expression.IsNormal())
            {
                data = expression.Value.Decode <ExprDomain <TSymValue>, ExprDomain <TSymValue>, AssumeDecoder <TSymValue> >
                           (pc, condition, new AssumeDecoder <TSymValue> (true), data);
            }

            return(data);
        }
Example #9
0
 public void Initialize(Graph g, int id, Node begin, Node end, EdgeTag t)
 {
     graph  = g;
     Id     = id;
     Begin  = begin;
     End    = end;
     eTag   = t;
     Marks  = new MarkList();
     Colour = Color.black;
     UpdateLine();
     UpdateCollider();
     UpdateTagPosition();
 }
Example #10
0
        public override ExprDomain <TSymValue> Assume(APC pc, EdgeTag tag, TSymValue condition, ExprDomain <TSymValue> data)
        {
            FlatDomain <Expr <TSymValue> > aExpression = data [condition];

            if (aExpression.IsNormal())
            {
                bool truth = tag != EdgeTag.False;
                data = aExpression.Value.Decode <ExprDomain <TSymValue>, ExprDomain <TSymValue>, AssumeDecoder <TSymValue> >
                           (pc, condition, new AssumeDecoder <TSymValue> (truth), data);
            }

            return(data);
        }
Example #11
0
    public override void AddEdge(Node <T> from, Node <T> to)
    {
        EdgeTag <T, T2> newEdge  = new EdgeTag <T, T2>(from, to);
        EdgeTag <T, T2> backEdge = new EdgeTag <T, T2>(to, from);

        if (!edges.Contains(newEdge))
        {
            edges.Add(newEdge);
        }
        if (!edges.Contains(backEdge))
        {
            edges.Add(backEdge);
        }
    }
Example #12
0
    public void AddEdge(int beginId, int endId)
    {
        Edge    newEdge = Instantiate(prefabEdge, Vector3.zero, Quaternion.identity, transform);
        Node    begin   = nodes.Find(node => node.Id == beginId);
        Node    end     = nodes.Find(node => node.Id == endId);
        EdgeTag tag     = Instantiate(prefabEdgeTag, Vector3.zero, Quaternion.identity, canvas);

        tag.Initialize(newEdge);
        newEdge.Initialize(this, edgeIdCount, begin, end, tag);
        newEdge.BeginPosition = new Vector3(begin.transform.position.x, begin.transform.position.y, 1);
        newEdge.EndPosition   = new Vector3(end.transform.position.x, end.transform.position.y, 1);
        edges.Add(newEdge);
        edgeIdCount++;
    }
Example #13
0
    public void AddEdge(Node <T> from, Node <T> to, T2 tag)
    {
        EdgeTag <T, T2> newEdge  = new EdgeTag <T, T2>(from, to);
        EdgeTag <T, T2> backEdge = new EdgeTag <T, T2>(to, from);

        newEdge.Tag  = tag;
        backEdge.Tag = tag;
        if (!edges.Contains(newEdge))
        {
            edges.Add(newEdge);
        }
        if (!edges.Contains(backEdge))
        {
            edges.Add(backEdge);
        }
    }
Example #14
0
        private bool HandleConditionalBranch(Label pc, Label target, bool isTrueBranch, BlockWithLabels <Label> currentBlock)
        {
            currentBlock.AddLabel(pc);
            EdgeTag trueTag  = isTrueBranch ? EdgeTag.True : EdgeTag.False;
            EdgeTag falseTag = isTrueBranch ? EdgeTag.False : EdgeTag.True;

            AssumeBlock <Label> trueBlock = CurrentSubroutine.NewAssumeBlock(pc, trueTag);

            this.builder.RecordInformationSameAsOtherBlock(trueBlock, this.current_block);
            CurrentSubroutine.AddSuccessor(currentBlock, trueTag, trueBlock);
            CurrentSubroutine.AddSuccessor(trueBlock, EdgeTag.FallThrough, CurrentSubroutine.GetTargetBlock(target));

            AssumeBlock <Label> falseBlock = CurrentSubroutine.NewAssumeBlock(pc, falseTag);

            this.builder.RecordInformationSameAsOtherBlock(falseBlock, this.current_block);
            CurrentSubroutine.AddSuccessor(currentBlock, falseTag, falseBlock);
            this.current_block = falseBlock;

            return(false);
        }
Example #15
0
                public override TDomain Assume(APC pc, EdgeTag tag, TVar condition, TDomain data)
                {
                    var boxed = ToBoxedExpression(pc, condition);

                    if (tag != EdgeTag.False)
                    {
                        bool value;
                        if (boxed.IsTrivialCondition(out value))
                        {
                            return(!value ? data.Bottom : data);
                        }
                    }

                    List <int> thresholds;

                    if (ThresholdDB.TryGetAThreshold(boxed, expression_decoder, out thresholds))
                    {
                        ThresholdDB.Add(thresholds);
                    }

                    TDomain result;

                    switch (tag)
                    {
                    case EdgeTag.True:
                    case EdgeTag.Requires:
                    case EdgeTag.Assume:
                    case EdgeTag.Invariant:
                        result = data.AssumeTrue(boxed);
                        break;

                    case EdgeTag.False:
                        result = data.AssumeFalse(boxed);
                        break;

                    default:
                        result = data;
                        break;
                    }

                    if (tag != EdgeTag.False)
                    {
                        var abstractType =
                            ContextProvider.ValueContext.GetType(
                                ContextProvider.MethodContext.CFG.Post(pc), condition);
                        if (abstractType.IsNormal() &&
                            MetaDataProvider.Equal(abstractType.Value,
                                                   MetaDataProvider.System_Boolean))
                        {
                            var guard =
                                BoxedExpression.Binary(BinaryOperator.Ceq, boxed,
                                                       BoxedExpression.Const(1,
                                                                             MetaDataProvider
                                                                             .
                                                                             System_Int32));

                            result = result.AssumeTrue(guard);
                        }
                    }

                    return(result);
                }
Example #16
0
		public static bool Is (this EdgeTag current, EdgeTag mask)
		{
			return (current & mask) != EdgeTag.None;
		}
Example #17
0
 public static bool Is(this EdgeTag current, EdgeTag mask)
 {
     return((current & mask) != EdgeTag.None);
 }
Example #18
0
        public override sealed void AddEdgeSubroutine(CFGBlock from, CFGBlock to, Subroutine subroutine, EdgeTag tag)
        {
            if (subroutine == null)
            {
                return;
            }

            var key = Pair.From(from, to);

            Sequence <Pair <EdgeTag, Subroutine> > list;

            this.edge_subroutines.TryGetValue(key, out list);
            this.edge_subroutines[key] = list.Cons(Pair.From(tag, subroutine));
        }
Example #19
0
 public AssertionObligation(APC pc, EdgeTag tag, TVariable cond)
     : this(pc, tag, cond, false)
 {
 }
Example #20
0
 public abstract void AddEdgeSubroutine(CFGBlock from, CFGBlock to, Subroutine subroutine, EdgeTag tag);