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
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
** **
\* */
// $Id$
package scalac.ast;
/** List of trees.
*/
public final class TreeList {
Tree[] trees;
int len;
public TreeList(Tree[] ts) {
trees = ts;
len = ts.length;
}
public TreeList() {
clear();
}
public void append(Tree tree) {
if (len == trees.length) {
Tree[] ts = new Tree[len == 0 ? 4 : len * 2];
System.arraycopy(trees, 0, ts, 0, len);
trees = ts;
}
trees[len++] = tree;
}
public void append(Tree[] ts) {
for (int j = 0; j < ts.length; j++)
append(ts[j]);
}
public void append(TreeList tl) {
for (int j = 0; j < tl.len; j++)
append(tl.trees[j]);
}
public void clear() {
trees = new Tree[4];
len = 0;
}
public int length() {
return len;
}
public Tree get(int i) {
return trees[i];
}
public Tree first() {
return trees[0];
}
public Tree removeLast() {
return trees[--len];
}
public Tree[] toArray() {
Tree[] ts = new Tree[len];
System.arraycopy(trees, 0, ts, 0, len);
return ts;
}
public Tree[] copyTo(Tree[] ts) {
return copyTo(ts, 0);
}
public Tree[] copyTo(Tree[] ts, int from) {
System.arraycopy(trees, 0, ts, from, len);
return ts;
}
}
|