aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/compiler/ast/DoubleConst.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/javassist/compiler/ast/DoubleConst.java')
-rw-r--r--src/main/javassist/compiler/ast/DoubleConst.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main/javassist/compiler/ast/DoubleConst.java b/src/main/javassist/compiler/ast/DoubleConst.java
index b7063714..27de8878 100644
--- a/src/main/javassist/compiler/ast/DoubleConst.java
+++ b/src/main/javassist/compiler/ast/DoubleConst.java
@@ -16,6 +16,7 @@
package javassist.compiler.ast;
import javassist.compiler.CompileError;
+import javassist.compiler.TokenId;
/**
* Double constant.
@@ -28,6 +29,8 @@ public class DoubleConst extends ASTree {
public double get() { return value; }
+ public void set(double v) { value = v; }
+
/* Returns DoubleConstant or FloatConstant
*/
public int getType() { return type; }
@@ -37,4 +40,55 @@ public class DoubleConst extends ASTree {
public void accept(Visitor v) throws CompileError {
v.atDoubleConst(this);
}
+
+ public ASTree compute(int op, ASTree right) {
+ if (right instanceof IntConst)
+ return compute0(op, (IntConst)right);
+ else if (right instanceof DoubleConst)
+ return compute0(op, (DoubleConst)right);
+ else
+ return null;
+ }
+
+ private DoubleConst compute0(int op, DoubleConst right) {
+ int newType;
+ if (this.type == TokenId.DoubleConstant
+ || right.type == TokenId.DoubleConstant)
+ newType = TokenId.DoubleConstant;
+ else
+ newType = TokenId.FloatConstant;
+
+ return compute(op, this.value, right.value, newType);
+ }
+
+ private DoubleConst compute0(int op, IntConst right) {
+ return compute(op, this.value, (double)right.value, this.type);
+ }
+
+ private static DoubleConst compute(int op, double value1, double value2,
+ int newType)
+ {
+ double newValue;
+ switch (op) {
+ case '+' :
+ newValue = value1 + value2;
+ break;
+ case '-' :
+ newValue = value1 - value2;
+ break;
+ case '*' :
+ newValue = value1 * value2;
+ break;
+ case '/' :
+ newValue = value1 / value2;
+ break;
+ case '%' :
+ newValue = value1 % value2;
+ break;
+ default :
+ return null;
+ }
+
+ return new DoubleConst(newValue, newType);
+ }
}