示例#1
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);
        }
示例#2
0
        public override BlockWithLabels <Label> RecordInformationForNewBlock(Label currentLabel, BlockWithLabels <Label> previousBlock)
        {
            Label label;

            if (previousBlock != null && previousBlock.TryGetLastLabel(out label) && this.endOldStart.Contains(label))
            {
                OldValueSubroutine <Label> oldValueSubroutine = this.current_old_subroutine;
                oldValueSubroutine.Commit(previousBlock);
                this.current_old_subroutine = null;
                BlockWithLabels <Label> result = base.RecordInformationForNewBlock(currentLabel, this.block_prior_to_old);
                CurrentSubroutine.AddEdgeSubroutine(this.block_prior_to_old, result, oldValueSubroutine, EdgeTag.Old);
                return(result);
            }

            if (!this.beginOldStart.Contains(currentLabel))
            {
                return(base.RecordInformationForNewBlock(currentLabel, previousBlock));
            }
            this.current_old_subroutine = new OldValueSubroutine <Label> (this.SubroutineFacade,
                                                                          ((MethodContractSubroutine <Label>) this.current_subroutine).Method,
                                                                          this, currentLabel);
            this.block_prior_to_old = previousBlock;
            BlockWithLabels <Label> newBlock = base.RecordInformationForNewBlock(currentLabel, null);

            this.current_old_subroutine.RegisterBeginBlock(newBlock);
            return(newBlock);
        }
示例#3
0
        public virtual BlockWithLabels <Label> RecordInformationForNewBlock(Label currentLabel, BlockWithLabels <Label> previousBlock)
        {
            BlockWithLabels <Label> block = CurrentSubroutine.GetBlock(currentLabel);

            if (previousBlock != null)
            {
                BlockWithLabels <Label> newBlock  = block;
                BlockWithLabels <Label> prevBlock = previousBlock;
                if (block is MethodCallBlock <Label> && previousBlock is MethodCallBlock <Label> )
                {
                    BlockWithLabels <Label> ab = CurrentSubroutine.NewBlock();
                    RecordInformationSameAsOtherBlock(ab, previousBlock);
                    newBlock  = ab;
                    prevBlock = ab;
                    CurrentSubroutine.AddSuccessor(previousBlock, EdgeTag.FallThrough, ab);
                    CurrentSubroutine.AddSuccessor(ab, EdgeTag.FallThrough, block);
                }
                else
                {
                    CurrentSubroutine.AddSuccessor(previousBlock, EdgeTag.FallThrough, block);
                }

                InsertPostConditionEdges(previousBlock, newBlock);
                InsertPreConditionEdges(prevBlock, block);
            }
            return(block);
        }
示例#4
0
 protected SubroutineBase(SubroutineFacade subroutineFacade)
 {
     this.SubroutineFacade = subroutineFacade;
     this.entry            = new EntryBlock <Label> (this, ref this.BlockIdGenerator);
     this.exit             = new EntryExitBlock <Label> (this, ref this.BlockIdGenerator);
     this.exception_exit   = new CatchFilterEntryBlock <Label> (this, ref this.BlockIdGenerator);
 }
示例#5
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);
        }
示例#6
0
        public override bool Return(Label pc, Dummy source, BlockWithLabels <Label> currentBlock)
        {
            currentBlock.AddLabel(pc);
            CurrentSubroutine.AddSuccessor(currentBlock, EdgeTag.Return, CurrentSubroutine.Exit);
            CurrentSubroutine.AddReturnBlock(currentBlock);

            return(true);
        }
示例#7
0
 protected virtual void PrintHandlers(TextWriter tw, BlockWithLabels <Label> block)
 {
     tw.Write("  Handlers: ");
     if (block != ExceptionExit)
     {
         tw.Write("{0} ", ExceptionExit.Index);
     }
     tw.WriteLine();
 }
