summaryrefslogtreecommitdiff
path: root/sources/scalac/atree
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-11-05 16:31:19 +0000
committerpaltherr <paltherr@epfl.ch>2003-11-05 16:31:19 +0000
commit70245d69240b1de543dc644ea2fd29008eb74112 (patch)
tree26e5aed403b31ff5acccfc3b0d4feacdd761d127 /sources/scalac/atree
parentbdaca266612e6b878379253d57358ce672953e52 (diff)
downloadscala-70245d69240b1de543dc644ea2fd29008eb74112.tar.gz
scala-70245d69240b1de543dc644ea2fd29008eb74112.tar.bz2
scala-70245d69240b1de543dc644ea2fd29008eb74112.zip
- Added atree/AClass.java
- Added atree/AField.java - Added atree/AMember.java - Added atree/AMethod.java - Added atree/ARepository.java
Diffstat (limited to 'sources/scalac/atree')
-rw-r--r--sources/scalac/atree/AClass.java139
-rw-r--r--sources/scalac/atree/AField.java54
-rw-r--r--sources/scalac/atree/AMember.java87
-rw-r--r--sources/scalac/atree/AMethod.java74
-rw-r--r--sources/scalac/atree/ARepository.java51
-rw-r--r--sources/scalac/atree/ATreePrinter.java91
6 files changed, 496 insertions, 0 deletions
diff --git a/sources/scalac/atree/AClass.java b/sources/scalac/atree/AClass.java
new file mode 100644
index 0000000000..66cf4693e1
--- /dev/null
+++ b/sources/scalac/atree/AClass.java
@@ -0,0 +1,139 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.atree;
+
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+import scalac.symtab.Symbol;
+import scalac.symtab.Type;
+import scalac.util.Debug;
+
+/** This class represents an attributed class. */
+public class AClass extends ARepository {
+
+ //########################################################################
+ // Private Fields
+
+ /** The class symbol */
+ private final Symbol symbol;
+
+ /** The symbol to field map */
+ private final Map/*<Symbol,AField>*/ fields;
+
+ /** The symbol to method map */
+ private final Map/*Symbol,AMethod*/ methods;
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public AClass(Symbol symbol) {
+ this.symbol = symbol;
+ this.fields = new LinkedHashMap();
+ this.methods = new LinkedHashMap();
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Returns the symbol of this class. */
+ public Symbol symbol() {
+ return symbol;
+ }
+
+ /** Is this class public? */
+ public boolean isPublic() {
+ return symbol().isPublic();
+ }
+
+ /** Is this class private? */
+ public boolean isPrivate() {
+ return symbol().isPrivate();
+ }
+
+ /** Is this class protected? */
+ public boolean isProtected() {
+ return symbol().isProtected();
+ }
+
+ /** Is this class final? */
+ public boolean isFinal() {
+ return false; // !!!
+ }
+
+ /** Is this class abstract? */
+ public boolean isAbstract() {
+ return symbol.isAbstractClass();
+ }
+
+ /** Is this class an interface? */
+ public boolean isInterface() {
+ return symbol.isInterface();
+ }
+
+ /** Is this class deprecated? */
+ public boolean isDeprecated() {
+ return false; // !!!
+ }
+
+ /** Is this class synthetic? */
+ public boolean isSynthetic() {
+ return symbol().isSynthetic();
+ }
+
+ /** Adds the given field to this class. */
+ public void addField(AField field) {
+ assert !fields.containsKey(field.symbol()): field;
+ fields.put(field.symbol(), field);
+ }
+
+ /** Adds the given method to this class. */
+ public void addMethod(AMethod method) {
+ assert !methods.containsKey(method.symbol()): method;
+ methods.put(method.symbol(), method);
+ }
+
+ /** Returns the fields of this class. */
+ public AField[] fields() {
+ return (AField[])fields.values().toArray(new AField[fields.size()]);
+ }
+
+ /** Returns the methods of this class. */
+ public AMethod[] methods() {
+ return(AMethod[])methods.values().toArray(new AMethod[methods.size()]);
+ }
+
+ /** Returns the type parameters of this class. */
+ public Symbol[] tparams() {
+ return symbol.typeParams();
+ }
+
+ /** Returns the value parameters of this class. */
+ public Symbol[] vparams() {
+ return symbol.valueParams();
+ }
+
+ /** Returns the parent types of this class. */
+ public Type[] parents() {
+ switch (symbol.info()) {
+ case CompoundType(Type[] parts, _):
+ return parts;
+ default:
+ throw Debug.abort("illegal case", symbol.info());
+ }
+ }
+
+ /** Returns a string representation of this class. */
+ public String toString() {
+ return new ATreePrinter().printClass(this).toString();
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/atree/AField.java b/sources/scalac/atree/AField.java
new file mode 100644
index 0000000000..bbc27f7063
--- /dev/null
+++ b/sources/scalac/atree/AField.java
@@ -0,0 +1,54 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.atree;
+
+import scalac.symtab.Symbol;
+import scalac.symtab.Type;
+
+/** This class represents an attributed field. */
+public class AField extends AMember {
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public AField(Symbol symbol, boolean isStatic) {
+ super(symbol, isStatic);
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Is this field final? */
+ public boolean isFinal() {
+ return false; // !!!
+ }
+
+ /** Is this field volatile? */
+ public boolean isVolatile() {
+ return false; // !!!
+ }
+
+ /** Is this field transient? */
+ public boolean isTransient() {
+ return false; // !!!
+ }
+
+ /** Returns the type of this field. */
+ public Type type() {
+ return symbol().type();
+ }
+
+ /** Returns a string representation of this field. */
+ public String toString() {
+ return new ATreePrinter().printField(this).toString();
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/atree/AMember.java b/sources/scalac/atree/AMember.java
new file mode 100644
index 0000000000..4275180a4d
--- /dev/null
+++ b/sources/scalac/atree/AMember.java
@@ -0,0 +1,87 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.atree;
+
+import scalac.symtab.Symbol;
+
+/** This class represents an attributed class member. */
+public abstract class AMember {
+
+ //########################################################################
+ // Private Fields
+
+ /** The member symbol */
+ private final Symbol symbol;
+
+ /** The static flag */
+ private final boolean isStatic;
+
+ /** The member code */
+ private ACode code;
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public AMember(Symbol symbol, boolean isStatic) {
+ this.symbol = symbol;
+ this.isStatic = isStatic;
+ this.code = ACode.Void;
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Returns the symbol of this member. */
+ public Symbol symbol() {
+ return symbol;
+ }
+
+ /** Is this member public? */
+ public boolean isPublic() {
+ return symbol().isPublic();
+ }
+
+ /** Is this member private? */
+ public boolean isPrivate() {
+ return symbol().isPrivate();
+ }
+
+ /** Is this member protected? */
+ public boolean isProtected() {
+ return symbol().isProtected();
+ }
+
+ /** Is this member static? */
+ public boolean isStatic() {
+ return isStatic;
+ }
+
+ /** Is this member deprecated? */
+ public boolean isDeprecated() {
+ return false; // !!!
+ }
+
+ /** Is this member synthetic? */
+ public boolean isSynthetic() {
+ return symbol().isSynthetic();
+ }
+
+ /** Returns the member code. */
+ public ACode code() {
+ return code;
+ }
+
+ /** Sets the member code. */
+ public void setCode(ACode code) {
+ this.code = code;
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/atree/AMethod.java b/sources/scalac/atree/AMethod.java
new file mode 100644
index 0000000000..332f2284d4
--- /dev/null
+++ b/sources/scalac/atree/AMethod.java
@@ -0,0 +1,74 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.atree;
+
+import scalac.symtab.Symbol;
+import scalac.symtab.Type;
+
+/** This class represents an attributed method. */
+public class AMethod extends AMember {
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public AMethod(Symbol symbol, boolean isStatic) {
+ super(symbol, isStatic);
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Is this method final? */
+ public boolean isFinal() {
+ return symbol().isMethodFinal();
+ }
+
+ /** Is this method synchronized? */
+ public boolean isSynchronized() {
+ return false; // !!!
+ }
+
+ /** Is this method native? */
+ public boolean isNative() {
+ return false; // !!!
+ }
+
+ /** Is this method abstract? */
+ public boolean isAbstract() {
+ return symbol().isDeferred();
+ }
+
+ /** Is this method FP-strict? */
+ public boolean isStrictFP() {
+ return false; // !!!
+ }
+
+ /** Returns the type parameters of this method. */
+ public Symbol[] tparams() {
+ return symbol().type().typeParams();
+ }
+
+ /** Returns the value parameters of this method. */
+ public Symbol[] vparams() {
+ return symbol().type().valueParams();
+ }
+
+ /** Returns the result type of this method. */
+ public Type result() {
+ return symbol().type().resultType();
+ }
+
+ /** Returns a string representation of this method. */
+ public String toString() {
+ return new ATreePrinter().printMethod(this).toString();
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/atree/ARepository.java b/sources/scalac/atree/ARepository.java
new file mode 100644
index 0000000000..c1468a85a8
--- /dev/null
+++ b/sources/scalac/atree/ARepository.java
@@ -0,0 +1,51 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.atree;
+
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+/** This class represents a repository of attributed classes. */
+public class ARepository {
+
+ //########################################################################
+ // Private Fields
+
+ /** The symbol to class map */
+ private final Map/*<Symbol,AClass>*/ classes;
+
+ //########################################################################
+ // Public Constructors
+
+ /** Initializes this instance. */
+ public ARepository() {
+ this.classes = new LinkedHashMap();
+ }
+
+ //########################################################################
+ // Public Methods
+
+ /** Adds the given class to this repository. */
+ public void addClass(AClass clasz) {
+ assert !classes.containsKey(clasz.symbol()): clasz;
+ classes.put(clasz.symbol(), clasz);
+ }
+
+ /** Returns the classes of this repository. */
+ public AClass[] classes() {
+ return (AClass[])classes.values().toArray(new AClass[classes.size()]);
+ }
+
+ /** Returns a string representation of this repository. */
+ public String toString() {
+ return new ATreePrinter().printRepository(this).toString();
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/atree/ATreePrinter.java b/sources/scalac/atree/ATreePrinter.java
index 11c8a51d7e..971ede91ac 100644
--- a/sources/scalac/atree/ATreePrinter.java
+++ b/sources/scalac/atree/ATreePrinter.java
@@ -237,6 +237,97 @@ public class ATreePrinter {
//########################################################################
// Public Methods - Printing trees
+ /** Prints the repository. */
+ public ATreePrinter printRepository(ARepository repository) {
+ AClass[] classes = repository.classes();
+ for (int i = 0; i < classes.length; i++) printClass(classes[i]);
+ return this;
+ }
+
+ /** Prints the class. */
+ public ATreePrinter printClass(AClass clasz) {
+ printClassModifiers(clasz);
+ print(clasz.isInterface() ? "interface" : "class").space();
+ printSymbol(clasz.symbol());
+ Symbol[] tparams = clasz.tparams();
+ if (tparams.length != 0) symtab.printTypeParams(tparams);
+ Symbol[] vparams = clasz.vparams();
+ if (vparams.length != 0) symtab.printValueParams(vparams);
+ if (clasz.symbol().typeOfThis() != clasz.symbol().thisType())
+ space().print(':').printType(clasz.symbol().typeOfThis());
+ space().print("extends").space();
+ symtab.printTypes(clasz.parents()," with ");
+ lbrace();
+ printRepository(clasz);
+ AField[] fields = clasz.fields();
+ for (int i = 0; i < fields.length; i++) printField(fields[i]);
+ AMethod[] methods = clasz.methods();
+ for (int i = 0; i < methods.length; i++) printMethod(methods[i]);
+ return rbrace();
+ }
+
+ /** Prints the class modifiers. */
+ public ATreePrinter printClassModifiers(AClass clasz) {
+ if (clasz.isDeprecated()) print("deprecated").space();
+ if (clasz.isSynthetic()) print("synthetic").space();
+ if (clasz.isPublic()) print("public").space();
+ if (clasz.isPrivate()) print("private").space();
+ if (clasz.isProtected()) print("protected").space();
+ if (clasz.isFinal()) print("final").space();
+ if (clasz.isAbstract()) print("abstract").space();
+ return this;
+ }
+
+ /** Prints the member modifiers. */
+ public ATreePrinter printMemberModifiers(AMember member) {
+ if (member.isDeprecated()) print("deprecated").space();
+ if (member.isSynthetic()) print("synthetic").space();
+ if (member.isPublic()) print("public").space();
+ if (member.isPrivate()) print("private").space();
+ if (member.isProtected()) print("protected").space();
+ if (member.isStatic()) print("static").space();
+ return this;
+ }
+
+ /** Prints the member code. */
+ public ATreePrinter printMemberCode(AMember member) {
+ if (member.code() == ACode.Void) return this;
+ return print('=').space().printCode(member.code());
+ }
+
+ /** Prints the field. */
+ public ATreePrinter printField(AField field) {
+ printFieldModifiers(field);
+ symtab.printSignature(field.symbol()).space();
+ return printMemberCode(field).line();
+ }
+
+ /** Prints the field modifiers. */
+ public ATreePrinter printFieldModifiers(AField field) {
+ printMemberModifiers(field);
+ if (field.isFinal()) print("final").space();
+ if (field.isVolatile()) print("volatile").space();
+ if (field.isTransient()) print("transient").space();
+ return this;
+ }
+
+ /** Prints the method. */
+ public ATreePrinter printMethod(AMethod method) {
+ printMethodModifiers(method);
+ symtab.printSignature(method.symbol()).space();
+ return printMemberCode(method).line();
+ }
+
+ /** Prints the method modifiers. */
+ public ATreePrinter printMethodModifiers(AMethod method) {
+ printMemberModifiers(method);
+ if (method.isFinal()) print("final").space();
+ if (method.isSynchronized()) print("synchronized").space();
+ if (method.isNative()) print("native").space();
+ if (method.isAbstract()) print("abstract").space();
+ return this;
+ }
+
/** Prints the code. */
public ATreePrinter printCode(ACode code) {
switch (code) {