-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Annotated SyntaxList #40729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotated SyntaxList #40729
Changes from all commits
17a2845
06b439d
e314c74
1c960cb
5df75e6
537c00b
8e507a5
8a6d920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,20 @@ | ||
| // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Syntax | ||
| { | ||
| internal class SyntaxListBuilder | ||
| { | ||
| private ArrayElement<GreenNode>[] _nodes; | ||
| private ArrayElement<GreenNode?>[] _nodes; | ||
| public int Count { get; private set; } | ||
|
|
||
| public SyntaxListBuilder(int size) | ||
| { | ||
| _nodes = new ArrayElement<GreenNode>[size]; | ||
| _nodes = new ArrayElement<GreenNode?>[size]; | ||
| } | ||
|
|
||
| public void Clear() | ||
|
|
@@ -32,7 +34,7 @@ internal void AddInternal(GreenNode item) | |
| throw new ArgumentNullException(); | ||
| } | ||
|
|
||
| if (_nodes == null || Count >= _nodes.Length) | ||
| if (Count >= _nodes.Length) | ||
| { | ||
| this.Grow(Count == 0 ? 8 : _nodes.Length * 2); | ||
| } | ||
|
|
@@ -47,7 +49,7 @@ public void AddRange(SyntaxNode[] items) | |
|
|
||
| public void AddRange(SyntaxNode[] items, int offset, int length) | ||
| { | ||
| if (_nodes == null || Count + length > _nodes.Length) | ||
| if (Count + length > _nodes.Length) | ||
| { | ||
| this.Grow(Count + length); | ||
| } | ||
|
|
@@ -81,15 +83,15 @@ public void AddRange(SyntaxList<SyntaxNode> list) | |
|
|
||
| public void AddRange(SyntaxList<SyntaxNode> list, int offset, int count) | ||
| { | ||
| if (_nodes == null || this.Count + count > _nodes.Length) | ||
| if (this.Count + count > _nodes.Length) | ||
| { | ||
| this.Grow(Count + count); | ||
| } | ||
|
|
||
| var dst = this.Count; | ||
| for (int i = offset, limit = offset + count; i < limit; i++) | ||
| { | ||
| _nodes[dst].Value = list.ItemInternal(i).Green; | ||
| _nodes[dst].Value = list.ItemInternal(i)!.Green; | ||
|
||
| dst++; | ||
| } | ||
|
|
||
|
|
@@ -115,7 +117,7 @@ public void AddRange(SyntaxNodeOrTokenList list) | |
|
|
||
| public void AddRange(SyntaxNodeOrTokenList list, int offset, int count) | ||
| { | ||
| if (_nodes == null || this.Count + count > _nodes.Length) | ||
| if (this.Count + count > _nodes.Length) | ||
| { | ||
| this.Grow(Count + count); | ||
| } | ||
|
|
@@ -144,7 +146,7 @@ public void AddRange(SyntaxTokenList list, int offset, int length) | |
|
|
||
| private void Grow(int size) | ||
| { | ||
| var tmp = new ArrayElement<GreenNode>[size]; | ||
| var tmp = new ArrayElement<GreenNode?>[size]; | ||
| Array.Copy(_nodes, tmp, _nodes.Length); | ||
| _nodes = tmp; | ||
| } | ||
|
|
@@ -153,7 +155,7 @@ public bool Any(int kind) | |
| { | ||
| for (int i = 0; i < Count; i++) | ||
| { | ||
| if (_nodes[i].Value.RawKind == kind) | ||
| if (_nodes[i].Value!.RawKind == kind) | ||
|
||
| { | ||
| return true; | ||
| } | ||
|
|
@@ -162,7 +164,7 @@ public bool Any(int kind) | |
| return false; | ||
| } | ||
|
|
||
| internal GreenNode ToListNode() | ||
| internal GreenNode? ToListNode() | ||
| { | ||
| switch (this.Count) | ||
| { | ||
|
|
@@ -175,7 +177,7 @@ internal GreenNode ToListNode() | |
| case 3: | ||
| return InternalSyntax.SyntaxList.List(_nodes[0].Value, _nodes[1].Value, _nodes[2].Value); | ||
| default: | ||
| var tmp = new ArrayElement<GreenNode>[this.Count]; | ||
| var tmp = new ArrayElement<GreenNode?>[this.Count]; | ||
| for (int i = 0; i < this.Count; i++) | ||
| { | ||
| tmp[i].Value = _nodes[i].Value; | ||
|
|
@@ -198,7 +200,7 @@ public static implicit operator SyntaxList<SyntaxNode>(SyntaxListBuilder builder | |
| internal void RemoveLast() | ||
| { | ||
| this.Count -= 1; | ||
| this._nodes[Count] = default(ArrayElement<GreenNode>); | ||
| this._nodes[Count] = default; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.