1 19 20 package soot.javaToJimple; 21 22 public class CastInsertionVisitor extends polyglot.visit.AscriptionVisitor { 23 24 public CastInsertionVisitor(polyglot.frontend.Job job, polyglot.types.TypeSystem ts, polyglot.ast.NodeFactory nf) { 25 super(job, ts, nf); 26 } 27 28 public polyglot.ast.Expr ascribe(polyglot.ast.Expr e, polyglot.types.Type toType) { 29 30 polyglot.types.Type fromType = e.type(); 34 36 if (toType == null){ 37 return e; 38 } 39 if (toType.isVoid()) { 40 return e; 41 } 42 43 polyglot.util.Position p = e.position(); 44 45 if (toType.equals(fromType)){ 46 return e; 47 } 48 49 57 if (toType.isPrimitive() && fromType.isPrimitive()) { 58 59 polyglot.ast.Expr newExpr; 60 61 if (fromType.isFloat() || fromType.isLong() || fromType.isDouble()){ 64 if (toType.isFloat() || toType.isLong() || toType.isDouble() || toType.isInt()){ 65 newExpr = nf.Cast(p, nf.CanonicalTypeNode(p, toType), e).type(toType); 66 } 67 else { 68 newExpr = nf.Cast(p, nf.CanonicalTypeNode(p, toType), nf.Cast(p, nf.CanonicalTypeNode(p, ts.Int()), e).type(ts.Int())).type(toType); 69 } 70 } 71 else { 72 newExpr = nf.Cast(p, nf.CanonicalTypeNode(p, toType), e).type(toType); 73 } 74 return newExpr; 75 } 76 77 return e; 78 79 } 80 81 public polyglot.ast.Node leaveCall(polyglot.ast.Node old, polyglot.ast.Node n, polyglot.visit.NodeVisitor v) throws polyglot.types.SemanticException { 82 83 n = super.leaveCall(old, n, v); 84 85 return n; 86 } 87 } 88 | Popular Tags |