/
ParseNodeList.cs
119 lines (95 loc) · 2.79 KB
/
ParseNodeList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// ParseNodeList.cs
// Script#/Core/Compiler
// This source code is subject to terms and conditions of the Apache License, Version 2.0.
//
using System;
using System.Collections;
using System.Diagnostics;
namespace ScriptSharp.CodeModel {
internal sealed class ParseNodeList : IEnumerable {
private ArrayList _list;
public ParseNodeList() {
}
public ParseNodeList(ParseNode node) {
Append(node);
}
public int Count {
get {
if (_list == null) {
return 0;
}
else {
return _list.Count;
}
}
}
public ParseNode this[int index] {
get {
return (ParseNode)_list[index];
}
}
public void Append(ParseNode node) {
if (node != null) {
EnsureListCreated();
_list.Add(node);
}
}
public void Append(ParseNodeList nodes) {
EnsureListCreated();
_list.AddRange(nodes._list);
}
private void EnsureListCreated() {
if (_list == null) {
_list = new ArrayList();
}
}
public ParseNodeEnumerator GetEnumerator() {
return new ParseNodeEnumerator(this);
}
internal void SetParent(ParseNode parent) {
if (_list != null) {
_list.TrimToSize();
foreach (ParseNode child in this) {
child.SetParent(parent);
}
}
}
#region Implementation of IEnumerable
IEnumerator IEnumerable.GetEnumerator() {
return GetEnumerator();
}
#endregion
public sealed class ParseNodeEnumerator : IEnumerator {
private ArrayList _list;
private int _current;
public ParseNodeEnumerator(ParseNodeList nodes) {
_list = nodes._list;
}
public ParseNode Current {
get {
return (ParseNode)_list[_current - 1];
}
}
public bool MoveNext() {
if ((_list != null) && (_current < _list.Count)) {
_current += 1;
return true;
}
return false;
}
#region Implementation of IEnumerator
object IEnumerator.Current {
get {
return Current;
}
}
bool IEnumerator.MoveNext() {
return MoveNext();
}
void IEnumerator.Reset() {
_current = 0;
}
#endregion
}
}
}