diff options
-rw-r--r-- | config/list/compiler.lst | 1 | ||||
-rw-r--r-- | sources/scalac/atree/AConstant.java | 39 | ||||
-rw-r--r-- | sources/scalac/atree/ATreePrinter.java | 38 |
3 files changed, 75 insertions, 3 deletions
diff --git a/config/list/compiler.lst b/config/list/compiler.lst index d861f4ad0a..71859c3385 100644 --- a/config/list/compiler.lst +++ b/config/list/compiler.lst @@ -40,6 +40,7 @@ ast/printer/TreePrinter.java atree/AArithmeticOp.java atree/AComparisonOp.java +atree/AConstant.java atree/ALogicalOp.java atree/APrimitive.java atree/AShiftOp.java diff --git a/sources/scalac/atree/AConstant.java b/sources/scalac/atree/AConstant.java new file mode 100644 index 0000000000..626ab2a5da --- /dev/null +++ b/sources/scalac/atree/AConstant.java @@ -0,0 +1,39 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scalac.atree; + +/** This class represents a constant. */ +public class AConstant { + + //######################################################################## + // Public Cases + + public case UNIT; + public case BOOLEAN(boolean value); + public case BYTE(byte value); + public case SHORT(short value); + public case CHAR(char value); + public case INT(int value); + public case LONG(long value); + public case FLOAT(float value); + public case DOUBLE(double value); + public case STRING(String value); + public case NULL; + public case ZERO; + + //######################################################################## + // Public Methods + + /** Returns a string representation of this constant. */ + public String toString() { + return new ATreePrinter().printConstant(this).toString(); + } + + //######################################################################## +} diff --git a/sources/scalac/atree/ATreePrinter.java b/sources/scalac/atree/ATreePrinter.java index f4304ec99e..d59faf1064 100644 --- a/sources/scalac/atree/ATreePrinter.java +++ b/sources/scalac/atree/ATreePrinter.java @@ -237,7 +237,7 @@ public class ATreePrinter { //######################################################################## // Public Methods - Printing trees - /** Prints the primitive */ + /** Prints the primitive. */ public ATreePrinter printPrimitive(APrimitive primitive) { switch (primitive) { case Negation(ATypeKind type): @@ -263,12 +263,12 @@ public class ATreePrinter { } } - /** Prints the primitive operation of given type */ + /** Prints the primitive operation of given type. */ public ATreePrinter printPrimitiveOp(String op, ATypeKind type) { return printPrimitiveOp(op, type, null); } - /** Prints the primitive operation of given types */ + /** Prints the primitive operation of given types. */ public ATreePrinter printPrimitiveOp(String op, ATypeKind t1,ATypeKind t2){ print('<').print(op).print('>'); if (t1 != null && global.uniqid) print('#').print(t1.toString()); @@ -276,6 +276,38 @@ public class ATreePrinter { return this; } + /** Prints the constant. */ + public ATreePrinter printConstant(AConstant constant) { + switch (constant) { + case UNIT: + return print("()"); + case BOOLEAN(boolean value): + return print(value); + case BYTE(byte value): + return print(value); + case SHORT(short value): + return print(value); + case CHAR(char value): + return print('\'').print(value).print('\''); + case INT(int value): + return print(value); + case LONG(long value): + return print(value); + case FLOAT(float value): + return print(value); + case DOUBLE(double value): + return print(value); + case STRING(String value): + return print('\"').print(value).print('\"'); + case NULL: + return print("null"); + case ZERO: + return print("<zero>"); + default: + throw Debug.abort("unknown case", constant); + } + } + //######################################################################## // Public Methods - Converting |