KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > bcg > Label


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.bcg;
26
27 import java.io.DataOutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 public class Label {
31     boolean anchored;
32     Label(boolean anchored) { this.anchored = anchored; }
33
34     boolean isAnchored() { return anchored; }
35     
36     Code target;
37
38     void setTarget(Code target) {
39         this.target = target;
40         target.addLabel(this);
41     }
42     Code getTarget() { return target; }
43
44     int getPc() { return target.getPc(); }
45
46     void writeRelativeShort(int src, DataOutputStream JavaDoc stream) throws IOException JavaDoc {
47         int relative = target.getPc() - src;
48         if (! Asserts.isShort(relative)) {
49             throw new CodeBuilder.TooWideJumpException();
50         } else {
51             stream.writeShort((short) relative);
52         }
53     }
54     void writeRelativeInt(int src, DataOutputStream JavaDoc stream) throws IOException JavaDoc {
55         long relative = target.getPc() - src;
56         stream.writeInt((int) relative);
57     }
58
59     // only used for debugging, can be static
60
static int labelCount = 0;
61     int myLabelNum = -1;
62     public String JavaDoc toString() {
63         if (getTarget().getPc() != -1) return "" + getTarget().getPc();
64         Label l = (CodeBuilder.DEBUG) ? this : (Label) getTarget().getLabels().get(0);
65         if (l.myLabelNum == -1) l.myLabelNum = labelCount++;
66         return "_" + l.myLabelNum;
67     }
68 }
69
Popular Tags