001: /*
002: * Copyright 2004 Brian S O'Neill
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.cojen.classfile;
018:
019: import java.lang.reflect.Constructor;
020: import java.lang.reflect.Method;
021:
022: /**
023: * Delegates all method calls to another CodeAssembler. Override any method to
024: * track activity or change the way code is generated.
025: *
026: * @author Brian S O'Neill
027: */
028: public class DelegatedCodeAssembler implements CodeAssembler {
029: protected final CodeAssembler mAssembler;
030:
031: public DelegatedCodeAssembler(CodeAssembler assembler) {
032: if (assembler == null) {
033: throw new IllegalArgumentException();
034: }
035: mAssembler = assembler;
036: }
037:
038: public int getParameterCount() {
039: return mAssembler.getParameterCount();
040: }
041:
042: public LocalVariable getParameter(int index) {
043: return mAssembler.getParameter(index);
044: }
045:
046: public LocalVariable createLocalVariable(String name, TypeDesc type) {
047: return mAssembler.createLocalVariable(name, type);
048: }
049:
050: public Label createLabel() {
051: return mAssembler.createLabel();
052: }
053:
054: public void exceptionHandler(Location startLocation,
055: Location endLocation, String catchClassName) {
056: mAssembler.exceptionHandler(startLocation, endLocation,
057: catchClassName);
058: }
059:
060: public void mapLineNumber(int lineNumber) {
061: mAssembler.mapLineNumber(lineNumber);
062: }
063:
064: public void inline(Object code) {
065: mAssembler.inline(code);
066: }
067:
068: public void loadNull() {
069: mAssembler.loadNull();
070: }
071:
072: public void loadConstant(String value) {
073: mAssembler.loadConstant(value);
074: }
075:
076: public void loadConstant(TypeDesc type) {
077: mAssembler.loadConstant(type);
078: }
079:
080: public void loadConstant(boolean value) {
081: mAssembler.loadConstant(value);
082: }
083:
084: public void loadConstant(int value) {
085: mAssembler.loadConstant(value);
086: }
087:
088: public void loadConstant(long value) {
089: mAssembler.loadConstant(value);
090: }
091:
092: public void loadConstant(float value) {
093: mAssembler.loadConstant(value);
094: }
095:
096: public void loadConstant(double value) {
097: mAssembler.loadConstant(value);
098: }
099:
100: public void loadLocal(LocalVariable local) {
101: mAssembler.loadLocal(local);
102: }
103:
104: public void loadThis() {
105: mAssembler.loadThis();
106: }
107:
108: public void storeLocal(LocalVariable local) {
109: mAssembler.storeLocal(local);
110: }
111:
112: public void loadFromArray(TypeDesc type) {
113: mAssembler.loadFromArray(type);
114: }
115:
116: public void storeToArray(TypeDesc type) {
117: mAssembler.storeToArray(type);
118: }
119:
120: public void loadField(String fieldName, TypeDesc type) {
121: mAssembler.loadField(fieldName, type);
122: }
123:
124: public void loadField(String className, String fieldName,
125: TypeDesc type) {
126: mAssembler.loadField(className, fieldName, type);
127: }
128:
129: public void loadField(TypeDesc classDesc, String fieldName,
130: TypeDesc type) {
131: mAssembler.loadField(classDesc, fieldName, type);
132: }
133:
134: public void loadStaticField(String fieldName, TypeDesc type) {
135: mAssembler.loadStaticField(fieldName, type);
136: }
137:
138: public void loadStaticField(String className, String fieldName,
139: TypeDesc type) {
140: mAssembler.loadStaticField(className, fieldName, type);
141: }
142:
143: public void loadStaticField(TypeDesc classDesc, String fieldName,
144: TypeDesc type) {
145: mAssembler.loadStaticField(classDesc, fieldName, type);
146: }
147:
148: public void storeField(String fieldName, TypeDesc type) {
149: mAssembler.storeField(fieldName, type);
150: }
151:
152: public void storeField(String className, String fieldName,
153: TypeDesc type) {
154: mAssembler.storeField(className, fieldName, type);
155: }
156:
157: public void storeField(TypeDesc classDesc, String fieldName,
158: TypeDesc type) {
159: mAssembler.storeField(classDesc, fieldName, type);
160: }
161:
162: public void storeStaticField(String fieldName, TypeDesc type) {
163: mAssembler.storeStaticField(fieldName, type);
164: }
165:
166: public void storeStaticField(String className, String fieldName,
167: TypeDesc type) {
168: mAssembler.storeStaticField(className, fieldName, type);
169: }
170:
171: public void storeStaticField(TypeDesc classDesc, String fieldName,
172: TypeDesc type) {
173: mAssembler.storeStaticField(classDesc, fieldName, type);
174: }
175:
176: public void returnVoid() {
177: mAssembler.returnVoid();
178: }
179:
180: public void returnValue(TypeDesc type) {
181: mAssembler.returnValue(type);
182: }
183:
184: public void convert(TypeDesc fromType, TypeDesc toType) {
185: mAssembler.convert(fromType, toType);
186: }
187:
188: public void convert(TypeDesc fromType, TypeDesc toType,
189: int fpConvertMode) {
190: mAssembler.convert(fromType, toType, fpConvertMode);
191: }
192:
193: public void invoke(Method method) {
194: mAssembler.invoke(method);
195: }
196:
197: public void invokeVirtual(String methodName, TypeDesc ret,
198: TypeDesc[] params) {
199: mAssembler.invokeVirtual(methodName, ret, params);
200: }
201:
202: public void invokeVirtual(String className, String methodName,
203: TypeDesc ret, TypeDesc[] params) {
204: mAssembler.invokeVirtual(className, methodName, ret, params);
205: }
206:
207: public void invokeVirtual(TypeDesc classDesc, String methodName,
208: TypeDesc ret, TypeDesc[] params) {
209: mAssembler.invokeVirtual(classDesc, methodName, ret, params);
210: }
211:
212: public void invokeStatic(String methodName, TypeDesc ret,
213: TypeDesc[] params) {
214: mAssembler.invokeStatic(methodName, ret, params);
215: }
216:
217: public void invokeStatic(String className, String methodName,
218: TypeDesc ret, TypeDesc[] params) {
219: mAssembler.invokeStatic(className, methodName, ret, params);
220: }
221:
222: public void invokeStatic(TypeDesc classDesc, String methodName,
223: TypeDesc ret, TypeDesc[] params) {
224: mAssembler.invokeStatic(classDesc, methodName, ret, params);
225: }
226:
227: public void invokeInterface(String className, String methodName,
228: TypeDesc ret, TypeDesc[] params) {
229: mAssembler.invokeInterface(className, methodName, ret, params);
230: }
231:
232: public void invokeInterface(TypeDesc classDesc, String methodName,
233: TypeDesc ret, TypeDesc[] params) {
234: mAssembler.invokeInterface(classDesc, methodName, ret, params);
235: }
236:
237: public void invokePrivate(String methodName, TypeDesc ret,
238: TypeDesc[] params) {
239: mAssembler.invokePrivate(methodName, ret, params);
240: }
241:
242: public void invokeSuper(Method method) {
243: mAssembler.invokeSuper(method);
244: }
245:
246: public void invokeSuper(String super ClassName, String methodName,
247: TypeDesc ret, TypeDesc[] params) {
248: mAssembler.invokeSuper(super ClassName, methodName, ret, params);
249: }
250:
251: public void invokeSuper(TypeDesc super ClassDesc, String methodName,
252: TypeDesc ret, TypeDesc[] params) {
253: mAssembler.invokeSuper(super ClassDesc, methodName, ret, params);
254: }
255:
256: public void invoke(Constructor constructor) {
257: mAssembler.invoke(constructor);
258: }
259:
260: public void invokeConstructor(TypeDesc[] params) {
261: mAssembler.invokeConstructor(params);
262: }
263:
264: public void invokeConstructor(String className, TypeDesc[] params) {
265: mAssembler.invokeConstructor(className, params);
266: }
267:
268: public void invokeConstructor(TypeDesc classDesc, TypeDesc[] params) {
269: mAssembler.invokeConstructor(classDesc, params);
270: }
271:
272: public void invokeSuperConstructor(TypeDesc[] params) {
273: mAssembler.invokeSuperConstructor(params);
274: }
275:
276: public void newObject(TypeDesc type) {
277: mAssembler.newObject(type);
278: }
279:
280: public void newObject(TypeDesc type, int dimensions) {
281: mAssembler.newObject(type, dimensions);
282: }
283:
284: public void dup() {
285: mAssembler.dup();
286: }
287:
288: public void dupX1() {
289: mAssembler.dupX1();
290: }
291:
292: public void dupX2() {
293: mAssembler.dupX2();
294: }
295:
296: public void dup2() {
297: mAssembler.dup2();
298: }
299:
300: public void dup2X1() {
301: mAssembler.dup2X1();
302: }
303:
304: public void dup2X2() {
305: mAssembler.dup2X2();
306: }
307:
308: public void pop() {
309: mAssembler.pop();
310: }
311:
312: public void pop2() {
313: mAssembler.pop2();
314: }
315:
316: public void swap() {
317: mAssembler.swap();
318: }
319:
320: public void swap2() {
321: mAssembler.swap2();
322: }
323:
324: public void branch(Location location) {
325: mAssembler.branch(location);
326: }
327:
328: public void ifNullBranch(Location location, boolean choice) {
329: mAssembler.ifNullBranch(location, choice);
330: }
331:
332: public void ifEqualBranch(Location location, boolean choice) {
333: mAssembler.ifEqualBranch(location, choice);
334: }
335:
336: public void ifZeroComparisonBranch(Location location, String choice)
337: throws IllegalArgumentException {
338: mAssembler.ifZeroComparisonBranch(location, choice);
339: }
340:
341: public void ifComparisonBranch(Location location, String choice)
342: throws IllegalArgumentException {
343: mAssembler.ifComparisonBranch(location, choice);
344: }
345:
346: public void ifComparisonBranch(Location location, String choice,
347: TypeDesc type) throws IllegalArgumentException {
348: mAssembler.ifComparisonBranch(location, choice, type);
349: }
350:
351: public void switchBranch(int[] cases, Location[] locations,
352: Location defaultLocation) {
353: mAssembler.switchBranch(cases, locations, defaultLocation);
354: }
355:
356: public void jsr(Location location) {
357: mAssembler.jsr(location);
358: }
359:
360: public void ret(LocalVariable local) {
361: mAssembler.ret(local);
362: }
363:
364: public void math(byte opcode) {
365: mAssembler.math(opcode);
366: }
367:
368: public void arrayLength() {
369: mAssembler.arrayLength();
370: }
371:
372: public void throwObject() {
373: mAssembler.throwObject();
374: }
375:
376: public void checkCast(TypeDesc type) {
377: mAssembler.checkCast(type);
378: }
379:
380: public void instanceOf(TypeDesc type) {
381: mAssembler.instanceOf(type);
382: }
383:
384: public void integerIncrement(LocalVariable local, int amount) {
385: mAssembler.integerIncrement(local, amount);
386: }
387:
388: public void monitorEnter() {
389: mAssembler.monitorEnter();
390: }
391:
392: public void monitorExit() {
393: mAssembler.monitorExit();
394: }
395:
396: public void nop() {
397: mAssembler.nop();
398: }
399:
400: public void breakpoint() {
401: mAssembler.breakpoint();
402: }
403: }
|