01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.codegen;
11:
12: import org.eclipse.jdt.core.compiler.CharOperation;
13: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
14:
15: public class ExceptionLabel extends Label {
16:
17: public int ranges[] = { POS_NOT_SET, POS_NOT_SET };
18: public int count = 0; // incremented each time placeStart or placeEnd is called
19: public TypeBinding exceptionType;
20:
21: public ExceptionLabel(CodeStream codeStream,
22: TypeBinding exceptionType) {
23: super (codeStream);
24: this .exceptionType = exceptionType;
25: }
26:
27: public void place() {
28: // register the handler inside the codeStream then normal place
29: codeStream.registerExceptionHandler(this );
30: if (CodeStream.DEBUG)
31: System.out
32: .println("\t\t\t\t<place at: " + codeStream.position + " - " + this ); //$NON-NLS-1$ //$NON-NLS-2$
33: this .position = codeStream.getPosition();
34: }
35:
36: public void placeEnd() {
37: int endPosition = codeStream.position;
38: if (this .ranges[this .count - 1] == endPosition) { // start == end ?
39: // discard empty exception handler
40: this .count--;
41: } else {
42: this .ranges[this .count++] = endPosition;
43: }
44: }
45:
46: public void placeStart() {
47: int startPosition = codeStream.position;
48: if (this .count > 0
49: && this .ranges[this .count - 1] == startPosition) { // start == previous end ?
50: // reopen current handler
51: this .count--;
52: return;
53: }
54: // only need to grow on even additions (i.e. placeStart only)
55: int length;
56: if (this .count == (length = this .ranges.length)) {
57: System.arraycopy(this .ranges, 0,
58: this .ranges = new int[length * 2], 0, length);
59: }
60: this .ranges[this .count++] = startPosition;
61: }
62:
63: public String toString() {
64: String basic = getClass().getName();
65: basic = basic.substring(basic.lastIndexOf('.') + 1);
66: StringBuffer buffer = new StringBuffer(basic);
67: buffer.append('@').append(Integer.toHexString(hashCode()));
68: buffer
69: .append("(type=").append(this .exceptionType == null ? CharOperation.NO_CHAR : this .exceptionType.readableName()); //$NON-NLS-1$
70: buffer.append(", position=").append(position); //$NON-NLS-1$
71: buffer.append(", ranges = "); //$NON-NLS-1$
72: if (this .count == 0) {
73: buffer.append("[]"); //$NON-NLS-1$
74: } else {
75: for (int i = 0; i < this .count; i++) {
76: if ((i & 1) == 0) {
77: buffer.append("[").append(ranges[i]); //$NON-NLS-1$
78: } else {
79: buffer.append(",").append(ranges[i]).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
80: }
81: }
82: if ((this .count & 1) == 1) {
83: buffer.append(",?]"); //$NON-NLS-1$
84: }
85: }
86: buffer.append(')');
87: return buffer.toString();
88: }
89: }
|