1 19 20 package soot.javaToJimple.jj.ast; 21 22 import polyglot.ast.*; 23 import polyglot.types.*; 24 import polyglot.visit.*; 25 import polyglot.ext.jl.ast.*; 26 import polyglot.util.*; 27 28 public class JjBinary_c extends Binary_c { 29 30 public JjBinary_c(Position pos, Expr left, Binary.Operator op, Expr right){ 31 super(pos, left, op, right); 32 } 33 34 public Type childExpectedType(Expr child, AscriptionVisitor av){ 35 Expr other; 36 37 if (child == left) { 39 other = right; 40 } 41 else if (child == right) { 42 other = left; 43 } 44 else { 45 return child.type(); 46 } 47 48 TypeSystem ts = av.typeSystem(); 49 50 if (op == EQ || op == NE) { 51 if (other.type().isReference() || other.type().isNull()) { 53 return ts.Object(); 54 } 55 56 if (other.type().isBoolean()) { 57 return ts.Boolean(); 58 } 59 60 if (other.type().isNumeric()) { 61 if (other.type().isDouble() || child.type().isDouble()) { 62 return ts.Double(); 63 } 64 else if (other.type().isFloat() || child.type().isFloat()) { 65 return ts.Float(); 66 } 67 else if (other.type().isLong() || child.type().isLong()) { 68 return ts.Long(); 69 } 70 else { 71 return ts.Int(); 72 } 73 } 74 } 75 76 if (op == ADD && ts.equals(type, ts.String())) { 77 return ts.String(); 79 } 80 81 if (op == GT || op == LT || op == GE || op == LE) { 82 if (other.type().isBoolean()) { 83 return ts.Boolean(); 84 } 85 if (other.type().isNumeric()) { 86 if (other.type().isDouble() || child.type().isDouble()) { 87 return ts.Double(); 88 } 89 else if (other.type().isFloat() || child.type().isFloat()) { 90 return ts.Float(); 91 } 92 else if (other.type().isLong() || child.type().isLong()) { 93 return ts.Long(); 94 } 95 else { 96 return ts.Int(); 97 } 98 } 99 } 100 101 if (op == COND_OR || op == COND_AND) { 102 return ts.Boolean(); 103 } 104 105 if (op == BIT_AND || op == BIT_OR || op == BIT_XOR) { 106 if (other.type().isBoolean()) { 107 return ts.Boolean(); 108 } 109 if (other.type().isNumeric()) { 110 if (other.type().isLong() || child.type().isLong()) { 111 return ts.Long(); 112 } 113 else { 114 return ts.Int(); 115 } 116 } 117 } 118 119 if (op == ADD || op == SUB || op == MUL || op == DIV || op == MOD) { 120 123 if (other.type().isNumeric()) { 124 if (other.type().isDouble() || child.type().isDouble()) { 125 return ts.Double(); 126 } 127 else if (other.type().isFloat() || child.type().isFloat()) { 128 return ts.Float(); 129 } 130 else if (other.type().isLong() || child.type().isLong()) { 131 return ts.Long(); 132 } 133 else { 134 return ts.Int(); 135 } 136 } 137 } 138 139 if (op == SHL || op == SHR || op == USHR) { 140 if (child == right || !child.type().isLong()) { 141 return ts.Int(); 142 } else { 143 return child.type(); 144 } 145 } 146 147 return child.type(); 148 149 150 } 151 152 166 } 167 168 | Popular Tags |