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

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


  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

  this.resetSecretLocals();
  super.resetForCodeGenUnusedLocals();
}
public void resetSecretLocals() {
  for (int i = 0, max = this.locals.length; i < max; i++) {
    LocalVariableBinding localVariableBinding = this.locals[i];
    if (localVariableBinding != null && localVariableBinding.isSecret()) {
      // all other locals are reinitialized inside the computation of their resolved positions
      localVariableBinding.resetInitializations();
    }
  }
}
View Full Code Here

        if (this.codeStream.lastEntryPC == oldPosition) {
          this.codeStream.lastEntryPC = this.position;
        }
        // end of new code
        if ((this.codeStream.generateAttributes & (ClassFileConstants.ATTR_VARS | ClassFileConstants.ATTR_STACK_MAP_TABLE | ClassFileConstants.ATTR_STACK_MAP)) != 0) {
          LocalVariableBinding locals[] = this.codeStream.locals;
          for (int i = 0, max = locals.length; i < max; i++) {
            LocalVariableBinding local = locals[i];
            if ((local != null) && (local.initializationCount > 0)) {
              if (local.initializationPCs[((local.initializationCount - 1) << 1) + 1] == oldPosition) {
                // we want to prevent interval of size 0 to have a negative size.
                // see PR 1GIRQLA: ITPJCORE:ALL - ClassFormatError for local variable attribute
                local.initializationPCs[((local.initializationCount - 1) << 1) + 1] = this.position;
View Full Code Here

  UnconditionalFlowInfo flowInfo = this.upstreamNullFlowInfo.
    addPotentialNullInfoFrom(callerFlowInfo.unconditionalInitsWithoutSideEffect());
  if ((this.tagBits & FlowContext.DEFER_NULL_DIAGNOSTIC) != 0) {
    // check only immutable null checks on innermost looping context
    for (int i = 0; i < this.nullCount; i++) {
      LocalVariableBinding local = this.nullLocals[i];
      ASTNode location = this.nullReferences[i];
      // final local variable
      switch (this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) {
        case CAN_ONLY_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            this.nullReferences[i] = null;
            if ((this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == (CAN_ONLY_NON_NULL | IN_COMPARISON_NON_NULL)) {
              if ((this.nullCheckTypes[i] & HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNonNull(local, location);
              }
            } else {
              scope.problemReporter().localVariableNonNullComparedToNull(local, location);
            }
            continue;
          }
          break;
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            this.nullReferences[i] = null;
            if ((this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
              if ((this.nullCheckTypes[i] & HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNonNull(local, location);
              }
            } else {
              scope.problemReporter().localVariableNonNullComparedToNull(local, location);
            }
            continue;
          }
          if (flowInfo.isDefinitelyNull(local)) {
            this.nullReferences[i] = null;
            if ((this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) {
              if ((this.nullCheckTypes[i] & HIDE_NULL_COMPARISON_WARNING) == 0) {
                scope.problemReporter().localVariableRedundantCheckOnNull(local, location);
              }
            } else {
              scope.problemReporter().localVariableNullComparedToNonNull(local, location);
            }
            continue;
          }
          break;
        case CAN_ONLY_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL | IN_COMPARISON_NON_NULL:
        case CAN_ONLY_NULL | IN_ASSIGNMENT:
        case CAN_ONLY_NULL | IN_INSTANCEOF:
          Expression expression = (Expression)location;
          if (flowInfo.isDefinitelyNull(local)) {
            this.nullReferences[i] = null;
            switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
              case FlowContext.IN_COMPARISON_NULL:
                if (((this.nullCheckTypes[i] & CHECK_MASK & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariableNullReference(local, expression);
                  continue;
                }
                if ((this.nullCheckTypes[i] & HIDE_NULL_COMPARISON_WARNING) == 0) {
                  scope.problemReporter().localVariableRedundantCheckOnNull(local, expression);
                }
                continue;
              case FlowContext.IN_COMPARISON_NON_NULL:
                if (((this.nullCheckTypes[i] & CHECK_MASK & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariableNullReference(local, expression);
                  continue;
                }
                scope.problemReporter().localVariableNullComparedToNonNull(local, expression);
                continue;
              case FlowContext.IN_ASSIGNMENT:
                scope.problemReporter().localVariableRedundantNullAssignment(local, expression);
                continue;
              case FlowContext.IN_INSTANCEOF:
                scope.problemReporter().localVariableNullInstanceof(local, expression);
                continue;
            }
          } else if (flowInfo.isPotentiallyNull(local)) {
            switch(this.nullCheckTypes[i] & CONTEXT_MASK) {
              case FlowContext.IN_COMPARISON_NULL:
                this.nullReferences[i] = null;
                if (((this.nullCheckTypes[i] & CHECK_MASK & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariablePotentialNullReference(local, expression);
                  continue;
                }
                break;
              case FlowContext.IN_COMPARISON_NON_NULL:
                this.nullReferences[i] = null;
                if (((this.nullCheckTypes[i] & CHECK_MASK & ~HIDE_NULL_COMPARISON_WARNING_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning
                  scope.problemReporter().localVariablePotentialNullReference(local, expression);
                  continue;
                }
                break;
            }
          } 
          break;
        case MAY_NULL:
          if (flowInfo.isDefinitelyNull(local)) {
            this.nullReferences[i] = null;
            scope.problemReporter().localVariableNullReference(local, location);
            continue;
          }
          break;
        case ASSIGN_TO_NONNULL:
          int nullStatus = flowInfo.nullStatus(local);
          if (nullStatus != FlowInfo.NON_NULL) {
            this.parent.recordNullityMismatch(scope, (Expression)location, this.providedExpectedTypes[i][0], this.providedExpectedTypes[i][1], nullStatus);
          }
          continue; // no more delegation to parent
        case EXIT_RESOURCE:
            FakedTrackingVariable trackingVar = local.closeTracker;
            if (trackingVar != null) {
              if (trackingVar.hasDefinitelyNoResource(flowInfo)) {
                continue; // no resource - no warning.
              }
              if (trackingVar.isClosedInFinallyOfEnclosing(scope)) {
                continue;
              }
              if (this.parent.recordExitAgainstResource(scope, flowInfo, trackingVar, location)) {
                this.nullReferences[i] = null;
                continue;
              }
            }
          break;
        case IN_UNBOXING:
          checkUnboxing(scope, (Expression) location, flowInfo);
          continue; // delegation to parent already handled in the above.
        default:
          // never happens
      }
      // https://bugs.eclipse.org/376263: avoid further deferring if the upstream info
      // already has definite information (which might get lost for deferred checking).
      if (!(this.nullCheckTypes[i] == MAY_NULL && upstreamCopy.isDefinitelyNonNull(local))) {
        this.parent.recordUsingNullReference(scope, local, location,
            this.nullCheckTypes[i], flowInfo);
      }
    }
  }
  else {
    // check inconsistent null checks on outermost looping context
    for (int i = 0; i < this.nullCount; i++) {
      ASTNode location = this.nullReferences[i];
      // final local variable
      LocalVariableBinding local = this.nullLocals[i];
      switch (this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) {
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            this.nullReferences[i] = null;
View Full Code Here

    recordNullReference(null, expression, IN_UNBOXING);
}

/** Record the fact that we see an early exit (in 'reference') while 'trackingVar' is in scope and may be unclosed. */
public boolean recordExitAgainstResource(BlockScope scope, FlowInfo flowInfo, FakedTrackingVariable trackingVar, ASTNode reference) {
  LocalVariableBinding local = trackingVar.binding;
  if (flowInfo.isDefinitelyNonNull(local)) {
    return false;
  }
  if (flowInfo.isDefinitelyNull(local)) {
    scope.problemReporter().unclosedCloseable(trackingVar, reference);
View Full Code Here

  // until the point where it is safely handled (Smarter - see comment at the end)
  FlowContext traversedContext = this;
  ArrayList abruptlyExitedLoops = null;
  if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7 && location instanceof ThrowStatement) {
    Expression throwExpression = ((ThrowStatement)location).exception;
    LocalVariableBinding throwArgBinding = throwExpression.localVariableBinding();
    if (throwExpression instanceof SingleNameReference // https://bugs.eclipse.org/bugs/show_bug.cgi?id=350361
        && throwArgBinding instanceof CatchParameterBinding && throwArgBinding.isEffectivelyFinal()) {
      CatchParameterBinding parameter = (CatchParameterBinding) throwArgBinding;
      checkExceptionHandlers(parameter.getPreciseTypes(), location, flowInfo, scope);
      return;
    }
  }
View Full Code Here

  private void createParameters(JMethod method, AbstractMethodDeclaration x) {
    if (x.arguments != null) {
      for (Argument argument : x.arguments) {
        SourceInfo info = makeSourceInfo(argument);
        LocalVariableBinding binding = argument.binding;
        createParameter(info, binding, method);
      }
    }
    method.freezeParamTypes();
  }
View Full Code Here

      clinitBlock.addStmt(insertionPoint, declStmt);
      return valuesField;
    }

    private JLocal createLocal(LocalDeclaration x) {
      LocalVariableBinding b = x.binding;
      TypeBinding resolvedType = x.type.resolvedType;
      JType localType;
      if (resolvedType.constantPoolName() != null) {
        localType = typeMap.get(resolvedType);
      } else {
        // Special case, a statically unreachable local type.
        localType = JNullType.INSTANCE;
      }
      SourceInfo info = makeSourceInfo(x);
      JLocal newLocal =
          JProgram.createLocal(info, intern(x.name), localType, b.isFinal(), curMethod.body);
      curMethod.locals.put(b, newLocal);
      return newLocal;
    }
View Full Code Here

      // Synthetic args for inner classes
      if (isNested) {
        // Synthetic locals for local classes
        if (targetBinding.syntheticOuterLocalVariables() != null) {
          for (SyntheticArgumentBinding arg : targetBinding.syntheticOuterLocalVariables()) {
            LocalVariableBinding targetVariable = arg.actualOuterLocalVariable;
            VariableBinding[] path = scope.getEmulationPath(targetVariable);
            assert path.length == 1;
            if (curMethod.scope.isInsideInitializer()
                && path[0] instanceof SyntheticArgumentBinding) {
              SyntheticArgumentBinding sb = (SyntheticArgumentBinding) path[0];
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.