1 package polyglot.ext.pao.extension; 2 3 import polyglot.ast.*; 4 import polyglot.ext.pao.types.PaoTypeSystem; 5 import polyglot.types.MethodInstance; 6 7 11 public class PaoBinaryExt_c extends PaoExt_c { 12 19 public Node rewrite(PaoTypeSystem ts, NodeFactory nf) { 20 Binary b = (Binary) node(); 21 Expr l = b.left(); 22 Expr r = b.right(); 23 24 if (b.operator() == Binary.EQ || b.operator() == Binary.NE) { 25 MethodInstance mi = ((PaoTypeSystem) ts).primitiveEquals(); 26 27 if (ts.isSubtype(l.type(), mi.container()) || 30 ts.equals(l.type(), ts.Object())) { 31 if (r.type().isReference()) { 37 TypeNode x = nf.CanonicalTypeNode(b.position(), 41 mi.container()); 42 Call y = nf.Call(b.position(), x, mi.name(), l, r); 43 y = (Call) y.type(mi.returnType()); 44 if (b.operator() == Binary.NE) { 45 return nf.Unary(b.position(), Unary.NOT, y).type(mi.returnType()); 46 } 47 else { 48 return y; 49 } 50 } 51 } 52 } 53 54 return super.rewrite(ts, nf); 56 } 57 } 58 | Popular Tags |