001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.reflect;
022:
023: /**
024: * Catch stores information about a protected block and an exception handler in
025: * a method. The startPC, endPC, and handlerPC are indices into the bytecode of
026: * the method where the protected block begins and ends and the catch block
027: * begins, respectively. They are indices into the code array.
028: *
029: * @see EDU.purdue.cs.bloat.file.Code#code
030: *
031: * @author Nate Nystrom (<a
032: * href="mailto:nystrom@cs.purdue.edu">nystrom@cs.purdue.edu</a>)
033: */
034: public class Catch {
035: private int startPC;
036:
037: private int endPC;
038:
039: private int handlerPC;
040:
041: private int catchType;
042:
043: /**
044: * Constructor.
045: *
046: * @param startPC
047: * The start PC of the protected block.
048: * @param endPC
049: * The PC of the instruction after the end of the protected
050: * block.
051: * @param handlerPC
052: * The start PC of the exception handler.
053: * @param catchType
054: * The type of exception to catch.
055: */
056: public Catch(final int startPC, final int endPC,
057: final int handlerPC, final int catchType) {
058: this .startPC = startPC;
059: this .endPC = endPC;
060: this .handlerPC = handlerPC;
061: this .catchType = catchType;
062: }
063:
064: /**
065: * Get the start PC of the protected block.
066: *
067: * @return The start PC of the protected block.
068: * @see Catch#setStartPC
069: */
070: public int startPC() {
071: return startPC;
072: }
073:
074: /**
075: * Set the start PC of the protected block.
076: *
077: * @param pc
078: * The start PC of the protected block.
079: * @see Catch#startPC
080: */
081: public void setStartPC(final int pc) {
082: startPC = pc;
083: }
084:
085: /**
086: * Get the end PC of the protected block.
087: *
088: * @return The PC of the instruction after the end of the protected block.
089: * @see Catch#setEndPC
090: */
091: public int endPC() {
092: return endPC;
093: }
094:
095: /**
096: * Set the end PC of the protected block.
097: *
098: * @param pc
099: * The PC of the instruction after the end of the protected
100: * block.
101: * @see Catch#endPC
102: */
103: public void setEndPC(final int pc) {
104: endPC = pc;
105: }
106:
107: /**
108: * Get the start PC of the exception handler.
109: *
110: * @return The start PC of the exception handler.
111: * @see Catch#setHandlerPC
112: */
113: public int handlerPC() {
114: return handlerPC;
115: }
116:
117: /**
118: * Set the start PC of the exception handler.
119: *
120: * @param pc
121: * The start PC of the exception handler.
122: * @see Catch#handlerPC
123: */
124: public void setHandlerPC(final int pc) {
125: handlerPC = pc;
126: }
127:
128: /**
129: * Get the index into the constant pool of the type of exception to catch.
130: *
131: * @return Index of the type of exception to catch.
132: * @see Catch#setCatchTypeIndex
133: */
134: public int catchTypeIndex() {
135: return catchType;
136: }
137:
138: /**
139: * Set the index into the constant pool of the type of exception to catch.
140: *
141: * @param index
142: * Index of the type of exception to catch.
143: * @see Catch#catchTypeIndex
144: */
145: public void setCatchTypeIndex(final int index) {
146: this .catchType = index;
147: }
148:
149: public Object clone() {
150: return (new Catch(this .startPC, this .endPC, this .handlerPC,
151: this .catchType));
152: }
153:
154: /**
155: * Returns a string representation of the catch information.
156: */
157: public String toString() {
158: return "(try-catch " + startPC + " " + endPC + " " + handlerPC
159: + " " + catchType + ")";
160: }
161: }
|