protected void Page_Load(object sender, EventArgs e) { DataTable table = new DataTable(); table.Columns.Add("col1", typeof(string)); DataRow row; row = table.NewRow(); row["col1"] = "123"; table.Rows.Add(row); row = table.NewRow(); row["col1"] = "456"; table.Rows.Add(row); LinqList <DataRow> rows = new LinqList <DataRow>(table.Rows); // do a simple select DataRow [] selectedRows = (from r in rows where (string)r["col1"] == "123" select r).ToArray(); if (selectedRows.Length > 0) { lable1.Text = "success"; } else { lable1.Text = "failed"; } }
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; }
private Emit(CallingConventions callConvention, Type returnType, Type[] parameterTypes, bool allowUnverifiable, bool doVerify, bool strictBranchVerification) { CallingConventions = callConvention; AllowsUnverifiableCIL = allowUnverifiable; IsVerifying = doVerify; UsesStrictBranchVerification = strictBranchVerification; ReturnType = TypeOnStack.Get(returnType); ParameterTypes = parameterTypes; IL = new BufferedILGenerator <DelegateType>(); Trackers = new LinqList <VerifiableTracker>(); AllLocals = new LinqList <Local>(); UnusedLocals = new LinqHashSet <Local>(); UnusedLabels = new LinqHashSet <Label>(); UnmarkedLabels = new LinqHashSet <Label>(); Branches = new LinqList <SigilTuple <OpCode, Label, int> >(); Marks = new LinqDictionary <Label, int>(); Returns = new LinqList <int>(); Throws = new LinqList <int>(); BranchPatches = new LinqDictionary <int, SigilTuple <Label, UpdateOpCodeDelegate, OpCode> >(); CurrentExceptionBlock = new Stack <ExceptionBlock>(); TryBlocks = new LinqDictionary <ExceptionBlock, SigilTuple <int, int> >(); CatchBlocks = new LinqDictionary <CatchBlock, SigilTuple <int, int> >(); FinallyBlocks = new LinqDictionary <FinallyBlock, SigilTuple <int, int> >(); ReadonlyPatches = new LinqList <SigilTuple <int, TypeOnStack> >(); Shorthand = new EmitShorthand <DelegateType>(this); FreedLocals = new LinqList <Local>(); CurrentLocals = new LinqDictionary <string, Local>(); Locals = new LocalLookup(CurrentLocals); CurrentLabels = new LinqDictionary <string, Label>(); Labels = new LabelLookup(CurrentLabels); ElidableCasts = new LinqList <int>(); TypesProducedAtIndex = new LinqDictionary <int, LinqList <TypeOnStack> >(); var start = DefineLabel("__start"); CurrentVerifiers = IsVerifying ? new RollingVerifier(start, UsesStrictBranchVerification) : new RollingVerifierWithoutVerification(start); MarkLabel(start); }
private void AddRange(LinqList<VerifiableTracker> trackers, LinqList<LinqStack<LinqList<TypeOnStack>>> stacks) { if (trackers.Count != stacks.Count) { throw new Exception(); } for (var i = 0; i < trackers.Count; i++) { Add(trackers[i], stacks[i]); } }
public virtual VerificationResult ConditionalBranch(params Label[] toLabels) { foreach(var to in toLabels) { var intoVerified = VerifyBranchInto(to); if (intoVerified != null) { return intoVerified; } UpdateRestores(to); if (!RestoreOnMark.ContainsKey(to)) { if (!RestoreOnMark.ContainsKey(to)) { RestoreOnMark[to] = new LinqList<VerifiableTracker>(); RestoreStacksOnMark[to] = new LinqList<LinqStack<LinqList<TypeOnStack>>>(); } RestoreOnMark[to].AddRange(CurrentlyInScope.Select(t => t.Clone())); RestoreStacksOnMark[to].AddRange(CurrentlyInScopeStacks.Select(s => CopyStack(s))); } if (!ExpectedStacksAtLabels.ContainsKey(to)) { ExpectedStacksAtLabels[to] = new LinqList<SigilTuple<bool, LinqStack<LinqList<TypeOnStack>>>>(); } ExpectedStacksAtLabels[to].Add(GetCurrentStack()); var verify = CheckStackMatches(to); if (verify != null) { return verify; } } return VerificationResult.Successful(); }
/// <summary> /// Traces where the values produced by certain operations are used. /// /// For example: /// ldc.i4 32 /// ldc.i4 64 /// add /// ret /// /// Would be represented by a series of OperationResultUsage like so: /// - (lcd.i4 32) -> add /// - (ldc.i4 64) -> add /// - (add) -> ret /// </summary> public IEnumerable <OperationResultUsage <DelegateType> > TraceOperationResultUsage() { var ret = new List <OperationResultUsage <DelegateType> >(); foreach (var r in TypesProducedAtIndex.AsEnumerable()) { var allUsage = new LinqList <InstructionAndTransitions>(r.Value.SelectMany(k => k.UsedBy.Select(u => u.Item1)).AsEnumerable()); var usedBy = new List <Operation <DelegateType> >(allUsage.Select(u => IL.Operations[u.InstructionIndex.Value]).Distinct().AsEnumerable()); if (r.Key < IL.Operations.Count) { var key = IL.Operations[r.Key]; if (key != null) { ret.Add(new OperationResultUsage <DelegateType>(key, usedBy, r.Value.AsEnumerable())); } } } return(ret); }
public virtual VerificationResult UnconditionalBranch(Label to) { // If we've recorded elsewhere that the label we're branching to *must* receive // an empty stack, then inject a transition that expects that if (MustBeEmptyWhenBranchedTo.Contains(to)) { var trans = new LinqList<StackTransition>(); trans.Add(new StackTransition(sizeMustBe: 0)); var stackIsEmpty = Transition(new InstructionAndTransitions(null, null, trans)); if (stackIsEmpty != null) return stackIsEmpty; } var intoVerified = VerifyBranchInto(to); if (intoVerified != null) { return intoVerified; } UpdateRestores(to); if (!RestoreOnMark.ContainsKey(to)) { RestoreOnMark[to] = new LinqList<VerifiableTracker>(); RestoreStacksOnMark[to] = new LinqList<LinqStack<LinqList<TypeOnStack>>>(); } if (!ExpectedStacksAtLabels.ContainsKey(to)) { ExpectedStacksAtLabels[to] = new LinqList<SigilTuple<bool, LinqStack<LinqList<TypeOnStack>>>>(); } ExpectedStacksAtLabels[to].Add(GetCurrentStack()); var verify = CheckStackMatches(to); if (verify != null) { return verify; } RestoreOnMark[to].AddRange(CurrentlyInScope); RestoreStacksOnMark[to].AddRange(CurrentlyInScopeStacks); EmptyCurrentScope(); MarkCreatesNewVerifier = true; return VerificationResult.Successful(); }
public virtual VerificationResult UnconditionalBranch(Label to) { var intoVerified = VerifyBranchInto(to); if (intoVerified != null) { return intoVerified; } UpdateRestores(to); if (!RestoreOnMark.ContainsKey(to)) { RestoreOnMark[to] = new LinqList<VerifiableTracker>(); RestoreStacksOnMark[to] = new LinqList<LinqStack<LinqList<TypeOnStack>>>(); } if (!ExpectedStacksAtLabels.ContainsKey(to)) { ExpectedStacksAtLabels[to] = new LinqList<SigilTuple<bool, LinqStack<LinqList<TypeOnStack>>>>(); } ExpectedStacksAtLabels[to].Add(GetCurrentStack()); var verify = CheckStackMatches(to); if (verify != null) { return verify; } RestoreOnMark[to].AddRange(CurrentlyInScope); RestoreStacksOnMark[to].AddRange(CurrentlyInScopeStacks); EmptyCurrentScope(); MarkCreatesNewVerifier = true; return VerificationResult.Successful(); }
private static LinqList<Type> GetBases(Type t) { if (TypeHelpers.IsValueType(t)) return new LinqList<Type>(); var ret = new LinqList<Type>(); t = TypeHelpers.GetBaseType(t); while (t != null) { ret.Add(t); t = TypeHelpers.GetBaseType(t); } return ret; }
public InstructionAndTransitions(OpCode? instr, int? ix, LinqList<StackTransition> trans) { Instruction = instr; Transitions = trans; InstructionIndex = ix; }
private int FindStackFailureIndex(LinqStack<LinqList<TypeOnStack>> types, IEnumerable<StackTransition> ops, out IEnumerable<TypeOnStack> expected) { var stillLegal = new LinqList<StackTransition>(ops); for (var i = 0; i < types.Count; i++) { var actuallyIs = types.ElementAt(i); var legal = stillLegal.Where(l => actuallyIs.Any(a => l.PoppedFromStack[i].IsAssignableFrom(a))).ToList(); if (legal.Count == 0) { expected = stillLegal.Select(l => l.PoppedFromStack[i]).Distinct().ToList().AsEnumerable(); return i; } stillLegal = new LinqList<StackTransition>(legal); } throw new Exception("Shouldn't be possible"); }
private LinqList<StackTransition> GetLegalTransitions(LinqList<StackTransition> ops, LinqStack<LinqList<TypeOnStack>> runningStack) { var ret = new LinqList<StackTransition>(ops.Count); for (var i = 0; i < ops.Count; i++) { var w = ops[i]; if (LinqAlternative.All(w.PoppedFromStack, u => u == TypeOnStack.Get<PopAllType>())) { ret.Add(w); continue; } var onStack = runningStack.Peek(IsBaseless, w.PoppedCount); if (onStack == null) { continue; } if (LinqAlternative.Any(w.PushedToStack, p => p == TypeOnStack.Get<SamePointerType>())) { if (w.PushedToStack.Length > 1) { throw new Exception("SamePointerType can be only product of a transition which contains it"); } var shouldBePointer = LinqAlternative.SelectMany(onStack, p => p.Where(x => x.IsPointer || x == TypeOnStack.Get<WildcardType>()).AsEnumerable()).Distinct().ToList(); if (shouldBePointer.Count == 0) continue; w = new StackTransition(w.PoppedFromStack, new [] { shouldBePointer.Single() }); } if (LinqAlternative.Any(w.PushedToStack, p => p == TypeOnStack.Get<SameByRefType>())) { if (w.PushedToStack.Length > 1) { throw new Exception("SameByRefType can be only product of a transition which contains it"); } var shouldBeByRef = LinqAlternative.SelectMany(onStack, p => p.Where(x => x.IsReference || x == TypeOnStack.Get<WildcardType>()).AsEnumerable()).Distinct().ToList(); if (shouldBeByRef.Count == 0) continue; w = new StackTransition(w.PoppedFromStack, new[] { shouldBeByRef.Single() }); } bool outerContinue = false; for (var j = 0; j < w.PoppedCount; j++) { var shouldBe = w.PoppedFromStack[j]; var actuallyIs = onStack[j]; if (!actuallyIs.Any(a => shouldBe.IsAssignableFrom(a))) { outerContinue = true; break; } } if (outerContinue) continue; ret.Add(w); } return ret; }
private static void UpdateStack(LinqStack<LinqList<TypeOnStack>> stack, InstructionAndTransitions wrapped, bool isBaseless) { var legal = wrapped.Transitions; var instr = wrapped.Instruction; var legalSize = 0; legal.Each( t => { legalSize += t.PushedToStack.Length; if (t.Before != null) t.Before(stack, isBaseless); } ); if (legal.Any(l => LinqAlternative.Any(l.PoppedFromStack, u => u == TypeOnStack.Get<PopAllType>()))) { if (instr.HasValue) { for (var i = 0; i < stack.Count; i++) { var ix = stack.Count - i - 1; stack.ElementAt(i).Each(y => y.Mark(wrapped, ix)); } } stack.Clear(); } else { var toPop = legal.First().PoppedCount; for (var j = 0; j < toPop && stack.Count > 0; j++) { var popped = stack.Pop(); if (instr.HasValue) { var ix = toPop - j - 1; popped.Each(y => y.Mark(wrapped, ix)); } } } var toPush = new LinqList<TypeOnStack>(legalSize); var pushed = new LinqHashSet<TypeOnStack>(); for(var i = 0; i < legal.Count; i++) { foreach (var p in legal[i].PushedToStack) { if (pushed.Contains(p)) continue; toPush.Add(p); pushed.Add(p); } } if (toPush.Count > 0) { stack.Push(toPush); } }
public static VerificationResult FailureTypeMismatch(Label involving, LinqList<TypeOnStack> expected, LinqList<TypeOnStack> actual) { return new VerificationResult { Success = false, IsTypeMismatch = true, ExpectedOnStack = expected, ActuallyOnStack = actual }; }
public virtual VerificationResult Transition(InstructionAndTransitions legalTransitions) { var stacks = new LinqList<LinqStack<LinqList<TypeOnStack>>>(); VerificationResult last = null; foreach (var x in CurrentlyInScope.AsEnumerable()) { var inner = x.Transition(legalTransitions); if (!inner.Success) return inner; last = inner; stacks.Add(CopyStack(inner.Stack)); } CurrentlyInScopeStacks = stacks; return last; }
private void EmptyCurrentScope() { CurrentlyInScope = new LinqList<VerifiableTracker>(); CurrentlyInScopeStacks = new LinqList<LinqStack<LinqList<TypeOnStack>>>(); }
private static LinqList<Type> GetBases(Type t) { if (t.IsValueType) return new LinqList<Type>(); var ret = new LinqList<Type>(); t = t.BaseType; while (t != null) { ret.Add(t); t = t.BaseType; } 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(); }
/// <summary> /// /// </summary> /// <returns></returns> public List<RepositoryEntity> OpenDataBase() { List<RepositoryEntity> result = new List<RepositoryEntity>(); //var appData = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //var dataPath = appData + @"\OmeSystemPlan\BluePlumGit"; //if (!Directory.Exists(dataPath)) //{ // // ディレクトリの作成 // Directory.CreateDirectory(dataPath); //} //using (var conn = new SQLiteConnection("Data Source=Configuration.db")) //{ // conn.Open(); // conn.Close(); //} var ta = new RepositorysTableAdapter(); var repositorys = ta.GetData(); foreach (RepositorysDataSet.RepositorysRow row in repositorys.Rows) { Console.WriteLine("{0}, {1}", row.name, row.path); } LinqList<RepositorysDataSet.RepositorysRow> rows = new LinqList<RepositorysDataSet.RepositorysRow>(repositorys.Rows); result = rows.Select( (row) => { RepositoryEntity ret = new RepositoryEntity { ID = row.id, Name = row.name, Path = row.path, }; return ret; } ).ToList<RepositoryEntity>(); return result; }