diff options
author | Martin Odersky <odersky@gmail.com> | 2003-02-13 14:41:36 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-02-13 14:41:36 +0000 |
commit | 4177daab2f54bdb20c71f623296a8bb32616fd12 (patch) | |
tree | 23f08b43f3758e825d5965b336030603a65bbcf7 /sources/scalac/ast/TreeList.java | |
parent | 33d6e170c97ca7b2f991896a0729941a7240b6d6 (diff) | |
download | scala-4177daab2f54bdb20c71f623296a8bb32616fd12.tar.gz scala-4177daab2f54bdb20c71f623296a8bb32616fd12.tar.bz2 scala-4177daab2f54bdb20c71f623296a8bb32616fd12.zip |
Initial version.
Diffstat (limited to 'sources/scalac/ast/TreeList.java')
-rw-r--r-- | sources/scalac/ast/TreeList.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/sources/scalac/ast/TreeList.java b/sources/scalac/ast/TreeList.java new file mode 100644 index 0000000000..d35627c686 --- /dev/null +++ b/sources/scalac/ast/TreeList.java @@ -0,0 +1,71 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +** ** +** $Id +\* */ + +package scalac.ast; + + +public final class TreeList { + Tree[] trees; + int len; + + public TreeList(Tree[] ts) { + trees = ts; + len = ts.length; + } + + public TreeList() { + this(new Tree[4]); + len = 0; + } + + public void append(Tree tree) { + if (len == trees.length) { + Tree[] ts = new Tree[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 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) { + System.arraycopy(trees, 0, ts, 0, len); + return ts; + } +} |