Use AIDL_* errors over libbase logging.
This:
- gives us line numbers in source AIDL files reflecting errors
- makes it possible aidl_parser_fuzzer can detect when we return an
error but don't provide any output logging
Bug: N/A
Test: aidl_unittest
Change-Id: I0479fd8d87547c1f0b1be754f9b8f6865db3cbef
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 5c7cb3a..5626e40 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -134,7 +134,7 @@
}
// TODO: factor out all these macros
-#define SHOULD_NOT_REACH() CHECK(false) << LOG(FATAL) << ": should not reach here: "
+#define SHOULD_NOT_REACH() AIDL_FATAL(AIDL_LOCATION_HERE) << "Should not reach."
#define OPEQ(__y__) (string(op_) == string(__y__))
#define COMPUTE_UNARY(T, __op__) \
if (op == string(#__op__)) { \
@@ -290,8 +290,8 @@
AidlConstantValue::Type AidlBinaryConstExpression::UsualArithmeticConversion(Type left,
Type right) {
// These are handled as special cases
- CHECK(left != Type::STRING && right != Type::STRING);
- CHECK(left != Type::FLOATING && right != Type::FLOATING);
+ AIDL_FATAL_IF(left == Type::STRING || right == Type::STRING, AIDL_LOCATION_HERE);
+ AIDL_FATAL_IF(left == Type::FLOATING || right == Type::FLOATING, AIDL_LOCATION_HERE);
// Kinds in concern: bool, (u)int[8|32|64]
if (left == right) return left; // easy case
@@ -308,7 +308,7 @@
template <typename T>
T AidlConstantValue::cast() const {
- CHECK(is_evaluated_ == true);
+ AIDL_FATAL_IF(!is_evaluated_, this);
#define CASE_CAST_T(__type__) return static_cast<T>(static_cast<__type__>(final_value_));
@@ -419,7 +419,7 @@
}
AidlConstantValue* AidlConstantValue::Integral(const AidlLocation& location, const string& value) {
- CHECK(!value.empty());
+ AIDL_FATAL_IF(value.empty(), location);
Type parsed_type;
int64_t parsed_value = 0;
@@ -433,7 +433,7 @@
AidlConstantValue* AidlConstantValue::Array(
const AidlLocation& location, std::unique_ptr<vector<unique_ptr<AidlConstantValue>>> values) {
- CHECK(values != nullptr) << location;
+ AIDL_FATAL_IF(values == nullptr, location);
return new AidlConstantValue(location, Type::ARRAY, std::move(values));
}
@@ -583,7 +583,7 @@
break;
}
- CHECK(err != 0);
+ AIDL_FATAL_IF(err == 0, this);
AIDL_ERROR(this) << "Invalid type specifier for " << ToString(final_type_) << ": " << type_string;
return "";
}
@@ -715,17 +715,18 @@
case Type::BINARY:
return "a binary expression";
case Type::ERROR:
- LOG(FATAL) << "aidl internal error: error type failed to halt program";
+ AIDL_FATAL(AIDL_LOCATION_HERE) << "aidl internal error: error type failed to halt program";
return "";
default:
- LOG(FATAL) << "aidl internal error: unknown constant type: " << static_cast<int>(type);
+ AIDL_FATAL(AIDL_LOCATION_HERE)
+ << "aidl internal error: unknown constant type: " << static_cast<int>(type);
return ""; // not reached
}
}
bool AidlUnaryConstExpression::CheckValid() const {
if (is_evaluated_) return is_valid_;
- CHECK(unary_ != nullptr);
+ AIDL_FATAL_IF(unary_ == nullptr, this);
is_valid_ = unary_->CheckValid();
if (!is_valid_) {
@@ -782,8 +783,8 @@
bool AidlBinaryConstExpression::CheckValid() const {
bool success = false;
if (is_evaluated_) return is_valid_;
- CHECK(left_val_ != nullptr);
- CHECK(right_val_ != nullptr);
+ AIDL_FATAL_IF(left_val_ == nullptr, this);
+ AIDL_FATAL_IF(right_val_ == nullptr, this);
success = left_val_->CheckValid();
if (!success) {
@@ -811,8 +812,8 @@
return is_valid_;
}
is_evaluated_ = true;
- CHECK(left_val_ != nullptr);
- CHECK(right_val_ != nullptr);
+ AIDL_FATAL_IF(left_val_ == nullptr, type);
+ AIDL_FATAL_IF(right_val_ == nullptr, type);
// Recursively evaluate the binary expression tree
if (!left_val_->is_evaluated_ || !right_val_->is_evaluated_) {
@@ -926,8 +927,8 @@
value_(checked_value),
final_type_(parsed_type),
final_value_(parsed_value) {
- CHECK(!value_.empty() || type_ == Type::ERROR) << location;
- CHECK(type_ == Type::INT8 || type_ == Type::INT32 || type_ == Type::INT64) << location;
+ AIDL_FATAL_IF(value_.empty() && type_ != Type::ERROR, location);
+ AIDL_FATAL_IF(type_ != Type::INT8 && type_ != Type::INT32 && type_ != Type::INT64, location);
}
AidlConstantValue::AidlConstantValue(const AidlLocation& location, Type type,
@@ -936,7 +937,7 @@
type_(type),
value_(checked_value),
final_type_(type) {
- CHECK(!value_.empty() || type_ == Type::ERROR) << location;
+ AIDL_FATAL_IF(value_.empty() && type_ != Type::ERROR, location);
switch (type_) {
case Type::INT8:
case Type::INT32:
@@ -957,7 +958,7 @@
is_valid_(false),
is_evaluated_(false),
final_type_(type) {
- CHECK(type_ == Type::ARRAY);
+ AIDL_FATAL_IF(type_ != Type::ARRAY, location);
}
AidlUnaryConstExpression::AidlUnaryConstExpression(const AidlLocation& location, const string& op,