示例#8
0
        public override void RecordInformationSameAsOtherBlock(BlockWithLabels <Label> newBlock, BlockWithLabels <Label> currentBlock)
        {
            Sequence <Handler> list;

            if (!CurrentSubroutineWithHandlers.ProtectingHandlers.TryGetValue(currentBlock, out list))
            {
                return;
            }
            CurrentSubroutineWithHandlers.ProtectingHandlers.Add(newBlock, list);
        }
示例#9
0
        protected SubroutineBase(SubroutineFacade SubroutineFacade,
                                 Label startLabel, SubroutineBuilder <Label> builder)
            : this(SubroutineFacade)
        {
            this.StartLabel           = startLabel;
            Builder                   = builder;
            CodeProvider              = builder.CodeProvider;
            this.entry_after_requires = GetTargetBlock(startLabel);

            AddSuccessor(this.entry, EdgeTag.Entry, this.entry_after_requires);
        }
示例#10
0
        public MethodSubroutine(SubroutineFacade SubroutineFacade,
                                Method method, Label startLabel,
                                SubroutineWithHandlersBuilder <Label, Handler> builder) : base(SubroutineFacade, startLabel, builder)
        {
            this.method = method;
            IMetaDataProvider metaDataProvider = this.SubroutineFacade.MetaDataProvider;

            builder.BuildBlocks(startLabel, this);
            BlockWithLabels <Label> targetBlock = GetTargetBlock(startLabel);

            Commit();

            TypeNode   type      = metaDataProvider.DeclaringType(method);
            Subroutine invariant = this.SubroutineFacade.GetInvariant(type);

            if (invariant != null && !metaDataProvider.IsConstructor(method) && !metaDataProvider.IsStatic(method))
            {
                AddEdgeSubroutine(Entry, targetBlock, invariant, EdgeTag.Entry);
                Subroutine requires = this.SubroutineFacade.GetRequires(method);
                if (requires != null)
                {
                    AddEdgeSubroutine(Entry, targetBlock, requires, EdgeTag.Entry);
                }
            }
            else
            {
                AddEdgeSubroutine(Entry, targetBlock, this.SubroutineFacade.GetRequires(method), EdgeTag.Entry);
            }

            if (this.blocks_ending_in_return_point == null)
            {
                return;
            }

            Subroutine ensures = this.SubroutineFacade.GetEnsures(method);
            bool       putInvariantAfterExit = !metaDataProvider.IsStatic(method) &&
                                               !metaDataProvider.IsFinalizer(method) && !metaDataProvider.IsDispose(method);

            foreach (var block in this.blocks_ending_in_return_point)
            {
                if (putInvariantAfterExit)
                {
                    AddEdgeSubroutine(block, Exit, invariant, EdgeTag.Exit);
                }
                AddEdgeSubroutine(block, Exit, ensures, EdgeTag.Exit);
            }

            if (ensures != null)
            {
                throw new NotImplementedException();
            }

            this.blocks_ending_in_return_point = null;
        }
示例#11
0
        public override void AddReturnBlock(BlockWithLabels <Label> block)
        {
            if (this.blocks_ending_in_return_point == null)
            {
                this.blocks_ending_in_return_point = new HashSet <BlockWithLabels <Label> > ();
            }

            this.blocks_ending_in_return_point.Add(block);

            base.AddReturnBlock(block);
        }
示例#12
0
 private void TraceAggregateSequentally(Label currentLabel)
 {
     do
     {
         if (this.builder.IsBlockStart(currentLabel))
         {
             this.current_block = this.builder.RecordInformationForNewBlock(currentLabel, this.current_block);
         }
         if (this.builder.CodeProvider.Decode <BlockBuilder <Label>, BlockWithLabels <Label>, bool> (currentLabel, this, this.current_block))
         {
             this.current_block = null;
         }
     } while (this.builder.CodeProvider.Next(currentLabel, out currentLabel));
 }
