KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > codegen > CaseLabel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.compiler.codegen;
12
13 public class CaseLabel extends BranchLabel {
14     
15     public int instructionPosition = POS_NOT_SET;
16     
17 /**
18  * CaseLabel constructor comment.
19  * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
20  */

21 public CaseLabel(CodeStream codeStream) {
22     super(codeStream);
23 }
24
25 /*
26 * Put down a reference to the array at the location in the codestream.
27 * #placeInstruction() must be performed prior to any #branch()
28 */

29 void branch() {
30     if (position == POS_NOT_SET) {
31         addForwardReference(codeStream.position);
32         // Leave 4 bytes free to generate the jump offset afterwards
33
codeStream.position += 4;
34         codeStream.classFileOffset += 4;
35     } else { //Position is set. Write it!
36
/*
37          * Position is set. Write it if it is not a wide branch.
38          */

39         this.codeStream.writeSignedWord(this.position - this.instructionPosition);
40     }
41 }
42
43 /*
44 * No support for wide branches yet
45 */

46 void branchWide() {
47     this.branch(); // case label branch is already wide
48
}
49
50 public boolean isCaseLabel() {
51     return true;
52 }
53 public boolean isStandardLabel(){
54     return false;
55 }
56 /*
57 * Put down a reference to the array at the location in the codestream.
58 */

59 public void place() {
60     if ((this.tagBits & USED) != 0) {
61         position = codeStream.getPosition();
62     } else {
63         position = codeStream.position;
64     }
65     if (instructionPosition != POS_NOT_SET) {
66         int offset = position - instructionPosition;
67         int[] forwardRefs = forwardReferences();
68         for (int i = 0, length = forwardReferenceCount(); i < length; i++) {
69             codeStream.writeSignedWord(forwardRefs[i], offset);
70         }
71         // add the label int the codeStream labels collection
72
codeStream.addLabel(this);
73     }
74 }
75
76 /*
77 * Put down a reference to the array at the location in the codestream.
78 */

79 void placeInstruction() {
80     if (instructionPosition == POS_NOT_SET) {
81         instructionPosition = codeStream.position;
82     }
83 }
84 }
85
Popular Tags