Package org.eclipse.jdt.internal.compiler.lookup

Examples of org.eclipse.jdt.internal.compiler.lookup.FieldBinding


    }
  }
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // assigning to a field
      int pc = codeStream.position;
      FieldBinding codegenBinding = ((FieldBinding) this.binding).original();
      if (!codegenBinding.isStatic()) { // need a receiver?
        if ((this.bits & ASTNode.DepthMASK) != 0) {
          ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
          Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
          codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
        } else {
View Full Code Here


    codeStream.recordPositionsFrom(pc, this.sourceStart);
    return;
  } else {
    switch (this.bits & ASTNode.RestrictiveFlagMASK) {
      case Binding.FIELD : // reading a field
        FieldBinding codegenField = ((FieldBinding) this.binding).original();
        Constant fieldConstant = codegenField.constant();
        if (fieldConstant != Constant.NotAConstant) {
          // directly use inlined value for constant fields
          if (valueRequired) {
            codeStream.generateConstant(fieldConstant, this.implicitConversion);
          }
          codeStream.recordPositionsFrom(pc, this.sourceStart);
          return;
        }
        if (codegenField.isStatic()) {
          if (!valueRequired
              // if no valueRequired, still need possible side-effects of <clinit> invocation, if field belongs to different class
              && ((FieldBinding)this.binding).original().declaringClass == this.actualReceiverType.erasure()
              && ((this.implicitConversion & TypeIds.UNBOXING) == 0)
              && this.genericCast == null) {
View Full Code Here

* are optimized in one access: e.g "a = a + 1" optimized into "a++".
*/
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, MethodBinding writeAccessor, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // assigning to a field
      FieldBinding codegenField = ((FieldBinding) this.binding).original();
      if (codegenField.isStatic()) {
        if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) {
          TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */);         
          codeStream.fieldAccess(Opcodes.OPC_getstatic, codegenField, constantPoolDeclaringClass);
        } else {
          codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessors[SingleNameReference.READ], null /* default declaringClass */);
        }
      } else {
        if ((this.bits & ASTNode.DepthMASK) != 0) {
          ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
          Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
          codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
        } else {
          codeStream.aload_0();
        }
        codeStream.dup();
        if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) {
          TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */);
          codeStream.fieldAccess(Opcodes.OPC_getfield, codegenField, constantPoolDeclaringClass);
        } else {
          codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessors[SingleNameReference.READ], null /* default declaringClass */);
        }
      }
      break;
    case Binding.LOCAL : // assigning to a local variable (cannot assign to outer local)
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      // using incr bytecode if possible
      Constant assignConstant;
      switch (localBinding.type.id) {
        case T_JavaLangString :
          codeStream.generateStringConcatenationAppend(currentScope, this, expression);
          if (valueRequired) {
            codeStream.dup();
          }
          codeStream.store(localBinding, false);
          return;
        case T_int :
          assignConstant = expression.constant;
          if (localBinding.resolvedPosition == -1) {
            if (valueRequired) {
              /*
               * restart code gen because we either:
               * - need the value
               * - the constant can have potential side-effect
               */
              localBinding.useFlag = LocalVariableBinding.USED;
              throw new AbortMethod(CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE, null);
            } else if (assignConstant == Constant.NotAConstant) {
              // we only need to generate the value of the expression's constant if it is not a constant expression
              expression.generateCode(currentScope, codeStream, false);
            }
            return;
          }
          if ((assignConstant != Constant.NotAConstant)
              && (assignConstant.typeID() != TypeIds.T_float) // only for integral types
              && (assignConstant.typeID() != TypeIds.T_double)) { // TODO (philippe) is this test needed ?
            switch (operator) {
              case PLUS :
                int increment  = assignConstant.intValue();
                if (increment != (short) increment) break; // not representable as a 16-bits value
                codeStream.iinc(localBinding.resolvedPosition, increment);
                if (valueRequired) {
                  codeStream.load(localBinding);
                }
                return;
              case MINUS :
                increment  = -assignConstant.intValue();
                if (increment != (short) increment) break; // not representable as a 16-bits value
                codeStream.iinc(localBinding.resolvedPosition, increment);
                if (valueRequired) {
                  codeStream.load(localBinding);
                }
                return;
            }
          }
          //$FALL-THROUGH$
        default :
          if (localBinding.resolvedPosition == -1) {
            assignConstant = expression.constant;
            if (valueRequired) {
              /*
               * restart code gen because we either:
               * - need the value
               * - the constant can have potential side-effect
               */
              localBinding.useFlag = LocalVariableBinding.USED;
              throw new AbortMethod(CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE, null);
            } else if (assignConstant == Constant.NotAConstant) {
              // we only need to generate the value of the expression's constant if it is not a constant expression
              expression.generateCode(currentScope, codeStream, false);
            }
            return;
          }
          codeStream.load(localBinding);
      }
  }
  // perform the actual compound operation
  int operationTypeID;
  switch(operationTypeID = (this.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4) {
    case T_JavaLangString :
    case T_JavaLangObject :
    case T_undefined :
      // we enter here if the single name reference is a field of type java.lang.String or if the type of the
      // operation is java.lang.Object
      // For example: o = o + ""; // where the compiled type of o is java.lang.Object.
      codeStream.generateStringConcatenationAppend(currentScope, null, expression);
      // no need for generic cast on previous #getfield since using Object string buffer methods.
      break;
    default :
      // promote the array reference to the suitable operation type
      if (this.genericCast != null)
        codeStream.checkcast(this.genericCast);
      codeStream.generateImplicitConversion(this.implicitConversion);
      // generate the increment value (will by itself  be promoted to the operation value)
      if (expression == IntLiteral.One){ // prefix operation
        codeStream.generateConstant(expression.constant, this.implicitConversion);
      } else {
        expression.generateCode(currentScope, codeStream, true);
      }
      // perform the operation
      codeStream.sendOperator(operator, operationTypeID);
      // cast the value back to the array reference type
      codeStream.generateImplicitConversion(assignmentImplicitConversion);
  }
  // store the result back into the variable
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // assigning to a field
      FieldBinding codegenField = ((FieldBinding) this.binding).original();
      fieldStore(currentScope, codeStream, codegenField, writeAccessor, this.actualReceiverType, true /* implicit this*/, valueRequired);
      // no need for generic cast as value got dupped
      return;
    case Binding.LOCAL : // assigning to a local variable
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
View Full Code Here

}

