Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Internal Changes #1611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions common/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,35 @@ cc_test(
"@com_google_protobuf//:protobuf",
],
)

cc_library(
name = "value_conversion",
srcs = ["value_conversion.cc"],
hdrs = ["value_conversion.h"],
deps = [
"//common:any",
"//common:value",
"//common:value_kind",
"//extensions/protobuf:value",
"//internal:proto_time_encoding",
"//internal:status_macros",
"//internal:time",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:cord",
"@com_google_absl//absl/time",
"@com_google_cel_spec//proto/cel/expr:checked_cc_proto",
"@com_google_cel_spec//proto/cel/expr:syntax_cc_proto",
"@com_google_cel_spec//proto/cel/expr:value_cc_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:checked_cc_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:value_cc_proto",
"@com_google_protobuf//:any_cc_proto",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:struct_cc_proto",
"@com_google_protobuf//:timestamp_cc_proto",
"@com_google_protobuf//src/google/protobuf/io",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "conformance/value_conversion.h"
#include "common/internal/value_conversion.h"

#include <string>
#include <utility>
Expand All @@ -38,38 +38,38 @@
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "google/protobuf/message.h"

namespace cel::conformance_internal {
namespace cel::common_internal {
namespace {

using ConformanceKind = cel::expr::Value::KindCase;
using ConformanceMapValue = cel::expr::MapValue;
using ConformanceListValue = cel::expr::ListValue;
using ExprValueKind = cel::expr::Value::KindCase;
using ExprMapValue = cel::expr::MapValue;
using ExprListValue = cel::expr::ListValue;

std::string ToString(ConformanceKind kind_case) {
std::string ToString(ExprValueKind kind_case) {
switch (kind_case) {
case ConformanceKind::kBoolValue:
case ExprValueKind::kBoolValue:
return "bool_value";
case ConformanceKind::kInt64Value:
case ExprValueKind::kInt64Value:
return "int64_value";
case ConformanceKind::kUint64Value:
case ExprValueKind::kUint64Value:
return "uint64_value";
case ConformanceKind::kDoubleValue:
case ExprValueKind::kDoubleValue:
return "double_value";
case ConformanceKind::kStringValue:
case ExprValueKind::kStringValue:
return "string_value";
case ConformanceKind::kBytesValue:
case ExprValueKind::kBytesValue:
return "bytes_value";
case ConformanceKind::kTypeValue:
case ExprValueKind::kTypeValue:
return "type_value";
case ConformanceKind::kEnumValue:
case ExprValueKind::kEnumValue:
return "enum_value";
case ConformanceKind::kMapValue:
case ExprValueKind::kMapValue:
return "map_value";
case ConformanceKind::kListValue:
case ExprValueKind::kListValue:
return "list_value";
case ConformanceKind::kNullValue:
case ExprValueKind::kNullValue:
return "null_value";
case ConformanceKind::kObjectValue:
case ExprValueKind::kObjectValue:
return "object_value";
default:
return "unknown kind case";
Expand Down Expand Up @@ -104,47 +104,47 @@ absl::StatusOr<Value> FromObject(
arena);
}

absl::StatusOr<MapValue> MapValueFromConformance(
const ConformanceMapValue& map_value,
absl::StatusOr<MapValue> MapValueFromExpr(
const ExprMapValue& map_value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena) {
auto builder = cel::NewMapValueBuilder(arena);
for (const auto& entry : map_value.entries()) {
CEL_ASSIGN_OR_RETURN(auto key,
FromConformanceValue(entry.key(), descriptor_pool,
FromExprValue(entry.key(), descriptor_pool,
message_factory, arena));
CEL_ASSIGN_OR_RETURN(auto value,
FromConformanceValue(entry.value(), descriptor_pool,
FromExprValue(entry.value(), descriptor_pool,
message_factory, arena));
CEL_RETURN_IF_ERROR(builder->Put(std::move(key), std::move(value)));
}

return std::move(*builder).Build();
}

absl::StatusOr<ListValue> ListValueFromConformance(
const ConformanceListValue& list_value,
absl::StatusOr<ListValue> ListValueFromExpr(
const ExprListValue& list_value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena) {
auto builder = cel::NewListValueBuilder(arena);
for (const auto& elem : list_value.values()) {
CEL_ASSIGN_OR_RETURN(
auto value,
FromConformanceValue(elem, descriptor_pool, message_factory, arena));
FromExprValue(elem, descriptor_pool, message_factory, arena));
CEL_RETURN_IF_ERROR(builder->Add(std::move(value)));
}

return std::move(*builder).Build();
}

absl::StatusOr<ConformanceMapValue> MapValueToConformance(
absl::StatusOr<ExprMapValue> MapValueToExpr(
const MapValue& map_value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena) {
ConformanceMapValue result;
ExprMapValue result;

CEL_ASSIGN_OR_RETURN(auto iter, map_value.NewIterator());

Expand All @@ -157,9 +157,9 @@ absl::StatusOr<ConformanceMapValue> MapValueToConformance(

CEL_ASSIGN_OR_RETURN(
auto key,
ToConformanceValue(key_value, descriptor_pool, message_factory, arena));
ToExprValue(key_value, descriptor_pool, message_factory, arena));
CEL_ASSIGN_OR_RETURN(auto value,
ToConformanceValue(value_value, descriptor_pool,
ToExprValue(value_value, descriptor_pool,
message_factory, arena));

auto* entry = result.add_entries();
Expand All @@ -171,12 +171,12 @@ absl::StatusOr<ConformanceMapValue> MapValueToConformance(
return result;
}

absl::StatusOr<ConformanceListValue> ListValueToConformance(
absl::StatusOr<ExprListValue> ListValueToExpr(
const ListValue& list_value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena) {
ConformanceListValue result;
ExprListValue result;

CEL_ASSIGN_OR_RETURN(auto iter, list_value.NewIterator());

Expand All @@ -185,7 +185,7 @@ absl::StatusOr<ConformanceListValue> ListValueToConformance(
iter->Next(descriptor_pool, message_factory, arena));
CEL_ASSIGN_OR_RETURN(
*result.add_values(),
ToConformanceValue(elem, descriptor_pool, message_factory, arena));
ToExprValue(elem, descriptor_pool, message_factory, arena));
}

return result;
Expand All @@ -208,44 +208,44 @@ absl::StatusOr<google::protobuf::Any> ToProtobufAny(

} // namespace

absl::StatusOr<Value> FromConformanceValue(
absl::StatusOr<Value> FromExprValue(
const cel::expr::Value& value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena) {
google::protobuf::LinkMessageReflection<cel::expr::Value>();
switch (value.kind_case()) {
case ConformanceKind::kBoolValue:
case ExprValueKind::kBoolValue:
return cel::BoolValue(value.bool_value());
case ConformanceKind::kInt64Value:
case ExprValueKind::kInt64Value:
return cel::IntValue(value.int64_value());
case ConformanceKind::kUint64Value:
case ExprValueKind::kUint64Value:
return cel::UintValue(value.uint64_value());
case ConformanceKind::kDoubleValue:
case ExprValueKind::kDoubleValue:
return cel::DoubleValue(value.double_value());
case ConformanceKind::kStringValue:
case ExprValueKind::kStringValue:
return cel::StringValue(value.string_value());
case ConformanceKind::kBytesValue:
case ExprValueKind::kBytesValue:
return cel::BytesValue(value.bytes_value());
case ConformanceKind::kNullValue:
case ExprValueKind::kNullValue:
return cel::NullValue();
case ConformanceKind::kObjectValue:
case ExprValueKind::kObjectValue:
return FromObject(value.object_value(), descriptor_pool, message_factory,
arena);
case ConformanceKind::kMapValue:
return MapValueFromConformance(value.map_value(), descriptor_pool,
case ExprValueKind::kMapValue:
return MapValueFromExpr(value.map_value(), descriptor_pool,
message_factory, arena);
case ConformanceKind::kListValue:
return ListValueFromConformance(value.list_value(), descriptor_pool,
case ExprValueKind::kListValue:
return ListValueFromExpr(value.list_value(), descriptor_pool,
message_factory, arena);

default:
return absl::UnimplementedError(absl::StrCat(
"FromConformanceValue not supported ", ToString(value.kind_case())));
"FromExprValue not supported ", ToString(value.kind_case())));
}
}

absl::StatusOr<cel::expr::Value> ToConformanceValue(
absl::StatusOr<cel::expr::Value> ToExprValue(
const Value& value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
Expand Down Expand Up @@ -293,14 +293,14 @@ absl::StatusOr<cel::expr::Value> ToConformanceValue(
case ValueKind::kMap: {
CEL_ASSIGN_OR_RETURN(
*result.mutable_map_value(),
MapValueToConformance(value.GetMap(), descriptor_pool,
MapValueToExpr(value.GetMap(), descriptor_pool,
message_factory, arena));
break;
}
case ValueKind::kList: {
CEL_ASSIGN_OR_RETURN(
*result.mutable_list_value(),
ListValueToConformance(value.GetList(), descriptor_pool,
ListValueToExpr(value.GetList(), descriptor_pool,
message_factory, arena));
break;
}
Expand All @@ -312,10 +312,10 @@ absl::StatusOr<cel::expr::Value> ToConformanceValue(
}
default:
return absl::UnimplementedError(
absl::StrCat("ToConformanceValue not supported ",
absl::StrCat("ToExprValue not supported ",
ValueKindToString(value->kind())));
}
return result;
}

} // namespace cel::conformance_internal
} // namespace cel::common_internal
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.
//
// Converters to/from serialized Value to/from runtime values.
#ifndef THIRD_PARTY_CEL_CPP_CONFORMANCE_VALUE_CONVERSION_H_
#define THIRD_PARTY_CEL_CPP_CONFORMANCE_VALUE_CONVERSION_H_
#ifndef THIRD_PARTY_CEL_CPP_COMMON_INTERNAL_VALUE_CONVERSION_H_
#define THIRD_PARTY_CEL_CPP_COMMON_INTERNAL_VALUE_CONVERSION_H_

#include "cel/expr/checked.pb.h"
#include "cel/expr/syntax.pb.h"
Expand All @@ -32,7 +32,7 @@
#include "google/protobuf/message.h"
#include "google/protobuf/message_lite.h"

namespace cel::conformance_internal {
namespace cel::common_internal {

ABSL_MUST_USE_RESULT
inline bool UnsafeConvertWireCompatProto(
Expand Down Expand Up @@ -97,17 +97,17 @@ inline bool ConvertWireCompatProto(
return UnsafeConvertWireCompatProto(src, dest);
}

absl::StatusOr<Value> FromConformanceValue(
absl::StatusOr<Value> FromExprValue(
const cel::expr::Value& value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena);

absl::StatusOr<cel::expr::Value> ToConformanceValue(
absl::StatusOr<cel::expr::Value> ToExprValue(
const Value& value,
const google::protobuf::DescriptorPool* ABSL_NONNULL descriptor_pool,
google::protobuf::MessageFactory* ABSL_NONNULL message_factory,
google::protobuf::Arena* ABSL_NONNULL arena);

} // namespace cel::conformance_internal
#endif // THIRD_PARTY_CEL_CPP_CONFORMANCE_VALUE_CONVERSION_H_
} // namespace cel::common_internal
#endif // THIRD_PARTY_CEL_CPP_COMMON_INTERNAL_VALUE_CONVERSION_H_
34 changes: 1 addition & 33 deletions conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,12 @@ package(default_visibility = ["//visibility:public"])

licenses(["notice"])

cc_library(
name = "value_conversion",
srcs = ["value_conversion.cc"],
hdrs = ["value_conversion.h"],
deps = [
"//common:any",
"//common:value",
"//common:value_kind",
"//extensions/protobuf:value",
"//internal:proto_time_encoding",
"//internal:status_macros",
"//internal:time",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:cord",
"@com_google_absl//absl/time",
"@com_google_cel_spec//proto/cel/expr:checked_cc_proto",
"@com_google_cel_spec//proto/cel/expr:syntax_cc_proto",
"@com_google_cel_spec//proto/cel/expr:value_cc_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:checked_cc_proto",
"@com_google_googleapis//google/api/expr/v1alpha1:value_cc_proto",
"@com_google_protobuf//:any_cc_proto",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:struct_cc_proto",
"@com_google_protobuf//:timestamp_cc_proto",
"@com_google_protobuf//src/google/protobuf/io",
],
)

cc_library(
name = "service",
testonly = True,
srcs = ["service.cc"],
hdrs = ["service.h"],
deps = [
":value_conversion",
"//checker:optional",
"//checker:standard_library",
"//checker:type_checker_builder",
Expand All @@ -69,6 +36,7 @@ cc_library(
"//common:source",
"//common:type",
"//common:value",
"//common/internal:value_conversion",
"//eval/public:activation",
"//eval/public:builtin_func_registrar",
"//eval/public:cel_expr_builder_factory",
Expand Down
Loading