1) Added missing strings for italic, underline and strike through.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / lookup / LocalVariableBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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 net.sourceforge.phpdt.internal.compiler.lookup;
12
13 import net.sourceforge.phpdt.internal.compiler.ast.LocalDeclaration;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
15
16 public class LocalVariableBinding extends VariableBinding {
17
18         public boolean isArgument;
19
20         public int resolvedPosition; // for code generation (position in method
21                                                                         // context)
22
23         public static final int UNUSED = 0;
24
25         public static final int USED = 1;
26
27         public static final int FAKE_USED = 2;
28
29         public int useFlag; // for flow analysis (default is UNUSED)
30
31         public BlockScope declaringScope; // back-pointer to its declaring scope
32
33         public LocalDeclaration declaration; // for source-positions
34
35         public int[] initializationPCs;
36
37         public int initializationCount = 0;
38
39         // for synthetic local variables
40         public LocalVariableBinding(char[] name, TypeBinding type, int modifiers,
41                         boolean isArgument) {
42
43                 this.name = name;
44                 this.type = type;
45                 this.modifiers = modifiers;
46                 if (this.isArgument = isArgument)
47                         this.constant = Constant.NotAConstant;
48         }
49
50         // regular local variable or argument
51         public LocalVariableBinding(LocalDeclaration declaration, TypeBinding type,
52                         int modifiers, boolean isArgument) {
53
54                 this(declaration.name, type, modifiers, isArgument);
55                 this.declaration = declaration;
56         }
57
58         /*
59          * API Answer the receiver's binding type from Binding.BindingID.
60          */
61         public final int bindingType() {
62
63                 return LOCAL;
64         }
65
66         // Answer whether the variable binding is a secret variable added for code
67         // gen purposes
68         public boolean isSecret() {
69
70                 return declaration == null && !isArgument;
71         }
72
73         public void recordInitializationEndPC(int pc) {
74
75                 if (initializationPCs[((initializationCount - 1) << 1) + 1] == -1)
76                         initializationPCs[((initializationCount - 1) << 1) + 1] = pc;
77         }
78
79         public void recordInitializationStartPC(int pc) {
80
81                 if (initializationPCs == null)
82                         return;
83                 // optimize cases where reopening a contiguous interval
84                 if ((initializationCount > 0)
85                                 && (initializationPCs[((initializationCount - 1) << 1) + 1] == pc)) {
86                         initializationPCs[((initializationCount - 1) << 1) + 1] = -1; // reuse
87                                                                                                                                                         // previous
88                                                                                                                                                         // interval
89                                                                                                                                                         // (its
90                                                                                                                                                         // range
91                                                                                                                                                         // will
92                                                                                                                                                         // be
93                                                                                                                                                         // augmented)
94                 } else {
95                         int index = initializationCount << 1;
96                         if (index == initializationPCs.length) {
97                                 System
98                                                 .arraycopy(
99                                                                 initializationPCs,
100                                                                 0,
101                                                                 (initializationPCs = new int[initializationCount << 2]),
102                                                                 0, index);
103                         }
104                         initializationPCs[index] = pc;
105                         initializationPCs[index + 1] = -1;
106                         initializationCount++;
107                 }
108         }
109
110         public String toString() {
111
112                 String s = super.toString();
113                 switch (useFlag) {
114                 case USED:
115                         s += "[pos: " + String.valueOf(resolvedPosition) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
116                         break;
117                 case UNUSED:
118                         s += "[pos: unused]"; //$NON-NLS-1$
119                         break;
120                 case FAKE_USED:
121                         s += "[pos: fake_used]"; //$NON-NLS-1$
122                         break;
123                 }
124                 s += "[id:" + String.valueOf(id) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
125                 if (initializationCount > 0) {
126                         s += "[pc: "; //$NON-NLS-1$
127                         for (int i = 0; i < initializationCount; i++) {
128                                 if (i > 0)
129                                         s += ", "; //$NON-NLS-1$
130                                 s += String.valueOf(initializationPCs[i << 1])
131                                                 + "-" + ((initializationPCs[(i << 1) + 1] == -1) ? "?" : String.valueOf(initializationPCs[(i << 1) + 1])); //$NON-NLS-2$ //$NON-NLS-1$
132                         }
133                         s += "]"; //$NON-NLS-1$
134                 }
135                 return s;
136         }
137 }