}
- void checkOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,TypeDescriptor td) {
+ void checkOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on, TypeDescriptor td) {
+ checkExpressionNode(md, nametable, on.getLeft(), null);
+ if (on.getRight()!=null)
+ checkExpressionNode(md, nametable, on.getRight(), null);
+ TypeDescriptor ltd=on.getLeft().getType();
+ TypeDescriptor rtd=on.getRight()!=null?on.getRight().getType():null;
+ TypeDescriptor thistype=null;
+ if (rtd!=null) {
+ // 5.6.2 Binary Numeric Promotion
+ //TODO unboxing of reference objects
+ if (ltd.isDouble()||rtd.isDouble())
+ thistype=new TypeDescriptor(TypeDescriptor.DOUBLE);
+ else if (ltd.isFloat()||rtd.isFloat())
+ thistype=new TypeDescriptor(TypeDescriptor.FLOAT);
+ else if (ltd.isLong()||rtd.isLong())
+ thistype=new TypeDescriptor(TypeDescriptor.LONG);
+ else
+ thistype=new TypeDescriptor(TypeDescriptor.INT);
+
+ } else {
+ //5.6.1 Unary Numeric Promotion
+ if (ltd.isByte()||ltd.isShort()||ltd.isInt())
+ thistype=new TypeDescriptor(TypeDescriptor.INT);
+ else
+ thistype=ltd;
+ }
+ on.setType(thistype);
+ if (!typeutil.isSuperorType(td, thistype))
+ throw new Error("Type of rside not compatible with type of lside"+on.printNode(0));
}
int type;
ClassDescriptor class_desc;
+ public boolean isByte() {
+ return type==BYTE;
+ }
+ public boolean isShort() {
+ return type==SHORT;
+ }
+ public boolean isInt() {
+ return type==INT;
+ }
+ public boolean isLong() {
+ return type==LONG;
+ }
+ public boolean isChar() {
+ return type==CHAR;
+ }
+ public boolean isBoolean() {
+ return type==BOOLEAN;
+ }
+ public boolean isFloat() {
+ return type==FLOAT;
+ }
+ public boolean isDouble() {
+ return type==DOUBLE;
+ }
+
+
public void setClassDescriptor(ClassDescriptor cd) {
class_desc=cd;
}
-
+
public boolean isVoid() {
return type==VOID;
}