diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-18 18:33:03 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-18 18:33:03 +0000 |
commit | d3819b93ab8b2de3d5cc35c33b8258ccdb5a931a (patch) | |
tree | dfc6f7f497e58ea3321e6f687b11313d2afa86b5 /sources/meta | |
parent | 0e82079908655682e5140ad521cef0572cb6d2a4 (diff) | |
download | scala-d3819b93ab8b2de3d5cc35c33b8258ccdb5a931a.tar.gz scala-d3819b93ab8b2de3d5cc35c33b8258ccdb5a931a.tar.bz2 scala-d3819b93ab8b2de3d5cc35c33b8258ccdb5a931a.zip |
Removed old Scalac code in sources and various ...
Removed old Scalac code in sources and various other obsolete elements.
Diffstat (limited to 'sources/meta')
31 files changed, 0 insertions, 3330 deletions
diff --git a/sources/meta/GenerateAll.java b/sources/meta/GenerateAll.java deleted file mode 100644 index d522fbcb58..0000000000 --- a/sources/meta/GenerateAll.java +++ /dev/null @@ -1,99 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta; - -import java.io.File; -import java.io.FileWriter; -import java.io.BufferedWriter; -import java.io.PrintWriter; -import java.io.PrintStream; -import java.io.IOException; - -import meta.util.AbstractMain; -import meta.util.AbstractFileExpander; -import meta.util.TextExpander; -import meta.util.TextWriter; - -/** A program that invokes all file generators. */ -public class GenerateAll extends AbstractMain { - - //######################################################################## - // Public Constants - - public static final AbstractFileExpander[] expanders = { - new meta.scala.MetaFunction(0), - new meta.scala.MetaFunction(1), - new meta.scala.MetaFunction(2), - new meta.scala.MetaFunction(3), - new meta.scala.MetaFunction(4), - new meta.scala.MetaFunction(5), - new meta.scala.MetaFunction(6), - new meta.scala.MetaFunction(7), - new meta.scala.MetaFunction(8), - new meta.scala.MetaFunction(9), - new meta.scala.MetaTuple(1), - new meta.scala.MetaTuple(2), - new meta.scala.MetaTuple(3), - new meta.scala.MetaTuple(4), - new meta.scala.MetaTuple(5), - new meta.scala.MetaTuple(6), - new meta.scala.MetaTuple(7), - new meta.scala.MetaTuple(8), - new meta.scala.MetaTuple(9), - new meta.scalac.ast.MetaTree(), - new meta.scalac.ast.MetaTreeFactory(), - new meta.scalac.ast.MetaDefaultTreeFactory(), - new meta.scalac.ast.MetaTreeCopier(), - new meta.scalac.ast.MetaStrictTreeCopier(), - new meta.scalac.ast.MetaLazyTreeCopier(), - new meta.scalac.ast.MetaTraverser(), - new meta.scalac.ast.MetaTransformer(), - new meta.scalac.checkers.MetaCheckTreeNodes(), - }; - - //######################################################################## - // Public Functions - - public static void usage(PrintStream out) { - out.println("usage: " + script() + " <outputdir> [<logfile>]"); - } - - public static void main(String[] args) throws Exception { - if (args.length < 1 || 2 < args.length) { - usage(System.err); - throw abort(); - } - int errors = 0; - File root = new File(args[0]); - PrintWriter filelist = args.length <= 1 ? null : - new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); - for (int i = 0; i < expanders.length; i++) { - File source = expanders[i].getSourceFile(root); - File target = expanders[i].getTargetFile(root); - System.out.println("Generating file " + target); - if (filelist != null) {filelist.println(target);filelist.flush();} - try { - TextWriter writer = expanders[i].getTextWriter(); - TextExpander expander = new TextExpander(writer, expanders[i]); - expander.expandText(source); - errors += expander.getErrorCount(); - target.delete(); - FileWriter output = new FileWriter(target); - output.write(writer.toString()); - output.close(); - target.setReadOnly(); - } catch (IOException exception) { - throw abort(exception); - } - } - if (errors > 0) throw abort(); - } - - //######################################################################## -} diff --git a/sources/meta/java/AbstractJavaExpander.java b/sources/meta/java/AbstractJavaExpander.java deleted file mode 100644 index c633ef8c45..0000000000 --- a/sources/meta/java/AbstractJavaExpander.java +++ /dev/null @@ -1,49 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.java; - -import meta.util.TextWriter; -import meta.util.AbstractFileExpander; - -/** A base class for java file expanders. */ -public abstract class AbstractJavaExpander extends AbstractFileExpander { - - //######################################################################## - // Public Fields - - /** The underlying java writer */ - public final JavaWriter writer; - - //######################################################################## - // Public Constructors - - public AbstractJavaExpander() { - this.writer = new JavaWriter(getPackage()); - } - - //######################################################################## - // Public Methods - - /** Returns the TextWriter in which this expander writes. */ - public TextWriter getTextWriter() { - return writer.getTextWriter(); - } - - /** Returns the suffix of the target file. Returns "java". */ - public String getTargetSuffix() { - return "java"; - } - - /** Prints the import statements. */ - public void printImports() { - writer.printImports(); - } - - //######################################################################## -} diff --git a/sources/meta/java/JavaWriter.java b/sources/meta/java/JavaWriter.java deleted file mode 100644 index d0106f3215..0000000000 --- a/sources/meta/java/JavaWriter.java +++ /dev/null @@ -1,394 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.java; - -import java.util.Iterator; -import java.util.Map; -import java.util.HashMap; -import java.util.Set; -import java.util.HashSet; -import java.util.TreeSet; - -import meta.util.TextWriter; -import meta.util.TextExpander; - -/** A string generator with support for java source code generation. */ -public class JavaWriter { - - //######################################################################## - // Public Constants - - /** The width of a separator */ - public static final int SEPARATOR_WIDTH = 78; - - //######################################################################## - // Private Fields - - /** The underlying text writer */ - private final TextWriter writer; - - /** The current package */ - private final String peckage; - - /** List of imports on-demand */ - private final Set/*<String>*/ owners; - - /** List of explicit imports (maps short names to full names) */ - private final Map/*<String,String>*/ types; - - //######################################################################## - // Public Constructors - - /** Creates a new JavaPrinter with no current package. */ - public JavaWriter() { - this((String)null); - } - - /** Creates a new JavaPrinter with the given current package. */ - public JavaWriter(String peckage) { - this(new TextWriter(" "), peckage); - } - - /** Creates a new JavaPrinter with no current package. */ - public JavaWriter(TextWriter writer) { - this(writer, null); - } - - /** Creates a new JavaPrinter with the given current package. */ - public JavaWriter(TextWriter writer, String peckage) { - this.writer = writer; - this.peckage = peckage; - this.owners = new HashSet(); - this.types = new HashMap(); - } - - //######################################################################## - // Public Methods - Importing types - - /** Returns the current package. */ - public String getPackage() { - return peckage; - } - - /** Returns true if the given type needs to be fully qualified. */ - public boolean needsQualification(Type type) { - type = type.getBaseType(); - String owner = type.getOwner(); - if (owner == null) return true; - Object current = types.get(type.getName()); - if (current != null) return !type.getFullName().equals(current); - return !owner.equals(getPackage()) && !owners.contains(owner); - } - - /** If necessary, adds an explicit import for the given type. */ - public void importType(Type type) { - importType(type, false); - } - - /** If necessary, adds an explicit import for the given type. */ - public void importType(Type type, boolean force) { - type = type.getBaseType(); - String owner = type.getOwner(); - if (owner == null) return; - if (!force && owner.equals(getPackage())) return; - if (!force && owners.contains(owner)) return; - String shortname = type.getName(); - String longname = type.getFullName(); - Object current = types.get(shortname); - if (current == null) { - types.put(shortname, longname); - } else if (!longname.equals(current)) { - throw new Error(); - } - } - - /** Adds an import on demand for members of the given type. */ - public void importFrom(Type type) { - importFrom(type.getFullName()); - } - - /** Adds an import on demand for members of the given owner. */ - public void importFrom(String owner) { - owners.add(owner); - } - - //######################################################################## - // Public Methods - Printing java statements and expressions - - /** Prints a package statement for the current package. */ - public JavaWriter printPackage() { - return getPackage() == null ? this : printPackage(getPackage()); - } - - /** Prints a package statement. */ - public JavaWriter printPackage(String peckage) { - return print("package ").print(peckage).println(";"); - } - - /** Prints an import statement. */ - public JavaWriter printImport(String inport) { - return print("import ").print(inport).println(";"); - } - - /** Prints import statements for the current imports. */ - public JavaWriter printImports() { - return printImports(getImports()); - } - - /** Prints a list of import statements. */ - public JavaWriter printImports(Set imports) { - for (Iterator i = imports.iterator(); i.hasNext(); ) - printImport((String)i.next()); - if (imports.size() > 0) println(); - return this; - } - - /** Prints a "do not edit" comment. */ - public JavaWriter printDoNotEdit() { - return printComment(TextExpander.DO_NOT_EDIT); - } - - /** Prints a single-line Java documentation comment. */ - public JavaWriter printDescription(String line) { - return print("/** ").print(line).println(" */"); - } - - /** Prints a multi-line Java documentation comment. */ - public JavaWriter printDescription(String[] lines) { - println("/**"); - for (int i = 0; i < lines.length; i++) print(" * ").println(lines[i]); - return println(" */"); - } - - /** Prints a single-line comment. */ - public JavaWriter printComment(String comment) { - return print("// ").println(comment); - } - - /** Prints a separator. */ - public JavaWriter printSeparator() { - println().print("//"); - int width = SEPARATOR_WIDTH - 2 - getIndentLevel() * getIndentWidth(); - for (int i = 0; i < width; i++) print("#"); - return println(); - } - - /** Prints a separator with the given title. */ - public JavaWriter printSeparator(String title) { - return printSeparator().printComment(title).println(); - } - - /** Prints a separator with the given title and subtitle. */ - public JavaWriter printSeparator(String title, String subtitle) { - return printSeparator(title + " - " + subtitle); - } - - //######################################################################## - // Public Methods - Printing simple values - - /** Prints a new line. */ - public JavaWriter println() { - return line(); - } - - /** Prints the boolean value followed by a new line. */ - public JavaWriter println(boolean value) { - return print(value).line(); - } - - /** Prints the byte value followed by a new line. */ - public JavaWriter println(byte value) { - return print(value).line(); - } - - /** Prints the short value followed by a new line. */ - public JavaWriter println(short value) { - return print(value).line(); - } - - /** Prints the char value followed by a new line. */ - public JavaWriter println(char value) { - return print(value).line(); - } - - /** Prints the int value followed by a new line. */ - public JavaWriter println(int value) { - return print(value).line(); - } - - /** Prints the long value followed by a new line. */ - public JavaWriter println(long value) { - return print(value).line(); - } - - /** Prints the float value followed by a new line. */ - public JavaWriter println(float value) { - return print(value).line(); - } - - /** Prints the double value followed by a new line. */ - public JavaWriter println(double value) { - return print(value).line(); - } - - /** Prints the string followed by a new line. */ - public JavaWriter println(String value) { - return print(value).line(); - } - - /** Prints the type followed by a new line. */ - public JavaWriter println(Type value) { - return print(value).line(); - } - - /** Prints the boolean value. */ - public JavaWriter print(boolean value) { - writer.print(value); - return this; - } - - /** Prints the byte value. */ - public JavaWriter print(byte value) { - writer.print(value); - return this; - } - - /** Prints the short value. */ - public JavaWriter print(short value) { - writer.print(value); - return this; - } - - /** Prints the char value. */ - public JavaWriter print(char value) { - writer.print(value); - return this; - } - - /** Prints the int value. */ - public JavaWriter print(int value) { - writer.print(value); - return this; - } - - /** Prints the long value. */ - public JavaWriter print(long value) { - writer.print(value); - return this; - } - - /** Prints the float value. */ - public JavaWriter print(float value) { - writer.print(value); - return this; - } - - /** Prints the long value. */ - public JavaWriter print(double value) { - writer.print(value); - return this; - } - - /** Prints the string. */ - public JavaWriter print(String value) { - writer.print(value); - return this; - } - - /** Prints the type. */ - public JavaWriter print(Type value) { - return print(value.getName(needsQualification(value))); - } - - //######################################################################## - // Public Methods - Formating - - /** Returns the indentation width. */ - public int getIndentWidth() { - return writer.getIndentWidth(); - } - - /** Returns the indentation level. */ - public int getIndentLevel() { - return writer.getIndentLevel(); - } - - /** Returns the indentation level. */ - public JavaWriter setIndentLevel(int level) { - writer.setIndentLevel(level); - return this; - } - - /** Increases the indentation level by one. */ - public JavaWriter indent() { - writer.indent(); - return this; - } - - /** Decreases the indentation level by one. */ - public JavaWriter undent() { - writer.undent(); - return this; - } - - /** Starts a new line. */ - public JavaWriter line() { - writer.line(); - return this; - } - - /** Inserts a white space. */ - public JavaWriter space() { - writer.space(); - return this; - } - - /** Prints an opening brace followed by a new line. */ - public JavaWriter lbrace() { - return space().println("{").indent(); - } - - /** Prints a closing brace followed by a new line. */ - public JavaWriter rbrace() { - return undent().space().println("}"); - } - - //######################################################################## - // Public Methods - Accessing - - /** Returns the underlying StringBuffer. */ - public TextWriter getTextWriter() { - return writer; - } - - /** Returns the underlying StringBuffer. */ - public StringBuffer getBuffer() { - return writer.getBuffer(); - } - - /** Returns the generated string. */ - public String toString() { - return writer.toString(); - } - - //######################################################################## - // Private Methods - - /** Returns the current list of imports (explicit and on-demand). */ - private Set getImports() { - Set imports = new TreeSet(); - for (Iterator i = owners.iterator(); i.hasNext(); ) - imports.add(i.next() + ".*"); - for (Iterator i = types.values().iterator(); i.hasNext(); ) - imports.add(i.next()); - return imports; - } - - //######################################################################## -} diff --git a/sources/meta/java/Type.java b/sources/meta/java/Type.java deleted file mode 100644 index 0d4545cbd4..0000000000 --- a/sources/meta/java/Type.java +++ /dev/null @@ -1,152 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.java; - -/** A representation for Java types. */ -public class Type { - - //######################################################################## - // Public Constants - - /** The Java primitive type void */ - public static final Type VOID = Primitive("void"); - - /** The Java primitive type boolean */ - public static final Type BOOLEAN = Primitive("boolean"); - - /** The Java primitive type byte */ - public static final Type BYTE = Primitive("byte"); - - /** The Java primitive type short */ - public static final Type SHORT = Primitive("short"); - - /** The Java primitive type char */ - public static final Type CHAR = Primitive("char"); - - /** The Java primitive type int */ - public static final Type INT = Primitive("int"); - - /** The Java primitive type long */ - public static final Type LONG = Primitive("long"); - - /** The Java primitive type float */ - public static final Type FLOAT = Primitive("float"); - - /** The Java primitive type double */ - public static final Type DOUBLE = Primitive("double"); - - //######################################################################## - // Public Cases - - /** A primitive type */ - public case Primitive(String name); - - /** A reference type (the owner may be null) */ - public case Reference(String owner, String name); - - /** An array type */ - public case Array(Type item); - - //######################################################################## - // Public Methods - - /** Returns the type's fully qualified name. */ - public String getFullName() { - return getName(true); - } - - /** Returns the type's short name. */ - public String getName() { - return getName(false); - } - - /** Returns the type's (possibly fully qualified) name. */ - public String getName(boolean qualified) { - switch (this) { - case Primitive(String name): - return name; - case Reference(String owner, String name): - return qualified && owner != null ? owner + "." + name : name; - case Array(Type item): - return item.getName(qualified) + "[]"; - default: - throw new Error("illegal case: " + getName(true)); - } - } - - /** Returns the type's owner (its package or enclosing type). */ - public String getOwner() { - switch (this) { - case Primitive(_): - return null; - case Reference(String owner, _): - return owner; - case Array(Type item): - return item.getOwner(); - default: - throw new Error("illegal case: " + getName(true)); - } - } - - /** If this is an array type, returns the type of the elements. */ - public Type getItemType() { - switch (this) { - case Array(Type item): - return item; - default: - throw new Error("not an array type: " + getName(true)); - } - } - - /** Returns the base type of this type. */ - public Type getBaseType() { - return isArray() ? getItemType() : this; - } - - /** Returns true if this is a primitive type. */ - public boolean isPrimitive() { - switch (this) { - case Primitive(_): - return true; - default: - return false; - } - } - - /** Returns true if this is an array type. */ - public boolean isArray() { - switch (this) { - case Array(_): - return true; - default: - return false; - } - } - - /** - * Returns the string representation of an array instantiation - * with the given bounds and whose elements are of this type. - */ - public String newArray(String bounds) { - switch (this) { - case Array(Type item): - return item.newArray(bounds + "[]"); - default: - return this + bounds; - } - } - - - /** Returns the string representation of this type. */ - public String toString() { - return getName(); - } - - //######################################################################## -} diff --git a/sources/meta/scala/AbstractScalaExpander.java b/sources/meta/scala/AbstractScalaExpander.java deleted file mode 100644 index 0e121bfca9..0000000000 --- a/sources/meta/scala/AbstractScalaExpander.java +++ /dev/null @@ -1,45 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scala; - -import meta.java.JavaWriter; -import meta.util.TextWriter; -import meta.util.AbstractFileExpander; - -/** A base class for scala file expanders. */ -public abstract class AbstractScalaExpander extends AbstractFileExpander { - - //######################################################################## - // Public Fields - - /** The underlying java writer */ - public final JavaWriter writer; - - //######################################################################## - // Public Constructors - - public AbstractScalaExpander() { - this.writer = new JavaWriter(getPackage()); - } - - //######################################################################## - // Public Methods - - /** Returns the TextWriter in which this expander writes. */ - public TextWriter getTextWriter() { - return writer.getTextWriter(); - } - - /** Returns the suffix of the target file. Returns "scala". */ - public String getTargetSuffix() { - return "scala"; - } - - //######################################################################## -} diff --git a/sources/meta/scala/MetaFunction.java b/sources/meta/scala/MetaFunction.java deleted file mode 100644 index 11ed9cc159..0000000000 --- a/sources/meta/scala/MetaFunction.java +++ /dev/null @@ -1,55 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scala; - -import meta.java.AbstractJavaExpander; - -public class MetaFunction extends AbstractScalaExpander { - - //######################################################################## - // Public Fields - - public final int arity; - - //######################################################################## - // Public Constructors - - public MetaFunction(int arity) { - this.arity = arity; - } - - //######################################################################## - // Public Methods - - public String getTargetBaseName() { - return super.getTargetBaseName() + arity; - } - - public void printn() { - writer.print(arity); - } - - public void printClassSignature() { - writer.print("["); - for (int i = 0; i < arity; i++) - writer.print("-T").print(i).print(", "); - writer.print("+R]"); - } - - public void printApplySignature() { - writer.print("("); - for (int i = 0; i < arity; i++) { - if (i > 0) writer.print(", "); - writer.print("v").print(i).print(":").space().print("T").print(i); - } - writer.print("): R"); - } - - //######################################################################## -} diff --git a/sources/meta/scala/MetaTuple.java b/sources/meta/scala/MetaTuple.java deleted file mode 100644 index 2c67d9b919..0000000000 --- a/sources/meta/scala/MetaTuple.java +++ /dev/null @@ -1,58 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scala; - -public class MetaTuple extends AbstractScalaExpander { - - //######################################################################## - // Public Fields - - public final int arity; - - //######################################################################## - // Public Constructors - - public MetaTuple(int arity) { - this.arity = arity; - } - - //######################################################################## - // Public Methods - - public String getTargetBaseName() { - return super.getTargetBaseName() + arity; - } - - public void printn() { - writer.print(arity); - } - - public void printTParams() { - for (int i = 1; i <= arity; i++) { - if (i > 1) writer.print(", "); - writer.print("+T").print(i); - } - } - - public void printVParams() { - for (int i = 1; i <= arity; i++) { - if (i > 1) writer.print(", "); - writer.print("_").print(i).print(": T").print(i); - } - } - - public void printToStringBody() { - for (int i = 1; i <= arity; i++) { - if (i > 1) writer.print(" + \",\" + "); - writer.print("_").print(i); - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/Phase.java b/sources/meta/scalac/Phase.java deleted file mode 100644 index 8092d6125b..0000000000 --- a/sources/meta/scalac/Phase.java +++ /dev/null @@ -1,46 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac; - -/** A representation for Scala compiler phases. */ -public class Phase { - - //######################################################################## - // Public Constants - - public static final Phase - START = new Phase("start", null), - PARSER = new Phase("parser", "PARSER"), - DESUGARIZER = new Phase("desugarizer", "ANALYZER"), - ANALYZER = new Phase("analyzer", "ANALYZER"), - REFCHECK = new Phase("refcheck", "REFCHECK"), - UNCURRY = new Phase("uncurry", "UNCURRY"), - TRANSMATCH = new Phase("transmatch", "TRANSMATCH"), - LAMBDALIFT = new Phase("lambdalift", "LAMBDALIFT"), - EXPLICITOUTER = new Phase("explicitouter", "EXPLICITOUTER"), - ERASURE = new Phase("erasure", "ERASURE"), - UNKNOWN = new Phase("? !!!", null), - END = new Phase("-", null); - - //######################################################################## - // Public Fields - - public final String name; - public final String constant; - - //######################################################################## - // Public Constructors - - public Phase(String name, String constant) { - this.name = name; - this.constant = constant; - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/AbstractTreeCaseExpander.java b/sources/meta/scalac/ast/AbstractTreeCaseExpander.java deleted file mode 100644 index c7e023c16f..0000000000 --- a/sources/meta/scalac/ast/AbstractTreeCaseExpander.java +++ /dev/null @@ -1,62 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -/** A base class for expanders that generate switches on tree nodes. */ -public abstract class AbstractTreeCaseExpander extends AbstractTreeExpander { - - //######################################################################## - // Public Constructors - - public AbstractTreeCaseExpander() { - writer.importType(t_Debug); - } - - //######################################################################## - // Public Methods - - public void printTreeSwitch() { - writer.println("switch (tree) {"); - writer.println(); - printTreeCases(); - writer.println("default:"); - writer.indent(); - writer.print("throw ").print(t_Debug). - println(".abort(\"unknown tree\", tree);"); - writer.undent(); - writer.println("}"); - } - - public void printTreeCases() { - for (int i = 0; i < tree.nodes.length; i++) { - printTreeCase(tree.nodes[i]); - writer.println(); - } - } - - public void printTreeCase(TreeNode node) { - printTreeCaseHeader(node); - writer.println().indent(); - printTreeCaseBody(node); - printTreeCaseFooter(node); - writer.undent(); - } - - public void printTreeCaseHeader(TreeNode node) { - node.printCase(writer, false); - } - - public abstract void printTreeCaseBody(TreeNode node); - - public void printTreeCaseFooter(TreeNode node) { - // do nothing - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/AbstractTreeExpander.java b/sources/meta/scalac/ast/AbstractTreeExpander.java deleted file mode 100644 index 503a9651a2..0000000000 --- a/sources/meta/scalac/ast/AbstractTreeExpander.java +++ /dev/null @@ -1,41 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; -import meta.java.AbstractJavaExpander; - -/** A base class for expanders that handle tree nodes. */ -public abstract class AbstractTreeExpander extends AbstractJavaExpander { - - //######################################################################## - // Public Fields - - public final Type t_Debug; - public final Tree tree; - - //######################################################################## - // Public Constructors - - public AbstractTreeExpander() { - this.t_Debug = TreeType.Reference("scalac.util", "Debug"); - this.tree = new Tree(); - writer.importFrom(t_Debug); - writer.importFrom(tree.getType(0)); - for (int i = 0; i < tree.nodes.length; i++) { - if (tree.nodes[i].fields != null) - for (int j = 0; j < tree.nodes[i].fields.length; j++) - writer.importType(tree.nodes[i].fields[j].type); - if (tree.nodes[i].hasSymbol()) - writer.importType(tree.nodes[i].getSymbol().type); - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/AbstractTreeMethodExpander.java b/sources/meta/scalac/ast/AbstractTreeMethodExpander.java deleted file mode 100644 index 7444759111..0000000000 --- a/sources/meta/scalac/ast/AbstractTreeMethodExpander.java +++ /dev/null @@ -1,31 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -/** A base class for expanders that generate one method per tree node. */ -public abstract class AbstractTreeMethodExpander extends AbstractTreeExpander { - - //######################################################################## - // Public Methods - - public void printTreeMethods() { - for (int i = 0; i < tree.nodes.length; i++) { - if (tree.nodes[i].fields != null) { - printTreeMethod(tree.nodes[i], false); - if (tree.nodes[i].hasSymbol()) - printTreeMethod(tree.nodes[i], true); - } - writer.println(); - } - } - - public abstract void printTreeMethod(TreeNode node, boolean withSymbol); - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaDefaultTreeFactory.java b/sources/meta/scalac/ast/MetaDefaultTreeFactory.java deleted file mode 100644 index fde4fe7773..0000000000 --- a/sources/meta/scalac/ast/MetaDefaultTreeFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -public class MetaDefaultTreeFactory extends AbstractTreeMethodExpander { - - //######################################################################## - // Public Methods - - public void printTreeMethod(TreeNode node, boolean withSymbol) { - node.printMethod(writer, "int pos", withSymbol).lbrace(); - node.printNew(writer.print(node + " t = "), withSymbol).println(";"); - writer.println("t.pos = pos;"); - writer.println("return t;"); - writer.rbrace(); - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaLazyTreeCopier.java b/sources/meta/scalac/ast/MetaLazyTreeCopier.java deleted file mode 100644 index c389ab9404..0000000000 --- a/sources/meta/scalac/ast/MetaLazyTreeCopier.java +++ /dev/null @@ -1,51 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -public class MetaLazyTreeCopier extends AbstractTreeMethodExpander { - - //######################################################################## - // Public Methods - - public void printTreeMethod(TreeNode node, boolean withSymbol) { - TreeField symbol = node.getSymbol(); - node.printMethod(writer, tree.getFormal("tree"), withSymbol).lbrace(); - if (!withSymbol && node.hasLinkedFields()) - writer.println("assert tree.symbol() == null : "+ - "\"tree's symbol is not null\";"); - writer.print(node.getType(0)).print(" t = ("). - print(node.getType(0)).println(")tree;"); - TreeField[] fields = node.getFields(withSymbol); - // !!! why do we copy if there is no symbol and no field - if (withSymbol || node.fields.length > 0) { - writer.print("if (").indent(); - if (withSymbol) writer.print("t.symbol() == " + symbol); - for (int i = 0; i < fields.length; i++) { - if (i > 0 ? true : withSymbol) writer.println(" &&"); - writer.print("t." + fields[i] + " == " + fields[i]); - } - writer.println(")"); - writer.println("return t;").undent(); - } - writer.print("return copier."); - node.printCall(writer, "tree", withSymbol).println(";"); - writer.rbrace(); - - if (withSymbol && node.hasLinkedFields()) { - node.printMethod(writer, tree.getFormal("tree"), false, true); - writer.lbrace(); - symbol.print(writer, true).println(" = tree.symbol();"); - node.printCall(writer.print("return "), "tree", true).println(";"); - writer.rbrace(); - return; - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaStrictTreeCopier.java b/sources/meta/scalac/ast/MetaStrictTreeCopier.java deleted file mode 100644 index 62823377dd..0000000000 --- a/sources/meta/scalac/ast/MetaStrictTreeCopier.java +++ /dev/null @@ -1,44 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -public class MetaStrictTreeCopier extends AbstractTreeMethodExpander { - - //######################################################################## - // Public Methods - - public void printTreeMethod(TreeNode node, boolean withSymbol) { - TreeField symbol = node.getSymbol(); - node.printMethod(writer, tree.getFormal("tree"), withSymbol).lbrace(); - if (!withSymbol && node.hasLinkedFields()) - writer.println("assert tree.symbol() == null : "+ - "\"tree's symbol is not null\";"); - writer.print(node.getType(0)).print(" t = make."); - node.printCall(writer, "tree.pos", withSymbol).println(";"); - writer.println("t.type = tree.type;"); - if (!withSymbol && node.hasSymbol() && !node.hasLinkedFields()) { - symbol.print(writer, true).println(" = tree.symbol();"); - writer.println("if ("+symbol+" != null) t.setSymbol("+symbol+");"); - } - writer.println("return t;"); - writer.rbrace(); - - if (withSymbol && node.hasLinkedFields()) { - node.printMethod(writer, tree.getFormal("tree"), false, true); - writer.lbrace(); - symbol.print(writer, true).println(" = tree.symbol();"); - node.printCall(writer.print("return "), "tree", true).println(";"); - writer.rbrace(); - } - } - - //######################################################################## -} - - diff --git a/sources/meta/scalac/ast/MetaTransformer.java b/sources/meta/scalac/ast/MetaTransformer.java deleted file mode 100644 index 79ebebaf2f..0000000000 --- a/sources/meta/scalac/ast/MetaTransformer.java +++ /dev/null @@ -1,77 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; - -public class MetaTransformer extends AbstractTreeCaseExpander { - - //######################################################################## - // Public Methods - - public void printTreeCaseBody(TreeNode node) { - if (node.fields == null) { - writer.println("return tree;"); - } else { - if (node.hasSymbol()) { - writer.print("if (tree.symbol() != null)").lbrace(); - printTransformNode(node, true); - writer.undent().print("} else").lbrace(); - } - printTransformNode(node, false); - if (node.hasSymbol()) writer.rbrace(); - } - } - - public void printTransformNode(TreeNode node, boolean withSymbol) { - TreeField[] fields = node.getFields(withSymbol); - writer.print("return copy." + node + "(tree"); - if (withSymbol) writer.print(", tree.symbol()"); - for (int i = 0; i < fields.length; i++) { - writer.print(", "); - if (Tree.isTree(fields[i].type)) - writer.print("transform(" + fields[i].name + ")"); - else - writer.print(fields[i].name); - } - writer.println(");"); - } - - public void printTransformArrays() { - for (int j = 1; j <= tree.arrays; j++) - printTransformArray(tree.getType(j), false); - for (int i = 0; i < tree.nodes.length; i++) - for (int j = 1; j <= tree.nodes[i].arrays; j++) - printTransformArray(tree.nodes[i].getType(j), j == 1); - } - - public void printTransformArray(Type type, boolean needCast) { - Type item = type.getItemType(); - Type erased = needCast ? tree.getType(0) : item; - String cast = needCast ? "(" + item + ")" : ""; - writer.print("public ").print(type).print(" transform"). - print("(").print(type).print(" ts)").lbrace(); - writer.print("for (int i = 0; i < ts.length; i++)").lbrace(); - writer.println(erased + " t = transform(ts[i]);"); - writer.print("if (t != ts[i])").lbrace(); - writer.println(type+" res = new "+item.newArray("[ts.length]")+";"); - writer.println("System.arraycopy(ts, 0, res, 0, i);"); - writer.println("res[i++] = "+cast+"t;"); - writer.print("for (; i < ts.length; i++)"). - println("res[i] = "+cast+"transform(ts[i]);"); - writer.println("return res;"); - writer.rbrace(); - writer.rbrace(); - writer.println("return ts;"); - writer.rbrace(); - writer.line(); - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaTraverser.java b/sources/meta/scalac/ast/MetaTraverser.java deleted file mode 100644 index 0f166510db..0000000000 --- a/sources/meta/scalac/ast/MetaTraverser.java +++ /dev/null @@ -1,44 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; - -public class MetaTraverser extends AbstractTreeCaseExpander { - - //######################################################################## - // Public Methods - - public void printTreeCaseBody(TreeNode node) { - if (node.fields != null) - for (int i = 0; i < node.fields.length; i++) - if (Tree.isTree(node.fields[i].type)) - writer.println("traverse(" + node.fields[i] + ");"); - writer.println("return;"); - } - - public void printTraverseArrays() { - int max = tree.arrays; - for (int i = 0; i < tree.nodes.length; i++) - max = Math.max(max, tree.nodes[i].arrays); - for (int i = 1; i <= max; i++) - printTraverseArray(tree.getType(i)); - } - - public void printTraverseArray(Type type) { - writer.print("public void traverse"). - print("(").print(type).print(" trees)").lbrace(); - writer.print("for (int i = 0; i < trees.length; i++) "). - println("traverse(trees[i]);"); - writer.rbrace(); - writer.line(); - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaTree.java b/sources/meta/scalac/ast/MetaTree.java deleted file mode 100644 index 31b98d1d4b..0000000000 --- a/sources/meta/scalac/ast/MetaTree.java +++ /dev/null @@ -1,218 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; - -public class MetaTree extends AbstractTreeExpander { - - //######################################################################## - // Public Methods - - public void printEmptyArrays() { - printEmptyArrays(tree.getType(0), "EMPTY", tree.arrays); - for (int i = 0; i < tree.nodes.length; i++) { - TreeNode node = tree.nodes[i]; - printEmptyArrays(node.getType(0), node + "_EMPTY", node.arrays); - } - } - - public void printEmptyArrays(Type base, String prefix, int maxRank) { - Type type = base; - for (int rank = 1; rank <= maxRank; rank++) { - type = Type.Array(type); - writer.print("public static final ").print(type).print(" "+prefix); - for (int i = 0; i < rank; i++) writer.print("_ARRAY"); - writer.print(" = new ").print(base).print("[0]"); - for (int i = 1; i < rank; i++) writer.print("[]"); - writer.println(";"); - } - } - - public void printTreeCases() { - for (int i = 0; i < tree.nodes.length; i++) - printTreeCase(tree.nodes[i]); - } - - private void printTreeCase(TreeNode node) { - writer.printDescription(new String[] { - node.description, - "- kind : " + description(node.kind), - "- symbol : " + description(node.symbol), - "- introduced by: " + node.start.name, - "- eliminated by: " + node.stop.name, - }); - node.printDecl(writer.print("public case "), null, false); - if (node.fields != null) { - writer.lbrace(); - writer.println("assert CheckTreeNodes.instance.checkNode(this);"); - writer.rbrace(); - } else { - writer.println(";"); - } - if (node == tree.n_Empty) - writer.print("static { " + node + ".type = Type.NoType; }"); - writer.println(); - } - - private String description(TreeKind kind) { - switch (kind) { - case Any : return "this tree is of any kind"; - case Type: return "this tree is a type"; - case Term: return "this tree is a term"; - case Dual: return "this tree is a type or a term"; - case Test: return "this tree is a type or a term " + - "(determined by the kind of the name field)"; - case None: return "this tree is neither a type nor a term"; - default : throw new Error(kind.getClass().getName()); - } - } - - private String description(TreeSymbol symbol) { - switch (symbol) { - case NoSym : return "this tree has no symbol"; - case HasSym(_, false): return "this tree references a symbol"; - case HasSym(_, true ): return "this tree defines a symbol"; - default : throw new Error(symbol.getClass().getName()); - } - } - - public void printIsKind() { - printIsKind(tree.nodes, TreeKind.Type); - printIsKind(tree.nodes, TreeKind.Term); - } - - private void printIsKind(TreeNode[] nodes, TreeKind kind) { - writer.println("/** Returns true if this tree is a " + - kind.toString().toLowerCase() + ". */"); - writer.print("public boolean is" + kind + "()").lbrace(); - writer.println("switch (this) {"); - - for (int i = 0; i < nodes.length; i++) - if (nodes[i].kind != TreeKind.Test && nodes[i].kind.isA(kind)) - nodes[i].printCase(writer, true).println(); - writer.indent().println("return true;").undent(); - - for (int i = 0; i < nodes.length; i++) { - if (nodes[i].kind != TreeKind.Test) continue; - writer.print("case " + nodes[i].name + "("); - for (int j = 0; j < nodes[i].fields.length; j++) { - if (j > 0) writer.print(", "); - switch (nodes[i].fields[j].type) { - case TreeType.Name(Test): - writer.print(nodes[i].fields[j].type + " name"); - break; - default: - writer.print("_"); - break; - } - } - writer.println("):"); - writer.indent().print("return "); - switch (kind) { - case TreeKind.Type: - writer.print("name.isTypeName() && (symbol() == null || !symbol().isConstructor()) || name == Names.ERROR"); - break; - case TreeKind.Term: - writer.print("name.isTermName() || (symbol() != null && symbol().isConstructor())"); - break; - default: - throw new Error("unexpected kind " + kind); - } - writer.println(";").undent(); - } - - writer.println("default:"); - writer.indent().println("return false;").undent(); - - writer.println("}"); - writer.rbrace(); - writer.println(); - } - - public void printExtClasses() { - for (int i = 0;i < tree.nodes.length;i++) printExtClass(tree.nodes[i]); - } - - private void printExtClass(TreeNode node) { - TreeField symbol = node.getSymbol(); - if (symbol == null) return; - writer.print("public static class Ext"+node+" extends "+node).lbrace(); - symbol.print(writer.print("private "), true).println(";"); - writer.println(); - - printExtConstructor(node, false); - printExtConstructor(node, true); - writer.println(); - - writer.print("public boolean hasSymbol()").lbrace(); - writer.println("return true;"); - writer.rbrace(); - writer.println(); - - if (node.definesSymbol()) { - writer.print("public boolean definesSymbol()").lbrace(); - writer.println("return true;"); - writer.rbrace(); - writer.println(); - } - - writer.print("public ").print(symbol.type).print(" symbol()"); - writer.lbrace(); - writer.println("return " + symbol + ";"); - writer.rbrace(); - writer.println(); - - writer.print("public ").print(tree.getType(0)).print(" setSymbol"); - symbol.print(writer.print("("), true).print(")").lbrace(); - printSetSymbol(symbol); - for (int i = 0; i < node.fields.length; i++) { - TreeField field = node.fields[i]; - TreeFieldLink link = field.link; - if (link == null) continue; - link.print(writer.print("this."+field+" = "),symbol).println(";"); - } - writer.println("return this;"); - writer.rbrace(); - - writer.rbrace(); - writer.println(); - } - - private void printExtConstructor(TreeNode node, boolean withSymbol) { - node.printDecl(writer.print("public Ext"), null, withSymbol).lbrace(); - TreeField symbol = node.getSymbol(); - writer.print("super("); - for (int i = 0; i < node.fields.length; i++) { - if (i > 0) writer.print(", "); - if (withSymbol && node.fields[i].link != null) { - node.fields[i].link.print(writer, symbol); - } else { - writer.print(node.fields[i].name); - } - } - writer.println(");"); - if (withSymbol) printSetSymbol(symbol); - writer.rbrace(); - } - - private void printSetSymbol(TreeField symbol) { - writer.println("assert " + symbol + " != null : \"null symbol\";"); - writer.println("this." + symbol + " = " + symbol + ";"); - } - - public void printEmptyCases() { - for (int i = 0;i < tree.nodes.length;i++) { - tree.nodes[i].printCase(writer, false).println(); - writer.println(); - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaTreeCopier.java b/sources/meta/scalac/ast/MetaTreeCopier.java deleted file mode 100644 index 785c3a99da..0000000000 --- a/sources/meta/scalac/ast/MetaTreeCopier.java +++ /dev/null @@ -1,26 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -public class MetaTreeCopier extends AbstractTreeMethodExpander { - - //######################################################################## - // Public Methods - - public void printTreeMethod(TreeNode node, boolean withSymbol) { - node.printMethod(writer,tree.getFormal("tree"),withSymbol); - writer.println(";"); - if (withSymbol && node.hasLinkedFields()) { - node.printMethod(writer, tree.getFormal("tree"), false, true); - writer.println(";"); - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/MetaTreeFactory.java b/sources/meta/scalac/ast/MetaTreeFactory.java deleted file mode 100644 index 28b1f381c9..0000000000 --- a/sources/meta/scalac/ast/MetaTreeFactory.java +++ /dev/null @@ -1,21 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -public class MetaTreeFactory extends AbstractTreeMethodExpander { - - //######################################################################## - // Public Methods - - public void printTreeMethod(TreeNode node, boolean withSymbol) { - node.printMethod(writer, "int pos", withSymbol).println(";"); - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/Tree.java b/sources/meta/scalac/ast/Tree.java deleted file mode 100644 index 492461bc59..0000000000 --- a/sources/meta/scalac/ast/Tree.java +++ /dev/null @@ -1,441 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import java.util.List; -import java.util.ArrayList; - -import meta.java.Type; -import meta.scalac.Phase; - -/** This class describes all tree nodes. */ -public class Tree { - - //######################################################################## - // Private Fields - - private final TreeKind - Any = TreeKind.Any, - Type = TreeKind.Type, - Term = TreeKind.Term, - Dual = TreeKind.Dual, - Test = TreeKind.Test, - None = TreeKind.None; - - private final Type - t_int = TreeType.INT, - t_ints = TreeType.Array(t_int), - t_Object = TreeType.Reference(null, "Object"), - t_String = TreeType.Reference(null, "String"), - t_Global = TreeType.Reference("scalac", "Global"), - t_Unit = TreeType.Reference("scalac", "Unit"), - t_TreeGen = TreeType.Reference("scalac.ast", "TreeGen"), - t_AConstant = TreeType.Reference("scalac.atree", "AConstant"), - t_Symbol = TreeType.Reference("scalac.symtab", "Symbol"), - t_Type = TreeType.Reference("scalac.symtab", "Type"), - t_Name = TreeType.Name(Any), - t_TypeName = TreeType.Name(Type), - t_TermName = TreeType.Name(Term), - t_TestName = TreeType.Name(Test), - t_Names = TreeType.Array(t_Name), - t_Tree = getType(0), - t_TypeTree = getType(0, Type), - t_TermTree = getType(0, Term), - t_Trees = getType(1), - t_TypeTrees = getType(1, Type), - t_TermTrees = getType(1, Term); - - private final TreeFieldLink - SymFlags = TreeFieldLink.SymFlags, - SymName = TreeFieldLink.SymName; - - private final TreeField - tree_symbol = new TreeField(t_Symbol, "symbol"); - - private final TreeSymbol - NoSym = TreeSymbol.NoSym, - HasSym = TreeSymbol.HasSym(tree_symbol, false), - DefSym = TreeSymbol.HasSym(tree_symbol, true); - - private final List list - = new ArrayList(); - - //######################################################################## - // Public Fields - - public final TreeNode - n_Empty = node("Empty" , Any , NoSym), - n_Attributed = node("Attributed" , None, NoSym), - n_DocDef = node("DocDef" , None, NoSym), - n_ClassDef = node("ClassDef" , None, DefSym), - n_PackageDef = node("PackageDef" , None, NoSym), - n_ModuleDef = node("ModuleDef" , None, DefSym), - n_ValDef = node("ValDef" , None, DefSym), - n_PatDef = node("PatDef" , None, NoSym), - n_DefDef = node("DefDef" , None, DefSym), - n_AbsTypeDef = node("AbsTypeDef" , None, DefSym), - n_AliasTypeDef = node("AliasTypeDef" , None, DefSym), - n_Import = node("Import" , None, HasSym), - n_CaseDef = node("CaseDef" , None, NoSym), - n_Template = node("Template" , None, HasSym), - n_LabelDef = node("LabelDef" , Term, DefSym), - n_Block = node("Block" , Term, NoSym), - n_Sequence = node("Sequence" , Term, NoSym), - n_Alternative = node("Alternative" , Term, NoSym), - n_Bind = node("Bind" , Term, DefSym), - n_Visitor = node("Visitor" , Term, NoSym), - n_Function = node("Function" , Term, NoSym), - n_Assign = node("Assign" , Term, NoSym), - n_If = node("If" , Term, NoSym), - n_Switch = node("Switch" , Term, NoSym), - n_Return = node("Return" , Term, HasSym), - n_Throw = node("Throw" , Term, NoSym), - n_New = node("New" , Term, NoSym), - n_Create = node("Create" , Term, HasSym), - n_Typed = node("Typed" , Term, NoSym), - n_TypeApply = node("TypeApply" , Term, NoSym), - n_Apply = node("Apply" , Term, NoSym), - n_Super = node("Super" , Term, HasSym), - n_This = node("This" , Term, HasSym), - n_Select = node("Select" , Test, HasSym), - n_Ident = node("Ident" , Test, HasSym), - n_Literal = node("Literal" , Term, NoSym), - n_TypeTerm = node("TypeTerm" , Type, NoSym), - n_SingletonType = node("SingletonType" , Type, NoSym), - n_SelectFromType = node("SelectFromType", Type, HasSym), - n_FunType = node("FunType" , Type, NoSym), - n_CompoundType = node("CompoundType" , Type, NoSym), - n_AppliedType = node("AppliedType" , Type, NoSym), - n_Try = node("Try" , Term, NoSym); - - public final TreeNode[] nodes; - public int arrays; - - //######################################################################## - // Public Constructors - - public Tree() { - nodes = (TreeNode[])list.toArray(new TreeNode[list.size()]); - - n_Empty. - setDescription("A tree node for the absence of a tree"). - setRange(Phase.PARSER, Phase.UNKNOWN). - noFields(); - - n_Attributed. - setDescription("Attributed definition"). - setRange(Phase.PARSER, Phase.ANALYZER). - addField(t_Tree, "attribute"). - addField(t_Tree, "definition"); - - n_DocDef. - setDescription("Documented definition"). - setRange(Phase.PARSER, Phase.ANALYZER). - addField(t_String, "comment"). - addField(t_Tree, "definition"); - - n_ClassDef. - setDescription("Class and data declaration"). - setRange(Phase.PARSER, Phase.END). - addField(t_int, "mods", SymFlags). - addField(t_TypeName, "name", SymName). - addField(n_AbsTypeDef.getType(1), "tparams"). - addField(n_ValDef.getType(2), "vparams"). - addField(t_TypeTree, "tpe"). - addField(n_Template.getType(0), "impl"); - - n_PackageDef. - setDescription("Package declaration"). - setRange(Phase.PARSER, Phase.UNKNOWN). - addField(t_TermTree, "packaged"). - addField(n_Template.getType(0), "impl"); - - n_ModuleDef. - setDescription("Module declaration"). - setRange(Phase.PARSER, Phase.REFCHECK). - addField(t_int, "mods", SymFlags). - addField(t_TermName, "name", SymName). - addField(t_TypeTree, "tpe"). - addField(n_Template.getType(0), "impl"); - - n_ValDef. - setDescription("Value declaration (var or let)"). - setRange(Phase.PARSER, Phase.END). - addField(t_int, "mods", SymFlags). - addField(t_TermName, "name", SymName). - addField(t_TypeTree, "tpe"). - addField(t_TermTree, "rhs"); - - - n_PatDef. - setDescription("Value declaration with patterns (val)"). - setRange(Phase.PARSER, Phase.DESUGARIZER). - addField(t_int, "mods"). - addField(t_TermTree, "pat"). - addField(t_TermTree, "rhs"); - - n_DefDef. - setDescription("Function declaration (def)"). - setRange(Phase.PARSER, Phase.END). - addField(t_int, "mods", SymFlags). - addField(t_TermName, "name", SymName). - addField(n_AbsTypeDef.getType(1), "tparams"). - addField(n_ValDef.getType(2), "vparams"). - addField(t_TypeTree, "tpe"). - addField(t_TermTree, "rhs"); - - n_AbsTypeDef. - setDescription("Type declaration"). - setRange(Phase.PARSER, Phase.END). // !!! needed for type params - addField(t_int, "mods", SymFlags). - addField(t_TypeName, "name", SymName). - addField(t_TypeTree, "rhs"). - addField(t_TypeTree, "lobound"); - - n_AliasTypeDef. - setDescription("Type alias"). - setRange(Phase.PARSER, Phase.EXPLICITOUTER). - addField(t_int, "mods", SymFlags). - addField(t_TypeName, "name", SymName). - addField(n_AbsTypeDef.getType(1), "tparams"). - addField(t_TypeTree, "rhs"); - - n_Import. - setDescription("Import declaration"). - setRange(Phase.PARSER, Phase.ANALYZER). - addField(t_TermTree, "expr"). - addField(t_Names, "selectors"); - - n_CaseDef. - setDescription("Case declaration"). - setRange(Phase.PARSER, Phase.TRANSMATCH). - addField(t_TermTree, "pat"). - addField(t_TermTree, "guard"). - addField(t_TermTree, "body"); - - n_Template. - setDescription("Instantiation templates"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTrees, "parents"). - addField(t_Trees, "body"); - - n_LabelDef. - setDescription("Labelled expression - the symbols in the array (must be Idents!) are those the label takes as argument"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermName, "name", SymName). - addField(n_Ident.getType(1), "params"). - addField(t_TermTree, "rhs"); - - n_Block. - setDescription("Block of expressions " + - "(semicolon separated expressions)"). - setRange(Phase.PARSER, Phase.END). - addField(t_Trees, "stats"). - addField(t_TermTree, "expr"); - - n_Sequence. - setDescription("Sequence of expressions (comma separated expressions)"). - setRange(Phase.PARSER, Phase.TRANSMATCH). - addField(t_TermTrees, "trees"); - - n_Alternative. - setDescription("Alternatives of expressions/patterns"). - setRange(Phase.PARSER, Phase.TRANSMATCH). - addField(t_TermTrees, "trees"); - - n_Bind. - setDescription("Bind of a variable to a rhs pattern, possibly recursive"). - setRange(Phase.PARSER, Phase.TRANSMATCH). - addField(t_TermName, "name", SymName). - addField(t_TermTree, "rhs"); - - - n_Visitor. - setDescription("Visitor (a sequence of cases)"). - setRange(Phase.PARSER, Phase.TRANSMATCH). - addField(n_CaseDef.getType(1), "cases"); - - - n_Function. - setDescription("Anonymous function"). - setRange(Phase.PARSER, Phase.ANALYZER). - addField(n_ValDef.getType(1), "vparams"). - addField(t_TermTree, "body"); - - n_Assign. - setDescription("Assignment"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTree, "lhs"). - addField(t_TermTree, "rhs"); - - n_If. - setDescription("Conditional expression"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTree, "cond"). - addField(t_TermTree, "thenp"). - addField(t_TermTree, "elsep"); - - n_Switch. - setDescription("Switch"). - setRange(Phase.REFCHECK, Phase.END). - addField(t_TermTree, "test"). - addField(t_ints, "tags"). - addField(t_TermTrees, "bodies"). - addField(t_TermTree, "otherwise"); - - n_Return. - setDescription("Return"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTree, "expr"); - - n_Throw. - setDescription("Throw"). - setRange(Phase.PARSER, Phase.ANALYZER). - addField(t_TermTree, "expr"); - - n_New. - setDescription("Instantiation"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTree, "init"); - - n_Create. - setDescription("Instance creation"). - setRange(Phase.ANALYZER, Phase.END). - addField(t_TermTree, "qualifier"). - addField(t_TypeTrees, "targs"); - - n_Typed. - setDescription("Type annotation"). - setRange(Phase.PARSER, Phase.EXPLICITOUTER). - addField(t_TermTree, "expr"). - addField(t_TypeTree, "tpe"); - - - n_TypeApply. - setDescription("Type application"). - setRange(Phase.PARSER, Phase.END). - addField(t_Tree, "fun"). - addField(t_TypeTrees, "args"); - - n_Apply. - setDescription("Value application"). - setRange(Phase.PARSER, Phase.END). - addField(t_Tree, "fun"). // !!! should be t_TermTree - addField(t_TermTrees, "args"); - - n_Super. - setDescription("Super reference"). - setRange(Phase.PARSER, Phase.END). - addField(t_TypeName, "qualifier", SymName). - addField(t_TypeName, "mixin"); - - n_This. - setDescription("Self reference"). - setRange(Phase.PARSER, Phase.END). - addField(t_TypeName, "qualifier", SymName); - - n_Select. - setDescription("Designator"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTree, "qualifier"). - addField(t_TestName, "selector", SymName); - - n_Ident. - setDescription("Identifier"). - setRange(Phase.PARSER, Phase.END). - addField(t_TestName, "name", SymName); - - n_Literal. - setDescription("Literal"). - setRange(Phase.PARSER, Phase.END). - addField(t_AConstant, "value"); - - n_TypeTerm. - setDescription("TypeTerm"). - setRange(Phase.PARSER, Phase.END); - - n_SingletonType. - setDescription("Singleton type"). - setRange(Phase.PARSER, Phase.REFCHECK). - addField(t_TermTree, "ref"); - - n_SelectFromType. - setDescription("Type selection"). - setRange(Phase.PARSER, Phase.REFCHECK). - addField(t_TypeTree, "qualifier"). - addField(t_TypeName, "selector", SymName); - - n_FunType. - setDescription("Function type"). - setRange(Phase.PARSER, Phase.REFCHECK). - addField(t_TypeTrees, "argtpes"). - addField(t_TypeTree, "restpe"); - - n_CompoundType. - setDescription("Object type (~ Template)"). - setRange(Phase.PARSER, Phase.REFCHECK). - addField(t_TypeTrees, "parents"). - addField(t_Trees, "refinements"); - - n_AppliedType. - setDescription("Applied type"). - setRange(Phase.PARSER, Phase.REFCHECK). - addField(t_TypeTree, "tpe"). - addField(t_TypeTrees, "args"); - - n_Try. - setDescription("Try Expression"). - setRange(Phase.PARSER, Phase.END). - addField(t_TermTree, "block"). - addField(t_TermTree, "catcher"). - addField(t_TermTree, "finalizer"); - } - - //######################################################################## - // Public Functions - - public static boolean isTree(Type type) { - switch (type) { - case Array(Type item): - return isTree(item); - case TreeType.Tree(_): - case TreeType.Node(_): - return true; - default: - return false; - } - } - - //######################################################################## - // Public Methods - - public Type getType(int rank) { - return getType(rank, Any); - } - - public Type getType(int rank, TreeKind kind) { - arrays = Math.max(arrays , rank); - return rank==0 ? TreeType.Tree(kind) : TreeType.Array(getType(rank-1)); - } - - public String getFormal(String name) { - return getType(0) + " " + name; - } - - //######################################################################## - // Private Methods - - private TreeNode node(String name, TreeKind kind, TreeSymbol symbol) { - TreeNode node = new TreeNode(name, kind, symbol); - list.add(node); - return node; - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/TreeField.java b/sources/meta/scalac/ast/TreeField.java deleted file mode 100644 index 19df9cb42e..0000000000 --- a/sources/meta/scalac/ast/TreeField.java +++ /dev/null @@ -1,63 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; -import meta.java.JavaWriter; - -/** This class describes a tree node field. */ -public class TreeField { - - //######################################################################## - // Public Fields - - public final Type type; - public final String name; - public final TreeFieldLink link; - - //######################################################################## - // Public Constructors - - public TreeField(Type type, String name) { - this(type, name, null); - } - - public TreeField(Type type, String name, TreeFieldLink link) { - this.type = type; - this.name = name; - this.link = link; - } - - //######################################################################## - // Public Function - - public static JavaWriter print(JavaWriter writer, TreeField[] fields, - boolean withType) - { - for (int i = 0; i < fields.length; i++) { - if (i > 0) writer.print(", "); - fields[i].print(writer, withType); - } - return writer; - } - - //######################################################################## - // Public Methods - - public JavaWriter print(JavaWriter writer, boolean withType) { - if (withType) writer.print(type).space(); - return writer.print(name); - } - - public String toString() { - return name; - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/TreeFieldLink.java b/sources/meta/scalac/ast/TreeFieldLink.java deleted file mode 100644 index 62e8dcfb10..0000000000 --- a/sources/meta/scalac/ast/TreeFieldLink.java +++ /dev/null @@ -1,60 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.JavaWriter; - -/** - * This class describes the possible links between a given field of a - * tree and the symbol of that tree. - */ -public class TreeFieldLink { - - //######################################################################## - // Public Cases - - /** Field is linked to the symbol's flags */ - public case SymFlags; - - /** Field is linked to the symbol's name */ - public case SymName; - - //######################################################################## - // Public Methods - - /** Returns the field or method to invoke to get the linked value. */ - public String getLink() { - switch (this) { - case SymFlags: - return "flags"; - case SymName: - return "name"; - default: - throw new Error("unknown case: " + this); - } - } - - /** Returns the name of this link. */ - public String toString() { - switch (this) { - case SymFlags: - return "flags"; - case SymName: - return "name"; - default: - throw new Error("unknown case: " + this); - } - } - - public JavaWriter print(JavaWriter writer, TreeField symbol) { - return writer.print(symbol.name).print('.').print(getLink()); - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/TreeKind.java b/sources/meta/scalac/ast/TreeKind.java deleted file mode 100644 index 35dcd0dd55..0000000000 --- a/sources/meta/scalac/ast/TreeKind.java +++ /dev/null @@ -1,63 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -/** This class enumerates the different kinds of tree nodes. */ -public class TreeKind { - - //######################################################################## - // Public Cases - - /** Designates a type, a term or anything else. */ - public case Any; - - /** Designates a type. */ - public case Type; - - /** Designates a term. */ - public case Term; - - /** Designates either a type or a term. */ - public case Dual; - - /** Designates either a type or a term (a test may indicate which one). */ - public case Test; - - /** Designates neither a type nor a term. */ - public case None; - - //######################################################################## - // Public Method - - public boolean isA(TreeKind that) { - switch (this) { - case Any : return true; - case Type: return that == Type; - case Term: return that == Term; - case Dual: return that == Type || that == Term || that == Dual; - case Test: return that == Type || that == Term || that == Dual; - case None: return that == None; - default : throw new Error(); - } - } - - public String toString() { - switch(this) { - case Any : return "Any"; - case Type: return "Type"; - case Term: return "Term"; - case Dual: return "Dual"; - case Test: return "Test"; - case None: return "None"; - default : throw new Error(); - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/TreeNode.java b/sources/meta/scalac/ast/TreeNode.java deleted file mode 100644 index 340eaa8109..0000000000 --- a/sources/meta/scalac/ast/TreeNode.java +++ /dev/null @@ -1,231 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; -import meta.java.JavaWriter; -import meta.scalac.Phase; - -/** This class describes a tree node. */ -public class TreeNode { - - //######################################################################## - // Public Fields - - public final String name; - public final TreeKind kind; - public final TreeSymbol symbol; - public String description; - public Phase start; - public Phase stop; - public TreeField[] fields; - public int arrays; - - //######################################################################## - // Public Constructors - - public TreeNode(String name, TreeKind kind, TreeSymbol symbol) { - this(name, kind, symbol, new TreeField[0]); - } - - public TreeNode(String name, TreeKind kind, TreeSymbol symbol, - TreeField[] fields) - { - this.name = name; - this.kind = kind; - this.symbol = symbol; - this.fields = fields; - } - - //######################################################################## - // Public Methods - Initializing - - public TreeNode setDescription(String description) { - this.description = description; - return this; - } - - public TreeNode setRange(Phase start, Phase stop) { - this.start = start; - this.stop = stop; - return this; - } - - public TreeNode noFields() { - fields = null; - return this; - } - - public TreeNode addField(Type type, String name) { - return addField(type, name, null); - } - - public TreeNode addField(Type type, String name, TreeFieldLink link) { - if (link != null && !hasSymbol()) - throw new Error("node "+this+" may not have linked fields"); - TreeField[] array = new TreeField[fields.length + 1]; - for (int i = 0; i < fields.length; i++) array[i] = fields[i]; - array[fields.length] = new TreeField(type, name, link); - fields = array; - return this; - } - - //######################################################################## - // Public Methods - Querying - - public Type getType(int rank) { - arrays = Math.max(arrays , rank); - return rank == 0 ? TreeType.Node(this) : Type.Array(getType(rank - 1)); - } - - public boolean hasExtClass() { - return hasSymbol(); - } - - public boolean hasSymbol() { - switch (symbol) { - case TreeSymbol.HasSym(_, _): - return true; - default: - return false; - } - } - - public boolean definesSymbol() { - switch (symbol) { - case TreeSymbol.HasSym(_, true): - return true; - default: - return false; - } - } - - public TreeField getSymbol() { - switch (symbol) { - case TreeSymbol.HasSym(TreeField field, _): - return field; - default: - return null; - } - } - - public boolean hasLinkedFields() { - for (int i = 0; i < fields.length; i++) - if (fields[i].link != null) return true; - return false; - } - - public TreeField[] getFields(boolean withoutLinkedFields) { - if (fields == null || !withoutLinkedFields) return fields; - int count = 0;; - for (int i = 0; i < fields.length; i++) - if (fields[i].link == null) count++; - TreeField[] array = new TreeField[count]; - for (int i = 0, j = 0; i < fields.length; i++) - if (fields[i].link == null) array[j++] = fields[i]; - return array; - } - - public String toString() { - return name; - } - - //######################################################################## - // Public Methods - Printing - - public JavaWriter printCase(JavaWriter writer, boolean withWildcards) { - writer.print("case "); - if (fields != null && withWildcards) { - writer.print(name).print('('); - for (int i = 0; i < fields.length; i++) { - if (i > 0) writer.print(", "); - writer.print("_"); - } - writer.print(')'); - } else { - printDecl(writer, null, false); - } - return writer.print(":").space(); - } - - public JavaWriter printNew(JavaWriter writer, boolean withSymbol) { - writer.print("new "); - if (hasExtClass()) writer.print("Ext"); - return printCall(writer, null, withSymbol); - } - - public JavaWriter printMethod(JavaWriter writer, String prefix, - boolean withSymbol) - { - return printMethod(writer, prefix, withSymbol, withSymbol); - } - - public JavaWriter printMethod(JavaWriter writer, String prefix, - boolean withSymbol, boolean withoutLinkedFields) - { - writer.print("public ").print(name).space(); - return printDecl(writer, prefix, withSymbol, withoutLinkedFields); - } - - public JavaWriter printDecl(JavaWriter writer, String prefix, - boolean withSymbol) - { - return printDecl(writer, prefix, withSymbol, withSymbol); - } - - public JavaWriter printDecl(JavaWriter writer, String prefix, - boolean withSymbol, boolean withoutLinkedFields) - { - return printPattern(writer,true,prefix,withSymbol,withoutLinkedFields); - } - - public JavaWriter printCall(JavaWriter writer, String prefix, - boolean withSymbol) - { - return printCall(writer, prefix, withSymbol, withSymbol); - } - - public JavaWriter printCall(JavaWriter writer, String prefix, - boolean withSymbol, boolean withoutLinkedFields) - { - return printPattern( - writer, false, prefix, withSymbol, withoutLinkedFields); - } - - public JavaWriter printPattern(JavaWriter writer, boolean withType, - String prefix, boolean withSymbol, boolean withoutLinkedFields) - { - writer.print(name); - if (fields != null || prefix != null || withSymbol) { - writer.print('('); - printFields(writer,withType,prefix,withSymbol,withoutLinkedFields); - writer.print(')'); - } - return writer; - } - - public JavaWriter printFields(JavaWriter writer, boolean withType, - String prefix, boolean withSymbol, boolean withoutLinkedFields) - { - TreeField[] fields = getFields(withoutLinkedFields); - if (prefix != null) { - writer.print(prefix); - if (withSymbol || (fields != null && fields.length > 0)) - writer.print(", "); - } - if (withSymbol) { - getSymbol().print(writer, withType); - if (fields != null && fields.length > 0) writer.print(", "); - } - TreeField.print(writer, fields, withType); - return writer; - } - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/TreeSymbol.java b/sources/meta/scalac/ast/TreeSymbol.java deleted file mode 100644 index 1e53be4013..0000000000 --- a/sources/meta/scalac/ast/TreeSymbol.java +++ /dev/null @@ -1,24 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -/** This class describes the symbol stored in some tree nodes. */ -public class TreeSymbol { - - //######################################################################## - // Public Cases - - /** Indicates the absence of symbol. */ - public case NoSym; - - /** Indicates the presence of a symbol. */ - public case HasSym(TreeField field, boolean isDef); - - //######################################################################## -} diff --git a/sources/meta/scalac/ast/TreeType.java b/sources/meta/scalac/ast/TreeType.java deleted file mode 100644 index 52c2e6d9b3..0000000000 --- a/sources/meta/scalac/ast/TreeType.java +++ /dev/null @@ -1,65 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.ast; - -import meta.java.Type; - -/** This class describes types used in tree nodes. */ -public class TreeType extends Type { - - //######################################################################## - // Private Constants - - private static final String NAME_PACKAGE = "scalac.util"; - private static final String NAME_NAME = "Name"; - private static final String NAME_FULLNAME = NAME_PACKAGE + "." + NAME_NAME; - private static final String TREE_PACKAGE = "scalac.ast"; - private static final String TREE_NAME = "Tree"; - private static final String TREE_FULLNAME = TREE_PACKAGE + "." + TREE_NAME; - - //######################################################################## - // Public Cases - - public case Name(TreeKind kind); - public case Tree(TreeKind kind); - public case Node(TreeNode node); - - //######################################################################## - // Public Methods - - /** Returns the type's (possibly fully qualified) name. */ - public String getName(boolean qualified) { - switch (this) { - case Name(_): - return qualified ? NAME_FULLNAME : NAME_NAME; - case Tree(_): - return qualified ? TREE_FULLNAME : TREE_NAME; - case Node(TreeNode node): - return qualified ? TREE_FULLNAME + "." + node.name : node.name; - default: - return super.getName(qualified); - } - } - - /** Returns the type's owner (its package or enclosing type). */ - public String getOwner() { - switch (this) { - case Name(_): - return NAME_PACKAGE; - case Tree(_): - return TREE_PACKAGE; - case Node(TreeNode node): - return TREE_FULLNAME; - default: - return super.getOwner(); - } - } - - //######################################################################## -} diff --git a/sources/meta/scalac/checkers/MetaCheckTreeNodes.java b/sources/meta/scalac/checkers/MetaCheckTreeNodes.java deleted file mode 100644 index 11ad75d77a..0000000000 --- a/sources/meta/scalac/checkers/MetaCheckTreeNodes.java +++ /dev/null @@ -1,158 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.scalac.checkers; - -import meta.java.Type; -import meta.scalac.ast.AbstractTreeCaseExpander; -import meta.scalac.ast.TreeKind; -import meta.scalac.ast.TreeType; -import meta.scalac.ast.TreeNode; -import meta.scalac.ast.TreeField; -import meta.scalac.ast.TreeFieldLink; - -public class MetaCheckTreeNodes extends AbstractTreeCaseExpander { - - //######################################################################## - // Public Methods - - public void printTreeCaseBody(TreeNode node) { - if (node.fields != null) { - for (int i = 0; i < node.fields.length; i++) { - TreeField field = node.fields[i]; - printCheckField(node, field.type, field.name, "i"); - } - if (node.hasLinkedFields()) { - writer.println("Symbol symbol = tree.symbol();"); - writer.print("if (symbol != null)").lbrace(); - for (int i = 0; i < node.fields.length; i++) - if (node.fields[i].link != null) - printCheckFieldLink(node.fields[i]); - writer.rbrace(); - } - } - printCheckNode(node); - writer.println("return;"); - } - - private void printCheckNode(TreeNode node) { - if (node.start.constant != null) { - writer.println("assert global.currentPhase.id >= " + - "phases."+node.start.constant + ".id() :").indent(); - writer.println("\"cannot create instance of " + node.name + - " before phase " + node.start.name + ", \" +"); - writer.println( - "\"current phase is \" + " + "global.currentPhase;").undent(); - } - if (node.stop.constant != null) { - writer.println("assert global.currentPhase.id <= " + - "phases."+node.stop.constant + ".id() :").indent(); - writer.println("\"cannot create instance of " + node.name + - " after phase " + node.stop.name + ", \" +"); - writer.println( - "\"current phase is \" + " + "global.currentPhase;").undent(); - } - } - - private void printCheckField(TreeNode node,Type type,String name,String i){ - if (type.isPrimitive()) return; - writer.println("assert " + name + " != null :").indent(); - printNullValue(node, name); - writer.println(";").undent(); - switch (type) { - case Reference(_, _): - break; - - case Array(Type item): - writer.print( - "for (int "+i+" = 0; "+i+" < "+name+".length; "+i+"++)"); - writer.lbrace(); - printCheckField(node, item, name+"["+i+"]", i+"i"); - writer.rbrace(); - break; - - case TreeType.Name(TreeKind kind): - if (kind != TreeKind.Any && kind != TreeKind.Test) { - writer.println("assert " + name + ".is" + kind + "Name() :") - .indent(); - printWrongKind(node, name, kind); - writer.println(";").undent(); - } - break; - - case TreeType.Tree(TreeKind kind): - if (kind != TreeKind.Any) { - writer.println("assert " + - name + ".is" + kind + "() :").indent(); - printWrongKind(node, name, kind); - writer.println(";").undent(); - } - break; - - case TreeType.Node(_): - break; - - default: - throw new Error(type.getClass().getName()); - } - } - - private void printCheckFieldLink(TreeField field) { - String getter = field.link.getLink(); - writer.println("assert symbol." +getter+ " == " +field+ " :").indent(); - writer.println("\"symbol and tree " + field.link + " differ: \"+" + - "symbol." + getter + "+\" != \"+" +field+ ";"); - writer.undent(); - } - - private void printNullValue(TreeNode node, String field) { - String expanded = getExpandedField(field); - writer.print("\"field " +expanded+ " of class " +node+ " is null\""); - } - - private void printWrongKind(TreeNode node, String field, TreeKind kind) { - String expanded = getExpandedField(field); - writer.println("\"field " + expanded + " of class " + node + - " is not of kind " + kind + ", \" +"); - writer.print("\"found: \" + Debug.show("+field+")"); - // !!! " + \" of kind \" + kind("+field+")"; - } - - private String getExpandedField(String field) { - int begin = field.indexOf('['); - if (begin < 0) return field; - StringBuffer buffer = new StringBuffer(field.substring(0, begin)); - for (int end; (end = field.indexOf(']', begin)) >= 0; begin = end + 1){ - String index = field.substring(begin + 1, end); - buffer.append("[\"+").append(index).append("+\"]"); - } - return buffer.toString(); - } - - //######################################################################## -} - - -/* !!! - - protected static String kind(Tree tree) { - switch (tree) { - case Select(_, Name name): return kind(name); - case Ident(Name name): return kind(name); - } - return "unknown"; - } - - protected static String kind(Name name) { - if (name.isTypeName()) return "Type"; - if (name.isTermName()) return "Term"; - if (name.isConstrName()) return "Constr"; - return "unknown"; - } - -*/ diff --git a/sources/meta/util/AbstractFileExpander.java b/sources/meta/util/AbstractFileExpander.java deleted file mode 100644 index d77f6b81b3..0000000000 --- a/sources/meta/util/AbstractFileExpander.java +++ /dev/null @@ -1,126 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.util; - -import java.io.File; - -/** A base class for file expanders. */ -public abstract class AbstractFileExpander { - - //######################################################################## - // Private Constants - - /** The meta package */ - private static final String meta = "meta"; - - /** The meta name prefix */ - private static final String Meta = "Meta"; - - //######################################################################## - // Public Methods - - /** Returns the TextWriter in which this expander writes. */ - public abstract TextWriter getTextWriter(); - - /** - * Returns the package associated with this expander or null if - * there no such package. The default implementation returns the - * package of this instance's class. If the outermost package is - * named "meta", this package is omitted. - */ - public String getPackage() { - String fullname = getClass().getName(); - int end = fullname.lastIndexOf('.'); - if (end < 0) return null; - int start = fullname.startsWith(meta + ".") ? meta.length() + 1 : 0; - return fullname.substring(start, end); - } - - /** - * Returns the name associated with this expander. The default - * implementation returns the name of this instance's class. If - * that name starts with "Meta", this prefix is omitted. - */ - public String getName() { - String fullname = getClass().getName(); - int index = fullname.lastIndexOf('.'); - String name = index < 0 ? fullname : fullname.substring(index + 1); - return name.startsWith(Meta) ? name.substring(Meta.length()) : name; - } - - /** - * Returns the directory of the target file. The default - * implementation returns the directory corresponding to the - * this instance's associated package. - */ - public String getTargetDirectory() { - String peckage = getPackage(); - return peckage == null ? "." : peckage.replace('.',File.separatorChar); - } - - /** - * Returns the base name of the target file. The default - * implementation returns this instance's associated name. - */ - public String getTargetBaseName() { - return getName(); - } - - /** - * Returns the suffix of the target file or null if it has no - * suffix. The default implementation returns null. - */ - public String getTargetSuffix() { - return null; - } - - /** Returns the target file. */ - public File getTargetFile(File root) { - String suffix = getTargetSuffix(); - String name = getTargetBaseName(); - if (suffix != null) name = name + "." + suffix; - return new File(new File(root, getTargetDirectory()), name); - } - - /** - * Returns the directory of the source file. The default - * implementation returns the directory of the target file. - */ - public String getSourceDirectory() { - return getTargetDirectory(); - } - - /** - * Returns the base name of the source file. The default - * implementation returns this instance's associated name. - */ - public String getSourceBaseName() { - return getName(); - } - - /** - * Returns the suffix of the source file or null if it has no - * suffix. The default implementation returns the target suffix - * suffixed with ".tmpl". - */ - public String getSourceSuffix() { - String suffix = getTargetSuffix(); - return (suffix == null ? "" : suffix + ".") + "tmpl"; - } - - /** Returns the source file. */ - public File getSourceFile(File root) { - String suffix = getSourceSuffix(); - String name = getSourceBaseName(); - if (suffix != null) name = name + "." + suffix; - return new File(new File(root, getSourceDirectory()), name); - } - - //######################################################################## -} diff --git a/sources/meta/util/AbstractMain.java b/sources/meta/util/AbstractMain.java deleted file mode 100644 index b7a3e190ff..0000000000 --- a/sources/meta/util/AbstractMain.java +++ /dev/null @@ -1,38 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.util; - -/** A base class for Java programs. */ -public abstract class AbstractMain { - - //######################################################################## - // Public Functions - - public static String script() { - StackTraceElement[] stack = new Throwable().getStackTrace(); - return stack[stack.length - 1].getClassName(); - } - - public static Error abort() { - System.exit(1); - throw new Error("abort"); - } - - public static Error abort(String error) { - System.err.println(script() + ": " + error); - System.exit(1); - throw new Error(); - } - - public static Error abort(Exception exception) { - return abort("caught exception " + exception.toString()); - } - - //######################################################################## -} diff --git a/sources/meta/util/TextExpander.java b/sources/meta/util/TextExpander.java deleted file mode 100644 index 5fe7fbdb38..0000000000 --- a/sources/meta/util/TextExpander.java +++ /dev/null @@ -1,275 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.util; - -import java.io.File; -import java.io.FileReader; -import java.io.BufferedReader; -import java.io.IOException; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; - -/** A macro expander with support for indentation */ -public class TextExpander { - - //######################################################################## - // Public Constants - - /** Default macro name prefix */ - public static final String MACRO_PREFIX = "print"; - - /** Default macro left quote */ - public static final String MACRO_LQUOTE = "{#"; - - /** Default macro right quote */ - public static final String MACRO_RQUOTE = "#}"; - - /** Do not edit warning */ - public static final String DO_NOT_EDIT = - "DO NOT EDIT. Automatically generated file!"; - - //######################################################################## - // Private Constants - - /** An empty array of Classes */ - private static final Class [] NO_PARAMS = new Class[0]; - - /** An empty array of Objects */ - private static final Object[] NO_ARGS = new Object[0]; - - //######################################################################## - // Private Fields - - /** The output text writer */ - private final TextWriter writer; - - /** The macro expander */ - private final Object expander; - - /** The current macro name prefix */ - private String prefix; - - /** The current macro left quote */ - private String lquote; - - /** The current macro right quote */ - private String rquote; - - /** The current input name */ - private String name; - - /** The current input line number */ - private int line; - - /** The current error count */ - private int errors; - - //######################################################################## - // Public Constructors - - /** Creates a new TextExpander. */ - public TextExpander(TextWriter writer, Object expander) { - this.writer = writer; - this.expander = expander; - this.prefix = MACRO_PREFIX; - this.lquote = MACRO_LQUOTE; - this.rquote = MACRO_RQUOTE; - } - - //######################################################################## - // Public Methods - Text expansion - - /** Expands the text from the given file. */ - public void expandText(File file) { - setInputName(file.toString()); - setInputLine(0); - try { - BufferedReader reader = new BufferedReader(new FileReader(file)); - expandText(reader); - reader.close(); - } catch (IOException exception) { - error("input error", exception); - } - } - - /** Expands the text from the given character stream. */ - public void expandText(BufferedReader reader) { - try { - for (String line; (line = reader.readLine()) != null;) { - this.line++; - expandLine(line); - } - } catch (IOException exception) { - error("input error", exception); - } - } - - /** Expands the given line. */ - public void expandLine(String line) { - int index = 0; - int column = 0; - for (; index < line.length(); index++) { - switch (line.charAt(index)) { - case ' ' : column += 1; continue; - case '\t': column += 8 - (column % 8); continue; - } - break; - } - if (index < line.length()) { - int width = writer.getIndentWidth(); - writer.setIndentLevel(column / width); - for (int i = 0; i < column % width; i++) writer.print(' '); - line = line.substring(index); - if (line.indexOf("$Id") >= 0) - line = line.replaceFirst("[$]Id.*[$]", DO_NOT_EDIT); - expand(line); - } - writer.println(); - } - - /** Expands the given string. */ - public void expand(String input) { - int start = 0; - while (true) { - int lindex = input.indexOf(lquote, start); - if (lindex < 0) break; - int rindex = input.indexOf(rquote, lindex + lquote.length()); - if (rindex < 0) { error("unclosed macro"); break; } - String macro = input.substring(lindex + lquote.length(), rindex); - if (macro.indexOf(lquote) >= 0) { error("unclosed macro"); break; } - if (start < lindex) writer.print(input.substring(start, lindex)); - expandMacro(macro); - start = rindex + rquote.length(); - } - if (start < input.length()) writer.print(input.substring(start)); - } - - //######################################################################## - // Public Methods - Macro expansion - - /** Expands the given macro. */ - public void expandMacro(String macro) { - String member = prefix + macro; - Class clasz = expander.getClass(); - try { - expandMacro(macro, clasz.getMethod(member, NO_PARAMS)); - } catch (NoSuchMethodException exception) { - error("macro '" + macro + "' is undefined"); - writer.print(lquote + macro + rquote); - } - } - - /** Expands the given macro by invoking the given method. */ - public void expandMacro(String macro, Method method) { - try { - method.invoke(expander, NO_ARGS); - } catch (IllegalAccessException exception) { - error("macro '" + macro + "' could not access method " + method); - writer.print(lquote + macro + rquote); - } catch (InvocationTargetException exception) { - error("macro '" + macro + "' raised an exception"); - exception.getTargetException().printStackTrace(); - } - } - - //######################################################################## - // Public Methods - Error messages - - /** Prints an error message. */ - public void error(String error) { - String prefix = name != null ? name + ":" : "error:"; - if (line > 0) prefix = prefix + line + ":"; - System.err.println(prefix + " " + error); - errors++; - } - - /** Prints an error message. */ - public void error(String error, Throwable exception) { - if (exception.getMessage() != null) - error(exception.getMessage()); - else - error(error + " (" + exception.getClass().getName() + ")"); - } - - //######################################################################## - // Public Methods - Getters - - /** Returns the output text writer. */ - public TextWriter getOutputWriter() { - return writer; - } - - /** Returns the macro expander. */ - public Object getMacroExpander() { - return expander; - } - - /** Returns the current macro name prefix. */ - public String getMacroPrefix() { - return prefix; - } - - /** Returns the current macro left quote. */ - public String getMacroLeftQuote() { - return lquote; - } - - /** Returns the current macro right quote. */ - public String getMacroRightQuote() { - return lquote; - } - - /** Returns the current input name. */ - public String getInputName() { - return name; - } - - /** Returns the current input line. */ - public int getInputLine() { - return line; - } - - /** Returns the current error count. */ - public int getErrorCount() { - return errors; - } - - //######################################################################## - // Public Methods - Setters - - /** Sets the current macro name prefix. */ - public void setMacroPrefix(String prefix) { - this.prefix = prefix; - } - - /** Sets the current macro quotes. */ - public void setMacroQuotes(String lquote, String rquote) { - this.lquote = lquote; - this.rquote = rquote; - } - - /** Sets the current input name. */ - public void setInputName(String name) { - this.name = name; - } - - /** Sets the current input line. */ - public void setInputLine(int line) { - this.line = line; - } - - /** Sets the current error count. */ - public void setErrorCount(int errors) { - this.errors = errors; - } - - //######################################################################## -} diff --git a/sources/meta/util/TextWriter.java b/sources/meta/util/TextWriter.java deleted file mode 100644 index 2884848e83..0000000000 --- a/sources/meta/util/TextWriter.java +++ /dev/null @@ -1,248 +0,0 @@ -/* ____ ____ ____ ____ ______ *\ -** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** -** /_____/\____/\___/\____/____/ ** -\* */ - -// $Id$ - -package meta.util; - -/** A string generator with support for indentation and spacing. */ -public class TextWriter { - - //######################################################################## - // Private Constants - - /** The line separator */ - private static final String LINE = System.getProperty("line.separator"); - - /** The default width of an indentation level */ - private static final String STEP = " "; - - //######################################################################## - // Private Fields - - /** The output buffer */ - private final StringBuffer buffer; - - /** The width of an indentation level */ - private final String step; - - /** The current indentation level */ - private int level; - - /** Do we need to align? */ - private boolean align; - - /** Do we need to print a white space? */ - private boolean space; - - /** Is there already a empty line? */ - private boolean line; - - //######################################################################## - // Public Constructors - - /** Creates a new TextWriter. */ - public TextWriter() { - this(new StringBuffer()); - } - - /** Creates a new TextWriter. */ - public TextWriter(String step) { - this(new StringBuffer(), step); - } - - /** Creates a new TextWriter. */ - public TextWriter(String step, int level) { - this(new StringBuffer(), step, level); - } - - /** Creates a new TextWriter. */ - public TextWriter(StringBuffer buffer) { - this(buffer, STEP, 0); - } - - /** Creates a new TextWriter. */ - public TextWriter(StringBuffer buffer, String step) { - this(buffer, step, 0); - } - - /** Creates a new TextWriter. */ - public TextWriter(StringBuffer buffer, String step, int level) { - this.buffer = buffer; - this.step = step; - this.level = level; - this.align = false; - this.space = false; - this.line = false; - } - - //######################################################################## - // Public Methods - Printing - - /** Prints a new line. */ - public TextWriter println() { - return line(); - } - - /** Prints the boolean value followed by a new line. */ - public TextWriter println(boolean value) { - return print(value).line(); - } - - /** Prints the byte value followed by a new line. */ - public TextWriter println(byte value) { - return print(value).line(); - } - - /** Prints the short value followed by a new line. */ - public TextWriter println(short value) { - return print(value).line(); - } - - /** Prints the char value followed by a new line. */ - public TextWriter println(char value) { - return print(value).line(); - } - - /** Prints the int value followed by a new line. */ - public TextWriter println(int value) { - return print(value).line(); - } - - /** Prints the long value followed by a new line. */ - public TextWriter println(long value) { - return print(value).line(); - } - - /** Prints the float value followed by a new line. */ - public TextWriter println(float value) { - return print(value).line(); - } - - /** Prints the double value followed by a new line. */ - public TextWriter println(double value) { - return print(value).line(); - } - - /** Prints the string followed by a new line. */ - public TextWriter println(String value) { - return print(value).line(); - } - - /** Prints the boolean value. */ - public TextWriter print(boolean value) { - return print(String.valueOf(value)); - } - - /** Prints the byte value. */ - public TextWriter print(byte value) { - return print(String.valueOf(value)); - } - - /** Prints the short value. */ - public TextWriter print(short value) { - return print(String.valueOf(value)); - } - - /** Prints the char value. */ - public TextWriter print(char value) { - return print(String.valueOf(value)); - } - - /** Prints the int value. */ - public TextWriter print(int value) { - return print(String.valueOf(value)); - } - - /** Prints the long value. */ - public TextWriter print(long value) { - return print(String.valueOf(value)); - } - - /** Prints the float value. */ - public TextWriter print(float value) { - return print(String.valueOf(value)); - } - - /** Prints the long value. */ - public TextWriter print(double value) { - return print(String.valueOf(value)); - } - - /** Prints the string. */ - public TextWriter print(String value) { - if (align) for (int i = 0; i < level; i++) buffer.append(step); - if (space) buffer.append(' '); - buffer.append(value); - align = false; - space = false; - line = false; - return this; - } - - //######################################################################## - // Public Methods - Formating - - /** Returns the indentation width. */ - public int getIndentWidth() { - return step == null ? -1 : step.length(); - } - - /** Returns the indentation level. */ - public int getIndentLevel() { - return level; - } - - /** Sets the indentation level. */ - public TextWriter setIndentLevel(int level) { - this.level = level; - return this; - } - - /** Increases the indentation level by one. */ - public TextWriter indent() { - level++; - return this; - } - - /** Decreases the indentation level by one. */ - public TextWriter undent() { - level--; - return this; - } - - /** Starts a new line. */ - public TextWriter line() { - if (step == null) return space(); - if (line) return this; - buffer.append(LINE); - line = align; - align = true; - space = false; - return this; - } - - /** Inserts a white space. */ - public TextWriter space() { - space = !align; - return this; - } - - //######################################################################## - // Public Methods - Accessing - - /** Returns the underlying StringBuffer. */ - public StringBuffer getBuffer() { - return buffer; - } - - /** Returns the generated string. */ - public String toString() { - return buffer.toString(); - } - - //######################################################################## -} |