Package org.eclipse.jdt.internal.compiler.impl

Examples of org.eclipse.jdt.internal.compiler.impl.Constant


    }
  } else {
    FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream);
    if (lastFieldBinding != null) {
      boolean isStatic = lastFieldBinding.isStatic();
      Constant fieldConstant = lastFieldBinding.constant();
      if (fieldConstant != Constant.NotAConstant) {
        if (!isStatic){
          codeStream.invokeObjectGetClass();
          codeStream.pop();
        }
View Full Code Here


      lastGenericCast = null;
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      lastReceiverType = localBinding.type;
      if (!needValue) break; // no value needed
      // regular local variable read
      Constant localConstant = localBinding.constant();
      if (localConstant != Constant.NotAConstant) {
        codeStream.generateConstant(localConstant, 0);
        // no implicit conversion
      } else {
        // outer local?
        if ((this.bits & ASTNode.DepthMASK) != 0) {
          // outer local can be reached either through a synthetic arg or a synthetic field
          VariableBinding[] path = currentScope.getEmulationPath(localBinding);
          codeStream.generateOuterAccess(path, this, localBinding, currentScope);
        } else {
          codeStream.load(localBinding);
        }
      }
      break;
    default : // should not occur
      return null;
  }

  // all intermediate field accesses are read accesses
  // only the last field binding is a write access
  int positionsLength = this.sourcePositions.length;
  FieldBinding initialFieldBinding = lastFieldBinding; // can be null if initial was a local binding
  if (this.otherBindings != null) {
    for (int i = 0; i < otherBindingsCount; i++) {
      int pc = codeStream.position;
      FieldBinding nextField = this.otherBindings[i].original();
      TypeBinding nextGenericCast = this.otherGenericCasts == null ? null : this.otherGenericCasts[i];
      if (lastFieldBinding != null) {
        needValue = !nextField.isStatic();
        Constant fieldConstant = lastFieldBinding.constant();
        if (fieldConstant != Constant.NotAConstant) {
          if (i > 0 && !lastFieldBinding.isStatic()) {
            codeStream.invokeObjectGetClass(); // perform null check
            codeStream.pop();
          }
View Full Code Here

  /* (non-Javadoc)
   * @see IVariableBinding#getConstantValue()
   * @since 3.0
   */
  public Object getConstantValue() {
    Constant c = this.binding.constant();
    if (c == null || c == Constant.NotAConstant) return null;
    switch (c.typeID()) {
      case TypeIds.T_boolean:
        return Boolean.valueOf(c.booleanValue());
      case TypeIds.T_byte:
        return new Byte(c.byteValue());
      case TypeIds.T_char:
        return new Character(c.charValue());
      case TypeIds.T_double:
        return new Double(c.doubleValue());
      case TypeIds.T_float:
        return new Float(c.floatValue());
      case TypeIds.T_int:
        return new Integer(c.intValue());
      case TypeIds.T_long:
        return new Long(c.longValue());
      case TypeIds.T_short:
        return new Short(c.shortValue());
      case TypeIds.T_JavaLangString:
        return c.stringValue();
    }
    return null;
  }
View Full Code Here

    switch (this.bits & RestrictiveFlagMASK) {
      case Binding.FIELD : // reading a field
        if (!valueRequired)
          break;
        FieldBinding codegenField = ((FieldBinding) this.binding).original();
        Constant fieldConstant = codegenField.constant();
        if (fieldConstant == Constant.NotAConstant) { // directly use inlined value for constant fields
          if (codegenField.canBeSeenBy(getReceiverType(currentScope), this, currentScope)) {
            TypeBinding someReceiverType = this.delegateThis != null ? this.delegateThis.type : this.actualReceiverType;
            TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenField, someReceiverType, true /* implicit this */);
            if (codegenField.isStatic()) {
View Full Code Here

      }
      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);
                }
View Full Code Here

  if (!CharOperation.equals(currentFieldInfo.getTypeName(), otherFieldInfo.getTypeName()))
    return true;
  if (currentFieldInfo.hasConstant() != otherFieldInfo.hasConstant())
    return true;
  if (currentFieldInfo.hasConstant()) {
    Constant currentConstant = currentFieldInfo.getConstant();
    Constant otherConstant = otherFieldInfo.getConstant();
    if (currentConstant.typeID() != otherConstant.typeID())
      return true;
    if (!currentConstant.getClass().equals(otherConstant.getClass()))
      return true;
    switch (currentConstant.typeID()) {
      case TypeIds.T_int :
        return currentConstant.intValue() != otherConstant.intValue();
      case TypeIds.T_byte :
        return currentConstant.byteValue() != otherConstant.byteValue();
      case TypeIds.T_short :
        return currentConstant.shortValue() != otherConstant.shortValue();
      case TypeIds.T_char :
        return currentConstant.charValue() != otherConstant.charValue();
      case TypeIds.T_long :
        return currentConstant.longValue() != otherConstant.longValue();
      case TypeIds.T_float :
        return currentConstant.floatValue() != otherConstant.floatValue();
      case TypeIds.T_double :
        return currentConstant.doubleValue() != otherConstant.doubleValue();
      case TypeIds.T_boolean :
        return currentConstant.booleanValue() != otherConstant.booleanValue();
      case TypeIds.T_JavaLangString :
        return !currentConstant.stringValue().equals(otherConstant.stringValue());
    }
  }
  return false;
}
View Full Code Here

  } else {
    FieldBinding codegenBinding = this.binding.original();
    boolean isStatic = codegenBinding.isStatic();
    this.receiver.generateCode(currentScope, codeStream, !isStatic);
    if (valueRequired) {
      Constant fieldConstant = codegenBinding.constant();
      if (fieldConstant == Constant.NotAConstant) {
        if (codegenBinding.declaringClass == null) { // array length
          codeStream.arraylength();
        } else {
          if (codegenBinding.canBeSeenBy(this.actualReceiverType, this, currentScope)) {
View Full Code Here

    return;
  }
  lastFieldBinding = generateReadSequence(currentScope, codeStream);
  if (lastFieldBinding != null) {
    boolean isStatic = lastFieldBinding.isStatic();
    Constant fieldConstant = lastFieldBinding.constant();
    if (fieldConstant != Constant.NotAConstant) {
      if (!isStatic){
        codeStream.invokeObjectGetClass();
        codeStream.pop();
      }
View Full Code Here

      lastGenericCast = null;
      LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
      lastReceiverType = localBinding.type;
      if (!needValue) break; // no value needed
      // regular local variable read
      Constant localConstant = localBinding.constant();
      if (localConstant != Constant.NotAConstant) {
        codeStream.generateConstant(localConstant, 0);
        // no implicit conversion
      } else {
        // outer local?
        if ((this.bits & DepthMASK) != 0) {
          // outer local can be reached either through a synthetic arg or a synthetic field
          VariableBinding[] path = currentScope.getEmulationPath(localBinding);
          codeStream.generateOuterAccess(path, this, localBinding, currentScope);
        } else {
          codeStream.load(localBinding);
        }
      }
      break;
    default : // should not occur
      return null;     
  }
  // all intermediate field accesses are read accesses
  // only the last field binding is a write access
  int positionsLength = this.sourcePositions.length;
  FieldBinding initialFieldBinding = lastFieldBinding; // can be null if initial was a local binding
  if (this.otherBindings != null) {
    for (int i = 0; i < otherBindingsCount; i++) {
      int pc = codeStream.position;
      FieldBinding nextField = this.otherBindings[i].original();
      TypeBinding nextGenericCast = this.otherGenericCasts == null ? null : this.otherGenericCasts[i];
      if (lastFieldBinding != null) {
        needValue = !nextField.isStatic();
        Constant fieldConstant = lastFieldBinding.constant();
        if (fieldConstant != Constant.NotAConstant) {
          if (i > 0 && !lastFieldBinding.isStatic()) {
            codeStream.invokeObjectGetClass(); // perform null check
            codeStream.pop();
          }
View Full Code Here

  uniqueKey[index++] = ')';
  System.arraycopy(returnTypeKey, 0, uniqueKey, index, returnTypeLength);
  return uniqueKey;
}
public Constant constant() {
  Constant fieldConstant = this.constant;
  if (fieldConstant == null) {
    if (isFinal()) {
      //The field has not been yet type checked.
      //It also means that the field is not coming from a class that
      //has already been compiled. It can only be from a class within
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.impl.Constant

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.