示例#13
0
 public override bool LoadField(Label pc, Field field, Dummy dest, Dummy obj, BlockWithLabels <Label> data)
 {
     if (CurrentSubroutine.IsMethod)
     {
         var      methodInfo = (IMethodInfo)CurrentSubroutine;
         Property property;
         if (this.builder.MetaDataProvider.IsPropertyGetter(methodInfo.Method, out property))
         {
             this.builder.SubroutineFacade.AddReads(methodInfo.Method, field);
         }
     }
     this.current_block.AddLabel(pc);
     return(false);
 }
示例#14
0
        public BlockWithLabels <Label> CreateCatchFilterHeader(Handler handler, Label label)
        {
            BlockWithLabels <Label> block;

            if (!this.LabelsThatStartBlocks.TryGetValue(label, out block))
            {
                block = new CatchFilterEntryBlock <Label> (this, ref this.BlockIdGenerator);

                this.CatchFilterHeaders.Add(handler, block);
                this.LabelsThatStartBlocks.Add(label, block);
                if (CodeProvider.IsFilterHandler(handler))
                {
                    BlockWithLabels <Label> targetBlock = GetTargetBlock(CodeProvider.FilterExpressionStart(handler));
                    this.FilterCodeBlocks.Add(handler, targetBlock);
                }
            }
            return(block);
        }
示例#15
0
        public override bool HasSingleSuccessor(APC point, out APC ifFound)
        {
            if (point.Index < point.Block.Count)
            {
                ifFound = new APC(point.Block, point.Index + 1, point.SubroutineContext);
                return(true);
            }

            if (IsSubroutineEnd(point.Block))
            {
                if (point.SubroutineContext == null)
                {
                    ifFound = APC.Dummy;
                    return(false);
                }

                ifFound = ComputeSubroutineContinuation(point);
                return(true);
            }

            BlockWithLabels <Label> onlyOne = null;

            foreach (BlockWithLabels <Label> successor in point.Block.Subroutine.SuccessorBlocks(point.Block))
            {
                if (onlyOne == null)
                {
                    onlyOne = successor;
                }
                else
                {
                    ifFound = APC.Dummy;
                    return(false);
                }
            }

            if (onlyOne != null)
            {
                ifFound = ComputeTargetFinallyContext(point, onlyOne);
                return(true);
            }

            ifFound = APC.Dummy;
            return(false);
        }
示例#16
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);
        }
示例#17
0
 protected override void PrintHandlers(TextWriter tw, BlockWithLabels <Label> block)
 {
     tw.Write("  Handlers: ");
     foreach (Handler handler in ProtectingHandlerList(block).AsEnumerable())
     {
         if (IsFaultOrFinally(handler))
         {
             tw.Write("SR{0} ", this.FaultFinallySubroutines [handler].Id);
         }
         else
         {
             tw.Write("{0} ", this.CatchFilterHeaders [handler].Index);
         }
     }
     if (block != ExceptionExit)
     {
         tw.Write("{0} ", ExceptionExit.Index);
     }
     tw.WriteLine();
 }
示例#18
0
 public void RegisterBeginBlock(BlockWithLabels <TLabel> beginOldBlock)
 {
     this.begin_old_block = beginOldBlock;
 }
示例#19
0
 public override bool DefaultVisit(Label pc, BlockWithLabels <Label> currentBlock)
 {
     currentBlock.AddLabel(pc);
     return(false);
 }
示例#20
0
 public override bool Nop(Label pc, BlockWithLabels <Label> currentBlock)
 {
     return(false);
 }
