public void ProcessMetadataLog(ByteBuffer buffer) { var reader = new ByteBufferReader(buffer); var typeId = reader.ReadVInt32(); while (typeId != 0) { var typeCategory = (TypeCategory)reader.ReadUInt8(); ITypeDescriptor descriptor; switch (typeCategory) { case TypeCategory.BuildIn: throw new ArgumentOutOfRangeException(); case TypeCategory.Class: descriptor = new ObjectTypeDescriptor(this, reader, NestedDescriptorReader); break; case TypeCategory.List: descriptor = new ListTypeDescriptor(this, reader, NestedDescriptorReader); break; case TypeCategory.Dictionary: descriptor = new DictionaryTypeDescriptor(this, reader, NestedDescriptorReader); break; case TypeCategory.Enum: descriptor = new EnumTypeDescriptor(this, reader); break; case TypeCategory.Nullable: descriptor = new NullableTypeDescriptor(this, reader, NestedDescriptorReader); break; default: throw new ArgumentOutOfRangeException(); } while (-typeId - 1 >= _id2InfoNew.Count) { _id2InfoNew.Add(null); } if (_id2InfoNew[-typeId - 1] == null) { _id2InfoNew[-typeId - 1] = new SerializerTypeInfo { Id = typeId, Descriptor = descriptor } } ; typeId = reader.ReadVInt32(); } for (var i = 0; i < _id2InfoNew.Count; i++) { _id2InfoNew[i] !.Descriptor !.MapNestedTypes(d => d is PlaceHolderDescriptor placeHolderDescriptor ? _id2InfoNew[-placeHolderDescriptor.TypeId - 1] !.Descriptor : d); } // This additional cycle is needed to fill names of recursive structures for (var i = 0; i < _id2InfoNew.Count; i++) { _id2InfoNew[i] !.Descriptor !.MapNestedTypes(d => d); } for (var i = 0; i < _id2InfoNew.Count; i++) { var infoForType = _id2InfoNew[i] !; for (var j = ReservedBuildinTypes; j < _id2Info.Count; j++) { if (infoForType !.Descriptor !.Equals(_id2Info[j] !.Descriptor)) { _remapToOld[infoForType.Descriptor] = _id2Info[j] !.Descriptor; _id2InfoNew[i] = _id2Info[j]; infoForType = _id2InfoNew[i]; break; } } if (infoForType !.Id < 0) { infoForType.Id = (int)_id2Info.Count; _id2Info.Add(infoForType); _typeOrDescriptor2Info[infoForType.Descriptor !] = infoForType;
protected override AstNode?Before(AstNode node, bool inList) { if (node is AstBinary astBinary) { DescendBinaryOrVar(); if (astBinary.Right == Remove) { return(astBinary.Left); // TODO tree transformer which remove alone symbol refs } return(astBinary); } if (node is AstVar astVar) { DescendBinaryOrVar(); return(astVar); } if (node is AstScope) { var parent = Parent(); SymbolDef?symbolDef = null; if (parent is AstBinary) { if (parent is AstAssign astAssign && astAssign.Left is AstSymbolRef symbolRef) { symbolDef = symbolRef.Thedef !; if (symbolDef.Global && symbolDef.Orig.Where(x => x is AstSymbolDeclaration).ToList().Count == 0) { return(node); } } else { return(node); } } if (parent is AstVarDef astVarDef) { if (astVarDef.Name is AstSymbol symbol) { symbolDef = symbol.Thedef; } else { return(node); } } if (node is AstLambda astLambda && !(Parent() is AstCall call && call.Expression == node) && (inList || _isInBinaryOrVar)) { if (symbolDef == null && astLambda.Name == null) { return(node); } if (symbolDef == null) { symbolDef = astLambda.Name !.Thedef !; } var canBeRemoved = true; var shouldPreserveName = false; var definitionScope = symbolDef.Scope; foreach (var reference in symbolDef.References) { // Referenced in same scope as defined and used differently than writing if (reference.Scope == definitionScope) { if (reference.Usage != SymbolUsage.Write) { canBeRemoved = false; break; } shouldPreserveName = true; } // Used in scope which is not defined by this function if (reference.Scope != definitionScope && !astLambda.IsParentScopeFor(reference.Scope)) { canBeRemoved = false; break; } } if (canBeRemoved) { ShouldIterateAgain = true; if (shouldPreserveName && !_isInBinaryOrVar) { var varDefs = new StructList <AstVarDef>(); varDefs.Add(new AstVarDef(new AstSymbolVar(symbolDef.Name))); return(new AstVar(ref varDefs)); } return(Remove); } } Descend(); return(node); }
public void As(Type type) { _asTypes.Add(new KeyAndType(null, type)); }
public void PrintProp(string name, string?value) { _propLines.Add(new string(' ', _indent * 2 + 2) + name + ": " + System.Web.HttpUtility.JavaScriptStringEncode(value)); }
public TSProject ResolveModule(string name) { if (Result.Modules.TryGetValue(name, out var module)) { if (module.IterationId == IterationId) { return(module.Valid ? module : null); } for (uint i = 0; i < module.NegativeChecks.Count; i++) { if (CheckItemExistence(module.NegativeChecks[i])) { goto again; } } if (module.Valid) { module.LoadProjectJson(true); if (module.PackageJsonChangeId == -1) { goto again; } } module.IterationId = IterationId; return(module.Valid ? module : null); } again :; var negativeChecks = new StructList <string>(); var dir = Owner.Owner.FullPath; while (dir.Length > 0) { var dc = Owner.DiskCache.TryGetItem(dir + "/node_modules/" + name) as IDirectoryCache; if (dc == null || dc.IsInvalid) { negativeChecks.Add(dir + "/node_modules/" + name); } else { if (dc.FullPath != dir + "/node_modules/" + name) { // Create it with proper casing return(ResolveModule(dc.Name)); } module = TSProject.Create(dc, Owner.DiskCache, Owner.Logger, dc.Name); module.LoadProjectJson(true); if (module.PackageJsonChangeId != -1) { module.NegativeChecks.AddRange(negativeChecks.AsSpan()); module.IterationId = IterationId; Result.Modules[name] = module; return(module); } } dir = PathUtils.Parent(dir).ToString(); } module = TSProject.CreateInvalid(name); module.NegativeChecks.TransferFrom(ref negativeChecks); module.IterationId = IterationId; Result.Modules[name] = module; return(null); }
public static void ProcessTextExpressions(string input, StructList <TextExpression> outputList) { //input = input.Trim(); // todo -- let style handle this int ptr = 0; int level = 0; StringBuilder builder = s_Builder; builder.Clear(); TextExpression currentExpression = default; char prev = '\0'; while (ptr < input.Length) { char current = input[ptr++]; if (current == '&') { // todo -- escape probably needs to go the other way round if (Escape(input, ref ptr, out char result)) { builder.Append(result); prev = current; continue; } } // handle escaping this with \ if (current == '{' && prev != '\\') { if (level == 0) { if (builder.Length > 0) { currentExpression.text = builder.ToString(); outputList.Add(currentExpression); currentExpression = default; builder.Clear(); } currentExpression.isExpression = true; level++; prev = current; continue; } level++; } // handle escaping this with \ if (current == '}' && prev != '\\') { level--; if (level == 0) { if (builder.Length > 0) { currentExpression.text = builder.ToString(); outputList.Add(currentExpression); currentExpression.isExpression = default; builder.Clear(); } prev = current; continue; } } // remove last character if escaping a brace if ((current == '}' || current == '{') && prev == '\\') { builder.Length--; } builder.Append(current); prev = current; } if (level != 0) { throw new Exception($"Error processing {input} into expressions. Too many unmatched braces"); } if (builder.Length > 0) { currentExpression.text = builder.ToString(); outputList.Add(currentExpression); } builder.Clear(); }
public void PushNode(AstNode node) { _stack.Add(node); }
internal int AddInstance(object instance) { _instances.Add(instance); return((int)_instances.Count - 1); }
public void AddSlotOverride(string slotName, UIElement context, int slotId) { slotInputs = slotInputs ?? StructList <SlotUsage> .Get(); slotInputs.Add(new SlotUsage(slotName, slotId, context)); }
public static IEnumerable <GridPoint2> GenerateMazeWalls <TCell>(IGrid <GridPoint2, TCell> grid) { var walls = grid.CloneStructure <bool>(); //true indicates passable foreach (var point in walls.Points) { walls[point] = point.GetColor(2, 2, 2) == 0; //Debug.Log(point); } var wallPoints = walls .Where(pair => pair.cell) .Select(pair => pair.point); foreach (var point in wallPoints) { yield return(point); } var wallList = new StructList <GridPoint2>(); var newMaizePoint = grid.Points.Where(p => p.GetColor(2, 2, 2) == 3).RandomItem(); var inMaze = new StructList <GridPoint2> { newMaizePoint }; var edges = newMaizePoint .GetVectorNeighbors(RectPoint.OrthogonalDirections) .In(grid); wallList.AddRange(edges); while (wallList.Any()) { var randomWall = wallList.RandomItem(); var faces = GetEdgeFaces(randomWall).Where(grid.Contains); //At least one of the two faces must be in the maze if (faces.Any(point => !inMaze.Contains(point))) { newMaizePoint = faces.First(point => !inMaze.Contains(point)); inMaze.Add(newMaizePoint); walls[randomWall] = true; yield return(randomWall); // Add all edges that are not passages edges = newMaizePoint .GetVectorNeighbors(RectPoint.OrthogonalDirections) .In(grid) .Where(edge => !(walls[edge])); wallList.AddRange(edges); } else { wallList.Remove(randomWall); } } }