001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package components;
028:
029: import java.io.DataOutput;
030: import java.io.DataInput;
031: import java.io.IOException;
032: import util.*;
033:
034: /*
035: * A class to represent the Exceptions table Attribute
036: * of a method
037: */
038:
039: public class ExceptionsAttribute extends Attribute {
040: public ClassConstant data[];
041:
042: public ExceptionsAttribute(UnicodeConstant name, int l,
043: ClassConstant d[]) {
044: super (name, l);
045: data = d;
046: }
047:
048: public void countConstantReferences(boolean isRelocatable) {
049: super .countConstantReferences(isRelocatable);
050: int n = data.length;
051: for (int i = 0; i < n; i++) {
052: data[i].incReference();
053: }
054: }
055:
056: protected int writeData(DataOutput o) throws IOException {
057: int n = data.length;
058: o.writeShort(n);
059: for (int i = 0; i < n; i++) {
060: o.writeShort(data[i].index);
061: // debug
062: if (data[i].index <= 0) {
063: System.err
064: .println(Localizer
065: .getString(
066: "exceptionsattribute.exceptions_table_references_negative_subscript",
067: data[i]));
068: }
069: // end debug
070: }
071: return 2 + 2 * n;
072: }
073:
074: public static Attribute readAttribute(DataInput i,
075: ConstantObject locals[], ConstantObject globals[])
076: throws IOException {
077: UnicodeConstant name;
078:
079: name = (UnicodeConstant) globals[i.readUnsignedShort()];
080: return finishReadAttribute(i, name, locals);
081: }
082:
083: //
084: // for those cases where we already read the name index
085: // and know that its not something requiring special handling.
086: //
087: public static Attribute finishReadAttribute(DataInput in,
088: UnicodeConstant name, ConstantObject t[])
089: throws IOException {
090: int l;
091: int n;
092: ClassConstant d[];
093:
094: l = in.readInt();
095: n = in.readUnsignedShort();
096: d = new ClassConstant[n];
097: for (int i = 0; i < n; i++) {
098: int index = in.readUnsignedShort();
099: d[i] = (ClassConstant) t[index];
100: }
101: return new ExceptionsAttribute(name, l, d);
102: }
103:
104: }
|