Skip to content

Commit

Permalink
Use ABSL_LOG macros over LOG macros
Browse files Browse the repository at this point in the history
LOG causes macro pollution and conflicts with ProxyWasm SDK (see proxy-wasm/proxy-wasm-cpp-sdk#154).

PiperOrigin-RevId: 533164114
  • Loading branch information
kyessenov committed May 18, 2023
1 parent 51bbf36 commit b35780e
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion eval/compiler/flat_expr_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ TEST(FlatExprBuilderTest, CustomDescriptorPoolForSelect) {
std::pair<google::protobuf::Message*, const google::protobuf::Reflection*> CreateTestMessage(
const google::protobuf::DescriptorPool& descriptor_pool,
google::protobuf::MessageFactory& message_factory, absl::string_view name) {
const google::protobuf::Descriptor* desc = descriptor_pool.FindMessageTypeByName(std::string(name));
const google::protobuf::Descriptor* desc = descriptor_pool.FindMessageTypeByName(name);
const google::protobuf::Message* message_prototype = message_factory.GetPrototype(desc);
google::protobuf::Message* message = message_prototype->New();
const google::protobuf::Reflection* refl = message->GetReflection();
Expand Down
1 change: 0 additions & 1 deletion eval/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ cc_library(
"//internal:status_macros",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
Expand Down
1 change: 0 additions & 1 deletion eval/internal/interop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "google/protobuf/arena.h"
#include "absl/base/attributes.h"
#include "absl/container/flat_hash_map.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
Expand Down
10 changes: 5 additions & 5 deletions eval/public/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ cc_library(
"//internal:status_macros",
"//internal:utf8",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
Expand Down Expand Up @@ -633,7 +633,7 @@ cc_library(
deps = [
":ast_visitor",
":source_position",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/types:variant",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
],
Expand All @@ -651,7 +651,7 @@ cc_library(
":ast_visitor_native",
":source_position_native",
"//base:ast_internal",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/types:variant",
],
)
Expand Down Expand Up @@ -835,7 +835,7 @@ cc_library(
deps = [
":ast_visitor",
":source_position",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/types:span",
"@com_google_absl//absl/types:variant",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
Expand Down Expand Up @@ -870,7 +870,7 @@ cc_library(
deps = [
":ast_visitor_native",
":source_position_native",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/types:span",
"@com_google_absl//absl/types:variant",
],
Expand Down
4 changes: 2 additions & 2 deletions eval/public/ast_rewrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <vector>

#include "google/api/expr/v1alpha1/syntax.pb.h"
#include "absl/log/log.h"
#include "absl/log/absl_log.h"
#include "absl/types/variant.h"
#include "eval/public/ast_visitor.h"
#include "eval/public/source_position.h"
Expand Down Expand Up @@ -196,7 +196,7 @@ struct PostVisitor {
case Expr::EXPR_KIND_NOT_SET:
break;
default:
LOG(ERROR) << "Unsupported Expr kind: " << expr->expr_kind_case();
ABSL_LOG(ERROR) << "Unsupported Expr kind: " << expr->expr_kind_case();
}

visitor->PostVisitExpr(expr, &position);
Expand Down
4 changes: 2 additions & 2 deletions eval/public/ast_rewrite_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stack>
#include <vector>

#include "absl/log/log.h"
#include "absl/log/absl_log.h"
#include "absl/types/variant.h"
#include "eval/public/ast_visitor_native.h"
#include "eval/public/source_position_native.h"
Expand Down Expand Up @@ -199,7 +199,7 @@ struct PostVisitor {
visitor->PostVisitComprehension(&comprehension, expr, position);
}
void operator()(absl::monostate) {
LOG(ERROR) << "Unsupported Expr kind";
ABSL_LOG(ERROR) << "Unsupported Expr kind";
}
} handler{visitor, record.expr, &position};
absl::visit(handler, record.expr->expr_kind());
Expand Down
4 changes: 2 additions & 2 deletions eval/public/ast_traverse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <stack>

#include "google/api/expr/v1alpha1/syntax.pb.h"
#include "absl/log/log.h"
#include "absl/log/absl_log.h"
#include "absl/types/variant.h"
#include "eval/public/ast_visitor.h"
#include "eval/public/source_position.h"
Expand Down Expand Up @@ -197,7 +197,7 @@ struct PostVisitor {
&position);
break;
default:
LOG(ERROR) << "Unsupported Expr kind: " << expr->expr_kind_case();
ABSL_LOG(ERROR) << "Unsupported Expr kind: " << expr->expr_kind_case();
}

visitor->PostVisitExpr(expr, &position);
Expand Down
4 changes: 2 additions & 2 deletions eval/public/ast_traverse_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <stack>

#include "absl/log/log.h"
#include "absl/log/absl_log.h"
#include "absl/types/variant.h"
#include "base/ast_internal.h"
#include "eval/public/ast_visitor_native.h"
Expand Down Expand Up @@ -174,7 +174,7 @@ struct PostVisitor {
&position);
}
void operator()(absl::monostate) {
LOG(ERROR) << "Unsupported Expr kind";
ABSL_LOG(ERROR) << "Unsupported Expr kind";
}
} handler{visitor, record.expr,
SourcePosition(expr->id(), record.source_info)};
Expand Down
2 changes: 1 addition & 1 deletion eval/public/builtin_func_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BuiltinsTest : public ::testing::Test {
Expr expr;
SourceInfo source_info;
auto call = expr.mutable_call_expr();
call->set_function(operation.data(), operation.size());
call->set_function(operation);

if (target.has_value()) {
std::string param_name = "target";
Expand Down
11 changes: 6 additions & 5 deletions eval/public/cel_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "absl/base/attributes.h"
#include "absl/base/macros.h"
#include "absl/base/optimization.h"
#include "absl/log/log.h"
#include "absl/log/absl_log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -489,7 +489,8 @@ class CelValue {

// Crashes with a null pointer error.
static void CrashNullPointer(Type type) ABSL_ATTRIBUTE_COLD {
LOG(FATAL) << "Null pointer supplied for " << TypeName(type); // Crash ok
ABSL_LOG(FATAL) << "Null pointer supplied for "
<< TypeName(type); // Crash ok
}

// Null pointer checker for pointer-based types.
Expand All @@ -502,9 +503,9 @@ class CelValue {
// Crashes with a type mismatch error.
static void CrashTypeMismatch(Type requested_type,
Type actual_type) ABSL_ATTRIBUTE_COLD {
LOG(FATAL) << "Type mismatch" // Crash ok
<< ": expected " << TypeName(requested_type) // Crash ok
<< ", encountered " << TypeName(actual_type); // Crash ok
ABSL_LOG(FATAL) << "Type mismatch" // Crash ok
<< ": expected " << TypeName(requested_type) // Crash ok
<< ", encountered " << TypeName(actual_type); // Crash ok
}

// Gets value of type specified
Expand Down
6 changes: 3 additions & 3 deletions eval/public/structs/cel_proto_lite_wrap_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ absl::StatusOr<BytesValue*> CreateMessageFromValue(
if (wrapper == nullptr) {
wrapper = google::protobuf::Arena::CreateMessage<BytesValue>(arena);
}
wrapper->set_value(view_val.value().data(), view_val.value().size());
wrapper->set_value(view_val.value());
return wrapper;
}

Expand Down Expand Up @@ -782,7 +782,7 @@ absl::StatusOr<StringValue*> CreateMessageFromValue(
if (wrapper == nullptr) {
wrapper = google::protobuf::Arena::CreateMessage<StringValue>(arena);
}
wrapper->set_value(view_val.value().data(), view_val.value().size());
wrapper->set_value(view_val.value());
return wrapper;
}

Expand Down Expand Up @@ -950,7 +950,7 @@ absl::StatusOr<Value*> CreateMessageFromValue(
case CelValue::Type::kString: {
CelValue::StringHolder val;
if (cel_value.GetValue(&val)) {
wrapper->set_string_value(val.value().data(), val.value().size());
wrapper->set_string_value(val.value());
}
} break;
case CelValue::Type::kTimestamp: {
Expand Down
6 changes: 3 additions & 3 deletions eval/public/structs/cel_proto_wrap_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ google::protobuf::Message* MessageFromValue(
if (!value.GetValue(&view_val)) {
return nullptr;
}
wrapper->set_value(view_val.value().data(), view_val.value().size());
wrapper->set_value(view_val.value());
return wrapper;
}

Expand Down Expand Up @@ -536,7 +536,7 @@ google::protobuf::Message* MessageFromValue(
if (!value.GetValue(&view_val)) {
return nullptr;
}
wrapper->set_value(view_val.value().data(), view_val.value().size());
wrapper->set_value(view_val.value());
return wrapper;
}

Expand Down Expand Up @@ -682,7 +682,7 @@ google::protobuf::Message* MessageFromValue(const CelValue& value, Value* json,
case CelValue::Type::kString: {
CelValue::StringHolder val;
if (value.GetValue(&val)) {
json->set_string_value(val.value().data(), val.value().size());
json->set_string_value(val.value());
return json;
}
} break;
Expand Down
12 changes: 6 additions & 6 deletions eval/public/structs/field_access_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ class SingleFieldTest : public testing::TestWithParam<AccessFieldTestParam> {
TEST_P(SingleFieldTest, Getter) {
TestAllTypes test_message;
ASSERT_TRUE(
google::protobuf::TextFormat::ParseFromString(std::string(message_textproto()), &test_message));
google::protobuf::TextFormat::ParseFromString(message_textproto(), &test_message));
google::protobuf::Arena arena;

ASSERT_OK_AND_ASSIGN(
CelValue accessed_value,
CreateValueFromSingleField(
&test_message,
test_message.GetDescriptor()->FindFieldByName(std::string(field_name())),
test_message.GetDescriptor()->FindFieldByName(field_name()),
ProtoWrapperTypeOptions::kUnsetProtoDefault,
&CelProtoWrapper::InternalWrapMessage, &arena));

Expand All @@ -204,7 +204,7 @@ TEST_P(SingleFieldTest, Setter) {
google::protobuf::Arena arena;

ASSERT_OK(SetValueToSingleField(
to_set, test_message.GetDescriptor()->FindFieldByName(std::string(field_name())),
to_set, test_message.GetDescriptor()->FindFieldByName(field_name()),
&test_message, &arena));

EXPECT_THAT(test_message, EqualsProto(message_textproto()));
Expand Down Expand Up @@ -361,14 +361,14 @@ class RepeatedFieldTest : public testing::TestWithParam<AccessFieldTestParam> {
TEST_P(RepeatedFieldTest, GetFirstElem) {
TestAllTypes test_message;
ASSERT_TRUE(
google::protobuf::TextFormat::ParseFromString(std::string(message_textproto()), &test_message));
google::protobuf::TextFormat::ParseFromString(message_textproto(), &test_message));
google::protobuf::Arena arena;

ASSERT_OK_AND_ASSIGN(
CelValue accessed_value,
CreateValueFromRepeatedField(
&test_message,
test_message.GetDescriptor()->FindFieldByName(std::string(field_name())), 0,
test_message.GetDescriptor()->FindFieldByName(field_name()), 0,
&CelProtoWrapper::InternalWrapMessage, &arena));

EXPECT_THAT(accessed_value, test::EqualsCelValue(cel_value()));
Expand All @@ -380,7 +380,7 @@ TEST_P(RepeatedFieldTest, AppendElem) {
google::protobuf::Arena arena;

ASSERT_OK(AddValueToRepeatedField(
to_add, test_message.GetDescriptor()->FindFieldByName(std::string(field_name())),
to_add, test_message.GetDescriptor()->FindFieldByName(field_name()),
&test_message, &arena));

EXPECT_THAT(test_message, EqualsProto(message_textproto()));
Expand Down
8 changes: 4 additions & 4 deletions eval/public/structs/proto_message_type_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ absl::StatusOr<bool> HasFieldImpl(const google::protobuf::Message* message,
absl::string_view field_name) {
ABSL_ASSERT(descriptor == message->GetDescriptor());
const Reflection* reflection = message->GetReflection();
const FieldDescriptor* field_desc = descriptor->FindFieldByName(std::string(field_name));
const FieldDescriptor* field_desc = descriptor->FindFieldByName(field_name);
if (field_desc == nullptr && reflection != nullptr) {
// Search to see whether the field name is referring to an extension.
field_desc = reflection->FindKnownExtensionByName(field_name);
Expand Down Expand Up @@ -122,7 +122,7 @@ absl::StatusOr<CelValue> GetFieldImpl(const google::protobuf::Message* message,
cel::MemoryManager& memory_manager) {
ABSL_ASSERT(descriptor == message->GetDescriptor());
const Reflection* reflection = message->GetReflection();
const FieldDescriptor* field_desc = descriptor->FindFieldByName(std::string(field_name));
const FieldDescriptor* field_desc = descriptor->FindFieldByName(field_name);
if (field_desc == nullptr && reflection != nullptr) {
std::string ext_name(field_name);
field_desc = reflection->FindKnownExtensionByName(ext_name);
Expand Down Expand Up @@ -332,7 +332,7 @@ ProtoMessageTypeAdapter::NewInstance(cel::MemoryManager& memory_manager) const {
}

bool ProtoMessageTypeAdapter::DefinesField(absl::string_view field_name) const {
return descriptor_->FindFieldByName(std::string(field_name)) != nullptr;
return descriptor_->FindFieldByName(field_name) != nullptr;
}

absl::StatusOr<bool> ProtoMessageTypeAdapter::HasField(
Expand Down Expand Up @@ -365,7 +365,7 @@ absl::Status ProtoMessageTypeAdapter::SetField(
UnwrapMessage(instance, "SetField"));

const google::protobuf::FieldDescriptor* field_descriptor =
descriptor_->FindFieldByName(std::string(field_name));
descriptor_->FindFieldByName(field_name);
CEL_RETURN_IF_ERROR(
ValidateSetFieldOp(field_descriptor != nullptr, field_name, "not found"));

Expand Down
2 changes: 1 addition & 1 deletion eval/public/structs/protobuf_descriptor_type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ProtobufDescriptorProvider::ProvideLegacyTypeInfo(
std::unique_ptr<ProtoMessageTypeAdapter> ProtobufDescriptorProvider::GetType(
absl::string_view name) const {
const google::protobuf::Descriptor* descriptor =
descriptor_pool_->FindMessageTypeByName(std::string(name));
descriptor_pool_->FindMessageTypeByName(name);
if (descriptor == nullptr) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/protobuf/type_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace cel::extensions {
absl::StatusOr<absl::optional<Handle<Type>>> ProtoTypeProvider::ProvideType(
TypeFactory& type_factory, absl::string_view name) const {
{
const auto* desc = pool_->FindMessageTypeByName(std::string(name));
const auto* desc = pool_->FindMessageTypeByName(name);
if (desc != nullptr) {
return type_factory.CreateStructType<ProtoStructType>(desc, factory_);
}
Expand Down

0 comments on commit b35780e

Please sign in to comment.