public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // assigning to a field
      FieldBinding fieldBinding = (FieldBinding)this.binding;
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
      // check if postIncrement is the only usage of a private field
      reportOnlyUselesslyReadPrivateField(currentScope, fieldBinding, valueRequired);
      FieldBinding codegenField = fieldBinding.original();
      if (codegenField.isStatic()) {
        if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) {
          TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */);
          codeStream.fieldAccess(Opcodes.OPC_getstatic, codegenField, constantPoolDeclaringClass);
        } else {
          codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessors[SingleNameReference.READ], null /* default declaringClass */);
        }
      } else {
        if ((this.bits & ASTNode.DepthMASK) != 0) {
          ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
          Object[] emulationPath = currentScope.getEmulationPath(targetType, true /*only exact match*/, false/*consider enclosing arg*/);
          codeStream.generateOuterAccess(emulationPath, this, targetType, currentScope);
        } else {
          codeStream.aload_0();
        }
        codeStream.dup();
        if ((this.syntheticAccessors == null) || (this.syntheticAccessors[SingleNameReference.READ] == null)) {
          TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, this.actualReceiverType, true /* implicit this */);
          codeStream.fieldAccess(Opcodes.OPC_getfield, codegenField, constantPoolDeclaringClass);
        } else {
          codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessors[SingleNameReference.READ], null /* default declaringClass */);
        }
      }
      TypeBinding operandType;
      if (this.genericCast != null) {
        codeStream.checkcast(this.genericCast);
        operandType = this.genericCast;
      } else {
        operandType = codegenField.type;
      }
      if (valueRequired) {
        if (codegenField.isStatic()) {
          switch (operandType.id) {
            case TypeIds.T_long :
            case TypeIds.T_double :
              codeStream.dup2();
              break;
View Full Code Here

  //If inlinable field, forget the access emulation, the code gen will directly target it
  if (this.constant != Constant.NotAConstant)
    return;

  if ((this.bits & Binding.FIELD) != 0) {
    FieldBinding fieldBinding = (FieldBinding) this.binding;
    FieldBinding codegenField = fieldBinding.original();
    if (((this.bits & ASTNode.DepthMASK) != 0)
      && (codegenField.isPrivate() // private access
        || (codegenField.isProtected() // implicit protected access
            && codegenField.declaringClass.getPackage() != currentScope.enclosingSourceType().getPackage()))) {
      if (this.syntheticAccessors == null)
        this.syntheticAccessors = new MethodBinding[2];
      this.syntheticAccessors[isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] =
          ((SourceTypeBinding)currentScope.enclosingSourceType().
View Full Code Here

public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
  if (runtimeTimeType == null || compileTimeType == null)
    return;
  // set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
  if (this.binding != null && this.binding.isValidBinding()) {
    FieldBinding originalBinding = this.binding.original();
    TypeBinding originalType = originalBinding.type;
      // extra cast needed if field type is type variable
    if (originalType.leafComponentType().isTypeVariable()) {
        TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
          ? compileTimeType  // unboxing: checkcast before conversion
View Full Code Here

  return this.binding;
}

public void generateAssignment(BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired) {
  int pc = codeStream.position;
  FieldBinding codegenBinding = this.binding.original();
  this.receiver.generateCode(currentScope, codeStream, !codegenBinding.isStatic());
  codeStream.recordPositionsFrom(pc, this.sourceStart);
  assignment.expression.generateCode(currentScope, codeStream, true);
  fieldStore(currentScope, codeStream, codegenBinding, this.syntheticAccessors == null ? null : this.syntheticAccessors[FieldReference.WRITE], this.actualReceiverType, this.receiver.isImplicitThis(), valueRequired);
  if (valueRequired) {
    codeStream.generateImplicitConversion(assignment.implicitConversion);
View Full Code Here

      codeStream.generateConstant(this.constant, this.implicitConversion);
    }
    codeStream.recordPositionsFrom(pc, this.sourceStart);
    return;
  }
  FieldBinding codegenBinding = this.binding.original();
  boolean isStatic = codegenBinding.isStatic();
  boolean isThisReceiver = this.receiver instanceof ThisReference;
  Constant fieldConstant = codegenBinding.constant();
  if (fieldConstant != Constant.NotAConstant) {
    if (!isThisReceiver) {
      this.receiver.generateCode(currentScope, codeStream, !isStatic);
      if (!isStatic){
        codeStream.invokeObjectGetClass();
View Full Code Here

public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
  boolean isStatic;
  // check if compound assignment is the only usage of a private field
  reportOnlyUselesslyReadPrivateField(currentScope, this.binding, valueRequired);
  FieldBinding codegenBinding = this.binding.original();
  this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic()));
  if (isStatic) {
    if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) {
      TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
      codeStream.fieldAccess(Opcodes.OPC_getstatic, codegenBinding, constantPoolDeclaringClass);
    } else {
View Full Code Here

public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) {
  boolean isStatic;
  // check if postIncrement is the only usage of a private field
  reportOnlyUselesslyReadPrivateField(currentScope, this.binding, valueRequired);
  FieldBinding codegenBinding = this.binding.original();
  this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic()));
  if (isStatic) {
    if (this.syntheticAccessors == null || this.syntheticAccessors[FieldReference.READ] == null) {
      TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
      codeStream.fieldAccess(Opcodes.OPC_getstatic, codegenBinding, constantPoolDeclaringClass);
    } else {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.FieldBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.