コード例 #1
0
/** @author Michał Ciszewski <*****@*****.**> */
public final class InvalidAddressOfExprError extends UnaryExprErroneousIssue {
  private static final ErrorCode _CODE =
      ErrorCode.onlyInstance(Issues.ErrorType.INVALID_ADDRESSOF_EXPR);
  public static final Code CODE = _CODE;

  private final boolean isLvalue;
  private final boolean isBitField;
  private final boolean inRegister;

  public InvalidAddressOfExprError(
      Type argType, Expression argExpr, boolean isLvalue, boolean isBitField, boolean inRegister) {
    super(_CODE, ADDRESSOF, argType, argExpr);

    this.isLvalue = isLvalue;
    this.isBitField = isBitField;
    this.inRegister = inRegister;
  }

  @Override
  public String generateDescription() {
    if (!argType.isFunctionType() && !isLvalue) {
      return format(
          "Cannot use expression '%s' as the operand for operator %s because it "
              + "is neither an lvalue nor a function designator",
          ASTWriter.writeToString(argExpr), op);
    } else if (argType.isObjectType() && isLvalue) {
      if (isBitField) {
        return format(
            "Cannot use expression '%s' as the operand for operator %s because it "
                + "designates a bit-field",
            ASTWriter.writeToString(argExpr), op);
      } else if (inRegister) {
        return format(
            "Cannot use expression '%s' as the operand for operator %s because it "
                + "designates an object in a register",
            ASTWriter.writeToString(argExpr), op);
      }
    }

    return format("Invalid operand '%s' for operator %s", ASTWriter.writeToString(argExpr), op);
  }
}
コード例 #2
0
/** @author Michał Ciszewski <*****@*****.**> */
public final class InvalidDereferenceExprError extends UnaryExprErroneousIssue {
  private static final ErrorCode _CODE =
      ErrorCode.onlyInstance(Issues.ErrorType.INVALID_DEREFERENCE_EXPR);
  public static final Code CODE = _CODE;

  public InvalidDereferenceExprError(Type argType, Expression argExpr) {
    super(_CODE, DEREFERENCE, argType, argExpr);
  }

  @Override
  public String generateDescription() {
    if (!argType.isPointerType()) {
      return format(
          "Operand '%s' of operator %s has type '%s' but expecting a pointer type",
          ASTWriter.writeToString(argExpr), op, argType);
    }

    return format(
        "Invalid operand '%s' of type '%s' for operator %s",
        ASTWriter.writeToString(argExpr), argType, op);
  }
}
コード例 #3
0
/** @author Michał Ciszewski <*****@*****.**> */
public final class InvalidConditionalExprError extends ErroneousIssue {
  private static final ErrorCode _CODE =
      ErrorCode.onlyInstance(Issues.ErrorType.INVALID_CONDITIONAL_EXPR);
  public static final Code CODE = _CODE;

  private final Type condType, trueType, falseType;
  private final Expression condExpr, trueExpr, falseExpr;

  public InvalidConditionalExprError(
      Type condType,
      Expression condExpr,
      Type trueType,
      Expression trueExpr,
      Type falseType,
      Expression falseExpr) {
    super(_CODE);

    checkNotNull(condType, "type of the condition cannot be null");
    checkNotNull(condExpr, "the condition expression cannot be null");
    checkNotNull(trueType, "type of the expression used if condition is true cannot be null");
    checkNotNull(trueExpr, "expression used if condition is true cannot be null");
    checkNotNull(falseType, "type of the expression used if condition is false cannot be null");
    checkNotNull(falseExpr, "expression used if condition is false cannot be null");

    this.condType = condType;
    this.condExpr = condExpr;
    this.trueType = trueType;
    this.trueExpr = trueExpr;
    this.falseType = falseType;
    this.falseExpr = falseExpr;
  }

  @Override
  public String generateDescription() {
    if (!condType.isGeneralizedScalarType()) {
      return format(
          "Condition operand '%s' for operator ?: has type '%s' but expecting a scalar type",
          ASTWriter.writeToString(condExpr), condType);
    } else if (trueType.isFieldTagType() && falseType.isFieldTagType()) {
      return format(
          "Middle and last operand for operator ?: are structures or unions of incompatible types '%s' and '%s'",
          trueType, falseType);
    } else if (trueType.isVoid() && !falseType.isVoid()) {
      return format(
          "Last operand '%s' for operator ?: has type '%s' but expecting 'void' as the middle operand has such type",
          ASTWriter.writeToString(falseExpr), falseType);
    } else if (!trueType.isVoid() && falseType.isVoid()) {
      return format(
          "Middle operand '%s' for operator ?: has type '%s' but expecting 'void' as the last operand has such type",
          ASTWriter.writeToString(trueExpr), trueType);
    } else if (trueType.isPointerType() && falseType.isPointerType()) {

      final PointerType truePtrType = (PointerType) trueType,
          falsePtrType = (PointerType) falseType;
      final Type trueRefType = truePtrType.getReferencedType(),
          falseRefType = falsePtrType.getReferencedType();

      if (trueRefType.isVoid() && !falseRefType.isObjectType()) {
        return format(
            "Last operand '%s' for operator ?: points not to an object and thus cannot be combined with a middle operand of type '%s'",
            ASTWriter.writeToString(falseExpr), trueType);
      } else if (!trueRefType.isObjectType() && falseRefType.isVoid()) {
        return format(
            "Middle operand '%s' for operator ?: points not to an object and thus cannot be combined with a last operand of type '%s'",
            ASTWriter.writeToString(trueExpr), falseType);
      }
    }

    return format(
        "Invalid middle and last operands of types '%s' and '%s' for operator ?:",
        trueType, falseType);
  }
}