removed Makefile; lifted repo/org.ibex.tool/src/ to src/
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / lookup / LocalVariableBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.lookup;
12
13 import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
14 import org.eclipse.jdt.internal.compiler.impl.Constant;
15
16 public class LocalVariableBinding extends VariableBinding {
17
18         public boolean isArgument;
19         public int resolvedPosition; // for code generation (position in method context)
20         
21         public static final int UNUSED = 0;
22         public static final int USED = 1;
23         public static final int FAKE_USED = 2;
24         public int useFlag; // for flow analysis (default is UNUSED)
25         
26         public BlockScope declaringScope; // back-pointer to its declaring scope
27         public LocalDeclaration declaration; // for source-positions
28
29         public int[] initializationPCs;
30         public int initializationCount = 0;
31
32         // for synthetic local variables        
33         public LocalVariableBinding(char[] name, TypeBinding type, int modifiers, boolean isArgument) {
34
35                 this.name = name;
36                 this.type = type;
37                 this.modifiers = modifiers;
38                 this.isArgument = isArgument;
39                 if (isArgument)
40                         this.constant = Constant.NotAConstant;
41         }
42         
43         // regular local variable or argument
44         public LocalVariableBinding(LocalDeclaration declaration, TypeBinding type, int modifiers, boolean isArgument) {
45
46                 this(declaration.name, type, modifiers, isArgument);
47                 this.declaration = declaration;
48         }
49
50         /* API
51         * Answer the receiver's binding type from Binding.BindingID.
52         */
53         public final int bindingType() {
54
55                 return LOCAL;
56         }
57         
58         // Answer whether the variable binding is a secret variable added for code gen purposes
59         public boolean isSecret() {
60
61                 return declaration == null && !isArgument;
62         }
63
64         public void recordInitializationEndPC(int pc) {
65
66                 if (initializationPCs[((initializationCount - 1) << 1) + 1] == -1)
67                         initializationPCs[((initializationCount - 1) << 1) + 1] = pc;
68         }
69
70         public void recordInitializationStartPC(int pc) {
71
72                 if (initializationPCs == null)  return;
73                 // optimize cases where reopening a contiguous interval
74                 if ((initializationCount > 0) && (initializationPCs[ ((initializationCount - 1) << 1) + 1] == pc)) {
75                         initializationPCs[ ((initializationCount - 1) << 1) + 1] = -1; // reuse previous interval (its range will be augmented)
76                 } else {
77                         int index = initializationCount << 1;
78                         if (index == initializationPCs.length) {
79                                 System.arraycopy(initializationPCs, 0, (initializationPCs = new int[initializationCount << 2]), 0, index);
80                         }
81                         initializationPCs[index] = pc;
82                         initializationPCs[index + 1] = -1;
83                         initializationCount++;
84                 }
85         }
86
87         public String toString() {
88
89                 String s = super.toString();
90                 switch (useFlag){
91                         case USED:
92                                 s += "[pos: " + String.valueOf(resolvedPosition) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
93                                 break;
94                         case UNUSED:
95                                 s += "[pos: unused]"; //$NON-NLS-1$
96                                 break;
97                         case FAKE_USED:
98                                 s += "[pos: fake_used]"; //$NON-NLS-1$
99                                 break;
100                 }
101                 s += "[id:" + String.valueOf(id) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
102                 if (initializationCount > 0) {
103                         s += "[pc: "; //$NON-NLS-1$
104                         for (int i = 0; i < initializationCount; i++) {
105                                 if (i > 0)
106                                         s += ", "; //$NON-NLS-1$
107                                 s += String.valueOf(initializationPCs[i << 1]) + "-" + ((initializationPCs[(i << 1) + 1] == -1) ? "?" : String.valueOf(initializationPCs[(i<< 1) + 1])); //$NON-NLS-2$ //$NON-NLS-1$
108                         }
109                         s += "]"; //$NON-NLS-1$
110                 }
111                 return s;
112         }
113 }