PHPLanguagePreferencePage.spanish and PHPEditorSyntaxPreferencePage.background added...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / lookup / LocalVariableBinding.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.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         public boolean isArgument;
18
19         public int resolvedPosition; // for code generation (position in method context)
20         public boolean used; // for flow analysis
21         public BlockScope declaringScope; // back-pointer to its declaring scope
22         public LocalDeclaration declaration; // for source-positions
23
24         public int[] initializationPCs;
25         public int initializationCount = 0;
26
27 // for synthetic local variables        
28 public LocalVariableBinding(char[] name, TypeBinding type, int modifiers, boolean isArgument) {
29         this.name = name;
30         this.type = type;
31         this.modifiers = modifiers;
32         if (this.isArgument = isArgument)
33                 this.constant = Constant.NotAConstant;
34 }
35
36 // regular local variable or argument
37 public LocalVariableBinding(LocalDeclaration declaration, TypeBinding type, int modifiers, boolean isArgument) {
38         this(declaration.name, type, modifiers, isArgument);
39         this.declaration = declaration;
40 }
41 /* API
42 * Answer the receiver's binding type from Binding.BindingID.
43 */
44
45 public final int bindingType() {
46         return LOCAL;
47 }
48 // Answer whether the variable binding is a secret variable added for code gen purposes
49
50 public boolean isSecret() {
51         return declaration == null && !isArgument;
52 }
53 public void recordInitializationEndPC(int pc) {
54         if (initializationPCs[((initializationCount - 1) << 1) + 1] == -1)
55                 initializationPCs[((initializationCount - 1) << 1) + 1] = pc;
56 }
57 public void recordInitializationStartPC(int pc) {
58         if (initializationPCs == null)
59                 return;
60         // optimize cases where reopening a contiguous interval
61         if ((initializationCount > 0) && (initializationPCs[ ((initializationCount - 1) << 1) + 1] == pc)) {
62                 initializationPCs[ ((initializationCount - 1) << 1) + 1] = -1; // reuse previous interval (its range will be augmented)
63         } else {
64                 int index = initializationCount << 1;
65                 if (index == initializationPCs.length) {
66                         System.arraycopy(initializationPCs, 0, (initializationPCs = new int[initializationCount << 2]), 0, index);
67                 }
68                 initializationPCs[index] = pc;
69                 initializationPCs[index + 1] = -1;
70                 initializationCount++;
71         }
72 }
73 public String toString() {
74         String s = super.toString();
75         if (!used)
76                 s += "[pos: unused]"; //$NON-NLS-1$
77         else
78                 s += "[pos: " + String.valueOf(resolvedPosition) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
79         s += "[id:" + String.valueOf(id) + "]"; //$NON-NLS-2$ //$NON-NLS-1$
80         if (initializationCount > 0) {
81                 s += "[pc: "; //$NON-NLS-1$
82                 for (int i = 0; i < initializationCount; i++) {
83                         if (i > 0)
84                                 s += ", "; //$NON-NLS-1$
85                         s += String.valueOf(initializationPCs[i << 1]) + "-" + ((initializationPCs[(i << 1) + 1] == -1) ? "?" : String.valueOf(initializationPCs[(i<< 1) + 1])); //$NON-NLS-2$ //$NON-NLS-1$
86                 }
87                 s += "]"; //$NON-NLS-1$
88         }
89         return s;
90 }
91 }