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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.internal.compiler.ast;
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;
28 public class SingleNameReference extends NameReference implements OperatorIds {
31 public MethodBinding[] syntheticAccessors; // [0]=read accessor [1]=write accessor
32 public static final int READ = 0;
33 public static final int WRITE = 1;
35 public SingleNameReference(char[] source, long pos) {
38 sourceStart = (int) (pos >>> 32);
39 sourceEnd = (int) pos;
41 public FlowInfo analyseAssignment(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, Assignment assignment, boolean isCompound) {
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);
54 manageSyntheticReadAccessIfNecessary(currentScope);
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"
63 // if (flowInfo.isReachable()) {
64 // localBinding.useFlag = LocalVariableBinding.USED;
65 // } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
66 // localBinding.useFlag = LocalVariableBinding.FAKE_USED;
70 if (assignment.expression != null) {
71 flowInfo = assignment.expression.analyseCode(currentScope, flowContext, flowInfo).unconditionalInits();
73 switch (bits & RestrictiveFlagMASK) {
74 case FIELD : // assigning to a field
75 manageSyntheticWriteAccessIfNecessary(currentScope);
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);
85 flowContext.recordSettingFinal(fieldBinding, this);
87 flowInfo.markAsDefinitelyAssigned(fieldBinding);
89 currentScope.problemReporter().cannotAssignToFinalField(fieldBinding, this);
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;
98 bits &= ~FirstAssignmentToLocalMASK;
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);
107 flowContext.recordSettingFinal(localBinding, this);
110 currentScope.problemReporter().cannotAssignToFinalOuterLocal(localBinding, this);
113 flowInfo.markAsDefinitelyAssigned(localBinding);
115 manageEnclosingInstanceAccessIfNecessary(currentScope);
118 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
119 return analyseCode(currentScope, flowContext, flowInfo, true);
121 public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) {
123 switch (bits & RestrictiveFlagMASK) {
124 case FIELD : // reading a field
126 manageSyntheticReadAccessIfNecessary(currentScope);
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);
137 // case LOCAL : // reading a local variable
138 // LocalVariableBinding localBinding;
139 // if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) binding)) {
140 // currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
142 // if (flowInfo.isReachable()) {
143 // localBinding.useFlag = LocalVariableBinding.USED;
144 // } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) {
145 // localBinding.useFlag = LocalVariableBinding.FAKE_USED;
149 manageEnclosingInstanceAccessIfNecessary(currentScope);
153 public TypeBinding checkFieldAccess(BlockScope scope) {
155 FieldBinding fieldBinding = (FieldBinding) binding;
157 bits &= ~RestrictiveFlagMASK; // clear bits
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;
167 constant = FieldReference.getConstantFor(fieldBinding, this, true, scope);
169 if (isFieldUseDeprecated(fieldBinding, scope))
170 scope.problemReporter().deprecatedField(fieldBinding, this);
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());
181 //====================================================
183 return fieldBinding.type;
186 //public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
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);
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);
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);
218 // this.generateReceiver(codeStream);
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);
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);
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);
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
244 // if ((localBinding.type == LongBinding) || (localBinding.type == DoubleBinding)) {
245 // codeStream.pop2();
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);
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);
266 // // implicit conversion
267 // if (valueRequired) {
268 // codeStream.generateImplicitConversion(assignment.implicitConversion);
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);
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
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);
291 // generateReceiver(codeStream);
294 // // managing private access
295 // if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
297 // codeStream.getstatic(fieldBinding);
299 // codeStream.getfield(fieldBinding);
302 // codeStream.invokestatic(syntheticAccessors[READ]);
304 // codeStream.generateImplicitConversion(implicitConversion);
305 // } else { // directly use the inlined value
306 // codeStream.generateConstant(fieldBinding.constant, implicitConversion);
310 // case LOCAL : // reading a local
311 // LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
312 // if (valueRequired) {
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);
319 // // regular local variable read
320 // codeStream.load(localBinding);
322 // codeStream.generateImplicitConversion(implicitConversion);
326 // codeStream.recordPositionsFrom(pc, this.sourceStart);
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++".
334 //public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
336 // this.generateCompoundAssignment(
339 // syntheticAccessors == null ? null : syntheticAccessors[WRITE],
342 // assignmentImplicitConversion,
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++".
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);
357 // codeStream.invokestatic(syntheticAccessors[READ]);
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);
365 // codeStream.aload_0();
368 // if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
369 // codeStream.getfield(fieldBinding);
371 // codeStream.invokestatic(syntheticAccessors[READ]);
375 // case LOCAL : // assigning to a local variable (cannot assign to outer local)
376 // LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding;
377 // Constant assignConstant;
379 // // using incr bytecode if possible
380 // switch (localBinding.type.id) {
382 // codeStream.generateStringAppend(currentScope, this, expression);
383 // if (valueRequired) {
386 // codeStream.store(localBinding, false);
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) {
395 // codeStream.iinc(localBinding.resolvedPosition, increment);
396 // if (valueRequired) {
397 // codeStream.load(localBinding);
401 // codeStream.iinc(localBinding.resolvedPosition, -increment);
402 // if (valueRequired) {
403 // codeStream.load(localBinding);
409 // codeStream.load(localBinding);
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);
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);
426 // expression.generateCode(currentScope, codeStream, true);
428 // // perform the operation
429 // codeStream.sendOperator(operator, operationTypeID);
430 // // cast the value back to the array reference type
431 // codeStream.generateImplicitConversion(assignmentImplicitConversion);
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);
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();
447 // codeStream.store(localBinding, false);
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);
458 // codeStream.invokestatic(syntheticAccessors[READ]);
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);
466 // codeStream.aload_0();
469 // if ((syntheticAccessors == null) || (syntheticAccessors[READ] == null)) {
470 // codeStream.getfield(fieldBinding);
472 // codeStream.invokestatic(syntheticAccessors[READ]);
475 // if (valueRequired) {
476 // if (fieldBinding.isStatic()) {
477 // if ((fieldBinding.type == LongBinding) || (fieldBinding.type == DoubleBinding)) {
478 // codeStream.dup2();
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();
486 // codeStream.dup_x1();
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);
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);
502 // if (postIncrement.operator == PLUS) {
503 // codeStream.iinc(localBinding.resolvedPosition, 1);
505 // codeStream.iinc(localBinding.resolvedPosition, -1);
508 // codeStream.load(localBinding);
509 // if (valueRequired){
510 // if ((localBinding.type == LongBinding) || (localBinding.type == DoubleBinding)) {
511 // codeStream.dup2();
516 // codeStream.generateConstant(postIncrement.expression.constant, implicitConversion);
517 // codeStream.sendOperator(postIncrement.operator, localBinding.type.id);
518 // codeStream.generateImplicitConversion(postIncrement.assignmentImplicitConversion);
520 // codeStream.store(localBinding, false);
524 //public void generateReceiver(CodeStream codeStream) {
525 // codeStream.aload_0();
527 public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope) {
529 //If inlinable field, forget the access emulation, the code gen will directly target it
530 if (((bits & DepthMASK) == 0) || (constant != NotAConstant)) return;
532 if ((bits & RestrictiveFlagMASK) == LOCAL) {
533 currentScope.emulateOuterAccess((LocalVariableBinding) binding);
536 public void manageSyntheticReadAccessIfNecessary(BlockScope currentScope) {
538 //If inlinable field, forget the access emulation, the code gen will directly target it
539 if (constant != NotAConstant)
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);
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);
574 public void manageSyntheticWriteAccessIfNecessary(BlockScope currentScope) {
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);
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);
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);
616 scope.problemReporter().unresolvableReference(this, binding);
620 public TypeBinding resolveType(BlockScope scope) {
621 // for code gen, harm the restrictiveFlag
623 this.actualReceiverType = this.receiverType = scope.enclosingSourceType();
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
634 if ((this.bits & IsStrictlyAssignedMASK) == 0) {
635 constant = variable.constant;
637 constant = NotAConstant;
639 if ((!variable.isFinal()) && ((bits & DepthMASK) != 0)) {
640 scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding)variable, this);
642 return this.resolvedType = variable.type;
645 return this.resolvedType = checkFieldAccess(scope);
648 // thus it was a type
649 bits &= ~RestrictiveFlagMASK; // clear bits
651 case TYPE : //========only type==============
652 constant = Constant.NotAConstant;
654 if (isTypeUseDeprecated((TypeBinding) binding, scope))
655 scope.problemReporter().deprecatedType((TypeBinding) binding, this);
656 return this.resolvedType = (TypeBinding) binding;
661 return this.resolvedType = this.reportError(scope);
663 public StringBuffer printExpression(int indent, StringBuffer output){
665 return output.append(token);
667 public String toStringExpression(){
669 return new String(token);}
670 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
671 visitor.visit(this, scope);
672 visitor.endVisit(this, scope);
674 public String unboundReferenceErrorName(){
676 return new String(token);}