01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2003, 2004 Ondrej Lhotak
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: package soot;
21:
22: import soot.jimple.*;
23:
24: /**
25: * UnitPrinter implementation for normal (full) Jimple, Grimp, and Baf
26: */
27: public class BriefUnitPrinter extends LabeledUnitPrinter {
28: public BriefUnitPrinter(Body body) {
29: super (body);
30: }
31:
32: private boolean baf;
33:
34: public void startUnit(Unit u) {
35: super .startUnit(u);
36: if (u instanceof Stmt) {
37: baf = false;
38: } else {
39: baf = true;
40: }
41: }
42:
43: public void methodRef(SootMethodRef m) {
44: handleIndent();
45: if (!baf && m.resolve().isStatic()) {
46: output.append(m.declaringClass().getName());
47: literal(".");
48: }
49: output.append(m.name());
50: }
51:
52: public void fieldRef(SootFieldRef f) {
53: handleIndent();
54: if (baf || f.resolve().isStatic()) {
55: output.append(f.declaringClass().getName());
56: literal(".");
57: }
58: output.append(f.name());
59: }
60:
61: public void identityRef(IdentityRef r) {
62: handleIndent();
63: if (r instanceof ThisRef) {
64: literal("@this");
65: } else if (r instanceof ParameterRef) {
66: ParameterRef pr = (ParameterRef) r;
67: literal("@parameter" + pr.getIndex());
68: } else if (r instanceof CaughtExceptionRef) {
69: literal("@caughtexception");
70: } else
71: throw new RuntimeException();
72: }
73:
74: private boolean eatSpace = false;
75:
76: public void literal(String s) {
77: handleIndent();
78: if (eatSpace && s.equals(" ")) {
79: eatSpace = false;
80: return;
81: }
82: eatSpace = false;
83: if (!baf) {
84: if (false || s.equals(Jimple.STATICINVOKE)
85: || s.equals(Jimple.VIRTUALINVOKE)
86: || s.equals(Jimple.INTERFACEINVOKE)) {
87: eatSpace = true;
88: return;
89: }
90: }
91: output.append(s);
92: }
93:
94: public void type(Type t) {
95: handleIndent();
96: output.append(t.toString());
97: }
98: }
|