示例#21
0
        public override BlockWithLabels <Label> RecordInformationForNewBlock(Label currentLabel, BlockWithLabels <Label> previousBlock)
        {
            BlockWithLabels <Label> result     = null;
            Queue <Handler>         handlerEnd = GetHandlerEnd(currentLabel);

            if (handlerEnd != null)
            {
                foreach (Handler handler in handlerEnd)
                {
                    this.subroutine_stack.Head.Commit();
                    this.subroutine_stack = this.subroutine_stack.Tail;
                    previousBlock         = null;
                }
            }
            Queue <Handler> tryEnd = GetTryEnd(currentLabel);

            if (tryEnd != null)
            {
                foreach (Handler handler in tryEnd)
                {
                    if (!Equals(handler, CurrentProtectingHanlders.Head))
                    {
                        throw new InvalidOperationException("wrong handler");
                    }
                    CurrentProtectingHanlders = CurrentProtectingHanlders.Tail;
                }
            }
            Handler handler1;

            if (IsHandlerStart(currentLabel, out handler1))
            {
                if (IsFaultOrFinally(handler1))
                {
                    SubroutineWithHandlers <Label, Handler> sub = !CodeProvider.IsFaultHandler(handler1)
                                                                                        ? new FinallySubroutine <Label, Handler> (this.SubroutineFacade, currentLabel, this)
                                                                                        : (FaultFinallySubroutineBase <Label, Handler>) new FaultSubroutine <Label, Handler> (this.SubroutineFacade, currentLabel, this);
                    CurrentSubroutineWithHandlers.FaultFinallySubroutines.Add(handler1, sub);
                    this.subroutine_stack = this.subroutine_stack.Cons(sub);
                    previousBlock         = null;
                }
                else
                {
                    result = CurrentSubroutineWithHandlers.CreateCatchFilterHeader(handler1, currentLabel);
                }
            }
            if (result == null)
            {
                result = base.RecordInformationForNewBlock(currentLabel, previousBlock);
            }
            Stack <Handler> tryStart = GetTryStart(currentLabel);

            if (tryStart != null)
            {
                foreach (Handler handler in tryStart)
                {
                    CurrentProtectingHanlders = CurrentProtectingHanlders.Cons(handler);
                }
            }

            CurrentSubroutineWithHandlers.ProtectingHandlers.Add(result, CurrentProtectingHanlders);
            return(result);
        }
示例#22
0
 public override bool EndOld(Label pc, Label matchingBegin, TypeNode type, Dummy dest, Dummy source, BlockWithLabels <Label> data)
 {
     this.current_block.AddLabel(pc);
     CurrentSubroutine.AddSuccessor(this.current_block, EdgeTag.EndOld, CurrentSubroutine.Exit);
     return(false);
 }
示例#23
0
 public virtual void AddReturnBlock(BlockWithLabels <Label> block)
 {
 }
示例#24
0
 public override bool EndFinally(Label pc, BlockWithLabels <Label> currentBlock)
 {
     currentBlock.AddLabel(pc);
     CurrentSubroutine.AddSuccessor(currentBlock, EdgeTag.EndSubroutine, CurrentSubroutine.Exit);
     return(true);
 }
示例#25
0
 public bool Aggregate(Label pc, Label aggregateStart, bool canBeTargetOfBranch, BlockWithLabels <Label> data)
 {
     TraceAggregateSequentally(aggregateStart);
     return(false);
 }
示例#26
0
 public override bool Rethrow(Label pc, BlockWithLabels <Label> currentBlock)
 {
     currentBlock.AddLabel(pc);
     return(true);
 }
示例#27
0
 public override bool Throw(Label pc, Dummy exception, BlockWithLabels <Label> currentBlock)
 {
     currentBlock.AddLabel(pc);
     return(true);
 }
示例#28
0
 public override bool BranchTrue(Label pc, Label target, Dummy cond, BlockWithLabels <Label> currentBlock)
 {
     return(HandleConditionalBranch(pc, target, true, currentBlock));
 }
示例#29
0
 public override bool BranchCond(Label pc, Label target, BranchOperator bop, Dummy value1, Dummy value2, BlockWithLabels <Label> currentBlock)
 {
     return(HandleConditionalBranch(pc, target, true, currentBlock));
 }
示例#30
0
        public override bool Branch(Label pc, Label target, bool leavesExceptionBlock, BlockWithLabels <Label> currentBlock)
        {
            currentBlock.AddLabel(pc);
            CurrentSubroutine.AddSuccessor(currentBlock, EdgeTag.Branch, CurrentSubroutine.GetTargetBlock(target));

            return(true);
        }