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; }
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); }
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()); }
private void Add(VerifiableTracker tracker, LinqStack<LinqList<TypeOnStack>> stack) { CurrentlyInScope.Add(tracker); CurrentlyInScopeStacks.Add(stack); if (CurrentlyInScope.Count != CurrentlyInScopeStacks.Count) { throw new Exception(); } }
private void Add(VerifiableTracker tracker, LinqStack <LinqList <TypeOnStack> > stack) { CurrentlyInScope.Add(tracker); CurrentlyInScopeStacks.Add(stack); if (CurrentlyInScope.Count != CurrentlyInScopeStacks.Count) { throw new Exception(); } }
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); }
public VerifiableTracker(Label beganAt, bool baseless = false, VerifiableTracker createdFrom = null) { IsBaseless = baseless; BeganAt = beganAt; MarkedLabelsAtTransitions[beganAt] = 0; if (createdFrom != null) { StartingStack = GetStack(createdFrom); } }
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); } }
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 }; }
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 }); }
public static VerificationResult FailureStackSize(VerifiableTracker verifier, int transitionIndex, int expectedSize) { return (new VerificationResult { Success = false, Verifier = verifier.Clone(), TransitionIndex = transitionIndex, IsStackSizeFailure = true, ExpectedStackSize = expectedSize }); }
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 }); }
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 }; }
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 }); }
public static VerificationResult Successful(VerifiableTracker verifier, LinqStack <LinqList <TypeOnStack> > stack) { return(new VerificationResult { Success = true, Stack = stack, Verifier = verifier }); }
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(); }
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 }; }
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; }
public static VerificationResult FailureStackSize(VerifiableTracker verifier, int transitionIndex, int expectedSize) { return new VerificationResult { Success = false, Verifier = verifier.Clone(), TransitionIndex = transitionIndex, IsStackSizeFailure = true, ExpectedStackSize = expectedSize }; }
public static VerificationResult Successful(VerifiableTracker verifier, LinqStack<LinqList<TypeOnStack>> stack) { return new VerificationResult { Success = true, Stack = stack, Verifier = verifier }; }