示例#1
0
        internal VerifiableTracker Concat(VerifiableTracker other)
        {
            var branchTo = BranchesAtTransitions.ContainsKey(other.BeganAt) ? BranchesAtTransitions[other.BeganAt] : Transitions.Count;
            var shouldTake = branchTo != Transitions.Count;

            var trans = new LinqList<InstructionAndTransitions>(branchTo + other.Transitions.Count);

            if (shouldTake)
            {
                for (var i = 0; i < branchTo; i++)
                {
                    trans.Add(Transitions[i]);
                }
            }
            else
            {
                trans.AddRange(Transitions);
            }

            trans.AddRange(other.Transitions);

            var canReuseCache = branchTo == Transitions.Count && IsBaseless && CachedVerifyStack != null;

            var ret =
                new VerifiableTracker(BeganAt, IsBaseless)
                {
                    StartingStack = new LinqStack<LinqList<TypeOnStack>>(StartingStack.Reverse().AsEnumerable()),
                    Transitions = trans,
                    CachedVerifyStack = canReuseCache ? new LinqStack<LinqList<TypeOnStack>>(CachedVerifyStack.Reverse().AsEnumerable()) : null,
                    CachedVerifyIndex = canReuseCache ? CachedVerifyIndex : null
                };

            return ret;
        }
示例#2
0
        internal VerifiableTracker Concat(VerifiableTracker other)
        {
            var branchTo   = BranchesAtTransitions.ContainsKey(other.BeganAt) ? BranchesAtTransitions[other.BeganAt] : Transitions.Count;
            var shouldTake = branchTo != Transitions.Count;

            var trans = new LinqList <InstructionAndTransitions>(branchTo + other.Transitions.Count);

            if (shouldTake)
            {
                for (var i = 0; i < branchTo; i++)
                {
                    trans.Add(Transitions[i]);
                }
            }
            else
            {
                trans.AddRange(Transitions);
            }

            trans.AddRange(other.Transitions);

            var canReuseCache = branchTo == Transitions.Count && IsBaseless && CachedVerifyStack != null;

            var ret =
                new VerifiableTracker(BeganAt, IsBaseless)
            {
                StartingStack     = new LinqStack <LinqList <TypeOnStack> >(StartingStack.Reverse().AsEnumerable()),
                Transitions       = trans,
                CachedVerifyStack = canReuseCache ? new LinqStack <LinqList <TypeOnStack> >(CachedVerifyStack.Reverse().AsEnumerable()) : null,
                CachedVerifyIndex = canReuseCache ? CachedVerifyIndex : null
            };

            return(ret);
        }
示例#3
0
        public virtual VerificationResult Mark(Label label)
        {
            // This is, effectively, "follows an unconditional branch & hasn't been seen before"
            if (MarkCreatesNewVerifier && UsesStrictBranchVerification && !ExpectedStacksAtLabels.ContainsKey(label))
            {
                MustBeEmptyWhenBranchedTo.Add(label);
            }

            if (CurrentlyInScope.Count > 0)
            {
                StacksAtLabels[label] = GetCurrentStack();

                var verify = CheckStackMatches(label);
                if (verify != null)
                {
                    return(verify);
                }
            }

            if (MarkCreatesNewVerifier)
            {
                var newVerifier = new VerifiableTracker(label, baseless: true);
                Add(newVerifier, new LinqStack <LinqList <TypeOnStack> >());
                MarkCreatesNewVerifier = false;
            }

            LinqList <VerifiableTracker> restore;

            if (RestoreOnMark.TryGetValue(label, out restore))
            {
                // don't copy, we want the *exact* same verifiers restore here
                AddRange(restore, RestoreStacksOnMark[label]);
                RestoreOnMark.Remove(label);
                RestoreStacksOnMark.Remove(label);
            }

            var based = CurrentlyInScope.FirstOrDefault(f => !f.IsBaseless);

            based = based ?? CurrentlyInScope.First();

            var fromLabel = new VerifiableTracker(label, based.IsBaseless, based);
            var fromStack = CurrentlyInScopeStacks[CurrentlyInScope.IndexOf(based)];

            Add(fromLabel, CopyStack(fromStack));

            if (!VerifyFromLabel.ContainsKey(label))
            {
                VerifyFromLabel[label] = new LinqList <VerifiableTracker>();
            }

            VerifyFromLabel[label].Add(fromLabel);

            RemoveUnnecessaryVerifiers();

            return(VerificationResult.Successful());
        }
