Small improvements in parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / SingleNameReference.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.phpeclipse.internal.compiler.ast;
12
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.flow.FlowContext;
15 import net.sourceforge.phpdt.internal.compiler.flow.FlowInfo;
16 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
17 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
18 import net.sourceforge.phpdt.internal.compiler.lookup.FieldBinding;
19 import net.sourceforge.phpdt.internal.compiler.lookup.LocalVariableBinding;
20 import net.sourceforge.phpdt.internal.compiler.lookup.MethodBinding;
21 import net.sourceforge.phpdt.internal.compiler.lookup.MethodScope;
22 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemFieldBinding;
23 import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReferenceBinding;
24 import net.sourceforge.phpdt.internal.compiler.lookup.SourceTypeBinding;
25 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
26 import net.sourceforge.phpdt.internal.compiler.lookup.VariableBinding;
27
28 public class SingleNameReference extends NameReference implements OperatorIds {
29         public char[] token;
30
31         public MethodBinding[] syntheticAccessors; // [0]=read accessor [1]=write accessor
32         public static final int READ = 0;
33         public static final int WRITE = 1;
34         
35 public SingleNameReference(char[] source, long pos) {
36         super();
37         token = source;
38         sourceStart = (int) (pos >>> 32);
39         sourceEnd = (int) pos;
40 }
41 public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
42
43         // compound assignment extra work
44         if (isCompound) { // check the variable part is initialized if blank final
45                 switch (bits & RestrictiveFlagMASK) {
46                         case FIELD : // reading a field
47                                 FieldBinding fieldBinding;
48                                 if ((fieldBinding = (FieldBinding) binding).isBlankFinal() 
49                                                 && currentScope.allowBlankFinalFieldAssignment(fieldBinding)) {
50                                         if (!flowInfo.isDefinitelyAssigned(fieldBinding)) {
51                                                 currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
52                                         }
53                                 }
54                                 manageSyntheticReadAccessIfNecessary(currentScope);
55                                 break;
56 //                      case LOCAL : // reading a local variable
57 //                              // check if assigning a final blank field
58 //                              LocalVariableBinding localBinding;
59 //                              if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
60 //                                      currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
61 //                                      // we could improve error msg here telling "cannot use compound assignment on final local variable"
62 //                              }
63 //                              if (flowInfo.isReachable()) {
64 //                                      localBinding.useFlag = LocalVariableBinding.USED;
65 //                              } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
66 //                                      localBinding.useFlag = LocalVariableBinding.FAKE_USED;
67 //                              }
68                 }
69         }
70         if (assignment.expression != null) {
71                 flowInfo = assignment.expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
72         }
73         switch (bits & RestrictiveFlagMASK) {
74                 case FIELD : // assigning to a field
75                         manageSyntheticWriteAccessIfNecessary(currentScope);
76
77                         // check if assigning a final field
78                         FieldBinding fieldBinding;
79                         if ((fieldBinding = (FieldBinding) binding).isFinal()) {
80                                 // inside a context where allowed
81                                 if (!isCompound && fieldBinding.isBlankFinal() && currentScope.allowBlankFinalFieldAssignment(fieldBinding)) {
82                                         if (flowInfo.isPotentiallyAssigned(fieldBinding)) {
83                                                 currentScope.problemReporter().duplicateInitializationOfBlankFinalField(fieldBinding, this);
84                                         } else {
85                                                 flowContext.recordSettingFinal(fieldBinding, this);                                             
86                                         }
87                                         flowInfo.markAsDefinitelyAssigned(fieldBinding);
88                                 } else {
89                                         currentScope.problemReporter().cannotAssignToFinalField(fieldBinding, this);
90                                 }
91                         }
92                         break;
93                 case LOCAL : // assigning to a local variable 
94                         LocalVariableBinding localBinding = (LocalVariableBinding) binding;
95                         if (!flowInfo.isDefinitelyAssigned(localBinding)){// for local variable debug attributes
96                                 bits |= FirstAssignmentToLocalMASK;
97                         } else {
98                                 bits &= ~FirstAssignmentToLocalMASK;
99                         }
100                         if (localBinding.isFinal()) {
101                                 if ((bits & DepthMASK) == 0) {
102                                         if (isCompound || !localBinding.isBlankFinal()){
103                                                 currentScope.problemReporter().cannotAssignToFinalLocal(localBinding, this);
104                                         } else if (flowInfo.isPotentiallyAssigned(localBinding)) {
105                                                 currentScope.problemReporter().duplicateInitializationOfFinalLocal(localBinding, this);
106                                         } else {
107                                                 flowContext.recordSettingFinal(localBinding, this);                                                             
108                                         }
109                                 } else {
110                                         currentScope.problemReporter().cannotAssignToFinalOuterLocal(localBinding, this);
111                                 }
112                         }
113                         flowInfo.markAsDefinitelyAssigned(localBinding);
114         }
115         manageEnclosingInstanceAccessIfNecessary(currentScope);
116         return flowInfo;
117 }
118 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
119         return analyseCode(currentScope, flowContext, flowInfo, true);
120 }
121 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
122
123         switch (bits & RestrictiveFlagMASK) {
124                 case FIELD : // reading a field
125                         if (valueRequired) {
126                                 manageSyntheticReadAccessIfNecessary(currentScope);
127                         }
128                         // check if reading a final blank field
129                         FieldBinding fieldBinding;
130                         if ((fieldBinding = (FieldBinding) binding).isBlankFinal() 
131                                         && currentScope.allowBlankFinalFieldAssignment(fieldBinding)) {
132                                 if (!flowInfo.isDefinitelyAssigned(fieldBinding)) {
133                                         currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this);
134                                 }
135                         }
136                         break;
137 //              case LOCAL : // reading a local variable
138 //                      LocalVariableBinding localBinding;
139 //                      if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
140 //                              currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
141 //                      }
142 //                      if (flowInfo.isReachable()) {
143 //                              localBinding.useFlag = LocalVariableBinding.USED;
144 //                      } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
145 //                              localBinding.useFlag = LocalVariableBinding.FAKE_USED;
146 //                      }
147         }
148         if (valueRequired) {
149                 manageEnclosingInstanceAccessIfNecessary(currentScope);
150         }
151         return flowInfo;
152 }
153 public TypeBinding checkFieldAccess(BlockScope scope) {
154
155         FieldBinding fieldBinding = (FieldBinding) binding;
156         
157         bits &= ~RestrictiveFlagMASK; // clear bits
158         bits |= FIELD;
159         if (!((FieldBinding) binding).isStatic()) {
160                 // must check for the static status....
161                 if (scope.methodScope().isStatic) {
162                         scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
163                         constant = NotAConstant;
164                         return fieldBinding.type;
165                 }
166         }
167         constant = FieldReference.getConstantFor(fieldBinding, this, true, scope);
168
169         if (isFieldUseDeprecated(fieldBinding, scope))
170                 scope.problemReporter().deprecatedField(fieldBinding, this);
171
172         MethodScope ms = scope.methodScope();
173         if ((this.bits & IsStrictlyAssignedMASK) == 0
174                 && ms.enclosingSourceType() == fieldBinding.declaringClass
175                 && ms.fieldDeclarationIndex != MethodScope.NotInFieldDecl
176                 && fieldBinding.id >= ms.fieldDeclarationIndex) {
177                 //if the field is static and ms is not .... then it is valid
178                 if (!fieldBinding.isStatic() || ms.isStatic)
179                         scope.problemReporter().forwardReference(this, 0, scope.enclosingSourceType());
180         }
181         //====================================================
182
183         return fieldBinding.type;
184
185 }
186 //public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
187 //
188 //      // optimizing assignment like: i = i + 1 or i = 1 + i
189 //      if (assignment.expression.isCompactableOperation()) {
190 //              BinaryExpression operation = (BinaryExpression) assignment.expression;
191 //              SingleNameReference variableReference;
192 //              if ((operation.left instanceof SingleNameReference) && ((variableReference = (SingleNameReference) operation.left).binding == binding)) {
193 //                      // i = i + value, then use the variable on the right hand side, since it has the correct implicit conversion
194 //                      variableReference.generateCompoundAssignment(currentScope, codeStream, syntheticAccessors == null ? null : syntheticAccessors[WRITE], operation.right, (operation.bits & OperatorMASK) >> OperatorSHIFT, operation.left.implicitConversion /*should be equivalent to no conversion*/, valueRequired);
195 //                      return;
196 //              }
197 //              int operator = (operation.bits & OperatorMASK) >> OperatorSHIFT;
198 //              if ((operation.right instanceof SingleNameReference)
199 //                      && ((operator == PLUS) || (operator == MULTIPLY)) // only commutative operations
200 //                      && ((variableReference = (SingleNameReference) operation.right).binding == binding)
201 //                      && (operation.left.constant != NotAConstant) // exclude non constant expressions, since could have side-effect
202 //                      && ((operation.left.implicitConversion >> 4) != T_String) // exclude string concatenation which would occur backwards
203 //                      && ((operation.right.implicitConversion >> 4) != T_String)) { // exclude string concatenation which would occur backwards
204 //                      // i = value + i, then use the variable on the right hand side, since it has the correct implicit conversion
205 //                      variableReference.generateCompoundAssignment(currentScope, codeStream, syntheticAccessors == null ? null : syntheticAccessors[WRITE], operation.left, operator, operation.right.implicitConversion /*should be equivalent to no conversion*/, valueRequired);
206 //                      return;
207 //              }
208 //      }
209 //      switch (bits & RestrictiveFlagMASK) {
210 //              case FIELD : // assigning to a field
211 //                      FieldBinding fieldBinding;
212 //                      if (!(fieldBinding = (FieldBinding) this.codegenBinding).isStatic()) { // need a receiver?
213 //                              if ((bits & DepthMASK) != 0) {
214 //                                      ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
215 //                                      Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
216 //                                      codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
217 //                              } else {
218 //                                      this.generateReceiver(codeStream);
219 //                              }
220 //                      }
221 //                      assignment.expression.generateCode(currentScope, codeStream, true);
222 //                      fieldStore(codeStream, fieldBinding, syntheticAccessors == null ? null : syntheticAccessors[WRITE], valueRequired);
223 //                      if (valueRequired) {
224 //                              codeStream.generateImplicitConversion(assignment.implicitConversion);
225 //                      }
226 //                      return;
227 //              case LOCAL : // assigning to a local variable
228 //                      LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
229 //                      if (localBinding.resolvedPosition != -1) {
230 //                              assignment.expression.generateCode(currentScope, codeStream, true);
231 //                      } else {
232 //                              if (assignment.expression.constant != NotAConstant) {
233 //                                      // assigning an unused local to a constant value = no actual assignment is necessary
234 //                                      if (valueRequired) {
235 //                                              codeStream.generateConstant(assignment.expression.constant, assignment.implicitConversion);
236 //                                      }
237 //                              } else {
238 //                                      assignment.expression.generateCode(currentScope, codeStream, true);
239 //                                      /* Even though the value may not be required, we force it to be produced, and discard it later
240 //                                      on if it was actually not necessary, so as to provide the same behavior as JDK1.2beta3. */
241 //                                      if (valueRequired) {
242 //                                              codeStream.generateImplicitConversion(assignment.implicitConversion); // implicit conversion
243 //                                      } else {
244 //                                              if ((localBinding.type == LongBinding) || (localBinding.type == DoubleBinding)) {
245 //                                                      codeStream.pop2();
246 //                                              } else {
247 //                                                      codeStream.pop();
248 //                                              }
249 //                                      }
250 //                              }
251 //                              return;
252 //                      }
253 //                      // 26903, need extra cast to store null in array local var      
254 //                      if (localBinding.type.isArrayType() 
255 //                              && (assignment.expression.resolvedType == NullBinding   // arrayLoc = null
256 //                                      || ((assignment.expression instanceof CastExpression)   // arrayLoc = (type[])null
257 //                                              && (((CastExpression)assignment.expression).innermostCastedExpression().resolvedType == NullBinding)))){
258 //                              codeStream.checkcast(localBinding.type); 
259 //                      }
260 //                      
261 //                      // normal local assignment (since cannot store in outer local which are final locations)
262 //                      codeStream.store(localBinding, valueRequired);
263 //                      if ((bits & FirstAssignmentToLocalMASK) != 0) { // for local variable debug attributes
264 //                              localBinding.recordInitializationStartPC(codeStream.position);
265 //                      }
266 //                      // implicit conversion
267 //                      if (valueRequired) {
268 //                              codeStream.generateImplicitConversion(assignment.implicitConversion);
269 //                      }
270 //      }
271 //}
272 //public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
273 //      int pc = codeStream.position;
274 //      if (constant != NotAConstant) {
275 //              if (valueRequired) {
276 //                      codeStream.generateConstant(constant, implicitConversion);
277 //              }
278 //      } else {
279 //              switch (bits & RestrictiveFlagMASK) {
280 //                      case FIELD : // reading a field
281 //                              FieldBinding fieldBinding;
282 //                              if (valueRequired) {
283 //                                      if ((fieldBinding = (FieldBinding) this.codegenBinding).constant == NotAConstant) { // directly use inlined value for constant fields
284 //                                              boolean isStatic;
285 //                                              if (!(isStatic = fieldBinding.isStatic())) {
286 //                                                      if ((bits & DepthMASK) != 0) {
287 //                                                              ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
288 //                                                              Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
289 //                                                              codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
290 //                                                      } else {
291 //                                                              generateReceiver(codeStream);
292 //                                                      }
293 //                                              }
294 //                                              // managing private access                                                      
295 //                                              if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
296 //                                                      if (isStatic) {
297 //                                                              codeStream.getstatic(fieldBinding);
298 //                                                      } else {
299 //                                                              codeStream.getfield(fieldBinding);
300 //                                                      }
301 //                                              } else {
302 //                                                      codeStream.invokestatic(syntheticAccessors[READ]);
303 //                                              }
304 //                                              codeStream.generateImplicitConversion(implicitConversion);
305 //                                      } else { // directly use the inlined value
306 //                                              codeStream.generateConstant(fieldBinding.constant, implicitConversion);
307 //                                      }
308 //                              }
309 //                              break;
310 //                      case LOCAL : // reading a local
311 //                              LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
312 //                              if (valueRequired) {
313 //                                      // outer local?
314 //                                      if ((bits & DepthMASK) != 0) {
315 //                                              // outer local can be reached either through a synthetic arg or a synthetic field
316 //                                              VariableBinding[] path = currentScope.getEmulationPath(localBinding);
317 //                                              codeStream.generateOuterAccess(path, this, localBinding, currentScope);
318 //                                      } else {
319 //                                              // regular local variable read
320 //                                              codeStream.load(localBinding);
321 //                                      }
322 //                                      codeStream.generateImplicitConversion(implicitConversion);
323 //                              }
324 //              }
325 //      }
326 //      codeStream.recordPositionsFrom(pc, this.sourceStart);
327 //}
328 ///*
329 // * Regular API for compound assignment, relies on the fact that there is only one reference to the
330 // * variable, which carries both synthetic read/write accessors.
331 // * The APIs with an extra argument is used whenever there are two references to the same variable which
332 // * are optimized in one access: e.g "a = a + 1" optimized into "a++".
333 // */
334 //public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
335 //
336 //      this.generateCompoundAssignment(
337 //              currentScope, 
338 //              codeStream, 
339 //              syntheticAccessors == null ? null : syntheticAccessors[WRITE],
340 //              expression,
341 //              operator, 
342 //              assignmentImplicitConversion, 
343 //              valueRequired);
344 //}
345 ///*
346 // * The APIs with an extra argument is used whenever there are two references to the same variable which
347 // * are optimized in one access: e.g "a = a + 1" optimized into "a++".
348 // */
349 //public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, MethodBinding writeAccessor, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
350 //      switch (bits & RestrictiveFlagMASK) {
351 //              case FIELD : // assigning to a field
352 //                      FieldBinding fieldBinding;
353 //                      if ((fieldBinding = (FieldBinding) this.codegenBinding).isStatic()) {
354 //                              if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
355 //                                      codeStream.getstatic(fieldBinding);
356 //                              } else {
357 //                                      codeStream.invokestatic(syntheticAccessors[READ]);
358 //                              }
359 //                      } else {
360 //                              if ((bits & DepthMASK) != 0) {
361 //                                      ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
362 //                                      Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
363 //                                      codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
364 //                              } else {
365 //                                      codeStream.aload_0();
366 //                              }
367 //                              codeStream.dup();
368 //                              if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
369 //                                      codeStream.getfield(fieldBinding);
370 //                              } else {
371 //                                      codeStream.invokestatic(syntheticAccessors[READ]);
372 //                              }
373 //                      }
374 //                      break;
375 //              case LOCAL : // assigning to a local variable (cannot assign to outer local)
376 //                      LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
377 //                      Constant assignConstant;
378 //                      int increment;
379 //                      // using incr bytecode if possible
380 //                      switch (localBinding.type.id) {
381 //                              case T_String :
382 //                                      codeStream.generateStringAppend(currentScope, this, expression);
383 //                                      if (valueRequired) {
384 //                                              codeStream.dup();
385 //                                      }
386 //                                      codeStream.store(localBinding, false);
387 //                                      return;
388 //                              case T_int :
389 //                                      if (((assignConstant = expression.constant) != NotAConstant) 
390 //                                              && (assignConstant.typeID() != T_float) // only for integral types
391 //                                              && (assignConstant.typeID() != T_double)
392 //                                              && ((increment = assignConstant.intValue()) == (short) increment)) { // 16 bits value
393 //                                              switch (operator) {
394 //                                                      case PLUS :
395 //                                                              codeStream.iinc(localBinding.resolvedPosition, increment);
396 //                                                              if (valueRequired) {
397 //                                                                      codeStream.load(localBinding);
398 //                                                              }
399 //                                                              return;
400 //                                                      case MINUS :
401 //                                                              codeStream.iinc(localBinding.resolvedPosition, -increment);
402 //                                                              if (valueRequired) {
403 //                                                                      codeStream.load(localBinding);
404 //                                                              }
405 //                                                              return;
406 //                                              }
407 //                                      }
408 //                              default :
409 //                                      codeStream.load(localBinding);
410 //                      }
411 //      }
412 //      // perform the actual compound operation
413 //      int operationTypeID;
414 //      if ((operationTypeID = implicitConversion >> 4) == T_String || operationTypeID == T_Object) {
415 //              // we enter here if the single name reference is a field of type java.lang.String or if the type of the 
416 //              // operation is java.lang.Object
417 //              // For example: o = o + ""; // where the compiled type of o is java.lang.Object.
418 //              codeStream.generateStringAppend(currentScope, null, expression);
419 //      } else {
420 //              // promote the array reference to the suitable operation type
421 //              codeStream.generateImplicitConversion(implicitConversion);
422 //              // generate the increment value (will by itself  be promoted to the operation value)
423 //              if (expression == IntLiteral.One){ // prefix operation
424 //                      codeStream.generateConstant(expression.constant, implicitConversion);                   
425 //              } else {
426 //                      expression.generateCode(currentScope, codeStream, true);
427 //              }               
428 //              // perform the operation
429 //              codeStream.sendOperator(operator, operationTypeID);
430 //              // cast the value back to the array reference type
431 //              codeStream.generateImplicitConversion(assignmentImplicitConversion);
432 //      }
433 //      // store the result back into the variable
434 //      switch (bits & RestrictiveFlagMASK) {
435 //              case FIELD : // assigning to a field
436 //                      fieldStore(codeStream, (FieldBinding) this.codegenBinding, writeAccessor, valueRequired);
437 //                      return;
438 //              case LOCAL : // assigning to a local variable
439 //                      LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
440 //                      if (valueRequired) {
441 //                              if ((localBinding.type == LongBinding) || (localBinding.type == DoubleBinding)) {
442 //                                      codeStream.dup2();
443 //                              } else {
444 //                                      codeStream.dup();
445 //                              }
446 //                      }
447 //                      codeStream.store(localBinding, false);
448 //      }
449 //}
450 //public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
451 //      switch (bits & RestrictiveFlagMASK) {
452 //              case FIELD : // assigning to a field
453 //                      FieldBinding fieldBinding;
454 //                      if ((fieldBinding = (FieldBinding) this.codegenBinding).isStatic()) {
455 //                              if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
456 //                                      codeStream.getstatic(fieldBinding);
457 //                              } else {
458 //                                      codeStream.invokestatic(syntheticAccessors[READ]);
459 //                              }
460 //                      } else {
461 //                              if ((bits & DepthMASK) != 0) {
462 //                                      ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT);
463 //                                      Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
464 //                                      codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
465 //                              } else {
466 //                                      codeStream.aload_0();
467 //                              }
468 //                              codeStream.dup();
469 //                              if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
470 //                                      codeStream.getfield(fieldBinding);
471 //                              } else {
472 //                                      codeStream.invokestatic(syntheticAccessors[READ]);
473 //                              }
474 //                      }
475 //                      if (valueRequired) {
476 //                              if (fieldBinding.isStatic()) {
477 //                                      if ((fieldBinding.type == LongBinding) || (fieldBinding.type == DoubleBinding)) {
478 //                                              codeStream.dup2();
479 //                                      } else {
480 //                                              codeStream.dup();
481 //                                      }
482 //                              } else { // Stack:  [owner][old field value]  ---> [old field value][owner][old field value]
483 //                                      if ((fieldBinding.type == LongBinding) || (fieldBinding.type == DoubleBinding)) {
484 //                                              codeStream.dup2_x1();
485 //                                      } else {
486 //                                              codeStream.dup_x1();
487 //                                      }
488 //                              }
489 //                      }
490 //                      codeStream.generateConstant(postIncrement.expression.constant, implicitConversion);
491 //                      codeStream.sendOperator(postIncrement.operator, fieldBinding.type.id);
492 //                      codeStream.generateImplicitConversion(postIncrement.assignmentImplicitConversion);
493 //                      fieldStore(codeStream, fieldBinding, syntheticAccessors == null ? null : syntheticAccessors[WRITE], false);
494 //                      return;
495 //              case LOCAL : // assigning to a local variable
496 //                      LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
497 //                      // using incr bytecode if possible
498 //                      if (localBinding.type == IntBinding) {
499 //                              if (valueRequired) {
500 //                                      codeStream.load(localBinding);
501 //                              }
502 //                              if (postIncrement.operator == PLUS) {
503 //                                      codeStream.iinc(localBinding.resolvedPosition, 1);
504 //                              } else {
505 //                                      codeStream.iinc(localBinding.resolvedPosition, -1);
506 //                              }
507 //                      } else {
508 //                              codeStream.load(localBinding);
509 //                              if (valueRequired){
510 //                                      if ((localBinding.type == LongBinding) || (localBinding.type == DoubleBinding)) {
511 //                                              codeStream.dup2();
512 //                                      } else {
513 //                                              codeStream.dup();
514 //                                      }
515 //                              }
516 //                              codeStream.generateConstant(postIncrement.expression.constant, implicitConversion);
517 //                              codeStream.sendOperator(postIncrement.operator, localBinding.type.id);
518 //                              codeStream.generateImplicitConversion(postIncrement.assignmentImplicitConversion);
519 //
520 //                              codeStream.store(localBinding, false);
521 //                      }
522 //      }
523 //}
524 //public void generateReceiver(CodeStream codeStream) {
525 //      codeStream.aload_0();
526 //}
527 public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope) {
528
529         //If inlinable field, forget the access emulation, the code gen will directly target it
530         if (((bits & DepthMASK) == 0) || (constant != NotAConstant)) return;
531
532         if ((bits & RestrictiveFlagMASK) == LOCAL) {
533                 currentScope.emulateOuterAccess((LocalVariableBinding) binding);
534         }
535 }
536 public void manageSyntheticReadAccessIfNecessary(BlockScope currentScope) {
537
538         //If inlinable field, forget the access emulation, the code gen will directly target it
539         if (constant != NotAConstant)
540                 return;
541
542         if ((bits & FIELD) != 0) {
543                 FieldBinding fieldBinding = (FieldBinding) binding;
544                 if (((bits & DepthMASK) != 0)
545                         && (fieldBinding.isPrivate() // private access
546                                 || (fieldBinding.isProtected() // implicit protected access
547                                                 && fieldBinding.declaringClass.getPackage() 
548                                                         != currentScope.enclosingSourceType().getPackage()))) {
549                         if (syntheticAccessors == null)
550                                 syntheticAccessors = new MethodBinding[2];
551                         syntheticAccessors[READ] = 
552                                 ((SourceTypeBinding)currentScope.enclosingSourceType().
553                                         enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT)).
554                                                 addSyntheticMethod(fieldBinding, true);
555                         currentScope.problemReporter().needToEmulateFieldReadAccess(fieldBinding, this);
556                         return;
557                 }
558                 // if the binding declaring class is not visible, need special action
559                 // for runtime compatibility on 1.2 VMs : change the declaring class of the binding
560                 // NOTE: from target 1.2 on, field's declaring class is touched if any different from receiver type
561                 // and not from Object or implicit static field access. 
562 //              if (fieldBinding.declaringClass != this.actualReceiverType
563 //                      && !this.actualReceiverType.isArrayType()       
564 //                      && fieldBinding.declaringClass != null
565 //                      && fieldBinding.constant == NotAConstant
566 //                      && ((currentScope.environment().options.targetJDK >= CompilerOptions.JDK1_2 
567 //                                      && !fieldBinding.isStatic()
568 //                                      && fieldBinding.declaringClass.id != T_Object) // no change for Object fields (if there was any)
569 //                              || !fieldBinding.declaringClass.canBeSeenBy(currentScope))){
570 //                      this.codegenBinding = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)this.actualReceiverType);
571 //              }
572         }
573 }
574 public void manageSyntheticWriteAccessIfNecessary(BlockScope currentScope) {
575
576         if ((bits & FIELD) != 0) {
577                 FieldBinding fieldBinding = (FieldBinding) binding;
578                 if (((bits & DepthMASK) != 0) 
579                         && (fieldBinding.isPrivate() // private access
580                                 || (fieldBinding.isProtected() // implicit protected access
581                                                 && fieldBinding.declaringClass.getPackage() 
582                                                         != currentScope.enclosingSourceType().getPackage()))) {
583                         if (syntheticAccessors == null)
584                                 syntheticAccessors = new MethodBinding[2];
585                         syntheticAccessors[WRITE] = 
586                                 ((SourceTypeBinding)currentScope.enclosingSourceType().
587                                         enclosingTypeAt((bits & DepthMASK) >> DepthSHIFT)).
588                                                 addSyntheticMethod(fieldBinding, false);
589                         currentScope.problemReporter().needToEmulateFieldWriteAccess(fieldBinding, this);
590                         return;
591                 }
592                 // if the binding declaring class is not visible, need special action
593                 // for runtime compatibility on 1.2 VMs : change the declaring class of the binding
594                 // NOTE: from target 1.2 on, field's declaring class is touched if any different from receiver type
595                 // and not from Object or implicit static field access. 
596 //              if (fieldBinding.declaringClass != this.actualReceiverType
597 //                      && !this.actualReceiverType.isArrayType()       
598 //                      && fieldBinding.declaringClass != null
599 //                      && fieldBinding.constant == NotAConstant
600 //                      && ((currentScope.environment().options.targetJDK >= CompilerOptions.JDK1_2 
601 //                                      && !fieldBinding.isStatic()
602 //                                      && fieldBinding.declaringClass.id != T_Object) // no change for Object fields (if there was any)
603 //                              || !fieldBinding.declaringClass.canBeSeenBy(currentScope))){
604 //                      this.codegenBinding = currentScope.enclosingSourceType().getUpdatedFieldBinding(fieldBinding, (ReferenceBinding)this.actualReceiverType);
605 //              }
606         }
607 }
608 public TypeBinding reportError(BlockScope scope) {
609         //=====error cases=======
610         constant = Constant.NotAConstant;
611         if (binding instanceof ProblemFieldBinding) {
612                 scope.problemReporter().invalidField(this, (FieldBinding) binding);
613         } else if (binding instanceof ProblemReferenceBinding) {
614                 scope.problemReporter().invalidType(this, (TypeBinding) binding);
615         } else {
616                 scope.problemReporter().unresolvableReference(this, binding);
617         }
618         return null;
619 }
620 public TypeBinding resolveType(BlockScope scope) {
621         // for code gen, harm the restrictiveFlag       
622
623         this.actualReceiverType = this.receiverType = scope.enclosingSourceType();
624         
625         if ((this.codegenBinding = this.binding = scope.getBinding(token, bits & RestrictiveFlagMASK, this)).isValidBinding()) {
626                 switch (bits & RestrictiveFlagMASK) {
627                         case VARIABLE : // =========only variable============
628                         case VARIABLE | TYPE : //====both variable and type============
629                                 if (binding instanceof VariableBinding) {
630                                         VariableBinding variable = (VariableBinding) binding;
631                                         if (binding instanceof LocalVariableBinding) {
632                                                 bits &= ~RestrictiveFlagMASK;  // clear bits
633                                                 bits |= LOCAL;
634                                                 if ((this.bits & IsStrictlyAssignedMASK) == 0) {
635                                                         constant = variable.constant;
636                                                 } else {
637                                                         constant = NotAConstant;
638                                                 }
639                                                 if ((!variable.isFinal()) && ((bits & DepthMASK) != 0)) {
640                                                         scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding)variable, this);
641                                                 }
642                                                 return this.resolvedType = variable.type;
643                                         }
644                                         // a field
645                                         return this.resolvedType = checkFieldAccess(scope);
646                                 }
647
648                                 // thus it was a type
649                                 bits &= ~RestrictiveFlagMASK;  // clear bits
650                                 bits |= TYPE;
651                         case TYPE : //========only type==============
652                                 constant = Constant.NotAConstant;
653                                 //deprecated test
654                                 if (isTypeUseDeprecated((TypeBinding) binding, scope))
655                                         scope.problemReporter().deprecatedType((TypeBinding) binding, this);
656                                 return this.resolvedType = (TypeBinding) binding;
657                 }
658         }
659
660         // error scenarii
661         return this.resolvedType = this.reportError(scope);
662 }
663 public StringBuffer printExpression(int indent, StringBuffer output){
664         
665                 return output.append(token);
666         }
667 public String toStringExpression(){
668
669         return new String(token);}
670 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
671         visitor.visit(this, scope);
672         visitor.endVisit(this, scope);
673 }
674 public String unboundReferenceErrorName(){
675
676         return new String(token);}
677 }