KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > DavaUnitPrinter


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
3  * Copyright (C) 2004-2005 Nomair A. Naeem
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */

20
21 package soot.dava;
22 import soot.AbstractUnitPrinter;
23 import soot.ArrayType;
24 import soot.RefType;
25 import soot.SootFieldRef;
26 import soot.SootMethodRef;
27 import soot.Type;
28 import soot.Unit;
29 import soot.jimple.IdentityRef;
30 import soot.jimple.Jimple;
31 import soot.jimple.ThisRef;
32
33 /**
34  * UnitPrinter implementation for Dava.
35  */

36 public class DavaUnitPrinter extends AbstractUnitPrinter {
37     public void methodRef( SootMethodRef m ) {
38         handleIndent();
39         output.append( m.name() );
40     }
41     public void fieldRef( SootFieldRef f ) {
42         handleIndent();
43         output.append(f.name());
44     }
45     public void identityRef( IdentityRef r ) {
46         handleIndent();
47         if( r instanceof ThisRef ) {
48             literal("this");
49         } else throw new RuntimeException JavaDoc();
50     }
51
52     private boolean eatSpace = false;
53     public void literal( String JavaDoc s ) {
54         handleIndent();
55         if( eatSpace && s.equals(" ") ) {
56             eatSpace = false;
57             return;
58         }
59         eatSpace = false;
60         if( false
61         || s.equals( Jimple.v().STATICINVOKE )
62         || s.equals( Jimple.v().VIRTUALINVOKE )
63         || s.equals( Jimple.v().INTERFACEINVOKE )
64           ) {
65             eatSpace = true;
66             return;
67         }
68         output.append(s);
69     }
70     public void type( Type t ) {
71         handleIndent();
72         if( t instanceof RefType ) {
73             output.append( ((RefType) t).getSootClass().getJavaStyleName() );
74         } else if( t instanceof ArrayType ) {
75             ((ArrayType) t).toString( this );
76         } else {
77             output.append( t.toString() );
78         }
79     }
80     public void unitRef( Unit u, boolean branchTarget ) {
81         throw new RuntimeException JavaDoc( "Dava doesn't have unit references!" );
82     }
83
84
85
86
87
88
89     public void addNot() {
90         output.append(" !");
91     }
92     public void addAggregatedOr() {
93         output.append(" || ");
94     }
95     public void addAggregatedAnd() {
96         output.append(" && " );
97     }
98     public void addLeftParen() {
99         output.append(" (" );
100     }
101     public void addRightParen() {
102         output.append(") " );
103     }
104
105     public void printString(String JavaDoc s){
106     output.append(s);
107     }
108
109 }
110
111
112
Popular Tags