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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.lookup;
13 import net.sourceforge.phpdt.internal.compiler.ast.LocalDeclaration;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
16 public class LocalVariableBinding extends VariableBinding {
17 public boolean isArgument;
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
24 public int[] initializationPCs;
25 public int initializationCount = 0;
27 // for synthetic local variables
28 public LocalVariableBinding(char[] name, TypeBinding type, int modifiers, boolean isArgument) {
31 this.modifiers = modifiers;
32 if (this.isArgument = isArgument)
33 this.constant = Constant.NotAConstant;
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;
42 * Answer the receiver's binding type from Binding.BindingID.
45 public final int bindingType() {
48 // Answer whether the variable binding is a secret variable added for code gen purposes
50 public boolean isSecret() {
51 return declaration == null && !isArgument;
53 public void recordInitializationEndPC(int pc) {
54 if (initializationPCs[((initializationCount - 1) << 1) + 1] == -1)
55 initializationPCs[((initializationCount - 1) << 1) + 1] = pc;
57 public void recordInitializationStartPC(int pc) {
58 if (initializationPCs == null)
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)
64 int index = initializationCount << 1;
65 if (index == initializationPCs.length) {
66 System.arraycopy(initializationPCs, 0, (initializationPCs = new int[initializationCount << 2]), 0, index);
68 initializationPCs[index] = pc;
69 initializationPCs[index + 1] = -1;
70 initializationCount++;
73 public String toString() {
74 String s = super.toString();
76 s += "[pos: unused]"; //$NON-NLS-1$
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++) {
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$
87 s += "]"; //$NON-NLS-1$