summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-11-05 15:43:04 +0000
committerpaltherr <paltherr@epfl.ch>2003-11-05 15:43:04 +0000
commit6be0cda04aab98ce53e578b5c8cda7b7895a3c7d (patch)
treea007b7946dbad5ae65c33966b1b9bc48d65d4266 /sources
parente592008b31f66bc809caeec102d24438be6ccfa1 (diff)
downloadscala-6be0cda04aab98ce53e578b5c8cda7b7895a3c7d.tar.gz
scala-6be0cda04aab98ce53e578b5c8cda7b7895a3c7d.tar.bz2
scala-6be0cda04aab98ce53e578b5c8cda7b7895a3c7d.zip
- Added atree/APrimitive.java
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/atree/APrimitive.java72
-rw-r--r--sources/scalac/atree/ATreePrinter.java42
2 files changed, 114 insertions, 0 deletions
diff --git a/sources/scalac/atree/APrimitive.java b/sources/scalac/atree/APrimitive.java
new file mode 100644
index 0000000000..90d9ca516d
--- /dev/null
+++ b/sources/scalac/atree/APrimitive.java
@@ -0,0 +1,72 @@
+/* ____ ____ ____ ____ ______ *\
+** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
+** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
+** /_____/\____/\___/\____/____/ **
+\* */
+
+// $Id$
+
+package scalac.atree;
+
+/** This class represents a primitive operation. */
+public class APrimitive {
+
+ //########################################################################
+ // Public Cases
+
+ // type : (type) => type
+ // range: type <- { BOOL, Ix, Ux, Rx }
+ // jvm : {i, l, f, d}neg
+ public case Negation(ATypeKind type);
+
+ // type : zero ? (type) => BOOL : (type,type) => BOOL
+ // range: type <- { BOOL, Ix, Ux, Rx, REF }
+ // jvm : if{eq, ne, lt, ge, le, gt}, if{null, nonnull}
+ // if_icmp{eq, ne, lt, ge, le, gt}, if_acmp{eq,ne}
+ public case Test(ATestOp op, ATypeKind type, boolean zero);
+
+ // type : (type,type) => I4
+ // range: type <- { Ix, Ux, Rx }
+ // jvm : lcmp, {f, d}cmp{l, g}
+ public case Comparison(AComparisonOp op, ATypeKind type);
+
+ // type : (type,type) => type
+ // range: type <- { Ix, Ux, Rx }
+ // jvm : {i, l, f, d}{add, sub, mul, div, rem}
+ public case Arithmetic(AArithmeticOp op, ATypeKind type);
+
+ // type : (type,type) => type
+ // range: type <- { BOOL, Ix, Ux }
+ // jvm : {i, l}{and, or, xor}
+ public case Logical(ALogicalOp op, ATypeKind type);
+
+ // type : (type,I4) => type
+ // range: type <- { Ix, Ux }
+ // jvm : {i, l}{shl, ushl, shr}
+ public case Shift(AShiftOp op, ATypeKind type);
+
+ // type : (src) => dst
+ // range: src,dst <- { Ix, Ux, Rx }
+ // jvm : i2{l, f, d}, l2{i, f, d}, f2{i, l, d}, d2{i, l, f}, i2{b, c, s}
+ public case Conversion(ATypeKind src, ATypeKind dst);
+
+ // type : (Array[REF]) => I4
+ // range: type <- { BOOL, Ix, Ux, Rx, REF }
+ // jvm : arraylength
+ public case ArrayLength(ATypeKind type);
+
+ // type : (lf,rg) => STR
+ // range: lf,rg <- { BOOL, Ix, Ux, Rx, REF, STR }
+ // jvm : -
+ public case StringConcat(ATypeKind lf, ATypeKind rg);
+
+ //########################################################################
+ // Public Methods
+
+ /** Returns a string representation of this primitive. */
+ public String toString() {
+ return new ATreePrinter().printPrimitive(this).toString();
+ }
+
+ //########################################################################
+}
diff --git a/sources/scalac/atree/ATreePrinter.java b/sources/scalac/atree/ATreePrinter.java
index a938bcf014..f4304ec99e 100644
--- a/sources/scalac/atree/ATreePrinter.java
+++ b/sources/scalac/atree/ATreePrinter.java
@@ -235,6 +235,48 @@ public class ATreePrinter {
}
//########################################################################
+ // Public Methods - Printing trees
+
+ /** Prints the primitive */
+ public ATreePrinter printPrimitive(APrimitive primitive) {
+ switch (primitive) {
+ case Negation(ATypeKind type):
+ return printPrimitiveOp("NEG", type);
+ case Test(ATestOp op, ATypeKind type, boolean zero):
+ return printPrimitiveOp(op.toString() + (zero ? "Z" : ""), type);
+ case Comparison(AComparisonOp op, ATypeKind type):
+ return printPrimitiveOp(op.toString(), type);
+ case Arithmetic(AArithmeticOp op, ATypeKind type):
+ return printPrimitiveOp(op.toString(), type);
+ case Logical(ALogicalOp op, ATypeKind type):
+ return printPrimitiveOp(op.toString(), type);
+ case Shift(AShiftOp op, ATypeKind type):
+ return printPrimitiveOp(op.toString(), type);
+ case Conversion(ATypeKind src, ATypeKind dst):
+ return printPrimitiveOp("CONV", src, dst);
+ case ArrayLength(ATypeKind type):
+ return printPrimitiveOp("LENGTH", type);
+ case StringConcat(ATypeKind lf, ATypeKind rg):
+ return printPrimitiveOp("CONCAT", lf, rg);
+ default:
+ throw Debug.abort("unknown case", primitive);
+ }
+ }
+
+ /** 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 */
+ public ATreePrinter printPrimitiveOp(String op, ATypeKind t1,ATypeKind t2){
+ print('<').print(op).print('>');
+ if (t1 != null && global.uniqid) print('#').print(t1.toString());
+ if (t2 != null && global.uniqid) print(',').print(t2.toString());
+ return this;
+ }
+
+ //########################################################################
// Public Methods - Converting
/** Returns the string representation of this printer. */