Lines 366-378
Link Here
|
366 |
FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); |
366 |
FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); |
367 |
if (lastFieldBinding != null) { |
367 |
if (lastFieldBinding != null) { |
368 |
boolean isStatic = lastFieldBinding.isStatic(); |
368 |
boolean isStatic = lastFieldBinding.isStatic(); |
369 |
if (lastFieldBinding.isConstantValue()) { |
369 |
Constant fieldConstant = lastFieldBinding.constant(); |
|
|
370 |
if (fieldConstant != Constant.NotAConstant) { |
370 |
if (!isStatic){ |
371 |
if (!isStatic){ |
371 |
codeStream.invokeObjectGetClass(); |
372 |
codeStream.invokeObjectGetClass(); |
372 |
codeStream.pop(); |
373 |
codeStream.pop(); |
373 |
} |
374 |
} |
374 |
if (valueRequired) { // inline the last field constant |
375 |
if (valueRequired) { // inline the last field constant |
375 |
codeStream.generateConstant(lastFieldBinding.constant(), implicitConversion); |
376 |
codeStream.generateConstant(fieldConstant, implicitConversion); |
376 |
} |
377 |
} |
377 |
} else { |
378 |
} else { |
378 |
if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { |
379 |
if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { |
Lines 554-560
Link Here
|
554 |
lastFieldBinding = (FieldBinding) this.codegenBinding; |
555 |
lastFieldBinding = (FieldBinding) this.codegenBinding; |
555 |
lastGenericCast = this.genericCast; |
556 |
lastGenericCast = this.genericCast; |
556 |
// if first field is actually constant, we can inline it |
557 |
// if first field is actually constant, we can inline it |
557 |
if (lastFieldBinding.isConstantValue()) { |
558 |
if (lastFieldBinding.constant() != Constant.NotAConstant) { |
558 |
break; |
559 |
break; |
559 |
} |
560 |
} |
560 |
if ((needValue || complyTo14) && !lastFieldBinding.isStatic()) { |
561 |
if ((needValue || complyTo14) && !lastFieldBinding.isStatic()) { |
Lines 573-580
Link Here
|
573 |
if (!needValue) break; // no value needed |
574 |
if (!needValue) break; // no value needed |
574 |
LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding; |
575 |
LocalVariableBinding localBinding = (LocalVariableBinding) this.codegenBinding; |
575 |
// regular local variable read |
576 |
// regular local variable read |
576 |
if (localBinding.isConstantValue()) { |
577 |
Constant localConstant = localBinding.constant(); |
577 |
codeStream.generateConstant(localBinding.constant(), 0); |
578 |
if (localConstant != Constant.NotAConstant) { |
|
|
579 |
codeStream.generateConstant(localConstant, 0); |
578 |
// no implicit conversion |
580 |
// no implicit conversion |
579 |
} else { |
581 |
} else { |
580 |
// outer local? |
582 |
// outer local? |
Lines 596-608
Link Here
|
596 |
TypeBinding nextGenericCast = this.otherGenericCasts == null ? null : this.otherGenericCasts[i]; |
598 |
TypeBinding nextGenericCast = this.otherGenericCasts == null ? null : this.otherGenericCasts[i]; |
597 |
if (lastFieldBinding != null) { |
599 |
if (lastFieldBinding != null) { |
598 |
needValue = !nextField.isStatic(); |
600 |
needValue = !nextField.isStatic(); |
599 |
if (lastFieldBinding.isConstantValue()) { |
601 |
Constant fieldConstant = lastFieldBinding.constant(); |
|
|
602 |
if (fieldConstant != Constant.NotAConstant) { |
600 |
if (lastFieldBinding != this.codegenBinding && !lastFieldBinding.isStatic()) { |
603 |
if (lastFieldBinding != this.codegenBinding && !lastFieldBinding.isStatic()) { |
601 |
codeStream.invokeObjectGetClass(); // perform null check |
604 |
codeStream.invokeObjectGetClass(); // perform null check |
602 |
codeStream.pop(); |
605 |
codeStream.pop(); |
603 |
} |
606 |
} |
604 |
if (needValue) { |
607 |
if (needValue) { |
605 |
codeStream.generateConstant(lastFieldBinding.constant(), 0); |
608 |
codeStream.generateConstant(fieldConstant, 0); |
606 |
} |
609 |
} |
607 |
} else { |
610 |
} else { |
608 |
if (needValue || complyTo14) { |
611 |
if (needValue || complyTo14) { |
Lines 694-700
Link Here
|
694 |
TypeBinding type = ((VariableBinding) binding).type; |
697 |
TypeBinding type = ((VariableBinding) binding).type; |
695 |
int index = indexOfFirstFieldBinding; |
698 |
int index = indexOfFirstFieldBinding; |
696 |
if (index == length) { // restrictiveFlag == FIELD |
699 |
if (index == length) { // restrictiveFlag == FIELD |
697 |
this.constant = FieldReference.getConstantFor((FieldBinding) binding, this, false, scope); |
700 |
this.constant = ((FieldBinding) binding).constant(); |
698 |
// perform capture conversion if read access |
701 |
// perform capture conversion if read access |
699 |
return (type != null && (this.bits & IsStrictlyAssignedMASK) == 0) |
702 |
return (type != null && (this.bits & IsStrictlyAssignedMASK) == 0) |
700 |
? type.capture(scope, this.sourceEnd) |
703 |
? type.capture(scope, this.sourceEnd) |
Lines 706-714
Link Here
|
706 |
otherDepths = new int[otherBindingsLength]; |
709 |
otherDepths = new int[otherBindingsLength]; |
707 |
|
710 |
|
708 |
// fill the first constant (the one of the binding) |
711 |
// fill the first constant (the one of the binding) |
709 |
this.constant = field != null |
712 |
this.constant = ((VariableBinding) binding).constant(); |
710 |
? FieldReference.getConstantFor((FieldBinding) binding, this, false, scope) |
|
|
711 |
: ((VariableBinding) binding).constant(); |
712 |
// save first depth, since will be updated by visibility checks of other bindings |
713 |
// save first depth, since will be updated by visibility checks of other bindings |
713 |
int firstDepth = (bits & DepthMASK) >> DepthSHIFT; |
714 |
int firstDepth = (bits & DepthMASK) >> DepthSHIFT; |
714 |
// iteration on each field |
715 |
// iteration on each field |
Lines 743-752
Link Here
|
743 |
if (isFieldUseDeprecated(field, scope, (this.bits & IsStrictlyAssignedMASK) !=0 && index+1 == length)) { |
744 |
if (isFieldUseDeprecated(field, scope, (this.bits & IsStrictlyAssignedMASK) !=0 && index+1 == length)) { |
744 |
scope.problemReporter().deprecatedField(field, this); |
745 |
scope.problemReporter().deprecatedField(field, this); |
745 |
} |
746 |
} |
746 |
Constant someConstant = FieldReference.getConstantFor(field, this, false, scope); |
|
|
747 |
// constant propagation can only be performed as long as the previous one is a constant too. |
747 |
// constant propagation can only be performed as long as the previous one is a constant too. |
748 |
if (this.constant != NotAConstant) { |
748 |
if (this.constant != Constant.NotAConstant) { |
749 |
this.constant = someConstant; |
749 |
this.constant = field.constant(); |
750 |
} |
750 |
} |
751 |
|
751 |
|
752 |
if (field.isStatic()) { |
752 |
if (field.isStatic()) { |
Lines 795-801
Link Here
|
795 |
|
795 |
|
796 |
if (!flowInfo.isReachable()) return; |
796 |
if (!flowInfo.isReachable()) return; |
797 |
// index == 0 denotes the first fieldBinding, index > 0 denotes one of the 'otherBindings', index < 0 denotes a write access (to last binding) |
797 |
// index == 0 denotes the first fieldBinding, index > 0 denotes one of the 'otherBindings', index < 0 denotes a write access (to last binding) |
798 |
if (fieldBinding.isConstantValue()) |
798 |
if (fieldBinding.constant() != Constant.NotAConstant) |
799 |
return; |
799 |
return; |
800 |
|
800 |
|
801 |
// if field from parameterized type got found, use the original field at codegen time |
801 |
// if field from parameterized type got found, use the original field at codegen time |
Lines 833-839
Link Here
|
833 |
if (fieldBinding.declaringClass != lastReceiverType |
833 |
if (fieldBinding.declaringClass != lastReceiverType |
834 |
&& !lastReceiverType.isArrayType() |
834 |
&& !lastReceiverType.isArrayType() |
835 |
&& fieldBinding.declaringClass != null // array.length |
835 |
&& fieldBinding.declaringClass != null // array.length |
836 |
&& !fieldBinding.isConstantValue()) { |
836 |
&& fieldBinding.constant() == Constant.NotAConstant) { |
837 |
CompilerOptions options = currentScope.compilerOptions(); |
837 |
CompilerOptions options = currentScope.compilerOptions(); |
838 |
if ((options.targetJDK >= ClassFileConstants.JDK1_2 |
838 |
if ((options.targetJDK >= ClassFileConstants.JDK1_2 |
839 |
&& (options.complianceLevel >= ClassFileConstants.JDK1_4 || !(index <= 1 && indexOfFirstFieldBinding == 1 && fieldBinding.isStatic())) |
839 |
&& (options.complianceLevel >= ClassFileConstants.JDK1_4 || !(index <= 1 && indexOfFirstFieldBinding == 1 && fieldBinding.isStatic())) |