示例#4
0
        private void Add(VerifiableTracker tracker, LinqStack<LinqList<TypeOnStack>> stack)
        {
            CurrentlyInScope.Add(tracker);
            CurrentlyInScopeStacks.Add(stack);

            if (CurrentlyInScope.Count != CurrentlyInScopeStacks.Count)
            {
                throw new Exception();
            }
        }
示例#5
0
        private void Add(VerifiableTracker tracker, LinqStack <LinqList <TypeOnStack> > stack)
        {
            CurrentlyInScope.Add(tracker);
            CurrentlyInScopeStacks.Add(stack);

            if (CurrentlyInScope.Count != CurrentlyInScopeStacks.Count)
            {
                throw new Exception();
            }
        }
示例#6
0
        private static LinqStack <LinqList <TypeOnStack> > GetStack(VerifiableTracker tracker)
        {
            var retStack = new LinqStack <LinqList <TypeOnStack> >(tracker.StartingStack.Reverse());

            foreach (var t in tracker.Transitions.AsEnumerable())
            {
                UpdateStack(retStack, t, tracker.IsBaseless);
            }

            return(retStack);
        }
示例#7
0
        public VerifiableTracker(Label beganAt, bool baseless = false, VerifiableTracker createdFrom = null)
        {
            IsBaseless = baseless;
            BeganAt = beganAt;

            MarkedLabelsAtTransitions[beganAt] = 0;

            if (createdFrom != null)
            {
                StartingStack = GetStack(createdFrom);
            }
        }
示例#8
0
        public VerifiableTracker(Label beganAt, bool baseless = false, VerifiableTracker createdFrom = null, bool canBePruned = true)
        {
            IsBaseless  = baseless;
            BeganAt     = beganAt;
            CanBePruned = canBePruned;

            MarkedLabelsAtTransitions[beganAt] = 0;

            if (createdFrom != null)
            {
                StartingStack = GetStack(createdFrom);
            }
        }
示例#9
0
        public static VerificationResult FailureStackMismatch(VerifiableTracker verifier, LinqStack<LinqList<TypeOnStack>> expected, LinqStack<LinqList<TypeOnStack>> incoming)
        {
            return
                new VerificationResult
                {
                    Success = false,

                    Verifier = verifier.Clone(),

                    IsStackMismatch = true,
                    ExpectedStack = expected,
                    IncomingStack = incoming
                };
        }
示例#10
0
        public static VerificationResult FailureStackMismatch(VerifiableTracker verifier, LinqStack <LinqList <TypeOnStack> > expected, LinqStack <LinqList <TypeOnStack> > incoming)
        {
            return
                (new VerificationResult
            {
                Success = false,

                Verifier = verifier.Clone(),

                IsStackMismatch = true,
                ExpectedStack = expected,
                IncomingStack = incoming
            });
        }
示例#11
0
        public static VerificationResult FailureStackSize(VerifiableTracker verifier, int transitionIndex, int expectedSize)
        {
            return
                (new VerificationResult
            {
                Success = false,

                Verifier = verifier.Clone(),
                TransitionIndex = transitionIndex,

                IsStackSizeFailure = true,
                ExpectedStackSize = expectedSize
            });
        }
示例#12
0
        public static VerificationResult FailureUnderflow(VerifiableTracker verifier, int transitionIndex, int expectedSize, LinqStack <LinqList <TypeOnStack> > stack)
        {
            return
                (new VerificationResult
            {
                Success = false,

                Verifier = verifier.Clone(),
                TransitionIndex = transitionIndex,

                IsStackUnderflow = true,
                ExpectedStackSize = expectedSize,
                Stack = stack
            });
        }
示例#13
0
        public static VerificationResult FailureUnderflow(VerifiableTracker verifier, int transitionIndex, int expectedSize, LinqStack<LinqList<TypeOnStack>> stack)
        {
            return
                new VerificationResult
                {
                    Success = false,

                    Verifier = verifier.Clone(),
                    TransitionIndex = transitionIndex,

                    IsStackUnderflow = true,
                    ExpectedStackSize = expectedSize,
                    Stack = stack
                };
        }
