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

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


        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682
        currentScope.resetEnclosingMethodStaticFlag();
      }
      break;
    case Binding.LOCAL : // reading a local variable
      LocalVariableBinding localBinding;
      if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) {
        currentScope.problemReporter().uninitializedLocalVariable(localBinding, this);
      }
      if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) {
        localBinding.useFlag = LocalVariableBinding.USED;
View Full Code Here


        codeStream.generateImplicitConversion(assignment.implicitConversion);
      }
      // no need for generic cast as value got dupped
      return;
    case Binding.LOCAL : // assigning to a local variable
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      if (localBinding.resolvedPosition != -1) {
        assignment.expression.generateCode(currentScope, codeStream, true);
      } else {
        if (assignment.expression.constant != Constant.NotAConstant) {
          // assigning an unused local to a constant value = no actual assignment is necessary
          if (valueRequired) {
            codeStream.generateConstant(assignment.expression.constant, assignment.implicitConversion);
          }
        } else {
          assignment.expression.generateCode(currentScope, codeStream, true);
          /* Even though the value may not be required, we force it to be produced, and discard it later
          on if it was actually not necessary, so as to provide the same behavior as JDK1.2beta3.  */
          if (valueRequired) {
            codeStream.generateImplicitConversion(assignment.implicitConversion); // implicit conversion
          } else {
            switch(localBinding.type.id) {
              case TypeIds.T_long :
              case TypeIds.T_double :
                codeStream.pop2();
                break;
              default :
                codeStream.pop();
                break;
            }           
          }
        }
        return;
      }
      // 26903, need extra cast to store null in array local var
      if (localBinding.type.isArrayType()
        && (assignment.expression.resolvedType == TypeBinding.NULL  // arrayLoc = null
          || ((assignment.expression instanceof CastExpression// arrayLoc = (type[])null
            && (((CastExpression)assignment.expression).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){
        codeStream.checkcast(localBinding.type);
      }

      // normal local assignment (since cannot store in outer local which are final locations)
      codeStream.store(localBinding, valueRequired);
      if ((this.bits & ASTNode.FirstAssignmentToLocal) != 0) { // for local variable debug attributes
        localBinding.recordInitializationStartPC(codeStream.position);
      }
      // implicit conversion
      if (valueRequired) {
        codeStream.generateImplicitConversion(assignment.implicitConversion);
      }
View Full Code Here

            codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessors[SingleNameReference.READ], null /* default declaringClass */);
          }
        }
        break;
      case Binding.LOCAL : // reading a local
        LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
        if (localBinding.resolvedPosition == -1) {
          if (valueRequired) {
            // restart code gen
            localBinding.useFlag = LocalVariableBinding.USED;
            throw new AbortMethod(CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE, null);
View Full Code Here

*/
public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) {
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.LOCAL:
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      // check if compound assignment is the only usage of this local
      Reference.reportOnlyUselesslyReadLocal(currentScope, localBinding, valueRequired);
      break;
    case Binding.FIELD:
      // check if compound assignment is the only usage of a private field
View Full Code Here

          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;
      if (valueRequired) {
        switch (localBinding.type.id) {
          case TypeIds.T_long :
          case TypeIds.T_double :
            codeStream.dup2();
View Full Code Here

      codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion);
      fieldStore(currentScope, codeStream, codegenField, this.syntheticAccessors == null ? null : this.syntheticAccessors[SingleNameReference.WRITE], this.actualReceiverType, true /*implicit this*/, false);
      // no need for generic cast
      return;
    case Binding.LOCAL : // assigning to a local variable
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
      // check if postIncrement is the only usage of this local
      Reference.reportOnlyUselesslyReadLocal(currentScope, localBinding, valueRequired);
      if (localBinding.resolvedPosition == -1) {
        if (valueRequired) {
View Full Code Here

  //If inlinable field, forget the access emulation, the code gen will directly target it
  if (((this.bits & ASTNode.DepthMASK) == 0) || (this.constant != Constant.NotAConstant)) {
    return;
  }
  if ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL) {
    LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
    if (localVariableBinding != null) {
      if ((localVariableBinding.tagBits & TagBits.NotInitialized) != 0) {
        // local was tagged as uninitialized
        return;
      }
View Full Code Here

  }
  switch (this.bits & ASTNode.RestrictiveFlagMASK) {
    case Binding.FIELD : // reading a field
      return FlowInfo.UNKNOWN;
    case Binding.LOCAL : // reading a local variable
      LocalVariableBinding local = (LocalVariableBinding) this.binding;
      if (local != null)
        return flowInfo.nullStatus(local);
  }
  return FlowInfo.NON_NULL; // never get there
}
View Full Code Here

  this.generateAttributes |= ClassFileConstants.ATTR_STACK_MAP;
}
public void addDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
  // Required to fix 1PR0XVS: LFRE:WINNT - Compiler: variable table for method appears incorrect
  loop: for (int i = 0; i < this.visibleLocalsCount; i++) {
    LocalVariableBinding localBinding = this.visibleLocals[i];
    if (localBinding != null) {
      // Check if the local is definitely assigned
      boolean isDefinitelyAssigned = isDefinitelyAssigned(scope, initStateIndex, localBinding);
      if (!isDefinitelyAssigned) {
        if (this.stateIndexes != null) {
          for (int j = 0, max = this.stateIndexesCounter; j < max; j++) {
            if (isDefinitelyAssigned(scope, this.stateIndexes[j], localBinding)) {
              if ((localBinding.initializationCount == 0) || (localBinding.initializationPCs[((localBinding.initializationCount - 1) << 1) + 1] != -1)) {
                /* There are two cases:
                 * 1) there is no initialization interval opened ==> add an opened interval
                 * 2) there is already some initialization intervals but the last one is closed ==> add an opened interval
                 * An opened interval means that the value at localBinding.initializationPCs[localBinding.initializationCount - 1][1]
                 * is equals to -1.
                 * initializationPCs is a collection of pairs of int:
                 *   first value is the startPC and second value is the endPC. -1 one for the last value means that the interval
                 *   is not closed yet.
                 */
                localBinding.recordInitializationStartPC(this.position);
              }
              continue loop;
            }
          }
        }
      } else {
        if ((localBinding.initializationCount == 0) || (localBinding.initializationPCs[((localBinding.initializationCount - 1) << 1) + 1] != -1)) {
          /* There are two cases:
           * 1) there is no initialization interval opened ==> add an opened interval
           * 2) there is already some initialization intervals but the last one is closed ==> add an opened interval
           * An opened interval means that the value at localBinding.initializationPCs[localBinding.initializationCount - 1][1]
           * is equals to -1.
           * initializationPCs is a collection of pairs of int:
           *   first value is the startPC and second value is the endPC. -1 one for the last value means that the interval
           *   is not closed yet.
           */
          localBinding.recordInitializationStartPC(this.position);
        }
      }
    }
  }
}
 
View Full Code Here

  this.stateIndexes[this.stateIndexesCounter++] = naturalExitMergeInitStateIndex;
}
public void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
  int index = this.visibleLocalsCount;
  loop : for (int i = 0; i < index; i++) {
    LocalVariableBinding localBinding = this.visibleLocals[i];
    if (localBinding != null && localBinding.initializationCount > 0) {
      boolean isDefinitelyAssigned = isDefinitelyAssigned(scope, initStateIndex, localBinding);
      if (!isDefinitelyAssigned) {
        if (this.stateIndexes != null) {
          for (int j = 0, max = this.stateIndexesCounter; j < max; j++) {
            if (isDefinitelyAssigned(scope, this.stateIndexes[j], localBinding)) {
              continue loop;
            }
          }
        }
        localBinding.recordInitializationEndPC(this.position);
      }
    }
  }
}
View Full Code Here

TOP

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

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.