01: // Copyright (c) 1997, 2004 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.bytecode;
05:
06: /**
07: * A Label represents a location in a Code attribute.
08: */
09:
10: public class Label {
11:
12: /** Offset in the fixup_offsets and fixup_labels arrays.
13: * The offset corresponds to the fixup itself. */
14: int first_fixup;
15:
16: /** The PC of where the label is, or -1 if not yet defined.
17: * This PC may be tentative if we later run processFixups.
18: * The offset in the code array is cattr.fixupOffset(first_fixup). */
19: int position;
20:
21: public final boolean defined() {
22: return position >= 0;
23: }
24:
25: public Label() {
26: position = -1;
27: }
28:
29: public Label(CodeAttr code) {
30: position = -1;
31: }
32:
33: public Label(int position) {
34: this .position = position;
35: }
36:
37: /**
38: * Define the value of a label as having the current location.
39: * @param code the "Code" attribute of the current method
40: */
41: public void define(CodeAttr code) {
42: code.setReachable(true);
43: if (position >= 0)
44: throw new Error("label definition more than once");
45:
46: position = code.PC;
47: first_fixup = code.fixup_count;
48: code.fixupAdd(CodeAttr.FIXUP_DEFINE, this);
49: }
50:
51: }
|