示例#14
0
        public static VerificationResult FailureTypeMismatch(VerifiableTracker verifier, int transitionIndex, int stackIndex, IEnumerable <TypeOnStack> expectedTypes, LinqStack <LinqList <TypeOnStack> > stack)
        {
            return
                (new VerificationResult
            {
                Success = false,

                Verifier = verifier.Clone(),
                TransitionIndex = transitionIndex,

                IsTypeMismatch = true,
                StackIndex = stackIndex,
                ExpectedAtStackIndex = LinqEnumerable <TypeOnStack> .For(expectedTypes),
                Stack = stack
            });
        }
示例#15
0
 public static VerificationResult Successful(VerifiableTracker verifier, LinqStack <LinqList <TypeOnStack> > stack)
 {
     return(new VerificationResult {
         Success = true, Stack = stack, Verifier = verifier
     });
 }
示例#16
0
        public virtual VerificationResult Mark(Label label)
        {
            // This is, effectively, "follows an unconditional branch & hasn't been seen before"
            if (MarkCreatesNewVerifier && UsesStrictBranchVerification && !ExpectedStacksAtLabels.ContainsKey(label))
            {
                MustBeEmptyWhenBranchedTo.Add(label);
            }

            if (CurrentlyInScope.Count > 0)
            {
                StacksAtLabels[label] = GetCurrentStack();

                var verify = CheckStackMatches(label);
                if (verify != null)
                {
                    return verify;
                }
            }

            if (MarkCreatesNewVerifier)
            {
                var newVerifier = new VerifiableTracker(label, baseless: true);
                Add(newVerifier, new LinqStack<LinqList<TypeOnStack>>());
                MarkCreatesNewVerifier = false;
            }

            LinqList<VerifiableTracker> restore;
            if (RestoreOnMark.TryGetValue(label, out restore))
            {
                // don't copy, we want the *exact* same verifiers restore here
                AddRange(restore, RestoreStacksOnMark[label]);
                RestoreOnMark.Remove(label);
                RestoreStacksOnMark.Remove(label);
            }

            var based = CurrentlyInScope.FirstOrDefault(f => !f.IsBaseless);
            based = based ?? CurrentlyInScope.First();

            var fromLabel = new VerifiableTracker(label, based.IsBaseless, based);
            var fromStack = CurrentlyInScopeStacks[CurrentlyInScope.IndexOf(based)];
            Add(fromLabel, CopyStack(fromStack));

            if (!VerifyFromLabel.ContainsKey(label))
            {
                VerifyFromLabel[label] = new LinqList<VerifiableTracker>();
            }

            VerifyFromLabel[label].Add(fromLabel);

            RemoveUnnecessaryVerifiers();

            return VerificationResult.Successful();
        }
示例#17
0
        public static VerificationResult FailureTypeMismatch(VerifiableTracker verifier, int transitionIndex, int stackIndex, IEnumerable<TypeOnStack> expectedTypes, LinqStack<LinqList<TypeOnStack>> stack)
        {
            return
                new VerificationResult
                {
                    Success = false,

                    Verifier = verifier.Clone(),
                    TransitionIndex = transitionIndex,

                    IsTypeMismatch = true,
                    StackIndex = stackIndex,
                    ExpectedAtStackIndex = LinqEnumerable<TypeOnStack>.For(expectedTypes),
                    Stack = stack
                };
        }
示例#18
0
        private static LinqStack<LinqList<TypeOnStack>> GetStack(VerifiableTracker tracker)
        {
            var retStack = new LinqStack<LinqList<TypeOnStack>>(tracker.StartingStack.Reverse());

            foreach (var t in tracker.Transitions.AsEnumerable())
            {
                UpdateStack(retStack, t, tracker.IsBaseless);
            }

            return retStack;
        }
示例#19
0
        public static VerificationResult FailureStackSize(VerifiableTracker verifier, int transitionIndex, int expectedSize)
        {
            return
                new VerificationResult
                {
                    Success = false,

                    Verifier = verifier.Clone(),
                    TransitionIndex = transitionIndex,

                    IsStackSizeFailure = true,
                    ExpectedStackSize = expectedSize
                };
        }
示例#20
0
 public static VerificationResult Successful(VerifiableTracker verifier, LinqStack<LinqList<TypeOnStack>> stack)
 {
     return new VerificationResult { Success = true, Stack = stack, Verifier = verifier };
 }