KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > bytecode > Label


1 // Copyright (c) 1997, 2004 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.bytecode;
5
6 /**
7  * A Label represents a location in a Code attribute.
8  */

9
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 () { return position >= 0; }
22
23   public Label ()
24   {
25     position = -1;
26   }
27
28   public Label (CodeAttr code)
29   {
30     position = -1;
31   }
32
33   public Label (int position)
34   {
35     this.position = position;
36   }
37
38   /**
39    * Define the value of a label as having the current location.
40    * @param code the "Code" attribute of the current method
41    */

42   public void define (CodeAttr code)
43   {
44     code.setReachable(true);
45     if (position >= 0)
46       throw new Error JavaDoc ("label definition more than once");
47
48     position = code.PC;
49     first_fixup = code.fixup_count;
50     code.fixupAdd(CodeAttr.FIXUP_DEFINE, this);
51   }
52
53   
54 }
55
Popular Tags