From af000b143afc74781116ea97f8f98b5c36a7e301 Mon Sep 17 00:00:00 2001 From: Firebase Rules Team Date: Tue, 12 Jun 2018 16:49:11 -0700 Subject: [PATCH] Project import generated by Copybara. PiperOrigin-RevId: 200304489 --- WORKSPACE | 4 +- eval/public/BUILD.bazel | 38 ++++++++++++++ eval/public/cel_value_internal.h | 90 ++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 eval/public/cel_value_internal.h diff --git a/WORKSPACE b/WORKSPACE index 750480f45..07942f30b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,7 +1,7 @@ http_archive( name = "com_google_protobuf", - strip_prefix = "protobuf-3.5.0", - urls = ["https://github.com/google/protobuf/archive/v3.5.0.zip"], + strip_prefix = "protobuf-3.5.1", + urls = ["https://github.com/google/protobuf/archive/v3.5.1.zip"], ) http_archive( diff --git a/eval/public/BUILD.bazel b/eval/public/BUILD.bazel index 78e574e34..7a02f7f4c 100644 --- a/eval/public/BUILD.bazel +++ b/eval/public/BUILD.bazel @@ -2,6 +2,26 @@ licenses(["notice"]) # Apache 2.0 exports_files(["LICENSE"]) +cc_library( + name = "cel_value_internal", + hdrs = [ + "cel_value_internal.h", + ], + visibility = ["//visibility:private"], + deps = [ + "@com_google_absl//absl/types:variant", + ], +) + +cc_library( + name = "cel_builtins", + hdrs = [ + "cel_builtins.h", + ], + deps = [ + ], +) + cc_library( name = "source_position", srcs = ["source_position.cc"], @@ -63,6 +83,24 @@ cc_test( ], ) +cc_test( + name = "activation_bind_helper_test", + size = "small", + srcs = [ + "activation_bind_helper_test.cc", + ], + tags = ["manual"], + deps = [ + ":activation", + #":activation_bind_helper", + #"//third_party/cel/cpp/eval/testutil:test_message_protos", + #"//util/gtl:ptr_util", + "@com_google_googletest//:gtest_main", + "@com_google_protobuf//:arena", + "@com_google_protobuf//:proto2", + ], +) + cc_test( name = "source_position_test", size = "small", diff --git a/eval/public/cel_value_internal.h b/eval/public/cel_value_internal.h new file mode 100644 index 000000000..ba13a3577 --- /dev/null +++ b/eval/public/cel_value_internal.h @@ -0,0 +1,90 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_INTERNAL_H_ +#define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_INTERNAL_H_ + +#include "third_party/absl/types/variant.h" + +namespace google { +namespace api { +namespace expr { +namespace runtime { + +namespace internal { + +// Helper classes needed for IndexOf metafunction implementation. +template +struct IndexDef {}; + +// This partial IndexDef type specialization provides additional constant +// "value", associated with the type. +template +struct IndexDef { + static constexpr int value = N; +}; + +// TypeIndexer is a template class, representing metafunction to find the index +// of a type in a type list. +template +struct TypeIndexer + : public TypeIndexer, + IndexDef::value> {}; + +template +struct TypeIndexer + : public IndexDef::value> {}; + +// ValueHolder class wraps absl::variant, adding IndexOf metafunction to it. +template +class ValueHolder { + public: + template + explicit ValueHolder(T t) : value_(t) {} + + // Metafunction to find the index of a type in a type list. + template + using IndexOf = TypeIndexer<0, sizeof...(Args), T, Args...>; + + template + const T *get() const { + return absl::get_if(&value_); + } + + template + bool is() const { + return absl::holds_alternative(value_); + } + + int index() const { return value_.index(); } + + template + ReturnType Visit(Op &&op) const { + return absl::visit(std::forward(op), value_); + } + + private: + absl::variant value_; +}; + +} // namespace internal + +} // namespace runtime +} // namespace expr +} // namespace api +} // namespace google + +#endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_INTERNAL_H_