KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > pao > extension > PaoInstanceofExt_c


1 package polyglot.ext.pao.extension;
2
3 import polyglot.ast.Instanceof;
4 import polyglot.ast.Node;
5 import polyglot.ast.NodeFactory;
6 import polyglot.ext.pao.types.PaoTypeSystem;
7 import polyglot.types.Type;
8
9 /**
10  * The <code>PaoExt</code> implementation for the
11  * <code>InstanceOf</code> AST node.
12  */

13 public class PaoInstanceofExt_c extends PaoExt_c {
14     /**
15      * Rewrites <code>instanceof</code> checks where the comparison type is
16      * a primitive type to use the boxed type instead. For example,
17      * "e instanceof int" gets rewritten to
18      * "e instanceof polyglot.ext.pao.runtime.Integer".
19      *
20      * @see PaoExt#rewrite(PaoTypeSystem, NodeFactory)
21      */

22     public Node rewrite(PaoTypeSystem ts, NodeFactory nf) {
23         Instanceof n = (Instanceof) node();
24         Type rtype = n.compareType().type();
25
26         if (rtype.isPrimitive()) {
27             Type t = ts.boxedType(rtype.toPrimitive());
28             return n.compareType(nf.CanonicalTypeNode(n.compareType().position(),
29                                                     t));
30         }
31
32         return n;
33     }
34 }
35
Popular Tags