001: package dk.brics.soot.intermediate.representation;
002:
003: public class StatementProcessor<T> {
004:
005: /**
006: * Constructs a new Statement processor.
007: */
008: public StatementProcessor() {
009: }
010:
011: /**
012: * Processes an {@link FooMethodCall}.
013: * This invokes {@link #pre(Statment)},
014: * if that returns null then {@link #process(FooMethodCall)} is invoked,
015: * Finally, {@link #post(Statement, Object)} is invoked.
016: * @param s Statement
017: * @return result
018: */
019: public T dispatch(FooMethodCall s) {
020: T t = pre(s);
021: if (t == null)
022: t = process(s);
023: post(s, t);
024: return t;
025: }
026:
027: /**
028: * Processes an {@link SomeMethodCall}.
029: * This invokes {@link #pre(Statment)},
030: * if that returns null then {@link #process(SomeMethodCall)} is invoked,
031: * Finally, {@link #post(Statement, Object)} is invoked.
032: * @param s Statement
033: * @return result
034: */
035: public T dispatch(SomeMethodCall s) {
036: T t = pre(s);
037: if (t == null)
038: t = process(s);
039: post(s, t);
040: return t;
041: }
042:
043: /**
044: * Processes an {@link FooInit}.
045: * This invokes {@link #pre(Statment)},
046: * if that returns null then {@link #process(FooInit)} is invoked,
047: * Finally, {@link #post(Statement, Object)} is invoked.
048: * @param s Statement
049: * @return result
050: */
051: public T dispatch(FooInit s) {
052: T t = pre(s);
053: if (t == null)
054: t = process(s);
055: post(s, t);
056: return t;
057: }
058:
059: /**
060: * Processes an {@link FooAssignment}.
061: * This invokes {@link #pre(Statment)},
062: * if that returns null then {@link #process(FooAssignment)} is invoked,
063: * Finally, {@link #post(Statement, Object)} is invoked.
064: * @param s Statement
065: * @return result
066: */
067: public T dispatch(FooAssignment s) {
068: T t = pre(s);
069: if (t == null)
070: t = process(s);
071: post(s, t);
072: return t;
073: }
074:
075: /**
076: * Processes an {@link Return}.
077: * This invokes {@link #pre(Statment)},
078: * if that returns null then {@link #process(Return)} is invoked,
079: * Finally, {@link #post(Statement, Object)} is invoked.
080: * @param s Statement
081: * @return result
082: */
083: public T dispatch(Return s) {
084: T t = pre(s);
085: if (t == null)
086: t = process(s);
087: post(s, t);
088: return t;
089: }
090:
091: /**
092: * Processes an {@link Nop}.
093: * This invokes {@link #pre(Statment)},
094: * if that returns null then {@link #process(Nop)} is invoked,
095: * Finally, {@link #post(Statement, Object)} is invoked.
096: * @param s Statement
097: * @return result
098: */
099: public T dispatch(Nop s) {
100: T t = pre(s);
101: if (t == null)
102: t = process(s);
103: post(s, t);
104: return t;
105: }
106:
107: /**
108: * Processes an {@link MethodHead}.
109: * This invokes {@link #pre(Statment)},
110: * if that returns null then {@link #process(MethodHead)} is invoked,
111: * Finally, {@link #post(Statement, Object)} is invoked.
112: * @param s Statement
113: * @return result
114: */
115: public T dispatch(MethodHead s) {
116: T t = pre(s);
117: if (t == null)
118: t = process(s);
119: post(s, t);
120: return t;
121: }
122:
123: /**
124: * Method to be invoked for processing an {@link FooMethodCall}.
125: * By default, nothing happens and null is returned.
126: * @param s current Statement
127: * @return result
128: */
129: public T process(FooMethodCall s) {
130: return null;
131: }
132:
133: /**
134: * Method to be invoked for processing an {@link SomeMethodCall}.
135: * By default, nothing happens and null is returned.
136: * @param s current Statement
137: * @return result
138: */
139: public T process(SomeMethodCall s) {
140: return null;
141: }
142:
143: /**
144: * Method to be invoked for processing an {@link FooInit}.
145: * By default, nothing happens and null is returned.
146: * @param s current Statement
147: * @return result
148: */
149: public T process(FooInit s) {
150: return null;
151: }
152:
153: /**
154: * Method to be invoked for processing an {@link FooAssignment}.
155: * By default, nothing happens and null is returned.
156: * @param s current Statement
157: * @return result
158: */
159: public T process(FooAssignment s) {
160: return null;
161: }
162:
163: /**
164: * Method to be invoked for processing an {@link Return}.
165: * By default, nothing happens and null is returned.
166: * @param s current Statement
167: * @return result
168: */
169: public T process(Return s) {
170: return null;
171: }
172:
173: /**
174: * Method to be invoked for processing an {@link Nop}.
175: * By default, nothing happens and null is returned.
176: * @param s current Statement
177: * @return result
178: */
179: public T process(Nop s) {
180: return null;
181: }
182:
183: /**
184: * Method to be invoked for processing an {@link MethodHead}.
185: * By default, nothing happens and null is returned.
186: * @param s current Statement
187: * @return result
188: */
189: public T process(MethodHead s) {
190: return null;
191: }
192:
193: /**
194: * Method to be invoked for preprocessing a {@link Statement}.
195: * By default, nothing happens and null is returned.
196: * @param s current Statement
197: * @return result
198: */
199: public T pre(Statement s) {
200: return null;
201: }
202:
203: /**
204: * Method to be invoked for postprocessing a {@link Statement}.
205: * By default, nothing happens.
206: * @param s current Statment
207: * @param t result from <code>process</code>
208: */
209: public void post(Statement s, T t) {
210: }
211:
212: }
|