/// <summary> /// Flattens the hierarchy for a class. /// </summary> /// <param name="baseType">Type of the base.</param> /// <param name="currentType">Type of the current.</param> private void FlattenHierarchy(NType baseType, NType currentType) { // Sort the descendants in alphabetical order currentType.Descendants.Sort(CompareByDisplayName); // Iterate on all descendants foreach (var descendantRef in currentType.Descendants) { var descendant = Registry.FindById(descendantRef.Id) as NType; if (descendant != null) { int level = 0; int index = 0; for (int i = 0; i < baseType.FlattenedHierarchy.Count; i++) { var flattenItem = baseType.FlattenedHierarchy[i]; if (flattenItem.Item2.Id == descendant.Bases[0].Id) { level = flattenItem.Item1; index = i; break; } } // Insert the descendant at the right position in the flattened view baseType.FlattenedHierarchy.Insert(index + 1, new Tuple <int, INMemberReference>(level + 1, descendant)); // Flatten the hierarchy for the descendant // note: recursive call here! FlattenHierarchy(baseType, descendant); } } }
/// <summary> /// Adds the property. /// </summary> /// <param name="parent">The parent.</param> /// <param name="propertyDef">The property def.</param> private void AddProperty(NType parent, PropertyDefinition propertyDef) { var propertyId = DocIdHelper.GetXmlId(propertyDef); var property = (NProperty)_registry.FindById(propertyId); if (property == null) { property = NewInstance <NProperty>(parent.Namespace, propertyDef); _registry.Register(property); property.Namespace = parent.Namespace; property.MemberType = NMemberType.Property; property.PropertyType = GetTypeReference(propertyDef.PropertyType); property.GetMethod = AddMethod(property, propertyDef.GetMethod, true); property.SetMethod = AddMethod(property, propertyDef.SetMethod, true); parent.AddMember(property); parent.HasProperties = true; // Setup visibility based on method var refMethod = property.GetMethod ?? property.SetMethod; property.Visibility = refMethod.Visibility; property.IsStatic = refMethod.IsStatic; property.IsFinal = refMethod.IsFinal; property.IsAbstract = refMethod.IsAbstract; property.SeeAlsos.Add(new NSeeAlso(parent)); property.SeeAlsos.Add(new NSeeAlso(parent.Namespace)); UpdatePageTitle(property); } property.SetApiGroup(CurrentMergeGroup, true); }
/// <summary> /// Adds the event. /// </summary> /// <param name="parent">The parent.</param> /// <param name="eventDef">The event def.</param> private void AddEvent(NType parent, EventDefinition eventDef) { var eventId = DocIdHelper.GetXmlId(eventDef); var @event = (NEvent)_registry.FindById(eventId); if (@event == null) { @event = NewInstance <NEvent>(parent.Namespace, eventDef); _registry.Register(@event); @event.MemberType = NMemberType.Event; @event.EventType = this.GetTypeReference(eventDef.EventType); parent.AddMember(@event); parent.HasEvents = true; var addMethod = AddMethod(@event, eventDef.AddMethod, true); var removeMethod = AddMethod(@event, eventDef.RemoveMethod, true); // Setup visibility based on event add/remove methods var refMethod = addMethod ?? removeMethod; @event.Visibility = refMethod.Visibility; @event.IsStatic = refMethod.IsStatic; @event.IsFinal = refMethod.IsFinal; @event.IsAbstract = refMethod.IsAbstract; // Add SeeAlso @event.SeeAlsos.Add(new NSeeAlso(parent)); @event.SeeAlsos.Add(new NSeeAlso(parent.Namespace)); UpdatePageTitle(@event); } @event.SetApiGroup(CurrentMergeGroup, true); }
public CellState(int totalStates, int neighborState, StatePageInfo info) { this.gridType = info.gridType.Value; advProbs = new double[totalStates, totalStates][, ]; prob = new double[totalStates, neighborState, info.neighbors.Value + 1]; double[][][] probs = info.probs.Select(x => x.Select(y => y.ToArray()).ToArray()).ToArray(); for (int i = 0; i < probs.Length; i++) { for (int j = 0; j < probs[i].Length; j++) { for (int k = 0; k < probs[i][j].Length; k++) { prob[i, j, k] = probs[i][j][k]; } } } containerSettings = info.containerSettings; stickingProbs = new double[totalStates]; walkProbs = info.moveProbs.ToArray(); stickingProbs = info.stickingProbs.ToArray(); sticking = info.sticking.Value; mobileNeighborhood = info.mobileNeighborhood.Value; mobile = info.mobile.Value; startingLocations = new List <Tuple <int, int> >(); startingLocations = info.startingLocations; this.neighborhoodType = info.nType; }
public void ApplyCompound(Mapping m) { if (type == NType.Algebra) { foreach (var item in m.Data) { if (item.point == data) { if (item.IsValue) { data = item.value.ToString(); type = NType.Number; } else { data = item.Expression.Root.data; Left = item.Expression.Root.Left; Right = item.Expression.Root.Right; type = item.Expression.Root.type; } break; } } } if (Left != null) { Left.ApplyCompound(m); } if (Right != null) { Right.ApplyCompound(m); } }
public List <TileNode> FindNodesByType(NType type) { List <TileNode> nodes = new List <TileNode>(); if (Application.isPlaying) { for (int i = 0; i < size.x; i++) { for (int j = 0; j < size.y; j++) { if (m[i, j].type == type) { nodes.Add(m[i, j]); } } } } else { TileNode[] allNodes = GetComponentsInChildren <TileNode>(true); for (int i = 0; i < allNodes.Length; i++) { if (allNodes[i].type == type) { nodes.Add(allNodes[i]); } } } return(nodes); }
/// <summary> /// Adds the field. /// </summary> /// <param name="parent">The parent.</param> /// <param name="fieldDef">The field def.</param> private void AddField(NType parent, FieldDefinition fieldDef) { if (fieldDef.IsSpecialName) { return; } var fieldId = DocIdHelper.GetXmlId(fieldDef); var field = (NField)_registry.FindById(fieldId); if (field == null) { field = NewInstance <NField>(parent.Namespace, fieldDef); _registry.Register(field); field.MemberType = NMemberType.Field; field.FieldType = GetTypeReference(fieldDef.FieldType); // Setup visibility field.IsStatic = fieldDef.IsStatic; if (fieldDef.IsPublic) { field.Visibility = NVisibility.Public; } else if (fieldDef.IsPrivate) { field.Visibility = NVisibility.Private; } else if (fieldDef.IsAssembly) { field.Visibility = NVisibility.Internal; } else if (fieldDef.IsFamily) { field.Visibility = NVisibility.Protected; } else if (fieldDef.IsFamilyOrAssembly) { field.Visibility = NVisibility.ProtectedInternal; } if (fieldDef.Constant != null) { field.ConstantValue = GetTextFromValue(fieldDef.Constant); } parent.AddMember(field); parent.HasFields = true; field.SeeAlsos.Add(new NSeeAlso(parent)); field.SeeAlsos.Add(new NSeeAlso(parent.Namespace)); UpdatePageTitle(field); } field.SetApiGroup(CurrentMergeGroup, true); }
public void Precache() { DynamicMethod method = new DynamicMethod("Db" + Guid.NewGuid().ToString(), typeof(CallModel), new Type[0]); ILGenerator il = method.GetILGenerator(); ConstructorInfo ctor = typeof(CallModel).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[0], null); il.Emit(OpCodes.Newobj, ctor); il.Emit(OpCodes.Ret); EmitFunc = (Func <CallModel>)(method.CreateDelegate(typeof(Func <CallModel>))); NatashaFunc = NType.Creator <CallModel>(); }
private NodeTag(NodeTag parent, Guid dbNodeId , string dbNodeName, string dbNodeDescription , int dbType, bool hasChild , Guid thumGuid, string thumbExt) { _dbParent = parent; _dbNodeId = dbNodeId; _dbNodeName = dbNodeName; _dbNodeDescription = dbNodeDescription; _dbType = (NType)dbType; _dbHasChild = hasChild; _dbThumbFile = new FileTag(thumGuid, thumbExt); }
public void ApplyMap(Mapping m) { if (type == NType.Algebra) { bool match = false; foreach (var item in m.Data) { if (item.point == data) { if (item.IsValue) { data = item.value.ToString(); type = NType.Number; } else { data = item.Expression.Root.data; Left = item.Expression.Root.Left; Right = item.Expression.Root.Right; type = item.Expression.Root.type; } match = true; break; } } if (!match && data != "n") { throw new Exception("Not Properly Mapped"); } } if (!((type == NType.DOperator) && (m.Data.Count == 1 && m.Data[0].point == "n"))) { if (Left != null) { Left.ApplyMap(m); } if (Right != null) { Right.ApplyMap(m); } } else { if (Right != null) { Right.ApplyMap(m); } } }
public static Variable NizkCombineFunctionResult(StatementResult result, NType resultNType) { switch (result) { case StatementResultOneCase ret: switch (ret.ExecutionResultType) { case StatementResultType.Continue: case StatementResultType.Break: throw new Exception($"Unexpected \"{ ret.ExecutionResultType.ToString()}\" statement."); case StatementResultType.Normal: case StatementResultType.Return: Debug.Assert((ret.ExecutionResultType != StatementResultType.Normal) || ret.ReturnVariable == null); if (ret.ReturnVariable != null) { return(ret.ReturnVariable.Assign(resultNType)); } if (resultNType == NType.Void) { return(NType.Void.GetEmptyVariable()); } else { throw new Exception("Missing \"return\" statement."); } default: throw CommonException.AssertFailedException(); } case StatementResultTwoCase ret: if (resultNType == NType.Void) { return(NType.Void.GetEmptyVariable()); } var trueVar = NizkCombineFunctionResult(ret.TrueCase, resultNType); var falseVar = NizkCombineFunctionResult(ret.FalseCase, resultNType); return(NizkConditionVariable(ret.Condition, trueVar, falseVar)); default: throw CommonException.AssertFailedException(); } }
public static void WriteLog(NType LogType, string msg, Exception ex = null) { switch (LogType) { case NType.Info: logger.Info(msg); break; case NType.Error: logger.Error(ex, msg); break; case NType.Debug: logger.Debug(ex, msg); break; } }
static void Main(string[] args) { Console.WriteLine("Roslyn 预热;"); var a = NType.Creator <Program>(); Console.WriteLine("3秒后开始编译;"); Thread.Sleep(3000); Test(); Console.WriteLine("请记录内存,5秒后开始释放;"); Thread.Sleep(5000); Release(); Console.WriteLine("请记录内存,5秒后开始回收;"); Thread.Sleep(5000); RunGc(); Console.WriteLine("存活检测,3秒后开始;"); Thread.Sleep(3000); CheckAlive(); Console.WriteLine("程序跑完!"); Console.ReadKey(); }
private void neighborBox_SelectedIndexChanged(object sender, EventArgs e) { switch (neighborBox.SelectedIndex) { case 0: neighbors = 0; nType = NType.None; break; case 1: neighbors = 4; nType = NType.VonNeumann; break; case 2: neighbors = 8; nType = NType.Moore; break; case 3: neighbors = 12; nType = NType.Hybrid; break; case 4: neighbors = -1; nType = NType.Advanced; break; default: neighbors = 0; nType = NType.None; break; } RefreshNeighborFields(); }
public Variable InternalConvert(NType leftType) { return(this.Type.InternalConvert(this, leftType)); }
public PinocchioTypeWires(NType type, PinocchioWire singleWire) { this.Type = type; this.Wires.Add(singleWire); }
public PinocchioTypeWires(PinocchioVariableWires variableWires) { this.Type = variableWires.RawVariable.Type; variableWires.Wires.ForEach(this.Wires.Add); }
public Neighborhood(NType type) { neighborType = type; }
void SetSettings() { nType = parent.nType; if (parent.gridType.HasValue) { gType = parent.gridType.Value; } if (parent.probs != null) { probs = parent.probs; } if (parent.moveProbs != null) { moveProbs = parent.moveProbs; } if (parent.stickingProbs != null) { stickingProbs = parent.stickingProbs; } if (parent.sticking.HasValue) { sticking = parent.sticking.Value; } if (parent.mobile.HasValue) { mobile = parent.mobile.Value; } if (parent.storage.HasValue) { storage = parent.storage.Value; } //if (parent.ai.HasValue) //{ // ai = parent.ai.Value; //} if (parent.growth.HasValue) { growth = parent.growth.Value; } if (parent.mobileNeighborhood.HasValue) { mobileN = parent.mobileNeighborhood.Value; } if (parent.startingLocations != null) { startingLocations = parent.startingLocations; } if (parent.storageObjects != null) { storageObjects = parent.storageObjects; } if (parent.neighbors.HasValue) { neighbors = parent.neighbors.Value; } if (parent.color.HasValue) { color = parent.color.Value; } if (parent.startingAmount.HasValue) { startingAmount = parent.startingAmount.Value; } }
private NClass ProcessInheritance(NType type) { NClass baseModel = null; if (type.Bases.Count > 0) { var directParent = type.Bases[0]; baseModel = (NClass)this.FindType(directParent.Id); } if (type.AllMembers.Count > 0) { return(baseModel); } type.AllMembers.AddRange(type.Members); if (baseModel != null) { this.ProcessInheritance(baseModel); var newMembers = new List <INMemberReference>(); foreach (var nMemberReference in baseModel.AllMembers) { // Don't add constructor as inherited member if (nMemberReference is NConstructor) { continue; } bool addInheritedMember = true; foreach (var currentMember in type.AllMembers) { var method = currentMember as NMethod; // Don't add method that are overriden if (method != null && method.Overrides != null && nMemberReference is NMethod) { if (method.Overrides.Id == nMemberReference.Id) { addInheritedMember = false; break; } } } if (addInheritedMember) { if (nMemberReference is NMethod) { type.HasMethods = true; } else if (nMemberReference is NProperty) { type.HasProperties = true; } else if (nMemberReference is NEvent) { type.HasEvents = true; } newMembers.Add(nMemberReference); } } type.AllMembers.AddRange(newMembers); } // Order elements type.AllMembers.Sort((from, to) => string.CompareOrdinal(@from.Name, to.Name)); // Recalculate a PageId based on the number of overriding methods. var counters = new Dictionary <string, int>(); var overrides = new Dictionary <string, int>(); foreach (var member in type.AllMembers.OfType <NMethod>()) { string id = PageIdFunction(member); // Count overrides if (!overrides.ContainsKey(member.Name)) { overrides.Add(member.Name, 0); } else { overrides[member.Name]++; } // Change only Id that are overlapping if (!counters.ContainsKey(id)) { counters.Add(id, 0); } else { counters[id]++; id = id + "_" + counters[id]; } member.PageId = id; } // Tag methods that are overriden foreach (var method in type.AllMembers.OfType <NMethod>()) { if (overrides.ContainsKey(method.Name) && overrides[method.Name] > 0) { method.HasOverrides = true; } } foreach (var nsubClass in type.Members.OfType <NType>()) { ProcessInheritance(nsubClass); } return(baseModel); }
public Variable ExplicitConvert(NType leftType) { return(this.Type.ExplicitConvert(this, leftType)); }
public void InfixNode() { List <NType> Complexity = new List <NType>(); int pos = 0; string temp = ""; int minLevel = 5; while (pos != data.Length) { NType t = Converter.SearchforPossibility(data, pos, out pos, out temp); Complexity.Add(t); if (t == NType.Operator) { if (temp == "+" || temp == "-") { minLevel = 0; } if ((temp == "*" || temp == "/")) { minLevel = minLevel > 1 ? 1 : minLevel; } if ((temp == "^")) { minLevel = minLevel > 2 ? 2 : minLevel; } } } if (Complexity.Count == 1) { if (Complexity[0] == NType.Number || Complexity[0] == NType.Algebra) { data = temp; type = Complexity[0]; } else if (Complexity[0] == NType.Bracket) { data = data.Snip(1, data.Length - 2); this.InfixNode(); } else { bool DOP = false; string t = RemoveUOperator(data, out data); int cutter = 0; int bracketCount = 0; for (int p = 0; p < t.Length; p++) { if (t[p] == '(') { bracketCount++; } if (t[p] == ')') { bracketCount--; } if (t[p] == ',' && bracketCount == 0) { cutter = p; DOP = true; break; } } if (DOP) { type = NType.DOperator; Left = new Node() { data = t.Snip(0, cutter - 1), type = NType.None }; Left.InfixNode(); Right = new Node() { data = t.Snip(cutter + 1, t.Length - 1), type = NType.None }; Right.InfixNode(); } else { type = NType.UOperator; Left = new Node() { data = t, type = NType.None }; Left.InfixNode(); } } } else { int bracketCount = 0; bool done = false; for (int npos = data.Length - 1; npos >= 0; npos--) { if (done) { break; } if (data[npos] == '(') { bracketCount++; } if (data[npos] == ')') { bracketCount--; } if (bracketCount == 0 && Operators.Contains(data[npos])) { switch (data[npos]) { case '+': case '-': Left = new Node() { type = NType.None, data = data.Snip(0, npos - 1) }; Right = new Node() { type = NType.None, data = data.Snip(npos + 1, data.Length - 1) }; Left.InfixNode(); Right.InfixNode(); data = data[npos].ToString(); type = NType.Operator; done = true; break; case '/': case '*': if (minLevel == 1) { Left = new Node() { type = NType.None, data = data.Snip(0, npos - 1) }; Right = new Node() { type = NType.None, data = data.Snip(npos + 1, data.Length - 1) }; Left.InfixNode(); Right.InfixNode(); data = data[npos].ToString(); type = NType.Operator; done = true; } break; case '^': if (minLevel == 2) { Left = new Node() { type = NType.None, data = data.Snip(0, npos - 1) }; Right = new Node() { type = NType.None, data = data.Snip(npos + 1, data.Length - 1) }; Left.InfixNode(); Right.InfixNode(); data = data[npos].ToString(); type = NType.Operator; done = true; } break; } } } } if (type == NType.None) { throw new Exception("Invalid Input"); } }
public Variable Assign(NType leftType) { return(this.Type.Assign(this, leftType)); }