public SyntaxList <TNode> VisitList <TNode>(SyntaxList <TNode> list) where TNode : LuaSyntaxNode { SyntaxListBuilder?alternate = null; for (int i = 0, n = list.Count; i < n; i++) { var item = list[i]; var visited = Visit(item); if (item != visited && alternate == null) { alternate = new SyntaxListBuilder(n); alternate.AddRange(list, 0, i); } if (alternate != null) { LorettaDebug.Assert(visited != null && visited.Kind != SyntaxKind.None, "Cannot remove node using Syntax.InternalSyntax.SyntaxRewriter."); alternate.Add(visited); } } if (alternate != null) { return(alternate.ToList()); } return(list); }
private static bool AreTokensEquivalent(GreenNode?before, GreenNode?after) { if (before is null || after is null) { return(before is null && after is null); } // NOTE(cyrusn): Do we want to drill into trivia? Can documentation ever affect the // global meaning of symbols? This can happen in java with things like the "@obsolete" // clause in doc comment. However, i don't know if anything like that exists in C#. // NOTE(cyrusn): I don't believe we need to examine skipped text. It isn't relevant from // the perspective of global symbolic information. LorettaDebug.Assert(before.RawKind == after.RawKind); if (before.IsMissing != after.IsMissing) { return(false); } // These are the tokens that don't have fixed text. return((SyntaxKind)before.RawKind switch { SyntaxKind.IdentifierToken => ((Green.SyntaxToken)before).ValueText != ((Green.SyntaxToken)after).ValueText, SyntaxKind.NumericLiteralToken or SyntaxKind.StringLiteralToken => ((Green.SyntaxToken)before).Text != ((Green.SyntaxToken)after).Text, _ => true, });
public ConstantValueString(string value) { // we should have just one Null regardless string or object. LorettaDebug.Assert(value != null, "null strings should be represented as Null constant."); _value = Rope.ForString(value); _constantValueReference = new WeakReference <string>(value); }
public static PooledHashSet <T> GetInstance() { var instance = s_poolInstance.Allocate(); LorettaDebug.Assert(instance.Count == 0); return(instance); }
internal static void AssertMessageSerializable(object[] args) { foreach (var arg in args) { LorettaDebug.Assert(arg != null); if (arg is IFormattable) { continue; } var type = arg.GetType(); if (type == typeof(string)) { continue; } var info = type.GetTypeInfo(); if (info.IsPrimitive) { continue; } throw ExceptionUtilities.UnexpectedValue(type); } }
private BlendedNode ReadNewToken() { LorettaDebug.Assert(_changeDelta > 0 || _oldTreeCursor.IsFinished); // The new text is either behind the cursor, or the cursor is done. In either event, // we need to lex a real token from the stream. var token = LexNewToken(); // If the oldTreeCursor was finished, then the below code isn't really necessary. // We'll just repeat the outer reader loop and call right back into ReadNewToken. // That will then call LexNewToken (which doesn't use either of these variables). If // oldTreeCursor wasn't finished then we need to update our state based on the token // we just read. var width = token.FullWidth; _newPosition += width; _changeDelta -= width; // By reading a token we may either have read into, or past, change ranges. Skip // past them. This will increase changeDelta which will indicate to us that we need // to keep on lexing. SkipPastChanges(); return(CreateBlendedNode(node: null, token: token)); }
internal SyntaxDiagnosticInfo(int offset, int width, ErrorCode code, params object[] args) : base(Lua.MessageProvider.Instance, (int)code, args) { LorettaDebug.Assert(width >= 0); Offset = offset; Width = width; }
public static PooledDictionary <K, V> GetInstance() { var instance = s_poolInstance.Allocate(); LorettaDebug.Assert(instance.Count == 0); return(instance); }
public TNode? this[int index] { get { if (_node == null) { return(null); } else if (_node.IsList) { LorettaDebug.Assert(index >= 0); LorettaDebug.Assert(index <= _node.SlotCount); return((TNode?)_node.GetSlot(index)); } else if (index == 0) { return((TNode?)_node); } else { throw ExceptionUtilities.Unreachable; } } }
internal TNode GetRequiredItem(int index) { var node = this[index]; LorettaDebug.Assert(node is object); return(node); }
private void DoDumpCompact(TreeDumperNode node, string indent) { LorettaDebug.Assert(node != null); LorettaDebug.Assert(indent != null); // Precondition: indentation and prefix has already been output // Precondition: indent is correct for node's *children* _sb.Append(node.Text); if (node.Value != null) { _sb.AppendFormat(": {0}", DumperString(node.Value)); } _sb.AppendLine(); var children = node.Children.ToList(); for (int i = 0; i < children.Count; ++i) { var child = children[i]; if (child == null) { continue; } _sb.Append(indent); _sb.Append(i == children.Count - 1 ? '\u2514' : '\u251C'); _sb.Append('\u2500'); // First precondition met; now work out the string needed to indent // the child node's children: DoDumpCompact(child, indent + (i == children.Count - 1 ? " " : "\u2502 ")); } }
private IScopeInternal PopScope(IScopeInternal scope) { var poppedScope = _scopeStack.Pop(); LorettaDebug.Assert(poppedScope == scope); return(poppedScope); }
private static void IntroSort(SegmentedArraySegment <T> keys, int depthLimit, Comparison <T> comparer) { LorettaDebug.Assert(keys.Length > 0); LorettaDebug.Assert(depthLimit >= 0); LorettaDebug.Assert(comparer != null); int partitionSize = keys.Length; while (partitionSize > 1) { if (partitionSize <= SegmentedArrayHelper.IntrosortSizeThreshold) { if (partitionSize == 2) { SwapIfGreater(keys, comparer, 0, 1); return; } if (partitionSize == 3) { SwapIfGreater(keys, comparer, 0, 1); SwapIfGreater(keys, comparer, 0, 2); SwapIfGreater(keys, comparer, 1, 2); return; } InsertionSort(keys[..partitionSize], comparer);
internal static int InternalBinarySearch(SegmentedArray <T> array, int index, int length, T value, IComparer <T> comparer) { LorettaDebug.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!"); int lo = index; int hi = index + length - 1; while (lo <= hi) { int i = lo + ((hi - lo) >> 1); int order = comparer.Compare(array[i], value); if (order == 0) { return(i); } if (order < 0) { lo = i + 1; } else { hi = i - 1; } } return(~lo); }
internal DiagnosticWithInfo(DiagnosticInfo info, Location location, bool isSuppressed = false) { LorettaDebug.Assert(info != null); LorettaDebug.Assert(location != null); _info = info; _location = location; _isSuppressed = isSuppressed; }
public StringBuilderText(StringBuilder builder, Encoding?encodingOpt, SourceHashAlgorithm checksumAlgorithm) : base(checksumAlgorithm: checksumAlgorithm) { LorettaDebug.Assert(builder != null); _builder = builder; _encodingOpt = encodingOpt; }
internal SyntaxNodeOrToken(SyntaxNode node) : this() { LorettaDebug.Assert(!node.Green.IsList, "node cannot be a list"); _position = node.Position; _nodeOrParent = node; _tokenIndex = -1; }
public GotoLabel(string name, GotoLabelStatementSyntax?label) { LorettaDebug.Assert(!string.IsNullOrEmpty(name)); Name = name; LabelSyntax = label; JumpSyntaxes = SpecializedCollections.ReadOnlyEnumerable(_jumps); }
public GotoLabelWalker( IDictionary <SyntaxNode, IScope> scopes, IDictionary <SyntaxNode, IGotoLabel> labels) : base(scopes) { LorettaDebug.AssertNotNull(labels); _labels = labels; }
internal NodeIteration this[int index] { get { LorettaDebug.Assert(_stack != null); LorettaDebug.Assert(index >= 0 && index < _count); return(_stack[index]); } }
internal static void IntrospectiveSort(SegmentedArraySegment <T> keys, Comparison <T> comparer) { LorettaDebug.Assert(comparer != null); if (keys.Length > 1) { IntroSort(keys, 2 * (SegmentedArraySortUtils.Log2((uint)keys.Length) + 1), comparer); } }
private static void SwapIfGreater(SegmentedArraySegment <T> keys, Comparison <T> comparer, int i, int j) { LorettaDebug.Assert(i != j); if (comparer(keys[i], keys[j]) > 0) { (keys[j], keys[i]) = (keys[i], keys[j]); } }
internal SyntaxToken(SyntaxNode?parent, GreenNode?token, int position, int index) { LorettaDebug.Assert(parent == null || !parent.Green.IsList, "list cannot be a parent"); LorettaDebug.Assert(token == null || token.IsToken, "token must be a token"); Parent = parent; Node = token; Position = position; Index = index; }
protected BaseWalker( IDictionary <SyntaxNode, IScope> scopes, SyntaxWalkerDepth depth = SyntaxWalkerDepth.Node) : base(depth) { LorettaDebug.AssertNotNull(scopes); _scopes = scopes; }
/// <summary> /// Creates an <see cref="InvalidOperationException"/> with information about an unexpected value. /// </summary> /// <param name="o">The unexpected value.</param> /// <returns>The <see cref="InvalidOperationException"/>, which should be thrown by the caller.</returns> internal static Exception UnexpectedValue(object?o) { string output = string.Format("Unexpected value '{0}' of type '{1}'", o, (o != null) ? o.GetType().FullName : "<unknown>"); LorettaDebug.Assert(false, output); // We do not throw from here because we don't want all Watson reports to be bucketed to this call. return(new InvalidOperationException(output)); }
private static SyntaxTree ComputeSyntaxTree(LuaSyntaxNode node) { ArrayBuilder <LuaSyntaxNode>?nodes = null; SyntaxTree?tree; // Find the nearest parent with a non-null syntax tree while (true) { tree = node._syntaxTree; if (tree != null) { break; } var parent = node.Parent; if (parent == null) { // set the tree on the root node atomically Interlocked.CompareExchange(ref node._syntaxTree, LuaSyntaxTree.CreateWithoutClone(node), null); tree = node._syntaxTree; break; } tree = parent._syntaxTree; if (tree != null) { node._syntaxTree = tree; break; } (nodes ??= ArrayBuilder <LuaSyntaxNode> .GetInstance()).Add(node); node = parent; } // Propagate the syntax tree downwards if necessary if (nodes != null) { LorettaDebug.Assert(tree != null); foreach (var n in nodes) { var existingTree = n._syntaxTree; if (existingTree != null) { LorettaDebug.Assert(existingTree == tree, "how could this node belong to a different tree?"); // yield the race break; } n._syntaxTree = tree; } nodes.Free(); } return(tree !); }
internal SyntaxNode?ItemInternal(int index) { if (_node?.IsList == true) { return(_node.GetNodeSlot(index)); } LorettaDebug.Assert(index == 0); return(_node); }
// Only the compiler creates instances. internal DiagnosticInfo(CommonMessageProvider messageProvider, bool isWarningAsError, int errorCode, params object[] arguments) : this(messageProvider, errorCode, arguments) { LorettaDebug.Assert(!isWarningAsError || _defaultSeverity == DiagnosticSeverity.Warning); if (isWarningAsError) { _effectiveSeverity = DiagnosticSeverity.Error; } }
/// <summary> /// Initializes a new instance of the <see cref="SyntaxNodeOrTokenList"/> structure. /// </summary> /// <param name="node">The underlying syntax node.</param> /// <param name="index">The index.</param> internal SyntaxNodeOrTokenList(SyntaxNode?node, int index) : this() { LorettaDebug.Assert(node != null || index == 0); if (node != null) { _node = node; this.index = index; } }
internal SyntaxTokenList(SyntaxNode?parent, GreenNode?tokenOrList, int position, int index) { LorettaDebug.Assert(tokenOrList != null || (position == 0 && index == 0 && parent == null)); LorettaDebug.Assert(position >= 0); LorettaDebug.Assert(tokenOrList == null || tokenOrList.IsToken || tokenOrList.IsList); _parent = parent; Node = tokenOrList; Position = position; _index = index; }