diff --git a/base/BUILD b/base/BUILD index 898cfc79b..7554034cf 100644 --- a/base/BUILD +++ b/base/BUILD @@ -2,29 +2,6 @@ licenses(["notice"]) # Apache v2.0 package(default_visibility = ["//visibility:public"]) -cc_library( - name = "testing", - testonly = True, - srcs = [ - "testing.cc", - ], - hdrs = [ - "testing.h", - ], - deps = [ - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "status_macros", - hdrs = [ - "status_macros.h", - ], -) - cc_library( name = "unilib", srcs = [ diff --git a/base/status_macros.h b/base/status_macros.h deleted file mode 100644 index eab123d70..000000000 --- a/base/status_macros.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 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_BASE_STATUS_MACROS_H_ -#define THIRD_PARTY_CEL_CPP_BASE_STATUS_MACROS_H_ - -#include // for use with down_cast<> - -#include - -// Early-returns the status if it is in error; otherwise, proceeds. -// -// The argument expression is guaranteed to be evaluated exactly once. -#if !defined(RETURN_IF_ERROR) -#define RETURN_IF_ERROR(__status) \ - do { \ - auto _status = __status; \ - if (!_status.ok()) { \ - return _status; \ - } \ - } while (false) -#endif - -#define CEL_CONCAT_(x, y) x##y -#define CEL_CONCAT(x, y) CEL_CONCAT_(x, y) - -#if !defined(ASSIGN_OR_RETURN) -#define ASSIGN_OR_RETURN(lhs, rexpr) \ - auto CEL_CONCAT(_statusor, __LINE__) = \ - static_cast(rexpr); \ - RETURN_IF_ERROR(CEL_CONCAT(_statusor, __LINE__).status()); \ - lhs = std::move(CEL_CONCAT(_statusor, __LINE__).value()); -#endif - -#if !defined(ASSERT_OK_AND_ASSIGN) -#define ASSERT_OK_AND_ASSIGN(lhs, rexpr) \ - ASSERT_OK_AND_ASSIGN_IMPL(CEL_CONCAT(_statusor, __LINE__), lhs, rexpr) - -#define ASSERT_OK_AND_ASSIGN_IMPL(statusor, lhs, rexpr) \ - auto statusor = (rexpr); \ - ASSERT_TRUE(statusor.status().ok()) << statusor.status(); \ - lhs = std::move(statusor.value()) -#endif - -template // use like this: down_cast(foo); -inline To down_cast(From* f) { // so we only accept pointers - static_assert( - (std::is_base_of::type>::value), - "target type not derived from source type"); - - // We skip the assert and hence the dynamic_cast if RTTI is disabled. -#if !defined(__GNUC__) || defined(__GXX_RTTI) - // Uses RTTI in dbg and fastbuild. asserts are disabled in opt builds. - assert(f == nullptr || dynamic_cast(f) != nullptr); -#endif // !defined(__GNUC__) || defined(__GXX_RTTI) - - return static_cast(f); -} - -#if !defined(ASSERT_OK) -#define ASSERT_OK(expression) ASSERT_TRUE(expression.ok()) -#endif - -#if !defined(EXPECT_OK) -#define EXPECT_OK(expression) EXPECT_TRUE(expression.ok()) -#endif - -#endif // THIRD_PARTY_CEL_CPP_BASE_STATUS_MACROS_H_ diff --git a/bazel/deps.bzl b/bazel/deps.bzl index 748162bc0..34efc6336 100644 --- a/bazel/deps.bzl +++ b/bazel/deps.bzl @@ -6,30 +6,47 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def base_deps(): """Base evaluator and test dependencies.""" + + # LTS, March 2021, Patch 2 + ABSL_SHA1 = "278e0a071885a22dcd2fd1b5576cc44757299343" + ABSL_SHA256 = "ff5ea6f91f9bcd0f368346ef707d0a80a372b71de5b6ae69ac11d0ca41688b8f" http_archive( name = "com_google_absl", + urls = ["https://github.com/abseil/abseil-cpp/archive/" + ABSL_SHA1 + ".zip"], + strip_prefix = "abseil-cpp-" + ABSL_SHA1, + sha256 = ABSL_SHA256, patches = ["//bazel:abseil.patch"], patch_args = ["-p1"], - strip_prefix = "abseil-cpp-master", - urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"], ) + # v1.11.0 + GOOGLETEST_SHA1 = "e2239ee6043f73722e7aa812a459f54a28552929" + GOOGLETEST_SHA256 = "8daa1a71395892f7c1ec5f7cb5b099a02e606be720d62f1a6a98f8f8898ec826" http_archive( name = "com_google_googletest", - urls = ["https://github.com/google/googletest/archive/master.zip"], - strip_prefix = "googletest-master", + urls = ["https://github.com/google/googletest/archive/" + GOOGLETEST_SHA1 + ".zip"], + strip_prefix = "googletest-" + GOOGLETEST_SHA1, + sha256 = GOOGLETEST_SHA256, ) + # v1.6.0 + BENCHMARK_SHA1 = "f91b6b42b1b9854772a90ae9501464a161707d1e" + BENCHMARK_SHA256 = "00bd0837db9266c758a087cdf0831a0d3e337c6bb9e3fad75d2be4f9bf480d95" http_archive( name = "com_github_google_benchmark", - urls = ["https://github.com/google/benchmark/archive/master.zip"], - strip_prefix = "benchmark-master", + urls = ["https://github.com/google/benchmark/archive/" + BENCHMARK_SHA1 + ".zip"], + strip_prefix = "benchmark-" + BENCHMARK_SHA1, + sha256 = BENCHMARK_SHA256, ) + # 2021-09-01 + RE2_SHA1 = "8e08f47b11b413302749c0d8b17a1c94777495d5" + RE2_SHA256 = "d635a3353bb8ffc33b0779c97c1c9d6f2dbdda286106a73bbcf498f66edacd74" http_archive( name = "com_googlesource_code_re2", - strip_prefix = "re2-main", - urls = ["https://github.com/google/re2/archive/main.zip"], + urls = ["https://github.com/google/re2/archive/" + RE2_SHA1 + ".zip"], + strip_prefix = "re2-" + RE2_SHA1, + sha256 = RE2_SHA256, ) PROTOBUF_VERSION = "3.18.0" diff --git a/common/BUILD b/common/BUILD index 52f4690a5..6651bdc8b 100644 --- a/common/BUILD +++ b/common/BUILD @@ -42,7 +42,7 @@ cc_test( srcs = ["escaping_test.cc"], deps = [ ":escaping", - "//base:testing", + "//internal:testing", ], ) @@ -51,10 +51,9 @@ cc_library( srcs = ["overflow.cc"], hdrs = ["overflow.h"], deps = [ - "//base:status_macros", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", "@com_google_absl//absl/time", ], ) @@ -64,7 +63,7 @@ cc_test( srcs = ["overflow_test.cc"], deps = [ ":overflow", - "//base:testing", + "//internal:testing", "@com_google_absl//absl/functional:function_ref", "@com_google_absl//absl/status", "@com_google_absl//absl/time", diff --git a/common/escaping_test.cc b/common/escaping_test.cc index d442644f5..61f617ce2 100644 --- a/common/escaping_test.cc +++ b/common/escaping_test.cc @@ -1,7 +1,6 @@ #include "common/escaping.h" -#include "base/testing.h" -#include "gtest/gtest.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/common/overflow.cc b/common/overflow.cc index 2a1c7de69..f7ee2a878 100644 --- a/common/overflow.cc +++ b/common/overflow.cc @@ -5,9 +5,8 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/str_cat.h" #include "absl/time/time.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" namespace google::api::expr::common { namespace { @@ -28,6 +27,7 @@ constexpr int64_t kInt32Min = std::numeric_limits::lowest(); constexpr int64_t kInt64Max = std::numeric_limits::max(); constexpr int64_t kInt64Min = std::numeric_limits::lowest(); constexpr uint64_t kUint32Max = std::numeric_limits::max(); +constexpr uint64_t kUint64Max = std::numeric_limits::max(); constexpr uint64_t kUintToIntMax = static_cast(kInt64Max); constexpr double kDoubleToIntMax = static_cast(kInt64Max); constexpr double kDoubleToIntMin = static_cast(kInt64Min); @@ -43,20 +43,14 @@ const int64_t kMinUnixTime = const int64_t kMaxUnixTime = (MaxTime() - absl::UnixEpoch()) / kOneSecondDuration; -template -Status CheckRange(bool valid_expression, absl::string_view error_message, - MP... message_parts) { +Status CheckRange(bool valid_expression, absl::string_view error_message) { return valid_expression ? absl::OkStatus() - : absl::OutOfRangeError( - absl::StrCat(error_message, message_parts...)); + : absl::OutOfRangeError(error_message); } -template -Status CheckArgument(bool valid_expression, absl::string_view error_message, - MP... message_parts) { +Status CheckArgument(bool valid_expression, absl::string_view error_message) { return valid_expression ? absl::OkStatus() - : absl::InvalidArgumentError( - absl::StrCat(error_message, message_parts...)); + : absl::InvalidArgumentError(error_message); } // Determine whether the duration is finite. @@ -79,8 +73,8 @@ StatusOr CheckedAdd(int64_t x, int64_t y) { } return absl::OutOfRangeError("integer overflow"); #else - RETURN_IF_ERROR(CheckRange(y > 0 ? x <= kInt64Max - y : x >= kInt64Min - y, - "integer overflow")); + CEL_RETURN_IF_ERROR(CheckRange( + y > 0 ? x <= kInt64Max - y : x >= kInt64Min - y, "integer overflow")); return x + y; #endif } @@ -93,8 +87,8 @@ StatusOr CheckedSub(int64_t x, int64_t y) { } return absl::OutOfRangeError("integer overflow"); #else - RETURN_IF_ERROR(CheckRange(y < 0 ? x <= kInt64Max + y : x >= kInt64Min + y, - "integer overflow")); + CEL_RETURN_IF_ERROR(CheckRange( + y < 0 ? x <= kInt64Max + y : x >= kInt64Min + y, "integer overflow")); return x - y; #endif } @@ -107,7 +101,7 @@ StatusOr CheckedNegation(int64_t v) { } return absl::OutOfRangeError("integer overflow"); #else - RETURN_IF_ERROR(CheckRange(v != kInt64Min, "integer overflow")); + CEL_RETURN_IF_ERROR(CheckRange(v != kInt64Min, "integer overflow")); return -v; #endif } @@ -120,7 +114,7 @@ StatusOr CheckedMul(int64_t x, int64_t y) { } return absl::OutOfRangeError("integer overflow"); #else - RETURN_IF_ERROR( + CEL_RETURN_IF_ERROR( CheckRange(!((x == -1 && y == kInt64Min) || (y == -1 && x == kInt64Min) || (x > 0 && y > 0 && x > kInt64Max / y) || (x < 0 && y < 0 && x < kInt64Max / y) || @@ -134,14 +128,16 @@ StatusOr CheckedMul(int64_t x, int64_t y) { } StatusOr CheckedDiv(int64_t x, int64_t y) { - RETURN_IF_ERROR(CheckRange(x != kInt64Min || y != -1, "integer overflow")); - RETURN_IF_ERROR(CheckArgument(y != 0, "divide by zero")); + CEL_RETURN_IF_ERROR( + CheckRange(x != kInt64Min || y != -1, "integer overflow")); + CEL_RETURN_IF_ERROR(CheckArgument(y != 0, "divide by zero")); return x / y; } StatusOr CheckedMod(int64_t x, int64_t y) { - RETURN_IF_ERROR(CheckRange(x != kInt64Min || y != -1, "integer overflow")); - RETURN_IF_ERROR(CheckArgument(y != 0, "modulus by zero")); + CEL_RETURN_IF_ERROR( + CheckRange(x != kInt64Min || y != -1, "integer overflow")); + CEL_RETURN_IF_ERROR(CheckArgument(y != 0, "modulus by zero")); return x % y; } @@ -153,7 +149,8 @@ StatusOr CheckedAdd(uint64_t x, uint64_t y) { } return absl::OutOfRangeError("unsigned integer overflow"); #else - RETURN_IF_ERROR(CheckRange(x <= kUint64Max - y, "unsigned integer overflow")); + CEL_RETURN_IF_ERROR( + CheckRange(x <= kUint64Max - y, "unsigned integer overflow")); return x + y; #endif } @@ -166,7 +163,7 @@ StatusOr CheckedSub(uint64_t x, uint64_t y) { } return absl::OutOfRangeError("unsigned integer overflow"); #else - RETURN_IF_ERROR(CheckRange(y <= x, "unsigned integer overflow")); + CEL_RETURN_IF_ERROR(CheckRange(y <= x, "unsigned integer overflow")); return x - y; #endif } @@ -179,24 +176,25 @@ StatusOr CheckedMul(uint64_t x, uint64_t y) { } return absl::OutOfRangeError("unsigned integer overflow"); #else - RETURN_IF_ERROR( + CEL_RETURN_IF_ERROR( CheckRange(y == 0 || x <= kUint64Max / y, "unsigned integer overflow")); return x * y; #endif } StatusOr CheckedDiv(uint64_t x, uint64_t y) { - RETURN_IF_ERROR(CheckArgument(y != 0, "divide by zero")); + CEL_RETURN_IF_ERROR(CheckArgument(y != 0, "divide by zero")); return x / y; } StatusOr CheckedMod(uint64_t x, uint64_t y) { - RETURN_IF_ERROR(CheckArgument(y != 0, "modulus by zero")); + CEL_RETURN_IF_ERROR(CheckArgument(y != 0, "modulus by zero")); return x % y; } StatusOr CheckedAdd(absl::Duration x, absl::Duration y) { - RETURN_IF_ERROR(CheckRange(IsFinite(x) && IsFinite(y), "integer overflow")); + CEL_RETURN_IF_ERROR( + CheckRange(IsFinite(x) && IsFinite(y), "integer overflow")); // absl::Duration can handle +- infinite durations, but the Go time.Duration // implementation caps the durations to those expressible within a single // int64_t rather than (seconds int64_t, nanos int32_t). @@ -208,26 +206,29 @@ StatusOr CheckedAdd(absl::Duration x, absl::Duration y) { // Since Go is the more conservative of the implementations and 290 year // durations seem quite reasonable, this code mirrors the conservative // overflow behavior which would be observed in Go. - ASSIGN_OR_RETURN(int64_t nanos, CheckedAdd(absl::ToInt64Nanoseconds(x), - absl::ToInt64Nanoseconds(y))); + CEL_ASSIGN_OR_RETURN(int64_t nanos, CheckedAdd(absl::ToInt64Nanoseconds(x), + absl::ToInt64Nanoseconds(y))); return absl::Nanoseconds(nanos); } StatusOr CheckedSub(absl::Duration x, absl::Duration y) { - RETURN_IF_ERROR(CheckRange(IsFinite(x) && IsFinite(y), "integer overflow")); - ASSIGN_OR_RETURN(int64_t nanos, CheckedSub(absl::ToInt64Nanoseconds(x), - absl::ToInt64Nanoseconds(y))); + CEL_RETURN_IF_ERROR( + CheckRange(IsFinite(x) && IsFinite(y), "integer overflow")); + CEL_ASSIGN_OR_RETURN(int64_t nanos, CheckedSub(absl::ToInt64Nanoseconds(x), + absl::ToInt64Nanoseconds(y))); return absl::Nanoseconds(nanos); } StatusOr CheckedNegation(absl::Duration v) { - RETURN_IF_ERROR(CheckRange(IsFinite(v), "integer overflow")); - ASSIGN_OR_RETURN(int64_t nanos, CheckedNegation(absl::ToInt64Nanoseconds(v))); + CEL_RETURN_IF_ERROR(CheckRange(IsFinite(v), "integer overflow")); + CEL_ASSIGN_OR_RETURN(int64_t nanos, + CheckedNegation(absl::ToInt64Nanoseconds(v))); return absl::Nanoseconds(nanos); } StatusOr CheckedAdd(absl::Time t, absl::Duration d) { - RETURN_IF_ERROR(CheckRange(IsFinite(t) && IsFinite(d), "timestamp overflow")); + CEL_RETURN_IF_ERROR( + CheckRange(IsFinite(t) && IsFinite(d), "timestamp overflow")); // First we break time into its components by truncating and subtracting. const int64_t s1 = absl::ToUnixSeconds(t); const int64_t ns1 = (t - absl::FromUnixSeconds(s1)) / absl::Nanoseconds(1); @@ -239,24 +240,24 @@ StatusOr CheckedAdd(absl::Time t, absl::Duration d) { const int64_t ns2 = absl::ToInt64Nanoseconds(d % kOneSecondDuration); // Add seconds first, detecting any overflow. - ASSIGN_OR_RETURN(int64_t s, CheckedAdd(s1, s2)); + CEL_ASSIGN_OR_RETURN(int64_t s, CheckedAdd(s1, s2)); // Nanoseconds cannot overflow as nanos are normalized to [0, 999999999]. absl::Duration ns = absl::Nanoseconds(ns2 + ns1); // Normalize nanoseconds to be positive and carry extra nanos to seconds. if (ns < absl::ZeroDuration() || ns >= kOneSecondDuration) { // Add seconds, or no-op if nanseconds negative (ns never < -999_999_999ns) - ASSIGN_OR_RETURN(s, CheckedAdd(s, ns / kOneSecondDuration)); + CEL_ASSIGN_OR_RETURN(s, CheckedAdd(s, ns / kOneSecondDuration)); ns -= (ns / kOneSecondDuration) * kOneSecondDuration; // Subtract a second to make the nanos positive. if (ns < absl::ZeroDuration()) { - ASSIGN_OR_RETURN(s, CheckedAdd(s, -1)); + CEL_ASSIGN_OR_RETURN(s, CheckedAdd(s, -1)); ns += kOneSecondDuration; } } // Check if the the number of seconds from Unix epoch is within our acceptable // range. - RETURN_IF_ERROR( + CEL_RETURN_IF_ERROR( CheckRange(s >= kMinUnixTime && s <= kMaxUnixTime, "timestamp overflow")); // Return resulting time. @@ -264,12 +265,13 @@ StatusOr CheckedAdd(absl::Time t, absl::Duration d) { } StatusOr CheckedSub(absl::Time t, absl::Duration d) { - ASSIGN_OR_RETURN(auto neg_duration, CheckedNegation(d)); + CEL_ASSIGN_OR_RETURN(auto neg_duration, CheckedNegation(d)); return CheckedAdd(t, neg_duration); } StatusOr CheckedSub(absl::Time t1, absl::Time t2) { - RETURN_IF_ERROR(CheckRange(IsFinite(t1) && IsFinite(t2), "integer overflow")); + CEL_RETURN_IF_ERROR( + CheckRange(IsFinite(t1) && IsFinite(t2), "integer overflow")); // First we break time into its components by truncating and subtracting. const int64_t s1 = absl::ToUnixSeconds(t1); const int64_t ns1 = (t1 - absl::FromUnixSeconds(s1)) / absl::Nanoseconds(1); @@ -277,49 +279,52 @@ StatusOr CheckedSub(absl::Time t1, absl::Time t2) { const int64_t ns2 = (t2 - absl::FromUnixSeconds(s2)) / absl::Nanoseconds(1); // Subtract seconds first, detecting any overflow. - ASSIGN_OR_RETURN(int64_t s, CheckedSub(s1, s2)); + CEL_ASSIGN_OR_RETURN(int64_t s, CheckedSub(s1, s2)); // Nanoseconds cannot overflow as nanos are normalized to [0, 999999999]. absl::Duration ns = absl::Nanoseconds(ns1 - ns2); // Scale the seconds result to nanos. - ASSIGN_OR_RETURN(const int64_t t, CheckedMul(s, kOneSecondNanos)); + CEL_ASSIGN_OR_RETURN(const int64_t t, CheckedMul(s, kOneSecondNanos)); // Add the seconds (scaled to nanos) to the nanosecond value. - ASSIGN_OR_RETURN(const int64_t v, - CheckedAdd(t, absl::ToInt64Nanoseconds(ns))); + CEL_ASSIGN_OR_RETURN(const int64_t v, + CheckedAdd(t, absl::ToInt64Nanoseconds(ns))); return absl::Nanoseconds(v); } StatusOr CheckedDoubleToInt64(double v) { - RETURN_IF_ERROR( + CEL_RETURN_IF_ERROR( CheckRange(std::isfinite(v) && v < kDoubleToIntMax && v > kDoubleToIntMin, "double out of int64_t range")); return static_cast(v); } StatusOr CheckedDoubleToUint64(double v) { - RETURN_IF_ERROR(CheckRange(std::isfinite(v) && v >= 0 && v < kDoubleTwoTo64, - "double out of uint64_t range")); + CEL_RETURN_IF_ERROR( + CheckRange(std::isfinite(v) && v >= 0 && v < kDoubleTwoTo64, + "double out of uint64_t range")); return static_cast(v); } StatusOr CheckedInt64ToUint64(int64_t v) { - RETURN_IF_ERROR(CheckRange(v >= 0, "int64 out of uint64_t range")); + CEL_RETURN_IF_ERROR(CheckRange(v >= 0, "int64 out of uint64_t range")); return static_cast(v); } StatusOr CheckedInt64ToInt32(int64_t v) { - RETURN_IF_ERROR( + CEL_RETURN_IF_ERROR( CheckRange(v >= kInt32Min && v <= kInt32Max, "int64 out of int32_t range")); return static_cast(v); } StatusOr CheckedUint64ToInt64(uint64_t v) { - RETURN_IF_ERROR(CheckRange(v <= kUintToIntMax, "uint64 out of int64_t range")); + CEL_RETURN_IF_ERROR( + CheckRange(v <= kUintToIntMax, "uint64 out of int64_t range")); return static_cast(v); } StatusOr CheckedUint64ToUint32(uint64_t v) { - RETURN_IF_ERROR(CheckRange(v <= kUint32Max, "uint64 out of uint32_t range")); + CEL_RETURN_IF_ERROR( + CheckRange(v <= kUint32Max, "uint64 out of uint32_t range")); return static_cast(v); } diff --git a/common/overflow_test.cc b/common/overflow_test.cc index 54f2e1070..7d90be33d 100644 --- a/common/overflow_test.cc +++ b/common/overflow_test.cc @@ -4,11 +4,10 @@ #include #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/functional/function_ref.h" #include "absl/status/status.h" #include "absl/time/time.h" +#include "internal/testing.h" namespace google::api::expr::common { namespace { diff --git a/conformance/BUILD b/conformance/BUILD index bb7b9e678..ab2a788a5 100644 --- a/conformance/BUILD +++ b/conformance/BUILD @@ -32,6 +32,7 @@ cc_binary( testonly = 1, srcs = ["server.cc"], deps = [ + "//eval/public:activation", "//eval/public:builtin_func_registrar", "//eval/public:cel_expr_builder_factory", "//eval/public:transform_utility", diff --git a/conformance/server.cc b/conformance/server.cc index 65b55ae56..317243c81 100644 --- a/conformance/server.cc +++ b/conformance/server.cc @@ -12,6 +12,7 @@ #include "absl/flags/flag.h" #include "absl/flags/parse.h" #include "absl/strings/str_split.h" +#include "eval/public/activation.h" #include "eval/public/builtin_func_registrar.h" #include "eval/public/cel_expr_builder_factory.h" #include "eval/public/containers/container_backed_list_impl.h" @@ -29,10 +30,7 @@ using ::google::protobuf::util::MessageToJsonString; ABSL_FLAG(bool, opt, false, "Enable optimizations (constant folding)"); -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { class ConformanceServiceImpl { public: @@ -218,10 +216,7 @@ int RunServer(bool optimize) { return 0; } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime int main(int argc, char** argv) { absl::ParseCommandLine(argc, argv); diff --git a/eval/compiler/BUILD b/eval/compiler/BUILD index 7c1d408e5..251d0b809 100644 --- a/eval/compiler/BUILD +++ b/eval/compiler/BUILD @@ -18,7 +18,6 @@ cc_library( ":constant_folding", ":qualified_reference_resolver", ":resolver", - "//base:status_macros", "//eval/eval:comprehension_step", "//eval/eval:const_value_step", "//eval/eval:container_access_step", @@ -39,6 +38,7 @@ cc_library( "//eval/public:cel_expression", "//eval/public:cel_function_registry", "//eval/public:source_position", + "//internal:status_macros", "@com_google_absl//absl/container:node_hash_map", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -55,8 +55,7 @@ cc_test( ], deps = [ ":flat_expr_builder", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:builtin_func_registrar", "//eval/public:cel_attribute", "//eval/public:cel_builtins", @@ -69,6 +68,8 @@ cc_test( "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", @@ -85,8 +86,7 @@ cc_test( ], deps = [ ":flat_expr_builder", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:builtin_func_registrar", "//eval/public:cel_attribute", "//eval/public:cel_builtins", @@ -96,6 +96,8 @@ cc_test( "//eval/public:unknown_attribute_set", "//eval/public:unknown_set", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", @@ -131,12 +133,11 @@ cc_test( ], deps = [ ":constant_folding", - "//base:status_macros", - "//base:testing", "//eval/public:builtin_func_registrar", "//eval/public:cel_function_registry", "//eval/testutil:test_message_cc_proto", - "@com_google_absl//absl/strings", + "//internal:status_macros", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", "@com_google_protobuf//:protobuf", ], @@ -152,11 +153,11 @@ cc_library( ], deps = [ ":resolver", - "//base:status_macros", "//eval/eval:const_value_step", "//eval/eval:expression_build_warning", "//eval/public:cel_builtins", "//eval/public:cel_function_registry", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -176,6 +177,7 @@ cc_library( "//eval/public:cel_function_registry", "//eval/public:cel_type_registry", "//eval/public:cel_value", + "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:optional", "@com_google_protobuf//:protobuf", @@ -189,13 +191,13 @@ cc_test( ], deps = [ ":qualified_reference_resolver", - "//base:status_macros", - "//base:testing", "//eval/public:builtin_func_registrar", "//eval/public:cel_builtins", "//eval/public:cel_function", "//eval/public:cel_function_registry", "//eval/public:cel_type_registry", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/status", "@com_google_absl//absl/types:optional", @@ -210,8 +212,6 @@ cc_test( ], deps = [ ":flat_expr_builder", - "//base:status_macros", - "//base:testing", "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_builtins", @@ -219,6 +219,8 @@ cc_test( "//eval/public:cel_options", "//eval/public:unknown_attribute_set", "//eval/public:unknown_set", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", @@ -231,12 +233,12 @@ cc_test( srcs = ["resolver_test.cc"], deps = [ ":resolver", - "//base:status_macros", - "//base:testing", "//eval/public:cel_function", "//eval/public:cel_function_registry", "//eval/public:cel_type_registry", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", ], ) diff --git a/eval/compiler/constant_folding.cc b/eval/compiler/constant_folding.cc index 7ef0e7f8c..deef91b40 100644 --- a/eval/compiler/constant_folding.cc +++ b/eval/compiler/constant_folding.cc @@ -6,14 +6,11 @@ #include "eval/public/cel_function_registry.h" #include "eval/public/containers/container_backed_list_impl.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Expr; class ConstantFoldingTransform { public: @@ -224,7 +221,4 @@ void FoldConstants(const Expr& expr, const CelFunctionRegistry& registry, constant_folder.Transform(expr, out); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/constant_folding.h b/eval/compiler/constant_folding.h index 20a1627bb..8cf56fae3 100644 --- a/eval/compiler/constant_folding.h +++ b/eval/compiler/constant_folding.h @@ -7,10 +7,7 @@ #include "eval/public/cel_function_registry.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // A transformation over input expression that produces a new expression with // constant sub-expressions replaced by generated idents in the constant_idents @@ -20,9 +17,6 @@ void FoldConstants(const google::api::expr::v1alpha1::Expr& expr, absl::flat_hash_map& constant_idents, google::api::expr::v1alpha1::Expr* out); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_COMPILER_CONSTANT_FOLDING_H_ diff --git a/eval/compiler/constant_folding_test.cc b/eval/compiler/constant_folding_test.cc index 87e4f7e4c..10dc4e03d 100644 --- a/eval/compiler/constant_folding_test.cc +++ b/eval/compiler/constant_folding_test.cc @@ -3,21 +3,17 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/text_format.h" #include "google/protobuf/util/message_differencer.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/builtin_func_registrar.h" #include "eval/public/cel_function_registry.h" #include "eval/testutil/test_message.pb.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Expr; // Validate select is preserved as-is TEST(ConstantFoldingTest, Select) { @@ -446,7 +442,4 @@ TEST(ConstantFoldingTest, MapComprehension) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/flat_expr_builder.cc b/eval/compiler/flat_expr_builder.cc index 765a140cd..09a10f18c 100644 --- a/eval/compiler/flat_expr_builder.cc +++ b/eval/compiler/flat_expr_builder.cc @@ -1,5 +1,6 @@ #include "eval/compiler/flat_expr_builder.h" +#include #include #include "google/api/expr/v1alpha1/checked.pb.h" @@ -34,24 +35,21 @@ #include "eval/public/cel_function_registry.h" #include "eval/public/source_position.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::api::expr::v1alpha1::CheckedExpr; -using google::api::expr::v1alpha1::Constant; -using google::api::expr::v1alpha1::Expr; -using google::api::expr::v1alpha1::Reference; -using google::api::expr::v1alpha1::SourceInfo; -using Ident = google::api::expr::v1alpha1::Expr::Ident; -using Select = google::api::expr::v1alpha1::Expr::Select; -using Call = google::api::expr::v1alpha1::Expr::Call; -using CreateList = google::api::expr::v1alpha1::Expr::CreateList; -using CreateStruct = google::api::expr::v1alpha1::Expr::CreateStruct; -using Comprehension = google::api::expr::v1alpha1::Expr::Comprehension; +using ::google::api::expr::v1alpha1::CheckedExpr; +using ::google::api::expr::v1alpha1::Constant; +using ::google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Reference; +using ::google::api::expr::v1alpha1::SourceInfo; +using Ident = ::google::api::expr::v1alpha1::Expr::Ident; +using Select = ::google::api::expr::v1alpha1::Expr::Select; +using Call = ::google::api::expr::v1alpha1::Expr::Call; +using CreateList = ::google::api::expr::v1alpha1::Expr::CreateList; +using CreateStruct = ::google::api::expr::v1alpha1::Expr::CreateStruct; +using Comprehension = ::google::api::expr::v1alpha1::Expr::Comprehension; // Forward declare to resolve circular dependency for short_circuiting visitors. class FlatExprVisitor; @@ -885,7 +883,4 @@ FlatExprBuilder::CreateExpression(const CheckedExpr* checked_expr) const { /*warnings=*/nullptr); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/flat_expr_builder.h b/eval/compiler/flat_expr_builder.h index 970c8a7ff..c203a6287 100644 --- a/eval/compiler/flat_expr_builder.h +++ b/eval/compiler/flat_expr_builder.h @@ -6,10 +6,7 @@ #include "absl/status/statusor.h" #include "eval/public/cel_expression.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // CelExpressionBuilder implementation. // Builds instances of CelExpressionFlatImpl. @@ -108,9 +105,6 @@ class FlatExprBuilder : public CelExpressionBuilder { bool enable_qualified_type_identifiers_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_COMPILER_FLAT_EXPR_BUILDER_H_ diff --git a/eval/compiler/flat_expr_builder_comprehensions_test.cc b/eval/compiler/flat_expr_builder_comprehensions_test.cc index 768476041..83752bf7d 100644 --- a/eval/compiler/flat_expr_builder_comprehensions_test.cc +++ b/eval/compiler/flat_expr_builder_comprehensions_test.cc @@ -1,12 +1,11 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/field_mask.pb.h" #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "eval/compiler/flat_expr_builder.h" +#include "eval/public/activation.h" #include "eval/public/builtin_func_registrar.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_builtins.h" @@ -16,12 +15,10 @@ #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" #include "eval/testutil/test_message.pb.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -29,7 +26,7 @@ using google::api::expr::v1alpha1::CheckedExpr; using google::api::expr::v1alpha1::Expr; using google::api::expr::v1alpha1::SourceInfo; using testing::HasSubstr; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; // [1, 2].filter(x, [3, 4].all(y, x < y)) const char kNestedComprehension[] = R"pb( @@ -207,7 +204,4 @@ TEST(FlatExprBuilderComprehensionsTest, InvalidComprehensionWithRewrite) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/flat_expr_builder_short_circuiting_conformance_test.cc b/eval/compiler/flat_expr_builder_short_circuiting_conformance_test.cc index 9a55484fa..83afcc396 100644 --- a/eval/compiler/flat_expr_builder_short_circuiting_conformance_test.cc +++ b/eval/compiler/flat_expr_builder_short_circuiting_conformance_test.cc @@ -3,8 +3,6 @@ #include #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" @@ -16,15 +14,14 @@ #include "eval/public/cel_options.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" + +namespace google::api::expr::runtime { -namespace google { -namespace api { -namespace expr { -namespace runtime { namespace { -using google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Expr; using testing::Eq; using testing::SizeIs; @@ -474,7 +471,5 @@ INSTANTIATE_TEST_SUITE_P(Test, ShortCircuitingTest, testing::Values(false, true), &TestName); } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime diff --git a/eval/compiler/flat_expr_builder_test.cc b/eval/compiler/flat_expr_builder_test.cc index cebb07a39..ce221a212 100644 --- a/eval/compiler/flat_expr_builder_test.cc +++ b/eval/compiler/flat_expr_builder_test.cc @@ -6,12 +6,11 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/field_mask.pb.h" #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" +#include "eval/public/activation.h" #include "eval/public/builtin_func_registrar.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_builtins.h" @@ -24,12 +23,10 @@ #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" #include "eval/testutil/test_message.pb.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -41,8 +38,8 @@ using google::protobuf::FieldMask; using testing::Eq; using testing::HasSubstr; using testing::Not; -using cel_base::testing::IsOk; -using cel_base::testing::StatusIs; +using cel::internal::IsOk; +using cel::internal::StatusIs; class ConcatFunction : public CelFunction { public: @@ -1394,8 +1391,8 @@ absl::Status RunTernaryExpression(CelValue selector, CelValue value1, arg2->mutable_ident_expr()->set_name("value2"); FlatExprBuilder builder; - ASSIGN_OR_RETURN(auto cel_expr, - builder.CreateExpression(&expr, &source_info)); + CEL_ASSIGN_OR_RETURN(auto cel_expr, + builder.CreateExpression(&expr, &source_info)); std::string variable = "test"; @@ -1404,7 +1401,7 @@ absl::Status RunTernaryExpression(CelValue selector, CelValue value1, activation.InsertValue("value1", value1); activation.InsertValue("value2", value2); - ASSIGN_OR_RETURN(auto eval, cel_expr->Evaluate(activation, arena)); + CEL_ASSIGN_OR_RETURN(auto eval, cel_expr->Evaluate(activation, arena)); *result = eval; return absl::OkStatus(); } @@ -1541,7 +1538,4 @@ TEST(FlatExprBuilderTest, EmptyCallList) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/qualified_reference_resolver.cc b/eval/compiler/qualified_reference_resolver.cc index 106136494..3c37525e9 100644 --- a/eval/compiler/qualified_reference_resolver.cc +++ b/eval/compiler/qualified_reference_resolver.cc @@ -1,5 +1,6 @@ #include "eval/compiler/qualified_reference_resolver.h" +#include #include #include "absl/status/status.h" @@ -12,18 +13,15 @@ #include "eval/eval/expression_build_warning.h" #include "eval/public/cel_builtins.h" #include "eval/public/cel_function_registry.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::api::expr::v1alpha1::Constant; -using google::api::expr::v1alpha1::Expr; -using google::api::expr::v1alpha1::Reference; +using ::google::api::expr::v1alpha1::Constant; +using ::google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Reference; // Determines if function is implemented with custom evaluation step instead of // registered. @@ -131,8 +129,8 @@ class ReferenceResolver { auto* list_expr = out->mutable_list_expr(); int list_size = list_expr->elements_size(); for (int i = 0; i < list_size; i++) { - ASSIGN_OR_RETURN(bool rewrite_result, - Rewrite(list_expr->mutable_elements(i))); + CEL_ASSIGN_OR_RETURN(bool rewrite_result, + Rewrite(list_expr->mutable_elements(i))); updated = updated || rewrite_result; } return updated; @@ -145,31 +143,32 @@ class ReferenceResolver { bool rewrite_result; if (out_expr->has_accu_init()) { - ASSIGN_OR_RETURN(rewrite_result, - Rewrite(out_expr->mutable_accu_init())); + CEL_ASSIGN_OR_RETURN(rewrite_result, + Rewrite(out_expr->mutable_accu_init())); updated = updated || rewrite_result; } if (out_expr->has_iter_range()) { - ASSIGN_OR_RETURN(rewrite_result, - Rewrite(out_expr->mutable_iter_range())); + CEL_ASSIGN_OR_RETURN(rewrite_result, + Rewrite(out_expr->mutable_iter_range())); updated = updated || rewrite_result; } if (out_expr->has_loop_condition()) { - ASSIGN_OR_RETURN(rewrite_result, - Rewrite(out_expr->mutable_loop_condition())); + CEL_ASSIGN_OR_RETURN(rewrite_result, + Rewrite(out_expr->mutable_loop_condition())); updated = updated || rewrite_result; } if (out_expr->has_loop_step()) { - ASSIGN_OR_RETURN(rewrite_result, - Rewrite(out_expr->mutable_loop_step())); + CEL_ASSIGN_OR_RETURN(rewrite_result, + Rewrite(out_expr->mutable_loop_step())); updated = updated || rewrite_result; } if (out_expr->has_result()) { - ASSIGN_OR_RETURN(rewrite_result, Rewrite(out_expr->mutable_result())); + CEL_ASSIGN_OR_RETURN(rewrite_result, + Rewrite(out_expr->mutable_result())); updated = updated || rewrite_result; } @@ -191,7 +190,7 @@ class ReferenceResolver { const Reference* reference) { auto* call_expr = out->mutable_call_expr(); if (reference != nullptr && reference->overload_id_size() == 0) { - RETURN_IF_ERROR(warnings_->AddWarning(absl::InvalidArgumentError( + CEL_RETURN_IF_ERROR(warnings_->AddWarning(absl::InvalidArgumentError( absl::StrCat("Reference map doesn't provide overloads for ", out->call_expr().function())))); } @@ -203,7 +202,7 @@ class ReferenceResolver { // should be rewritten. absl::StatusOr rewrite_result = Rewrite(call_expr->mutable_target()); - RETURN_IF_ERROR(rewrite_result.status()); + CEL_RETURN_IF_ERROR(rewrite_result.status()); bool target_updated = rewrite_result.value(); updated = target_updated; if (!target_updated) { @@ -228,7 +227,7 @@ class ReferenceResolver { auto maybe_resolved_function = BestOverloadMatch(resolver_, call_expr->function(), arg_num); if (!maybe_resolved_function.has_value()) { - RETURN_IF_ERROR(warnings_->AddWarning(absl::InvalidArgumentError( + CEL_RETURN_IF_ERROR(warnings_->AddWarning(absl::InvalidArgumentError( absl::StrCat("No overload found in reference resolve step for ", call_expr->function())))); } else if (maybe_resolved_function.value() != call_expr->function()) { @@ -242,13 +241,13 @@ class ReferenceResolver { !OverloadExists(resolver_, call_expr->function(), ArgumentsMatcher(arg_num + 1), /* receiver_style= */ true)) { - RETURN_IF_ERROR(warnings_->AddWarning(absl::InvalidArgumentError( + CEL_RETURN_IF_ERROR(warnings_->AddWarning(absl::InvalidArgumentError( absl::StrCat("No overload found in reference resolve step for ", call_expr->function())))); } for (int i = 0; i < arg_num; i++) { absl::StatusOr rewrite_result = Rewrite(call_expr->mutable_args(i)); - RETURN_IF_ERROR(rewrite_result.status()); + CEL_RETURN_IF_ERROR(rewrite_result.status()); updated = updated || rewrite_result.value(); } return updated; @@ -261,7 +260,7 @@ class ReferenceResolver { const Reference* reference) { if (reference != nullptr) { if (out->select_expr().test_only()) { - RETURN_IF_ERROR(warnings_->AddWarning( + CEL_RETURN_IF_ERROR(warnings_->AddWarning( absl::InvalidArgumentError("Reference map points to a presence " "test -- has(container.attr)"))); } else if (!reference->name().empty()) { @@ -302,7 +301,7 @@ class ReferenceResolver { break; case Expr::CreateStruct::Entry::kMapKey: { auto key_updated = Rewrite(new_entry->mutable_map_key()); - RETURN_IF_ERROR(key_updated.status()); + CEL_RETURN_IF_ERROR(key_updated.status()); updated = updated || key_updated.value(); break; } @@ -312,7 +311,7 @@ class ReferenceResolver { break; } auto value_updated = Rewrite(new_entry->mutable_value()); - RETURN_IF_ERROR(value_updated.status()); + CEL_RETURN_IF_ERROR(value_updated.status()); updated = updated || value_updated.value(); } return updated; @@ -340,7 +339,4 @@ absl::StatusOr> ResolveReferences( } } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/qualified_reference_resolver.h b/eval/compiler/qualified_reference_resolver.h index 069653412..80b7f84fe 100644 --- a/eval/compiler/qualified_reference_resolver.h +++ b/eval/compiler/qualified_reference_resolver.h @@ -1,6 +1,8 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_COMPILER_QUALIFIED_REFERENCE_RESOLVER_H_ #define THIRD_PARTY_CEL_CPP_EVAL_COMPILER_QUALIFIED_REFERENCE_RESOLVER_H_ +#include + #include "google/api/expr/v1alpha1/checked.pb.h" #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/map.h" @@ -10,10 +12,7 @@ #include "eval/compiler/resolver.h" #include "eval/eval/expression_build_warning.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // A transformation over input expression that produces a new expression with // subexpressions replaced by appropriate expressions referring to the @@ -25,8 +24,6 @@ absl::StatusOr> ResolveReferen const google::protobuf::Map& reference_map, const Resolver& resolver, BuilderWarnings* warnings); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime + #endif // THIRD_PARTY_CEL_CPP_EVAL_COMPILER_QUALIFIED_REFERENCE_RESOLVER_H_ diff --git a/eval/compiler/qualified_reference_resolver_test.cc b/eval/compiler/qualified_reference_resolver_test.cc index 57840794a..b5edb85d8 100644 --- a/eval/compiler/qualified_reference_resolver_test.cc +++ b/eval/compiler/qualified_reference_resolver_test.cc @@ -1,8 +1,8 @@ #include "eval/compiler/qualified_reference_resolver.h" +#include + #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/types/optional.h" #include "eval/public/builtin_func_registrar.h" @@ -10,17 +10,16 @@ #include "eval/public/cel_function.h" #include "eval/public/cel_function_registry.h" #include "eval/public/cel_type_registry.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { + namespace { -using google::api::expr::v1alpha1::Expr; -using google::api::expr::v1alpha1::Reference; +using ::google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Reference; using testing::ElementsAre; using testing::Eq; using testing::IsEmpty; @@ -723,7 +722,4 @@ TEST(ResolveReferences, EnumConstReferenceUsedInComprehension) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/resolver.cc b/eval/compiler/resolver.cc index 6c1b0ac6f..bc2c0c5f9 100644 --- a/eval/compiler/resolver.cc +++ b/eval/compiler/resolver.cc @@ -1,5 +1,7 @@ #include "eval/compiler/resolver.h" +#include + #include "google/protobuf/descriptor.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -7,10 +9,7 @@ #include "absl/types/optional.h" #include "eval/public/cel_builtins.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { Resolver::Resolver(absl::string_view container, const CelFunctionRegistry* function_registry, @@ -158,7 +157,4 @@ const google::protobuf::Descriptor* Resolver::FindDescriptor(absl::string_view n return nullptr; } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/compiler/resolver.h b/eval/compiler/resolver.h index 1f79867f1..739254e07 100644 --- a/eval/compiler/resolver.h +++ b/eval/compiler/resolver.h @@ -1,16 +1,17 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_COMPILER_RESOLVER_H_ #define THIRD_PARTY_CEL_CPP_EVAL_COMPILER_RESOLVER_H_ +#include +#include + +#include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "eval/public/cel_function_registry.h" #include "eval/public/cel_type_registry.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Resolver assists with finding functions and types within a container. // @@ -84,9 +85,6 @@ inline std::vector ArgumentsMatcher(int argument_count) { return argument_matcher; } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_COMPILER_RESOLVER_H_ diff --git a/eval/compiler/resolver_test.cc b/eval/compiler/resolver_test.cc index 7dc39b0a6..18ca873ae 100644 --- a/eval/compiler/resolver_test.cc +++ b/eval/compiler/resolver_test.cc @@ -2,19 +2,15 @@ #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "eval/public/cel_function.h" #include "eval/public/cel_function_registry.h" #include "eval/public/cel_type_registry.h" #include "eval/testutil/test_message.pb.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -193,7 +189,4 @@ TEST(ResolverTest, TestFindLazyOverloads) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/BUILD b/eval/eval/BUILD index 180963fd6..6a3b8d824 100644 --- a/eval/eval/BUILD +++ b/eval/eval/BUILD @@ -18,12 +18,13 @@ cc_library( ":attribute_trail", ":attribute_utility", ":evaluator_stack", - "//base:status_macros", - "//eval/public:activation", + "//eval/public:base_activation", "//eval/public:cel_attribute", "//eval/public:cel_expression", "//eval/public:cel_value", "//eval/public:unknown_attribute_set", + "//internal:casts", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -45,6 +46,7 @@ cc_library( deps = [ ":attribute_trail", "//eval/public:cel_value", + "@com_google_absl//absl/types:span", ], ) @@ -55,7 +57,7 @@ cc_test( ], deps = [ ":evaluator_stack", - "//base:testing", + "//internal:testing", ], ) @@ -64,15 +66,7 @@ cc_library( hdrs = [ "expression_step_base.h", ], - deps = [ - ":evaluator_core", - "//eval/public:activation", - "//eval/public:cel_expression", - "//eval/public:cel_value", - "@com_google_absl//absl/strings", - "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", - "@com_google_protobuf//:protobuf", - ], + deps = [":evaluator_core"], ) cc_library( @@ -104,12 +98,12 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//eval/public:activation", "//eval/public:cel_value", "//eval/public:unknown_attribute_set", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", "@com_google_protobuf//:protobuf", ], ) @@ -126,8 +120,6 @@ cc_library( ":attribute_trail", ":evaluator_core", ":expression_step_base", - "//eval/public:activation", - "//eval/public:cel_value", "//eval/public:unknown_attribute_set", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -148,8 +140,7 @@ cc_library( ":evaluator_core", ":expression_build_warning", ":expression_step_base", - "//base:status_macros", - "//eval/public:activation", + "//eval/public:base_activation", "//eval/public:cel_builtins", "//eval/public:cel_function", "//eval/public:cel_function_provider", @@ -157,6 +148,7 @@ cc_library( "//eval/public:unknown_attribute_set", "//eval/public:unknown_function_result_set", "//eval/public:unknown_set", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/types:optional", @@ -177,14 +169,15 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//eval/public:activation", "//eval/public:cel_value", "//eval/public/containers:field_access", "//eval/public/containers:field_backed_list_impl", "//eval/public/containers:field_backed_map_impl", + "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", + "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -202,7 +195,7 @@ cc_library( "//eval/public/containers:container_backed_list_impl", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/types:span", + "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -217,10 +210,10 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//base:status_macros", "//eval/public/containers:container_backed_map_impl", "//eval/public/containers:field_access", "//eval/public/structs:cel_proto_wrapper", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -240,10 +233,8 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//eval/public:activation", - "//eval/public:cel_value", "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:optional", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -259,14 +250,11 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//eval/public:activation", "//eval/public:cel_builtins", - "//eval/public:cel_function", "//eval/public:cel_value", "//eval/public:unknown_attribute_set", "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", + "@com_google_absl//absl/types:span", ], ) @@ -282,11 +270,10 @@ cc_library( ":attribute_trail", ":evaluator_core", ":expression_step_base", - "//base:status_macros", - "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_function", "//eval/public:cel_value", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", @@ -303,12 +290,13 @@ cc_test( ":comprehension_step", ":evaluator_core", ":ident_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_options", "//eval/public:cel_value", "//eval/public/structs:cel_proto_wrapper", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", @@ -325,12 +313,13 @@ cc_test( deps = [ ":attribute_trail", ":evaluator_core", - "//base:status_macros", - "//base:testing", "//eval/compiler:flat_expr_builder", + "//eval/public:activation", "//eval/public:builtin_func_registrar", "//eval/public:cel_attribute", "//eval/public:cel_value", + "//internal:status_macros", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -344,8 +333,9 @@ cc_test( deps = [ ":const_value_step", ":evaluator_core", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status:statusor", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], @@ -360,14 +350,15 @@ cc_test( deps = [ ":container_access_step", ":ident_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_builtins", "//eval/public:cel_value", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_protobuf//:protobuf", ], @@ -382,8 +373,9 @@ cc_test( deps = [ ":evaluator_core", ":ident_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", + "//internal:status_macros", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -399,8 +391,7 @@ cc_test( ":expression_build_warning", ":function_step", ":ident_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_function", "//eval/public:cel_function_registry", @@ -409,6 +400,8 @@ cc_test( "//eval/public:unknown_function_result_set", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", @@ -424,10 +417,11 @@ cc_test( deps = [ ":ident_step", ":logic_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:unknown_attribute_set", "//eval/public:unknown_set", + "//internal:status_macros", + "//internal:testing", ], ) @@ -440,13 +434,14 @@ cc_test( deps = [ ":ident_step", ":select_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:unknown_attribute_set", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -464,11 +459,11 @@ cc_test( ":const_value_step", ":create_list_step", ":ident_step", - "//base:status_macros", - "//base:testing", "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:unknown_attribute_set", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], @@ -483,13 +478,14 @@ cc_test( deps = [ ":create_struct_step", ":ident_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:cel_type_registry", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -519,7 +515,7 @@ cc_test( ], deps = [ ":expression_build_warning", - "//base:testing", + "//internal:testing", "@com_google_absl//absl/status", ], ) @@ -529,7 +525,6 @@ cc_library( srcs = ["attribute_trail.cc"], hdrs = ["attribute_trail.h"], deps = [ - "//eval/public:activation", "//eval/public:cel_attribute", "//eval/public:cel_expression", "//eval/public:cel_value", @@ -549,9 +544,9 @@ cc_test( ], deps = [ ":attribute_trail", - "//base:testing", "//eval/public:cel_attribute", "//eval/public:cel_value", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -562,9 +557,7 @@ cc_library( hdrs = ["attribute_utility.h"], deps = [ ":attribute_trail", - "//eval/public:activation", "//eval/public:cel_attribute", - "//eval/public:cel_expression", "//eval/public:cel_value", "//eval/public:unknown_attribute_set", "//eval/public:unknown_set", @@ -583,11 +576,11 @@ cc_test( ], deps = [ ":attribute_utility", - "//base:testing", "//eval/public:cel_attribute", "//eval/public:cel_value", "//eval/public:unknown_attribute_set", "//eval/public:unknown_set", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -603,14 +596,11 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//eval/public:activation", "//eval/public:cel_builtins", - "//eval/public:cel_function", "//eval/public:cel_value", "//eval/public:unknown_attribute_set", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", - "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -623,10 +613,11 @@ cc_test( deps = [ ":ident_step", ":ternary_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:unknown_attribute_set", "//eval/public:unknown_set", + "//internal:status_macros", + "//internal:testing", ], ) @@ -637,7 +628,6 @@ cc_library( deps = [ ":evaluator_core", ":expression_step_base", - "//eval/public:activation", "//eval/public:cel_value", "@com_google_absl//absl/status:statusor", ], @@ -650,9 +640,10 @@ cc_test( deps = [ ":evaluator_core", ":shadowable_value_step", - "//base:status_macros", - "//base:testing", + "//eval/public:activation", "//eval/public:cel_value", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status:statusor", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], diff --git a/eval/eval/attribute_trail.cc b/eval/eval/attribute_trail.cc index d7bfe2fa8..c6d3a5477 100644 --- a/eval/eval/attribute_trail.cc +++ b/eval/eval/attribute_trail.cc @@ -3,10 +3,8 @@ #include "absl/status/status.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { + // Creates AttributeTrail with attribute path incremented by "qualifier". AttributeTrail AttributeTrail::Step(CelAttributeQualifier qualifier, google::protobuf::Arena* arena) const { @@ -18,7 +16,5 @@ AttributeTrail AttributeTrail::Step(CelAttributeQualifier qualifier, return AttributeTrail(google::protobuf::Arena::Create( arena, attribute_->variable(), std::move(qualifiers))); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime diff --git a/eval/eval/attribute_trail.h b/eval/eval/attribute_trail.h index 48874726d..96a75097a 100644 --- a/eval/eval/attribute_trail.h +++ b/eval/eval/attribute_trail.h @@ -7,16 +7,12 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/arena.h" #include "absl/types/optional.h" -#include "eval/public/activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_expression.h" #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // AttributeTrail reflects current attribute path. // It is functionally similar to CelAttribute, yet intended to have better @@ -56,9 +52,7 @@ class AttributeTrail { : attribute_(attribute) {} const CelAttribute* attribute_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_ATTRIBUTE_TRAIL_H_ diff --git a/eval/eval/attribute_trail_test.cc b/eval/eval/attribute_trail_test.cc index ce186a2b3..ecc40e4af 100644 --- a/eval/eval/attribute_trail_test.cc +++ b/eval/eval/attribute_trail_test.cc @@ -1,15 +1,11 @@ #include "eval/eval/attribute_trail.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_value.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { using google::api::expr::v1alpha1::Expr; @@ -37,7 +33,4 @@ TEST(AttributeTrailTest, AttributeTrailStep) { CelAttribute(root, {CelAttributeQualifier::Create(step_value)})); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/attribute_utility.cc b/eval/eval/attribute_utility.cc index 02bc7121c..8cd1bf140 100644 --- a/eval/eval/attribute_utility.cc +++ b/eval/eval/attribute_utility.cc @@ -5,12 +5,9 @@ #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { -using google::protobuf::Arena; +using ::google::protobuf::Arena; bool AttributeUtility::CheckForMissingAttribute( const AttributeTrail& trail) const { @@ -107,7 +104,4 @@ const UnknownSet* AttributeUtility::MergeUnknowns( } return MergeUnknowns(args, initial_set); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/attribute_utility.h b/eval/eval/attribute_utility.h index a49b282d9..0b76387db 100644 --- a/eval/eval/attribute_utility.h +++ b/eval/eval/attribute_utility.h @@ -7,17 +7,12 @@ #include "absl/types/optional.h" #include "absl/types/span.h" #include "eval/eval/attribute_trail.h" -#include "eval/public/activation.h" #include "eval/public/cel_attribute.h" -#include "eval/public/cel_expression.h" #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Helper class for handling unknowns and missing attribute logic. Provides // helpers for merging unknown sets from arguments on the stack and for @@ -69,9 +64,7 @@ class AttributeUtility { const std::vector* missing_attribute_patterns_; google::protobuf::Arena* arena_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_UNKNOWNS_UTILITY_H_ diff --git a/eval/eval/attribute_utility_test.cc b/eval/eval/attribute_utility_test.cc index e15a5132b..4c70ebef1 100644 --- a/eval/eval/attribute_utility_test.cc +++ b/eval/eval/attribute_utility_test.cc @@ -1,19 +1,15 @@ #include "eval/eval/attribute_utility.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { -using google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Expr; using testing::Eq; using testing::NotNull; using testing::SizeIs; @@ -180,7 +176,4 @@ TEST(UnknownsUtilityTest, UnknownsUtilityCheckForMissingAttributes) { EXPECT_TRUE(utility1.CheckForMissingAttribute(trail)); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/comprehension_step.cc b/eval/eval/comprehension_step.cc index c3bc49b8e..cfb4dbfd0 100644 --- a/eval/eval/comprehension_step.cc +++ b/eval/eval/comprehension_step.cc @@ -1,16 +1,15 @@ #include "eval/eval/comprehension_step.h" +#include + #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "eval/eval/attribute_trail.h" #include "eval/eval/evaluator_core.h" #include "eval/public/cel_attribute.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Stack variables during comprehension evaluation: // 0. accu_init, then loop_step (any), available through accu_var @@ -108,20 +107,20 @@ absl::Status ComprehensionNextStep::Evaluate(ExecutionFrame* frame) const { absl::StrCat("ComprehensionNextStep: want int64_t, got ", CelValue::TypeName(current_index_value.type()))); } - RETURN_IF_ERROR(frame->IncrementIterations()); + CEL_RETURN_IF_ERROR(frame->IncrementIterations()); int64_t current_index = current_index_value.Int64OrDie(); if (current_index == -1) { - RETURN_IF_ERROR(frame->PushIterFrame()); + CEL_RETURN_IF_ERROR(frame->PushIterFrame()); } // Update stack for breaking out of loop or next round. CelValue loop_step = state[POS_LOOP_STEP]; frame->value_stack().Pop(5); frame->value_stack().Push(loop_step); - RETURN_IF_ERROR(frame->SetIterVar(accu_var_, loop_step)); + CEL_RETURN_IF_ERROR(frame->SetIterVar(accu_var_, loop_step)); if (current_index >= cel_list->size() - 1) { - RETURN_IF_ERROR(frame->ClearIterVar(iter_var_)); + CEL_RETURN_IF_ERROR(frame->ClearIterVar(iter_var_)); return frame->JumpTo(jump_offset_); } frame->value_stack().Push(iter_range, iter_range_attr); @@ -133,7 +132,7 @@ absl::Status ComprehensionNextStep::Evaluate(ExecutionFrame* frame) const { CelAttributeQualifier::Create(CelValue::CreateInt64(current_index)), frame->arena()); frame->value_stack().Push(current_value, iter_trail); - RETURN_IF_ERROR(frame->SetIterVar(iter_var_, current_value, iter_trail)); + CEL_RETURN_IF_ERROR(frame->SetIterVar(iter_var_, current_value, iter_trail)); return absl::OkStatus(); } @@ -173,7 +172,7 @@ absl::Status ComprehensionCondStep::Evaluate(ExecutionFrame* frame) const { } // The error jump skips the ComprehensionFinish clean-up step, so we // need to update the iteration variable stack here. - RETURN_IF_ERROR(frame->PopIterFrame()); + CEL_RETURN_IF_ERROR(frame->PopIterFrame()); return frame->JumpTo(error_jump_offset_); } bool loop_condition = loop_condition_value.BoolOrDie(); @@ -200,7 +199,7 @@ absl::Status ComprehensionFinish::Evaluate(ExecutionFrame* frame) const { CelValue result = frame->value_stack().Peek(); frame->value_stack().Pop(1); // result frame->value_stack().PopAndPush(result); - RETURN_IF_ERROR(frame->PopIterFrame()); + CEL_RETURN_IF_ERROR(frame->PopIterFrame()); return absl::OkStatus(); } @@ -248,7 +247,4 @@ absl::Status ListKeysStep::Evaluate(ExecutionFrame* frame) const { return absl::OkStatus(); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/comprehension_step.h b/eval/eval/comprehension_step.h index 93ebcb091..bff1d3642 100644 --- a/eval/eval/comprehension_step.h +++ b/eval/eval/comprehension_step.h @@ -1,17 +1,15 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_COMPREHENSION_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_COMPREHENSION_STEP_H_ +#include + +#include "google/api/expr/v1alpha1/syntax.pb.h" #include "eval/eval/evaluator_core.h" #include "eval/eval/expression_step_base.h" -#include "eval/public/activation.h" #include "eval/public/cel_function.h" #include "eval/public/cel_value.h" -#include "google/api/expr/v1alpha1/syntax.pb.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { class ComprehensionNextStep : public ExpressionStepBase { public: @@ -63,9 +61,6 @@ class ComprehensionFinish : public ExpressionStepBase { // otherwise it's a no-op. std::unique_ptr CreateListKeysStep(int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_COMPREHENSION_STEP_H_ diff --git a/eval/eval/comprehension_step_test.cc b/eval/eval/comprehension_step_test.cc index 652ef0af6..ed437c0e2 100644 --- a/eval/eval/comprehension_step_test.cc +++ b/eval/eval/comprehension_step_test.cc @@ -5,22 +5,19 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/struct.pb.h" #include "google/protobuf/wrappers.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" #include "eval/eval/evaluator_core.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_options.h" #include "eval/public/cel_value.h" #include "eval/public/structs/cel_proto_wrapper.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { using ::google::protobuf::ListValue; @@ -213,7 +210,4 @@ TEST_F(ListKeysStepTest, UnknownSetPassedThrough) { } } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/const_value_step.cc b/eval/eval/const_value_step.cc index 05ae1a61b..7a305cff0 100644 --- a/eval/eval/const_value_step.cc +++ b/eval/eval/const_value_step.cc @@ -1,17 +1,16 @@ #include "eval/eval/const_value_step.h" +#include + #include "google/protobuf/duration.pb.h" #include "google/protobuf/timestamp.pb.h" #include "absl/status/statusor.h" #include "eval/eval/expression_step_base.h" #include "eval/public/structs/cel_proto_wrapper.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { -using google::api::expr::v1alpha1::Constant; +using ::google::api::expr::v1alpha1::Constant; namespace { @@ -84,7 +83,4 @@ absl::StatusOr> CreateConstValueStep( CelValue::CreateInt64(value_descriptor->number()), expr_id, false); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/const_value_step.h b/eval/eval/const_value_step.h index 01a071295..f47a38600 100644 --- a/eval/eval/const_value_step.h +++ b/eval/eval/const_value_step.h @@ -1,14 +1,13 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_CONST_VALUE_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_CONST_VALUE_STEP_H_ +#include + #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { absl::optional ConvertConstant( const google::api::expr::v1alpha1::Constant* const_expr); @@ -17,9 +16,6 @@ absl::optional ConvertConstant( absl::StatusOr> CreateConstValueStep( CelValue value, int64_t expr_id, bool comes_from_ast = true); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_CONST_VALUE_STEP_H_ diff --git a/eval/eval/const_value_step_test.cc b/eval/eval/const_value_step_test.cc index 2d16db583..279b2d082 100644 --- a/eval/eval/const_value_step_test.cc +++ b/eval/eval/const_value_step_test.cc @@ -1,16 +1,13 @@ #include "eval/eval/const_value_step.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "base/status_macros.h" +#include "eval/public/activation.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -24,7 +21,7 @@ using google::protobuf::Arena; absl::StatusOr RunConstantExpression(const Expr* expr, const Constant* const_expr, Arena* arena) { - ASSIGN_OR_RETURN( + CEL_ASSIGN_OR_RETURN( auto step, CreateConstValueStep(ConvertConstant(const_expr).value(), expr->id())); @@ -162,7 +159,4 @@ TEST(ConstValueStepTest, TestEvaluationConstBytes) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/container_access_step.cc b/eval/eval/container_access_step.cc index 9bcaa42e5..ffd01d99b 100644 --- a/eval/eval/container_access_step.cc +++ b/eval/eval/container_access_step.cc @@ -1,5 +1,7 @@ #include "eval/eval/container_access_step.h" +#include + #include "google/protobuf/arena.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -9,10 +11,7 @@ #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -156,7 +155,4 @@ absl::StatusOr> CreateContainerAccessStep( return absl::make_unique(expr_id); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/container_access_step.h b/eval/eval/container_access_step.h index 2fcc8bdbc..b1562e7ec 100644 --- a/eval/eval/container_access_step.h +++ b/eval/eval/container_access_step.h @@ -1,23 +1,18 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_CONTAINER_ACCESS_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_CONTAINER_ACCESS_STEP_H_ +#include + +#include "google/api/expr/v1alpha1/syntax.pb.h" #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" -#include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for Select - based Execution step absl::StatusOr> CreateContainerAccessStep( const google::api::expr::v1alpha1::Expr::Call* call, int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_CONTAINER_ACCESS_STEP_H_ diff --git a/eval/eval/container_access_step_test.cc b/eval/eval/container_access_step_test.cc index 9fa47fbe8..9f7a2bf1c 100644 --- a/eval/eval/container_access_step_test.cc +++ b/eval/eval/container_access_step_test.cc @@ -5,22 +5,19 @@ #include #include "google/protobuf/struct.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_builtins.h" #include "eval/public/cel_value.h" #include "eval/public/containers/container_backed_list_impl.h" #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -28,7 +25,7 @@ using ::google::api::expr::v1alpha1::Expr; using ::google::api::expr::v1alpha1::SourceInfo; using ::google::protobuf::Struct; using testing::HasSubstr; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; using TestParamType = std::tuple; @@ -321,7 +318,4 @@ INSTANTIATE_TEST_SUITE_P(CombinedContainerTest, } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/create_list_step.cc b/eval/eval/create_list_step.cc index d3373c397..867293dd7 100644 --- a/eval/eval/create_list_step.cc +++ b/eval/eval/create_list_step.cc @@ -1,13 +1,13 @@ #include "eval/eval/create_list_step.h" +#include + #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "eval/eval/expression_step_base.h" #include "eval/public/containers/container_backed_list_impl.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -77,7 +77,4 @@ absl::StatusOr> CreateCreateListStep( create_list_expr->elements_size()); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/create_list_step.h b/eval/eval/create_list_step.h index fdd51fdcd..c195cbd68 100644 --- a/eval/eval/create_list_step.h +++ b/eval/eval/create_list_step.h @@ -1,24 +1,19 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_CREATE_LIST_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_CREATE_LIST_STEP_H_ +#include + +#include "google/api/expr/v1alpha1/syntax.pb.h" #include "absl/status/statusor.h" -#include "absl/types/span.h" #include "eval/eval/evaluator_core.h" -#include "eval/eval/expression_step_base.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for CreateList - based Execution step absl::StatusOr> CreateCreateListStep( const google::api::expr::v1alpha1::Expr::CreateList* create_list_expr, int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_CREATE_LIST_STEP_H_ diff --git a/eval/eval/create_list_step_test.cc b/eval/eval/create_list_step_test.cc index 6b523ab7d..e9a1fd626 100644 --- a/eval/eval/create_list_step_test.cc +++ b/eval/eval/create_list_step_test.cc @@ -1,7 +1,5 @@ #include "eval/eval/create_list_step.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "eval/eval/const_value_step.h" @@ -9,17 +7,16 @@ #include "eval/public/activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/unknown_attribute_set.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" + +namespace google::api::expr::runtime { -namespace google { -namespace api { -namespace expr { -namespace runtime { namespace { using testing::Eq; using testing::Not; -using cel_base::testing::IsOk; +using cel::internal::IsOk; using google::api::expr::v1alpha1::Expr; @@ -34,15 +31,15 @@ absl::StatusOr RunExpression(const std::vector& values, for (auto value : values) { auto expr0 = create_list->add_elements(); expr0->mutable_const_expr()->set_int64_value(value); - ASSIGN_OR_RETURN( + CEL_ASSIGN_OR_RETURN( auto const_step, CreateConstValueStep(ConvertConstant(&expr0->const_expr()).value(), expr0->id())); path.push_back(std::move(const_step)); } - ASSIGN_OR_RETURN(auto step, - CreateCreateListStep(create_list, dummy_expr.id())); + CEL_ASSIGN_OR_RETURN(auto step, + CreateCreateListStep(create_list, dummy_expr.id())); path.push_back(std::move(step)); CelExpressionFlatImpl cel_expr(&dummy_expr, std::move(path), 0, {}, @@ -68,14 +65,14 @@ absl::StatusOr RunExpressionWithCelValues( expr0->set_id(ind); expr0->mutable_ident_expr()->set_name(var_name); - ASSIGN_OR_RETURN(auto ident_step, - CreateIdentStep(&expr0->ident_expr(), expr0->id())); + CEL_ASSIGN_OR_RETURN(auto ident_step, + CreateIdentStep(&expr0->ident_expr(), expr0->id())); path.push_back(std::move(ident_step)); activation.InsertValue(var_name, value); } - ASSIGN_OR_RETURN(auto step0, - CreateCreateListStep(create_list, dummy_expr.id())); + CEL_ASSIGN_OR_RETURN(auto step0, + CreateCreateListStep(create_list, dummy_expr.id())); path.push_back(std::move(step0)); CelExpressionFlatImpl cel_expr(&dummy_expr, std::move(path), 0, {}, @@ -202,7 +199,4 @@ INSTANTIATE_TEST_SUITE_P(CombinedCreateListTest, CreateListStepTest, } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/create_struct_step.cc b/eval/eval/create_struct_step.cc index 14b4d5069..464c5ce9d 100644 --- a/eval/eval/create_struct_step.cc +++ b/eval/eval/create_struct_step.cc @@ -1,5 +1,6 @@ #include "eval/eval/create_struct_step.h" +#include #include #include @@ -8,15 +9,13 @@ #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "absl/strings/substitute.h" +#include "eval/eval/expression_step_base.h" #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/containers/field_access.h" #include "eval/public/structs/cel_proto_wrapper.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -202,7 +201,7 @@ absl::Status CreateStructStepForMessage::Evaluate(ExecutionFrame* frame) const { } CelValue result; - RETURN_IF_ERROR(DoEvaluate(frame, &result)); + CEL_RETURN_IF_ERROR(DoEvaluate(frame, &result)); frame->value_stack().Pop(entries_.size()); frame->value_stack().Push(result); @@ -230,7 +229,7 @@ absl::Status CreateStructStepForMap::DoEvaluate(ExecutionFrame* frame, int map_key_index = 2 * i; int map_value_index = map_key_index + 1; const CelValue& map_key = args[map_key_index]; - RETURN_IF_ERROR(CelValue::CheckMapKeyType(map_key)); + CEL_RETURN_IF_ERROR(CelValue::CheckMapKeyType(map_key)); map_entries.push_back({map_key, args[map_value_index]}); } @@ -257,7 +256,7 @@ absl::Status CreateStructStepForMap::Evaluate(ExecutionFrame* frame) const { } CelValue result; - RETURN_IF_ERROR(DoEvaluate(frame, &result)); + CEL_RETURN_IF_ERROR(DoEvaluate(frame, &result)); frame->value_stack().Pop(2 * entry_count_); frame->value_stack().Push(result); @@ -293,7 +292,4 @@ absl::StatusOr> CreateCreateStructStep( } } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/create_struct_step.h b/eval/eval/create_struct_step.h index e10e6d4ab..0f4b66838 100644 --- a/eval/eval/create_struct_step.h +++ b/eval/eval/create_struct_step.h @@ -1,18 +1,15 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_CREATE_STRUCT_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_CREATE_STRUCT_STEP_H_ +#include #include #include "google/protobuf/descriptor.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/eval/expression_step_base.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for CreateStruct - based Execution step absl::StatusOr> CreateCreateStructStep( @@ -26,9 +23,6 @@ inline absl::StatusOr> CreateCreateStructStep( expr_id); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_CREATE_STRUCT_STEP_H_ diff --git a/eval/eval/create_struct_step_test.cc b/eval/eval/create_struct_step_test.cc index 795a9d096..6e4df3119 100644 --- a/eval/eval/create_struct_step_test.cc +++ b/eval/eval/create_struct_step_test.cc @@ -1,24 +1,22 @@ #include "eval/eval/create_struct_step.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/cel_type_registry.h" #include "eval/public/containers/container_backed_list_impl.h" #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/testutil/test_message.pb.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { + namespace { using ::google::protobuf::Arena; @@ -29,7 +27,7 @@ using testing::HasSubstr; using testing::IsNull; using testing::Not; using testing::Pointwise; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; using testutil::EqualsProto; @@ -49,7 +47,7 @@ absl::StatusOr RunExpression(absl::string_view field, auto ident = expr0.mutable_ident_expr(); ident->set_name("message"); - ASSIGN_OR_RETURN(auto step0, CreateIdentStep(ident, expr0.id())); + CEL_ASSIGN_OR_RETURN(auto step0, CreateIdentStep(ident, expr0.id())); auto create_struct = expr1.mutable_struct_expr(); create_struct->set_message_name("google.api.expr.runtime.TestMessage"); @@ -62,8 +60,8 @@ absl::StatusOr RunExpression(absl::string_view field, return absl::Status(absl::StatusCode::kFailedPrecondition, "missing proto message type"); } - ASSIGN_OR_RETURN(auto step1, - CreateCreateStructStep(create_struct, desc, expr1.id())); + CEL_ASSIGN_OR_RETURN(auto step1, + CreateCreateStructStep(create_struct, desc, expr1.id())); path.push_back(std::move(step0)); path.push_back(std::move(step1)); @@ -132,15 +130,15 @@ absl::StatusOr RunCreateMapExpression( auto key_ident = expr.mutable_ident_expr(); key_ident->set_name(key_name); exprs.push_back(expr); - ASSIGN_OR_RETURN(auto step_key, - CreateIdentStep(key_ident, exprs.back().id())); + CEL_ASSIGN_OR_RETURN(auto step_key, + CreateIdentStep(key_ident, exprs.back().id())); expr.Clear(); auto value_ident = expr.mutable_ident_expr(); value_ident->set_name(value_name); exprs.push_back(expr); - ASSIGN_OR_RETURN(auto step_value, - CreateIdentStep(value_ident, exprs.back().id())); + CEL_ASSIGN_OR_RETURN(auto step_value, + CreateIdentStep(value_ident, exprs.back().id())); path.push_back(std::move(step_key)); path.push_back(std::move(step_value)); @@ -152,8 +150,8 @@ absl::StatusOr RunCreateMapExpression( index++; } - ASSIGN_OR_RETURN(auto step1, - CreateCreateStructStep(create_struct, expr1.id())); + CEL_ASSIGN_OR_RETURN(auto step1, + CreateCreateStructStep(create_struct, expr1.id())); path.push_back(std::move(step1)); CelExpressionFlatImpl cel_expr(&expr1, std::move(path), 0, {}, @@ -721,7 +719,4 @@ INSTANTIATE_TEST_SUITE_P(CombinedCreateStructTest, CreateCreateStructStepTest, } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/evaluator_core.cc b/eval/eval/evaluator_core.cc index 54d5672d8..ede1ef543 100644 --- a/eval/eval/evaluator_core.cc +++ b/eval/eval/evaluator_core.cc @@ -5,12 +5,11 @@ #include "absl/types/optional.h" #include "eval/eval/attribute_trail.h" #include "eval/public/cel_value.h" -#include "base/status_macros.h" +#include "internal/casts.h" +#include "internal/status_macros.h" + +namespace google::api::expr::runtime { -namespace google { -namespace api { -namespace expr { -namespace runtime { namespace { absl::Status CheckIterAccess(CelExpressionFlatEvaluationState* state, @@ -72,7 +71,7 @@ absl::Status ExecutionFrame::PopIterFrame() { absl::Status ExecutionFrame::SetIterVar(const std::string& name, const CelValue& val, AttributeTrail trail) { - RETURN_IF_ERROR(CheckIterAccess(state_, name)); + CEL_RETURN_IF_ERROR(CheckIterAccess(state_, name)); state_->IterStackTop()[name] = {val, trail}; return absl::OkStatus(); @@ -84,7 +83,7 @@ absl::Status ExecutionFrame::SetIterVar(const std::string& name, } absl::Status ExecutionFrame::ClearIterVar(const std::string& name) { - RETURN_IF_ERROR(CheckIterAccess(state_, name)); + CEL_RETURN_IF_ERROR(CheckIterAccess(state_, name)); state_->IterStackTop().erase(name); return absl::OkStatus(); } @@ -144,7 +143,8 @@ absl::StatusOr CelExpressionFlatImpl::Evaluate( absl::StatusOr CelExpressionFlatImpl::Trace( const BaseActivation& activation, CelEvaluationState* _state, CelEvaluationListener callback) const { - auto state = down_cast(_state); + auto state = + ::cel::internal::down_cast(_state); state->Reset(); // Using both unknown attribute patterns and unknown paths via FieldMask is @@ -197,7 +197,4 @@ absl::StatusOr CelExpressionFlatImpl::Trace( return value; } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/evaluator_core.h b/eval/eval/evaluator_core.h index 55c999b98..fc79a8c6d 100644 --- a/eval/eval/evaluator_core.h +++ b/eval/eval/evaluator_core.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -21,16 +22,13 @@ #include "eval/eval/attribute_trail.h" #include "eval/eval/attribute_utility.h" #include "eval/eval/evaluator_stack.h" -#include "eval/public/activation.h" +#include "eval/public/base_activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_expression.h" #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Forward declaration of ExecutionFrame, to resolve circular dependency. class ExecutionFrame; @@ -218,8 +216,8 @@ class CelExpressionFlatImpl : public CelExpression { // flattened AST tree. Max iterations dictates the maximum number of // iterations in the comprehension expressions (use 0 to disable the upper // bound). - CelExpressionFlatImpl(const google::api::expr::v1alpha1::Expr* root_expr, - ExecutionPath path, int max_iterations, + CelExpressionFlatImpl(const Expr* root_expr, ExecutionPath path, + int max_iterations, std::set iter_variable_names, bool enable_unknowns = false, bool enable_unknown_function_results = false, @@ -271,9 +269,6 @@ class CelExpressionFlatImpl : public CelExpression { bool enable_missing_attribute_errors_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_EVALUATOR_CORE_H_ diff --git a/eval/eval/evaluator_core_test.cc b/eval/eval/evaluator_core_test.cc index 74882fc9d..6061385ff 100644 --- a/eval/eval/evaluator_core_test.cc +++ b/eval/eval/evaluator_core_test.cc @@ -1,25 +1,21 @@ #include "eval/eval/evaluator_core.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/compiler/flat_expr_builder.h" #include "eval/eval/attribute_trail.h" +#include "eval/public/activation.h" #include "eval/public/builtin_func_registrar.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_value.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { -using google::api::expr::v1alpha1::Expr; +using ::google::api::expr::v1alpha1::Expr; using ::google::api::expr::runtime::RegisterBuiltinFunctions; using testing::_; using testing::Eq; -using testing::NotNull; // Fake expression implementation // Pushes int64_t(0) on top of value stack. @@ -262,7 +258,4 @@ TEST(EvaluatorCoreTest, TraceTest) { ASSERT_OK(eval_status); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/evaluator_stack.cc b/eval/eval/evaluator_stack.cc index 34907cb97..01569907f 100644 --- a/eval/eval/evaluator_stack.cc +++ b/eval/eval/evaluator_stack.cc @@ -1,9 +1,6 @@ #include "eval/eval/evaluator_stack.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { void EvaluatorStack::Clear() { for (auto& v : stack_) { @@ -16,7 +13,4 @@ void EvaluatorStack::Clear() { current_size_ = 0; } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/evaluator_stack.h b/eval/eval/evaluator_stack.h index 4521acb53..7f14fca9b 100644 --- a/eval/eval/evaluator_stack.h +++ b/eval/eval/evaluator_stack.h @@ -3,13 +3,11 @@ #include +#include "absl/types/span.h" #include "eval/eval/attribute_trail.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // CelValue stack. // Implementation is based on vector to allow passing parameters from @@ -127,8 +125,6 @@ class EvaluatorStack { size_t current_size_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime + #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_EVALUATOR_STACK_H_ diff --git a/eval/eval/evaluator_stack_test.cc b/eval/eval/evaluator_stack_test.cc index 5df305dbd..fc77c0041 100644 --- a/eval/eval/evaluator_stack_test.cc +++ b/eval/eval/evaluator_stack_test.cc @@ -1,12 +1,9 @@ #include "eval/eval/evaluator_stack.h" -#include "base/testing.h" -#include "gtest/gtest.h" +#include "internal/testing.h" + +namespace google::api::expr::runtime { -namespace google { -namespace api { -namespace expr { -namespace runtime { namespace { using testing::NotNull; @@ -72,7 +69,5 @@ TEST(EvaluatorStackTest, Clear) { } } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime diff --git a/eval/eval/expression_build_warning.cc b/eval/eval/expression_build_warning.cc index 59a54651a..dc634fb00 100644 --- a/eval/eval/expression_build_warning.cc +++ b/eval/eval/expression_build_warning.cc @@ -1,9 +1,6 @@ #include "eval/eval/expression_build_warning.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { absl::Status BuilderWarnings::AddWarning(const absl::Status& warning) { if (fail_immediately_) { @@ -13,7 +10,4 @@ absl::Status BuilderWarnings::AddWarning(const absl::Status& warning) { return absl::OkStatus(); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/expression_build_warning.h b/eval/eval/expression_build_warning.h index 20575abe9..db3e88da8 100644 --- a/eval/eval/expression_build_warning.h +++ b/eval/eval/expression_build_warning.h @@ -5,10 +5,7 @@ #include "absl/status/status.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Container for recording warnings. class BuilderWarnings { @@ -28,9 +25,6 @@ class BuilderWarnings { bool fail_immediately_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_EXPRESSION_BUILD_WARNING_H_ diff --git a/eval/eval/expression_build_warning_test.cc b/eval/eval/expression_build_warning_test.cc index e077a9408..f97440625 100644 --- a/eval/eval/expression_build_warning_test.cc +++ b/eval/eval/expression_build_warning_test.cc @@ -1,16 +1,12 @@ #include "eval/eval/expression_build_warning.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using cel_base::testing::IsOk; +using cel::internal::IsOk; TEST(BuilderWarnings, NoFailCollects) { BuilderWarnings warnings(false); @@ -31,7 +27,4 @@ TEST(BuilderWarnings, FailReturnsStatus) { } } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/expression_step_base.h b/eval/eval/expression_step_base.h index 0fac4d147..58353aabf 100644 --- a/eval/eval/expression_step_base.h +++ b/eval/eval/expression_step_base.h @@ -1,14 +1,11 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_EXPRESSION_STEP_BASE_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_EXPRESSION_STEP_BASE_H_ -#include +#include #include "eval/eval/evaluator_core.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { class ExpressionStepBase : public ExpressionStep { public: @@ -30,9 +27,6 @@ class ExpressionStepBase : public ExpressionStep { bool comes_from_ast_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_EXPRESSION_STEP_BASE_H_ diff --git a/eval/eval/function_step.cc b/eval/eval/function_step.cc index 9d8977fc3..fa36793c0 100644 --- a/eval/eval/function_step.cc +++ b/eval/eval/function_step.cc @@ -18,7 +18,7 @@ #include "eval/eval/evaluator_core.h" #include "eval/eval/expression_build_warning.h" #include "eval/eval/expression_step_base.h" -#include "eval/public/activation.h" +#include "eval/public/base_activation.h" #include "eval/public/cel_builtins.h" #include "eval/public/cel_function.h" #include "eval/public/cel_function_provider.h" @@ -26,12 +26,8 @@ #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_function_result_set.h" #include "eval/public/unknown_set.h" -#include "base/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -299,7 +295,4 @@ absl::StatusOr> CreateFunctionStep( expr_id); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/function_step.h b/eval/eval/function_step.h index 6342d84ab..3f9d772bb 100644 --- a/eval/eval/function_step.h +++ b/eval/eval/function_step.h @@ -1,22 +1,16 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_FUNCTION_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_FUNCTION_STEP_H_ -#include - +#include #include #include "google/api/expr/v1alpha1/syntax.pb.h" #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" #include "eval/public/cel_function.h" #include "eval/public/cel_function_provider.h" -#include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for Call-based execution step where the function will be // resolved at runtime (lazily) from an input Activation. @@ -31,9 +25,6 @@ absl::StatusOr> CreateFunctionStep( const google::api::expr::v1alpha1::Expr::Call* call, int64_t expr_id, std::vector& overloads); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_FUNCTION_STEP_H_ diff --git a/eval/eval/function_step_test.cc b/eval/eval/function_step_test.cc index 33fa5a19f..4bb670bf3 100644 --- a/eval/eval/function_step_test.cc +++ b/eval/eval/function_step_test.cc @@ -4,13 +4,12 @@ #include #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/memory/memory.h" #include "absl/strings/string_view.h" #include "eval/eval/evaluator_core.h" #include "eval/eval/expression_build_warning.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_function.h" #include "eval/public/cel_function_registry.h" @@ -19,12 +18,10 @@ #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/public/unknown_function_result_set.h" #include "eval/testutil/test_message.pb.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -32,7 +29,7 @@ using testing::ElementsAre; using testing::Eq; using testing::Not; using testing::UnorderedElementsAre; -using cel_base::testing::IsOk; +using cel::internal::IsOk; using google::api::expr::v1alpha1::Expr; @@ -785,7 +782,4 @@ TEST(FunctionStepTestUnknownFunctionResults, UnknownVsErrorPrecedenceTest) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/ident_step.cc b/eval/eval/ident_step.cc index b0dff885a..5d87872a9 100644 --- a/eval/eval/ident_step.cc +++ b/eval/eval/ident_step.cc @@ -1,5 +1,6 @@ #include "eval/eval/ident_step.h" +#include #include #include "google/protobuf/arena.h" @@ -10,10 +11,7 @@ #include "eval/eval/expression_step_base.h" #include "eval/public/unknown_attribute_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { class IdentStep : public ExpressionStepBase { @@ -106,7 +104,4 @@ absl::StatusOr> CreateIdentStep( return absl::make_unique(ident_expr->name(), expr_id); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/ident_step.h b/eval/eval/ident_step.h index 663b1f63c..a0cc87bbf 100644 --- a/eval/eval/ident_step.h +++ b/eval/eval/ident_step.h @@ -1,23 +1,18 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_IDENT_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_IDENT_STEP_H_ +#include +#include + #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" -#include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for Ident - based Execution step absl::StatusOr> CreateIdentStep( const google::api::expr::v1alpha1::Expr::Ident* ident, int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_IDENT_STEP_H_ diff --git a/eval/eval/ident_step_test.cc b/eval/eval/ident_step_test.cc index 3e0bb9500..ec6e40b62 100644 --- a/eval/eval/ident_step_test.cc +++ b/eval/eval/ident_step_test.cc @@ -1,20 +1,17 @@ #include "eval/eval/ident_step.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/eval/evaluator_core.h" -#include "base/status_macros.h" +#include "eval/public/activation.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::api::expr::v1alpha1::Expr; -using google::protobuf::FieldMask; +using ::google::api::expr::v1alpha1::Expr; +using ::google::protobuf::FieldMask; using testing::Eq; using google::protobuf::Arena; @@ -234,7 +231,4 @@ TEST(IdentStepTest, TestIdentStepUnknownAttribute) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/jump_step.cc b/eval/eval/jump_step.cc index 311ab6154..e99469d47 100644 --- a/eval/eval/jump_step.cc +++ b/eval/eval/jump_step.cc @@ -1,12 +1,12 @@ #include "eval/eval/jump_step.h" +#include + #include "absl/status/statusor.h" +#include "absl/types/optional.h" #include "eval/eval/expression_step_base.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -121,7 +121,4 @@ absl::StatusOr> CreateBoolCheckJumpStep( // TODO(issues/41) Make sure Unknowns are properly supported by ternary // operation. -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/jump_step.h b/eval/eval/jump_step.h index e84342a77..ef52ca343 100644 --- a/eval/eval/jump_step.h +++ b/eval/eval/jump_step.h @@ -1,17 +1,15 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_JUMP_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_JUMP_STEP_H_ +#include + #include "google/api/expr/v1alpha1/syntax.pb.h" #include "absl/status/statusor.h" +#include "absl/types/optional.h" #include "eval/eval/evaluator_core.h" #include "eval/eval/expression_step_base.h" -#include "eval/public/activation.h" -#include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { class JumpStepBase : public ExpressionStepBase { public: @@ -50,9 +48,6 @@ absl::StatusOr> CreateCondJumpStep( absl::StatusOr> CreateBoolCheckJumpStep( absl::optional jump_offset, int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_JUMP_STEP_H_ diff --git a/eval/eval/logic_step.cc b/eval/eval/logic_step.cc index 045116ac9..7be833874 100644 --- a/eval/eval/logic_step.cc +++ b/eval/eval/logic_step.cc @@ -1,16 +1,15 @@ #include "eval/eval/logic_step.h" +#include + #include "absl/status/statusor.h" -#include "absl/strings/str_cat.h" +#include "absl/types/span.h" #include "eval/eval/expression_step_base.h" #include "eval/public/cel_builtins.h" #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -121,7 +120,4 @@ absl::StatusOr> CreateOrStep(int64_t expr_id) { return absl::make_unique(LogicalOpStep::OpType::OR, expr_id); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/logic_step.h b/eval/eval/logic_step.h index 09bc60dc4..e626f9857 100644 --- a/eval/eval/logic_step.h +++ b/eval/eval/logic_step.h @@ -1,17 +1,13 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_LOGIC_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_LOGIC_STEP_H_ -#include "google/api/expr/v1alpha1/syntax.pb.h" +#include +#include + #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" -#include "eval/public/cel_function.h" -#include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for "And" Execution step absl::StatusOr> CreateAndStep(int64_t expr_id); @@ -19,9 +15,6 @@ absl::StatusOr> CreateAndStep(int64_t expr_id); // Factory method for "Or" Execution step absl::StatusOr> CreateOrStep(int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_LOGIC_STEP_H_ diff --git a/eval/eval/logic_step_test.cc b/eval/eval/logic_step_test.cc index 320ede736..635746607 100644 --- a/eval/eval/logic_step_test.cc +++ b/eval/eval/logic_step_test.cc @@ -1,16 +1,13 @@ #include "eval/eval/logic_step.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -31,13 +28,13 @@ class LogicStepTest : public testing::TestWithParam { ident_expr1->set_name("name1"); ExecutionPath path; - ASSIGN_OR_RETURN(auto step, CreateIdentStep(ident_expr0, expr0.id())); + CEL_ASSIGN_OR_RETURN(auto step, CreateIdentStep(ident_expr0, expr0.id())); path.push_back(std::move(step)); - ASSIGN_OR_RETURN(step, CreateIdentStep(ident_expr1, expr1.id())); + CEL_ASSIGN_OR_RETURN(step, CreateIdentStep(ident_expr1, expr1.id())); path.push_back(std::move(step)); - ASSIGN_OR_RETURN(step, (is_or) ? CreateOrStep(2) : CreateAndStep(2)); + CEL_ASSIGN_OR_RETURN(step, (is_or) ? CreateOrStep(2) : CreateAndStep(2)); path.push_back(std::move(step)); auto dummy_expr = absl::make_unique(); @@ -47,7 +44,7 @@ class LogicStepTest : public testing::TestWithParam { Activation activation; activation.InsertValue("name0", arg0); activation.InsertValue("name1", arg1); - ASSIGN_OR_RETURN(CelValue value, impl.Evaluate(activation, &arena_)); + CEL_ASSIGN_OR_RETURN(CelValue value, impl.Evaluate(activation, &arena_)); *result = value; return absl::OkStatus(); } @@ -301,7 +298,4 @@ TEST_F(LogicStepTest, TestOrLogicUnknownHandling) { INSTANTIATE_TEST_SUITE_P(LogicStepTest, LogicStepTest, testing::Bool()); } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/select_step.cc b/eval/eval/select_step.cc index 71de4ea08..dd3b10c42 100644 --- a/eval/eval/select_step.cc +++ b/eval/eval/select_step.cc @@ -1,8 +1,12 @@ #include "eval/eval/select_step.h" +#include + +#include "absl/memory/memory.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "eval/eval/evaluator_core.h" #include "eval/eval/expression_step_base.h" #include "eval/public/cel_value.h" @@ -10,16 +14,13 @@ #include "eval/public/containers/field_backed_list_impl.h" #include "eval/public/containers/field_backed_map_impl.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::protobuf::Descriptor; -using google::protobuf::FieldDescriptor; -using google::protobuf::Reflection; +using ::google::protobuf::Descriptor; +using ::google::protobuf::FieldDescriptor; +using ::google::protobuf::Reflection; // SelectStep performs message field access specified by Expr::Select // message. @@ -240,7 +241,4 @@ absl::StatusOr> CreateSelectStep( select_expr->field(), select_expr->test_only(), expr_id, select_path); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/select_step.h b/eval/eval/select_step.h index cfb8afafc..a86937c47 100644 --- a/eval/eval/select_step.h +++ b/eval/eval/select_step.h @@ -1,15 +1,16 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_SELECT_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_SELECT_STEP_H_ +#include +#include + +#include "google/api/expr/v1alpha1/syntax.pb.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for Select - based Execution step absl::StatusOr> CreateSelectStep( @@ -20,9 +21,6 @@ absl::StatusOr> CreateSelectStep( absl::StatusOr> CreateSelectStep( const google::api::expr::v1alpha1::Expr::Select* select_expr, int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_SELECT_STEP_H_ diff --git a/eval/eval/select_step_test.cc b/eval/eval/select_step_test.cc index 1ffa4fd46..5f0ae3327 100644 --- a/eval/eval/select_step_test.cc +++ b/eval/eval/select_step_test.cc @@ -1,33 +1,30 @@ #include "eval/eval/select_step.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/status/statusor.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/public/unknown_attribute_set.h" #include "eval/testutil/test_message.pb.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { + namespace { +using ::google::api::expr::v1alpha1::Expr; using testing::Eq; using testing::HasSubstr; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; using testutil::EqualsProto; -using google::api::expr::v1alpha1::Expr; - // Helper method. Creates simple pipeline containing Select step and runs it. absl::StatusOr RunExpression(const CelValue target, absl::string_view field, bool test, @@ -44,9 +41,9 @@ absl::StatusOr RunExpression(const CelValue target, auto ident = expr0->mutable_ident_expr(); ident->set_name("target"); - ASSIGN_OR_RETURN(auto step0, CreateIdentStep(ident, expr0->id())); - ASSIGN_OR_RETURN(auto step1, - CreateSelectStep(select, dummy_expr.id(), unknown_path)); + CEL_ASSIGN_OR_RETURN(auto step0, CreateIdentStep(ident, expr0->id())); + CEL_ASSIGN_OR_RETURN(auto step1, + CreateSelectStep(select, dummy_expr.id(), unknown_path)); path.push_back(std::move(step0)); path.push_back(std::move(step1)); @@ -666,8 +663,7 @@ TEST(SelectStepTest, UnknownPatternResolvesToUnknown) { } INSTANTIATE_TEST_SUITE_P(SelectStepTest, SelectStepTest, testing::Bool()); + } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime diff --git a/eval/eval/shadowable_value_step.cc b/eval/eval/shadowable_value_step.cc index e9bd9aed7..ccc7bf975 100644 --- a/eval/eval/shadowable_value_step.cc +++ b/eval/eval/shadowable_value_step.cc @@ -1,13 +1,12 @@ #include "eval/eval/shadowable_value_step.h" +#include + #include "absl/status/statusor.h" #include "eval/eval/expression_step_base.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -39,7 +38,4 @@ absl::StatusOr> CreateShadowableValueStep( return std::move(step); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/shadowable_value_step.h b/eval/eval/shadowable_value_step.h index 7671e159d..9794838f2 100644 --- a/eval/eval/shadowable_value_step.h +++ b/eval/eval/shadowable_value_step.h @@ -1,15 +1,14 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_SHADOWABLE_VALUE_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_SHADOWABLE_VALUE_STEP_H_ +#include +#include + #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Create an identifier resolution step with a default value that may be // shadowed by an identifier of the same name within the runtime-provided @@ -17,9 +16,6 @@ namespace runtime { absl::StatusOr> CreateShadowableValueStep( const std::string& identifier, const CelValue& value, int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_SHADOWABLE_VALUE_STEP_H_ diff --git a/eval/eval/shadowable_value_step_test.cc b/eval/eval/shadowable_value_step_test.cc index 4e0e6ae3c..71c070fff 100644 --- a/eval/eval/shadowable_value_step_test.cc +++ b/eval/eval/shadowable_value_step_test.cc @@ -1,28 +1,26 @@ #include "eval/eval/shadowable_value_step.h" #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" +#include "eval/public/activation.h" #include "eval/public/cel_value.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { -using google::protobuf::Arena; +using ::google::protobuf::Arena; using testing::Eq; absl::StatusOr RunShadowableExpression(const std::string& identifier, const CelValue& value, const Activation& activation, Arena* arena) { - ASSIGN_OR_RETURN(auto step, CreateShadowableValueStep(identifier, value, 1)); + CEL_ASSIGN_OR_RETURN(auto step, + CreateShadowableValueStep(identifier, value, 1)); ExecutionPath path; path.push_back(std::move(step)); @@ -69,7 +67,4 @@ TEST(ShadowableValueStepTest, TestEvaluateShadowedIdentifier) { } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/ternary_step.cc b/eval/eval/ternary_step.cc index f63006711..97d6f2607 100644 --- a/eval/eval/ternary_step.cc +++ b/eval/eval/ternary_step.cc @@ -1,5 +1,7 @@ #include "eval/eval/ternary_step.h" +#include + #include "absl/status/statusor.h" #include "absl/strings/str_cat.h" #include "eval/eval/expression_step_base.h" @@ -7,10 +9,7 @@ #include "eval/public/cel_value.h" #include "eval/public/unknown_attribute_set.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -72,7 +71,4 @@ absl::StatusOr> CreateTernaryStep( return absl::make_unique(expr_id); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/eval/ternary_step.h b/eval/eval/ternary_step.h index 49696da88..de43a03d0 100644 --- a/eval/eval/ternary_step.h +++ b/eval/eval/ternary_step.h @@ -1,25 +1,17 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_TERNARY_STEP_H_ #define THIRD_PARTY_CEL_CPP_EVAL_EVAL_TERNARY_STEP_H_ -#include "google/api/expr/v1alpha1/syntax.pb.h" +#include + #include "absl/status/statusor.h" #include "eval/eval/evaluator_core.h" -#include "eval/public/activation.h" -#include "eval/public/cel_function.h" -#include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Factory method for ternary (_?_:_) execution step absl::StatusOr> CreateTernaryStep( int64_t expr_id); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_EVAL_TERNARY_STEP_H_ diff --git a/eval/eval/ternary_step_test.cc b/eval/eval/ternary_step_test.cc index 19abd8b7c..f683f3a32 100644 --- a/eval/eval/ternary_step_test.cc +++ b/eval/eval/ternary_step_test.cc @@ -1,16 +1,13 @@ #include "eval/eval/ternary_step.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/eval/ident_step.h" +#include "eval/public/activation.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { @@ -39,16 +36,16 @@ class LogicStepTest : public testing::TestWithParam { ExecutionPath path; - ASSIGN_OR_RETURN(auto step, CreateIdentStep(ident_expr0, expr0.id())); + CEL_ASSIGN_OR_RETURN(auto step, CreateIdentStep(ident_expr0, expr0.id())); path.push_back(std::move(step)); - ASSIGN_OR_RETURN(step, CreateIdentStep(ident_expr1, expr1.id())); + CEL_ASSIGN_OR_RETURN(step, CreateIdentStep(ident_expr1, expr1.id())); path.push_back(std::move(step)); - ASSIGN_OR_RETURN(step, CreateIdentStep(ident_expr2, expr2.id())); + CEL_ASSIGN_OR_RETURN(step, CreateIdentStep(ident_expr2, expr2.id())); path.push_back(std::move(step)); - ASSIGN_OR_RETURN(step, CreateTernaryStep(4)); + CEL_ASSIGN_OR_RETURN(step, CreateTernaryStep(4)); path.push_back(std::move(step)); auto dummy_expr = absl::make_unique(); @@ -165,7 +162,4 @@ TEST_F(LogicStepTest, TestUnknownHandling) { INSTANTIATE_TEST_SUITE_P(LogicStepTest, LogicStepTest, testing::Bool()); } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/public/BUILD b/eval/public/BUILD index 2463da75a..6c75424b3 100644 --- a/eval/public/BUILD +++ b/eval/public/BUILD @@ -24,7 +24,7 @@ cc_library( ], deps = [ ":cel_value_internal", - "//base:status_macros", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -86,6 +86,7 @@ cc_library( "activation.h", ], deps = [ + ":base_activation", ":cel_attribute", ":cel_function", ":cel_value", @@ -158,7 +159,7 @@ cc_library( "cel_function_provider.h", ], deps = [ - ":activation", + ":base_activation", ":cel_function", "@com_google_absl//absl/status:statusor", ], @@ -224,7 +225,7 @@ cc_library( "cel_expression.h", ], deps = [ - ":activation", + ":base_activation", ":cel_function", ":cel_function_registry", ":cel_type_registry", @@ -349,7 +350,7 @@ cc_test( ":cel_value", ":unknown_attribute_set", ":unknown_set", - "//base:testing", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", @@ -365,8 +366,8 @@ cc_test( deps = [ ":cel_attribute", ":cel_value", - "//base:testing", "//eval/public/structs:cel_proto_wrapper", + "//internal:testing", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf", ], @@ -382,10 +383,10 @@ cc_test( ":activation", ":cel_attribute", ":cel_function", - "//base:status_macros", - "//base:testing", "//eval/eval:attribute_trail", "//eval/eval:ident_step", + "//internal:status_macros", + "//internal:testing", "//parser", ], ) @@ -397,7 +398,7 @@ cc_test( ], deps = [ ":ast_traverse", - "//base:testing", + "//internal:testing", ], ) @@ -410,9 +411,9 @@ cc_test( deps = [ ":activation", ":activation_bind_helper", - "//base:status_macros", - "//base:testing", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/status", ], @@ -424,10 +425,10 @@ cc_test( "cel_function_provider_test.cc", ], deps = [ - ":cel_function", + ":activation", ":cel_function_provider", - "//base:status_macros", - "//base:testing", + "//internal:status_macros", + "//internal:testing", ], ) @@ -437,11 +438,12 @@ cc_test( "cel_function_registry_test.cc", ], deps = [ + ":activation", ":cel_function", ":cel_function_provider", ":cel_function_registry", - "//base:status_macros", - "//base:testing", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status:statusor", ], ) @@ -453,11 +455,9 @@ cc_test( "cel_function_adapter_test.cc", ], deps = [ - ":cel_function", ":cel_function_adapter", - ":cel_value", - "//base:status_macros", - "//base:testing", + "//internal:status_macros", + "//internal:testing", ], ) @@ -482,8 +482,8 @@ cc_test( srcs = ["cel_type_registry_test.cc"], deps = [ ":cel_type_registry", - "//base:testing", "//eval/testutil:test_message_cc_proto", + "//internal:testing", "@com_google_absl//absl/container:flat_hash_map", "@com_google_protobuf//:protobuf", ], @@ -503,10 +503,10 @@ cc_test( ":cel_function_registry", ":cel_options", ":cel_value", - "//base:status_macros", - "//base:testing", "//eval/public/structs:cel_proto_wrapper", "//internal:proto_util", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", @@ -528,9 +528,9 @@ cc_test( ":cel_function_registry", ":cel_value", ":extension_func_registrar", - "//base:status_macros", - "//base:testing", "//eval/public/structs:cel_proto_wrapper", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", "@com_google_absl//absl/types:span", @@ -547,7 +547,7 @@ cc_test( ], deps = [ ":source_position", - "//base:testing", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", ], ) @@ -562,7 +562,7 @@ cc_test( ":cel_attribute", ":cel_value", ":unknown_attribute_set", - "//base:testing", + "//internal:testing", ], ) @@ -574,12 +574,12 @@ cc_test( ], deps = [ ":value_export_util", - "//base:status_macros", - "//base:testing", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/strings", ], @@ -609,10 +609,10 @@ cc_test( ":cel_function", ":cel_value", ":unknown_function_result_set", - "//base:testing", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", + "//internal:testing", "@com_google_absl//absl/time", "@com_google_absl//absl/types:span", "@com_google_protobuf//:protobuf", @@ -636,7 +636,7 @@ cc_test( ":unknown_attribute_set", ":unknown_function_result_set", ":unknown_set", - "//base:testing", + "//internal:testing", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", "@com_google_protobuf//:protobuf", ], @@ -652,11 +652,11 @@ cc_library( ], deps = [ ":cel_value", - "//base:status_macros", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", "//internal:proto_util", + "//internal:status_macros", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -672,6 +672,19 @@ cc_library( deps = ["//eval/public:cel_value"], ) +cc_library( + name = "base_activation", + hdrs = ["base_activation.h"], + deps = [ + ":cel_attribute", + ":cel_function", + ":cel_value", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/strings", + "@com_google_protobuf//:protobuf", + ], +) + cc_test( name = "set_util_test", size = "small", @@ -682,10 +695,10 @@ cc_test( ":cel_value", ":set_util", ":unknown_set", - "//base:testing", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/time", "@com_google_protobuf//:protobuf", @@ -702,9 +715,9 @@ cc_test( ":cel_expression", ":cel_options", ":cel_value", - "//base:testing", "//eval/public/testing:matchers", "//internal:proto_util", + "//internal:testing", "//parser", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/status", diff --git a/eval/public/activation.h b/eval/public/activation.h index 3268734c4..0ed587628 100644 --- a/eval/public/activation.h +++ b/eval/public/activation.h @@ -10,63 +10,13 @@ #include "absl/base/attributes.h" #include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" +#include "eval/public/base_activation.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_function.h" #include "eval/public/cel_value.h" #include "eval/public/cel_value_producer.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { - -// Base class for an activation. -class BaseActivation { - public: - BaseActivation() = default; - - // Non-copyable/non-assignable - BaseActivation(const BaseActivation&) = delete; - BaseActivation& operator=(const BaseActivation&) = delete; - - // Return a list of function overloads for the given name. - virtual std::vector FindFunctionOverloads( - absl::string_view) const = 0; - - // Provide the value that is bound to the name, if found. - // arena parameter is provided to support the case when we want to pass the - // ownership of returned object ( Message/List/Map ) to Evaluator. - virtual absl::optional FindValue(absl::string_view, - google::protobuf::Arena*) const = 0; - - ABSL_DEPRECATED( - "No longer supported in the activation. See " - "google::api::expr::runtime::AttributeUtility.") - virtual bool IsPathUnknown(absl::string_view) const { return false; } - - ABSL_DEPRECATED("Use missing_attribute_patterns() instead.") - virtual const google::protobuf::FieldMask& unknown_paths() const { - return google::protobuf::FieldMask::default_instance(); - } - - // Return the collection of attribute patterns that determine missing - // attributes. - virtual const std::vector& missing_attribute_patterns() - const { - static const std::vector empty; - return empty; - } - - // Return the collection of attribute patterns that determine "unknown" - // values. - virtual const std::vector& unknown_attribute_patterns() - const { - static const std::vector empty; - return empty; - } - - virtual ~BaseActivation() {} -}; +namespace google::api::expr::runtime { // Instance of Activation class is used by evaluator. // It provides binding between references used in expressions @@ -203,9 +153,6 @@ class Activation : public BaseActivation { std::vector unknown_attribute_patterns_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_ACTIVATION_H_ diff --git a/eval/public/activation_bind_helper.h b/eval/public/activation_bind_helper.h index 92b32b917..fe5828f12 100644 --- a/eval/public/activation_bind_helper.h +++ b/eval/public/activation_bind_helper.h @@ -34,7 +34,7 @@ enum class ProtoUnsetFieldOptions { // person.set_name("John Doe"); // person.age(42); // -// RETURN_IF_ERROR(BindProtoToActivation(&person, &arena, &activation)); +// CEL_RETURN_IF_ERROR(BindProtoToActivation(&person, &arena, &activation)); // // After this snippet, activation will have two parameters bound: // "name", with string value of "John Doe" diff --git a/eval/public/activation_bind_helper_test.cc b/eval/public/activation_bind_helper_test.cc index 4e87326ab..f644f1669 100644 --- a/eval/public/activation_bind_helper_test.cc +++ b/eval/public/activation_bind_helper_test.cc @@ -1,12 +1,11 @@ #include "eval/public/activation_bind_helper.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "eval/public/activation.h" #include "eval/testutil/test_message.pb.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" namespace google { namespace api { diff --git a/eval/public/activation_test.cc b/eval/public/activation_test.cc index 141965d57..ae3147ab6 100644 --- a/eval/public/activation_test.cc +++ b/eval/public/activation_test.cc @@ -1,13 +1,12 @@ #include "eval/public/activation.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/eval/attribute_trail.h" #include "eval/eval/ident_step.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_function.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "parser/parser.h" -#include "base/status_macros.h" namespace google { namespace api { @@ -24,7 +23,7 @@ using testing::HasSubstr; using testing::IsEmpty; using testing::Property; using testing::Return; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; class MockValueProducer : public CelValueProducer { public: diff --git a/eval/public/ast_traverse_test.cc b/eval/public/ast_traverse_test.cc index 7103a1769..5b38f13d7 100644 --- a/eval/public/ast_traverse_test.cc +++ b/eval/public/ast_traverse_test.cc @@ -14,8 +14,7 @@ #include "eval/public/ast_traverse.h" -#include "base/testing.h" -#include "gtest/gtest.h" +#include "internal/testing.h" namespace google::api::expr::runtime { diff --git a/eval/public/base_activation.h b/eval/public/base_activation.h new file mode 100644 index 000000000..a63f8c9b7 --- /dev/null +++ b/eval/public/base_activation.h @@ -0,0 +1,67 @@ +#ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_BASE_ACTIVATION_H_ +#define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_BASE_ACTIVATION_H_ + +#include + +#include "google/protobuf/field_mask.pb.h" +#include "absl/base/attributes.h" +#include "absl/strings/string_view.h" +#include "eval/public/cel_attribute.h" +#include "eval/public/cel_function.h" +#include "eval/public/cel_value.h" + +namespace google::api::expr::runtime { + +// Base class for an activation. +class BaseActivation { + public: + BaseActivation() = default; + + // Non-copyable/non-assignable + BaseActivation(const BaseActivation&) = delete; + BaseActivation& operator=(const BaseActivation&) = delete; + + // Return a list of function overloads for the given name. + virtual std::vector FindFunctionOverloads( + absl::string_view) const = 0; + + // Provide the value that is bound to the name, if found. + // arena parameter is provided to support the case when we want to pass the + // ownership of returned object ( Message/List/Map ) to Evaluator. + virtual absl::optional FindValue(absl::string_view, + google::protobuf::Arena*) const = 0; + + ABSL_DEPRECATED( + "No longer supported in the activation. See " + "google::api::expr::runtime::AttributeUtility.") + virtual bool IsPathUnknown(absl::string_view) const { return false; } + + ABSL_DEPRECATED("Use missing_attribute_patterns() instead.") + virtual const google::protobuf::FieldMask& unknown_paths() const { + return google::protobuf::FieldMask::default_instance(); + } + + // Return the collection of attribute patterns that determine missing + // attributes. + virtual const std::vector& missing_attribute_patterns() + const { + static const std::vector* empty = + new std::vector({}); + return *empty; + } + + // Return the collection of attribute patterns that determine "unknown" + // values. + virtual const std::vector& unknown_attribute_patterns() + const { + static const std::vector* empty = + new std::vector({}); + return *empty; + } + + virtual ~BaseActivation() {} +}; + +} // namespace google::api::expr::runtime + +#endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_BASE_ACTIVATION_H_ diff --git a/eval/public/builtin_func_registrar_test.cc b/eval/public/builtin_func_registrar_test.cc index 7a4e0ccec..b9afc4a19 100644 --- a/eval/public/builtin_func_registrar_test.cc +++ b/eval/public/builtin_func_registrar_test.cc @@ -6,8 +6,6 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/arena.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/container/flat_hash_map.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -20,6 +18,7 @@ #include "eval/public/cel_value.h" #include "eval/public/testing/matchers.h" #include "internal/proto_util.h" +#include "internal/testing.h" #include "parser/parser.h" namespace google::api::expr::runtime { @@ -31,7 +30,7 @@ using google::api::expr::v1alpha1::SourceInfo; using ::google::api::expr::internal::MakeGoogleApiDurationMax; using ::google::api::expr::internal::MakeGoogleApiDurationMin; using testing::HasSubstr; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; struct TestCase { std::string test_name; diff --git a/eval/public/builtin_func_test.cc b/eval/public/builtin_func_test.cc index bc5f239e0..2fcf2f712 100644 --- a/eval/public/builtin_func_test.cc +++ b/eval/public/builtin_func_test.cc @@ -2,8 +2,6 @@ #include #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/time/time.h" @@ -17,7 +15,8 @@ #include "eval/public/cel_value.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "internal/proto_util.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" namespace google::api::expr::runtime { namespace { diff --git a/eval/public/cel_attribute_test.cc b/eval/public/cel_attribute_test.cc index 39355af34..d2d07a565 100644 --- a/eval/public/cel_attribute_test.cc +++ b/eval/public/cel_attribute_test.cc @@ -1,11 +1,10 @@ #include "eval/public/cel_attribute.h" #include "google/protobuf/arena.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/strings/string_view.h" #include "eval/public/cel_value.h" #include "eval/public/structs/cel_proto_wrapper.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/public/cel_expression.h b/eval/public/cel_expression.h index dfdc1b952..de0f7d27f 100644 --- a/eval/public/cel_expression.h +++ b/eval/public/cel_expression.h @@ -1,6 +1,7 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_EXPRESSION_H_ #define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_EXPRESSION_H_ +#include #include #include @@ -8,7 +9,7 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" -#include "eval/public/activation.h" +#include "eval/public/base_activation.h" #include "eval/public/cel_function.h" #include "eval/public/cel_function_registry.h" #include "eval/public/cel_type_registry.h" diff --git a/eval/public/cel_function_adapter.h b/eval/public/cel_function_adapter.h index 09279aa6d..e641e1157 100644 --- a/eval/public/cel_function_adapter.h +++ b/eval/public/cel_function_adapter.h @@ -76,7 +76,7 @@ bool AddType(std::vector* arg_types) { // return i < j; // }; // -// ASSIGN_OR_RETURN(auto cel_func, +// CEL_ASSIGN_OR_RETURN(auto cel_func, // FunctionAdapter::Create("<", false, func)); template class FunctionAdapter : public CelFunction { diff --git a/eval/public/cel_function_adapter_test.cc b/eval/public/cel_function_adapter_test.cc index d96c9199a..4ede6b5fd 100644 --- a/eval/public/cel_function_adapter_test.cc +++ b/eval/public/cel_function_adapter_test.cc @@ -1,8 +1,7 @@ #include "eval/public/cel_function_adapter.h" -#include "base/testing.h" -#include "gtest/gtest.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/public/cel_function_provider.cc b/eval/public/cel_function_provider.cc index 135a5b8f7..02378de22 100644 --- a/eval/public/cel_function_provider.cc +++ b/eval/public/cel_function_provider.cc @@ -1,11 +1,11 @@ #include "eval/public/cel_function_provider.h" +#include + #include "absl/status/statusor.h" +#include "eval/public/base_activation.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { namespace { // Impl for simple provider that looks up functions in an activation function @@ -41,7 +41,4 @@ std::unique_ptr CreateActivationFunctionProvider() { return std::make_unique(); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/public/cel_function_provider.h b/eval/public/cel_function_provider.h index aa85920a9..78d54f46d 100644 --- a/eval/public/cel_function_provider.h +++ b/eval/public/cel_function_provider.h @@ -1,14 +1,13 @@ #ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_PROVIDER_H_ #define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_PROVIDER_H_ +#include + #include "absl/status/statusor.h" -#include "eval/public/activation.h" +#include "eval/public/base_activation.h" #include "eval/public/cel_function.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // CelFunctionProvider is an interface for providers of lazy CelFunctions (i.e. // implementation isn't available until evaluation time based on the @@ -30,9 +29,6 @@ class CelFunctionProvider { // use-case. std::unique_ptr CreateActivationFunctionProvider(); -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_PROVIDER_H_ diff --git a/eval/public/cel_function_provider_test.cc b/eval/public/cel_function_provider_test.cc index f82c8d36a..a0ac8134d 100644 --- a/eval/public/cel_function_provider_test.cc +++ b/eval/public/cel_function_provider_test.cc @@ -1,13 +1,11 @@ #include "eval/public/cel_function_provider.h" -#include "base/testing.h" -#include "gtest/gtest.h" -#include "base/status_macros.h" - -namespace google { -namespace api { -namespace expr { -namespace runtime { +#include "eval/public/activation.h" +#include "internal/status_macros.h" +#include "internal/testing.h" + +namespace google::api::expr::runtime { + namespace { using testing::Eq; @@ -71,7 +69,5 @@ TEST(CreateActivationFunctionProviderTest, AmbiguousLookup) { } } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime diff --git a/eval/public/cel_function_registry.cc b/eval/public/cel_function_registry.cc index 04755b490..b0a680263 100644 --- a/eval/public/cel_function_registry.cc +++ b/eval/public/cel_function_registry.cc @@ -1,9 +1,6 @@ #include "eval/public/cel_function_registry.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { absl::Status CelFunctionRegistry::Register( std::unique_ptr function) { @@ -106,7 +103,4 @@ bool CelFunctionRegistry::DescriptorRegistered( .empty()); } -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime diff --git a/eval/public/cel_function_registry.h b/eval/public/cel_function_registry.h index de1d64bcc..79fbbb4d1 100644 --- a/eval/public/cel_function_registry.h +++ b/eval/public/cel_function_registry.h @@ -8,10 +8,7 @@ #include "eval/public/cel_options.h" #include "eval/public/cel_value.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // CelFunctionRegistry class allows to register builtin or custom // CelFunction handlers with it and look them up when creating @@ -82,9 +79,6 @@ class CelFunctionRegistry { absl::node_hash_map functions_; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_FUNCTION_REGISTRY_H_ diff --git a/eval/public/cel_function_registry_test.cc b/eval/public/cel_function_registry_test.cc index 0891a7e46..66bd8218e 100644 --- a/eval/public/cel_function_registry_test.cc +++ b/eval/public/cel_function_registry_test.cc @@ -2,17 +2,15 @@ #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/statusor.h" +#include "eval/public/activation.h" #include "eval/public/cel_function.h" #include "eval/public/cel_function_provider.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" + +namespace google::api::expr::runtime { -namespace google { -namespace api { -namespace expr { -namespace runtime { namespace { using testing::Eq; @@ -108,7 +106,5 @@ TEST(CelFunctionRegistryTest, DefaultLazyProvider) { } } // namespace -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google + +} // namespace google::api::expr::runtime diff --git a/eval/public/cel_options.h b/eval/public/cel_options.h index 2d262ce92..dc5e3daa8 100644 --- a/eval/public/cel_options.h +++ b/eval/public/cel_options.h @@ -3,10 +3,7 @@ #include "google/protobuf/arena.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { // Options for unknown processing. enum class UnknownProcessingOptions { @@ -89,9 +86,6 @@ struct InterpreterOptions { bool enable_qualified_type_identifiers = false; }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_OPTIONS_H_ diff --git a/eval/public/cel_type_registry_test.cc b/eval/public/cel_type_registry_test.cc index e71e97ef8..97b24a860 100644 --- a/eval/public/cel_type_registry_test.cc +++ b/eval/public/cel_type_registry_test.cc @@ -1,10 +1,9 @@ #include "eval/public/cel_type_registry.h" #include "google/protobuf/any.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/container/flat_hash_map.h" #include "eval/testutil/test_message.pb.h" +#include "internal/testing.h" namespace google::api::expr::runtime { diff --git a/eval/public/cel_value.cc b/eval/public/cel_value.cc index c1a327562..516e7ec16 100644 --- a/eval/public/cel_value.cc +++ b/eval/public/cel_value.cc @@ -1,5 +1,6 @@ #include "eval/public/cel_value.h" +#include #include #include "absl/status/status.h" diff --git a/eval/public/cel_value.h b/eval/public/cel_value.h index 602aa5eb9..5a7e77a29 100644 --- a/eval/public/cel_value.h +++ b/eval/public/cel_value.h @@ -19,6 +19,8 @@ // const MyMessage * msg = google::protobuf::Arena::CreateMessage(arena); // CelValue value = CelProtoWrapper::CreateMessage(msg, &arena); +#include + #include "google/protobuf/message.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -27,7 +29,7 @@ #include "absl/time/time.h" #include "absl/types/optional.h" #include "eval/public/cel_value_internal.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" namespace google::api::expr::runtime { @@ -242,7 +244,9 @@ class CelValue { // Returns stored uint64_t value. // Fails if stored value type is not uint64_t. - uint64_t Uint64OrDie() const { return GetValueOrDie(Type::kUint64); } + uint64_t Uint64OrDie() const { + return GetValueOrDie(Type::kUint64); + } // Returns stored double value. // Fails if stored value type is not double. @@ -455,7 +459,7 @@ class CelMap { // as a `CelError` value, depending on the context. virtual absl::StatusOr Has(const CelValue& key) const { // This check safeguards against issues with invalid key types such as NaN. - RETURN_IF_ERROR(CelValue::CheckMapKeyType(key)); + CEL_RETURN_IF_ERROR(CelValue::CheckMapKeyType(key)); auto value = (*this)[key]; if (!value.has_value()) { return false; diff --git a/eval/public/cel_value_test.cc b/eval/public/cel_value_test.cc index 2be40611c..f1bc5d65b 100644 --- a/eval/public/cel_value_test.cc +++ b/eval/public/cel_value_test.cc @@ -1,13 +1,12 @@ #include "eval/public/cel_value.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/match.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_set.h" +#include "internal/testing.h" namespace google::api::expr::runtime { diff --git a/eval/public/containers/BUILD b/eval/public/containers/BUILD index 7592f3466..b491eec45 100644 --- a/eval/public/containers/BUILD +++ b/eval/public/containers/BUILD @@ -98,9 +98,8 @@ cc_test( ], deps = [ ":container_backed_map_impl", - "//base:testing", "//eval/public:cel_value", - "@com_google_absl//absl/strings", + "//internal:testing", ], ) @@ -112,9 +111,8 @@ cc_test( ], deps = [ ":field_backed_list_impl", - "//base:testing", - "//eval/eval:evaluator_core", "//eval/testutil:test_message_cc_proto", + "//internal:testing", "//testutil:util", ], ) @@ -127,8 +125,8 @@ cc_test( ], deps = [ ":field_backed_map_impl", - "//base:testing", "//eval/testutil:test_message_cc_proto", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", ], @@ -139,8 +137,8 @@ cc_test( srcs = ["field_access_test.cc"], deps = [ ":field_access", - "//base:testing", "//internal:proto_util", + "//internal:testing", "@com_google_absl//absl/status", "@com_google_absl//absl/time", "@com_google_cel_spec//proto/test/v1/proto3:test_all_types_cc_proto", diff --git a/eval/public/containers/container_backed_map_impl_test.cc b/eval/public/containers/container_backed_map_impl_test.cc index 234733ea2..971e804f5 100644 --- a/eval/public/containers/container_backed_map_impl_test.cc +++ b/eval/public/containers/container_backed_map_impl_test.cc @@ -4,9 +4,8 @@ #include #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/cel_value.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/public/containers/field_access_test.cc b/eval/public/containers/field_access_test.cc index 4b76388e1..767cff62b 100644 --- a/eval/public/containers/field_access_test.cc +++ b/eval/public/containers/field_access_test.cc @@ -4,11 +4,10 @@ #include "google/protobuf/arena.h" #include "google/protobuf/message.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/time/time.h" #include "internal/proto_util.h" +#include "internal/testing.h" #include "proto/test/v1/proto3/test_all_types.pb.h" namespace google::api::expr::runtime { @@ -21,7 +20,7 @@ using google::protobuf::Arena; using google::protobuf::FieldDescriptor; using test::v1::proto3::TestAllTypes; using testing::HasSubstr; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; TEST(FieldAccessTest, SetDuration) { Arena arena; diff --git a/eval/public/containers/field_backed_list_impl_test.cc b/eval/public/containers/field_backed_list_impl_test.cc index c3638ea39..c2732577c 100644 --- a/eval/public/containers/field_backed_list_impl_test.cc +++ b/eval/public/containers/field_backed_list_impl_test.cc @@ -1,8 +1,7 @@ #include "eval/public/containers/field_backed_list_impl.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/testutil/test_message.pb.h" +#include "internal/testing.h" #include "testutil/util.h" namespace google { diff --git a/eval/public/containers/field_backed_map_impl_test.cc b/eval/public/containers/field_backed_map_impl_test.cc index 63e8d2d53..a40075a62 100644 --- a/eval/public/containers/field_backed_map_impl_test.cc +++ b/eval/public/containers/field_backed_map_impl_test.cc @@ -2,11 +2,10 @@ #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "eval/testutil/test_message.pb.h" +#include "internal/testing.h" namespace google { namespace api { @@ -17,7 +16,7 @@ namespace { using testing::Eq; using testing::HasSubstr; using testing::UnorderedPointwise; -using cel_base::testing::StatusIs; +using cel::internal::StatusIs; class FieldBackedMapTestImpl : public FieldBackedMapImpl { public: diff --git a/eval/public/extension_func_test.cc b/eval/public/extension_func_test.cc index 1c1f63a43..7f3d05b05 100644 --- a/eval/public/extension_func_test.cc +++ b/eval/public/extension_func_test.cc @@ -4,8 +4,6 @@ #include "google/type/timeofday.pb.h" #include "google/protobuf/message.h" #include "google/protobuf/util/time_util.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "absl/time/civil_time.h" @@ -19,7 +17,8 @@ #include "eval/public/cel_value.h" #include "eval/public/extension_func_registrar.h" #include "eval/public/structs/cel_proto_wrapper.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/public/set_util_test.cc b/eval/public/set_util_test.cc index b553dd4c0..2a39821f7 100644 --- a/eval/public/set_util_test.cc +++ b/eval/public/set_util_test.cc @@ -6,7 +6,7 @@ #include "google/protobuf/struct.pb.h" #include "google/protobuf/arena.h" #include "google/protobuf/message.h" -#include "base/testing.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/time/clock.h" diff --git a/eval/public/source_position_test.cc b/eval/public/source_position_test.cc index 4aa34a026..ad794314d 100644 --- a/eval/public/source_position_test.cc +++ b/eval/public/source_position_test.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "google/api/expr/v1alpha1/syntax.pb.h" #include "eval/public/source_position.h" -#include "base/testing.h" -#include "gtest/gtest.h" +#include "google/api/expr/v1alpha1/syntax.pb.h" +#include "internal/testing.h" + namespace google { namespace api { namespace expr { diff --git a/eval/public/structs/BUILD b/eval/public/structs/BUILD index cbe8521e9..e4f77fbbb 100644 --- a/eval/public/structs/BUILD +++ b/eval/public/structs/BUILD @@ -32,13 +32,13 @@ cc_test( ], deps = [ ":cel_proto_wrapper", - "//base:status_macros", - "//base:testing", "//eval/public:cel_value", "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/testutil:test_message_cc_proto", "//internal:proto_util", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", diff --git a/eval/public/structs/cel_proto_wrapper_test.cc b/eval/public/structs/cel_proto_wrapper_test.cc index 413ba12cb..071b37142 100644 --- a/eval/public/structs/cel_proto_wrapper_test.cc +++ b/eval/public/structs/cel_proto_wrapper_test.cc @@ -10,8 +10,6 @@ #include "google/protobuf/wrappers.pb.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/time/time.h" @@ -20,8 +18,9 @@ #include "eval/public/containers/container_backed_map_impl.h" #include "eval/testutil/test_message.pb.h" #include "internal/proto_util.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" namespace google::api::expr::runtime { diff --git a/eval/public/testing/BUILD b/eval/public/testing/BUILD index baff66b1d..ab40cbc6a 100644 --- a/eval/public/testing/BUILD +++ b/eval/public/testing/BUILD @@ -10,10 +10,10 @@ cc_library( srcs = ["matchers.cc"], hdrs = ["matchers.h"], deps = [ - "//base:testing", "//eval/public:cel_value", "//eval/public:set_util", "//eval/public:unknown_set", + "//internal:testing", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", "@com_google_protobuf//:protobuf", @@ -25,9 +25,9 @@ cc_test( srcs = ["matchers_test.cc"], deps = [ ":matchers", - "//base:testing", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:testing", "//testutil:util", "@com_google_absl//absl/status", "@com_google_absl//absl/time", diff --git a/eval/public/testing/matchers.cc b/eval/public/testing/matchers.cc index 0b33e5d1d..18eb8b480 100644 --- a/eval/public/testing/matchers.cc +++ b/eval/public/testing/matchers.cc @@ -1,6 +1,6 @@ #include "eval/public/testing/matchers.h" -#include "base/testing.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/strings/string_view.h" #include "eval/public/set_util.h" diff --git a/eval/public/testing/matchers.h b/eval/public/testing/matchers.h index be8fa0e4c..1b59fb8bb 100644 --- a/eval/public/testing/matchers.h +++ b/eval/public/testing/matchers.h @@ -4,7 +4,7 @@ #include #include "google/protobuf/message.h" -#include "base/testing.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include "absl/strings/string_view.h" #include "absl/time/time.h" diff --git a/eval/public/testing/matchers_test.cc b/eval/public/testing/matchers_test.cc index 2c2a95d2f..64542ecef 100644 --- a/eval/public/testing/matchers_test.cc +++ b/eval/public/testing/matchers_test.cc @@ -1,11 +1,10 @@ #include "eval/public/testing/matchers.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/status/status.h" #include "absl/time/time.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/testutil/test_message.pb.h" +#include "internal/testing.h" #include "testutil/util.h" namespace google { diff --git a/eval/public/transform_utility.cc b/eval/public/transform_utility.cc index 705b44f47..5de240dfb 100644 --- a/eval/public/transform_utility.cc +++ b/eval/public/transform_utility.cc @@ -12,7 +12,7 @@ #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "internal/proto_util.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" namespace google { @@ -73,7 +73,7 @@ absl::Status CelValueToValue(const CelValue& value, Value* result) { auto& list = *value.ListOrDie(); auto* list_value = result->mutable_list_value(); for (int i = 0; i < list.size(); ++i) { - RETURN_IF_ERROR(CelValueToValue(list[i], list_value->add_values())); + CEL_RETURN_IF_ERROR(CelValueToValue(list[i], list_value->add_values())); } break; } @@ -84,13 +84,13 @@ absl::Status CelValueToValue(const CelValue& value, Value* result) { for (int i = 0; i < keys.size(); ++i) { CelValue key = keys[i]; auto* entry = map_value->add_entries(); - RETURN_IF_ERROR(CelValueToValue(key, entry->mutable_key())); + CEL_RETURN_IF_ERROR(CelValueToValue(key, entry->mutable_key())); auto optional_value = cel_map[key]; if (!optional_value) { return absl::Status(absl::StatusCode::kInternal, "key not found in map"); } - RETURN_IF_ERROR( + CEL_RETURN_IF_ERROR( CelValueToValue(*optional_value, entry->mutable_value())); } break; @@ -133,7 +133,7 @@ absl::StatusOr ValueToCelValue(const Value& value, case Value::kListValue: { std::vector list; for (const auto& subvalue : value.list_value().values()) { - ASSIGN_OR_RETURN(auto list_value, ValueToCelValue(subvalue, arena)); + CEL_ASSIGN_OR_RETURN(auto list_value, ValueToCelValue(subvalue, arena)); list.push_back(list_value); } return CelValue::CreateList( @@ -142,12 +142,13 @@ absl::StatusOr ValueToCelValue(const Value& value, case Value::kMapValue: { std::vector> key_values; for (const auto& entry : value.map_value().entries()) { - ASSIGN_OR_RETURN(auto map_key, ValueToCelValue(entry.key(), arena)); - RETURN_IF_ERROR(CelValue::CheckMapKeyType(map_key)); - ASSIGN_OR_RETURN(auto map_value, ValueToCelValue(entry.value(), arena)); + CEL_ASSIGN_OR_RETURN(auto map_key, ValueToCelValue(entry.key(), arena)); + CEL_RETURN_IF_ERROR(CelValue::CheckMapKeyType(map_key)); + CEL_ASSIGN_OR_RETURN(auto map_value, + ValueToCelValue(entry.value(), arena)); key_values.push_back(std::pair(map_key, map_value)); } - ASSIGN_OR_RETURN( + CEL_ASSIGN_OR_RETURN( auto cel_map, CreateContainerBackedMap(absl::Span>( key_values.data(), key_values.size()))); diff --git a/eval/public/unknown_attribute_set_test.cc b/eval/public/unknown_attribute_set_test.cc index eddbb72db..622872a5d 100644 --- a/eval/public/unknown_attribute_set_test.cc +++ b/eval/public/unknown_attribute_set_test.cc @@ -2,10 +2,9 @@ #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/cel_attribute.h" #include "eval/public/cel_value.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/public/unknown_function_result_set_test.cc b/eval/public/unknown_function_result_set_test.cc index 5ace68a24..2bf7bf5b9 100644 --- a/eval/public/unknown_function_result_set_test.cc +++ b/eval/public/unknown_function_result_set_test.cc @@ -9,8 +9,6 @@ #include "google/protobuf/struct.pb.h" #include "google/protobuf/timestamp.pb.h" #include "google/protobuf/arena.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/time/clock.h" #include "absl/time/time.h" #include "absl/types/span.h" @@ -19,6 +17,7 @@ #include "eval/public/containers/container_backed_list_impl.h" #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" +#include "internal/testing.h" namespace google { namespace api { namespace expr { diff --git a/eval/public/unknown_set_test.cc b/eval/public/unknown_set_test.cc index 51ccb5fc2..6333a5826 100644 --- a/eval/public/unknown_set_test.cc +++ b/eval/public/unknown_set_test.cc @@ -2,11 +2,10 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/arena.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/cel_attribute.h" #include "eval/public/unknown_attribute_set.h" #include "eval/public/unknown_function_result_set.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/public/value_export_util_test.cc b/eval/public/value_export_util_test.cc index 94e795608..a7248a78d 100644 --- a/eval/public/value_export_util_test.cc +++ b/eval/public/value_export_util_test.cc @@ -2,15 +2,14 @@ #include -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/strings/str_cat.h" #include "eval/public/containers/container_backed_list_impl.h" #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/testutil/test_message.pb.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" namespace google::api::expr::runtime { diff --git a/eval/tests/BUILD b/eval/tests/BUILD index 3d85c8cf4..47f44d2c3 100644 --- a/eval/tests/BUILD +++ b/eval/tests/BUILD @@ -17,8 +17,6 @@ cc_test( tags = ["manual"], deps = [ ":request_context_cc_proto", - "//base:status_macros", - "//base:testing", "//eval/public:activation", "//eval/public:builtin_func_registrar", "//eval/public:cel_expr_builder_factory", @@ -27,6 +25,8 @@ cc_test( "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", + "//internal:status_macros", + "//internal:testing", "@com_github_google_benchmark//:benchmark", "@com_github_google_benchmark//:benchmark_main", "@com_google_absl//absl/base:core_headers", @@ -44,8 +44,6 @@ cc_test( "end_to_end_test.cc", ], deps = [ - "//base:status_macros", - "//base:testing", "//eval/public:activation", "//eval/public:builtin_func_registrar", "//eval/public:cel_expr_builder_factory", @@ -53,6 +51,8 @@ cc_test( "//eval/public:cel_value", "//eval/public/structs:cel_proto_wrapper", "//eval/testutil:test_message_cc_proto", + "//internal:status_macros", + "//internal:testing", "//testutil:util", "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto", "@com_google_protobuf//:protobuf", @@ -66,8 +66,6 @@ cc_test( "unknowns_end_to_end_test.cc", ], deps = [ - "//base:status_macros", - "//base:testing", "//eval/eval:evaluator_core", "//eval/public:activation", "//eval/public:builtin_func_registrar", @@ -81,6 +79,8 @@ cc_test( "//eval/public/containers:container_backed_list_impl", "//eval/public/containers:container_backed_map_impl", "//eval/public/structs:cel_proto_wrapper", + "//internal:status_macros", + "//internal:testing", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", @@ -105,9 +105,9 @@ cc_library( testonly = 1, hdrs = ["mock_cel_expression.h"], deps = [ - "//base:testing", - "//eval/public:activation", + "//eval/public:base_activation", "//eval/public:cel_expression", + "//internal:testing", "@com_google_absl//absl/status:statusor", ], ) diff --git a/eval/tests/benchmark_test.cc b/eval/tests/benchmark_test.cc index 87665812f..e4bc9f6d5 100644 --- a/eval/tests/benchmark_test.cc +++ b/eval/tests/benchmark_test.cc @@ -2,8 +2,6 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/base/attributes.h" #include "absl/container/node_hash_set.h" #include "absl/strings/match.h" @@ -16,7 +14,8 @@ #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/tests/request_context.pb.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/eval/tests/end_to_end_test.cc b/eval/tests/end_to_end_test.cc index bd25109a9..2bb58a0f6 100644 --- a/eval/tests/end_to_end_test.cc +++ b/eval/tests/end_to_end_test.cc @@ -1,8 +1,6 @@ #include "google/api/expr/v1alpha1/syntax.pb.h" #include "google/protobuf/struct.pb.h" #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "eval/public/activation.h" #include "eval/public/builtin_func_registrar.h" #include "eval/public/cel_expr_builder_factory.h" @@ -10,8 +8,9 @@ #include "eval/public/cel_value.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/testutil/test_message.pb.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "testutil/util.h" -#include "base/status_macros.h" namespace google { namespace api { diff --git a/eval/tests/mock_cel_expression.h b/eval/tests/mock_cel_expression.h index cbf5f2edd..a27af27e8 100644 --- a/eval/tests/mock_cel_expression.h +++ b/eval/tests/mock_cel_expression.h @@ -3,15 +3,12 @@ #include -#include "base/testing.h" +#include "gmock/gmock.h" #include "absl/status/statusor.h" -#include "eval/public/activation.h" +#include "eval/public/base_activation.h" #include "eval/public/cel_expression.h" -namespace google { -namespace api { -namespace expr { -namespace runtime { +namespace google::api::expr::runtime { class MockCelExpression : public CelExpression { public: @@ -37,9 +34,6 @@ class MockCelExpression : public CelExpression { (const, override)); }; -} // namespace runtime -} // namespace expr -} // namespace api -} // namespace google +} // namespace google::api::expr::runtime #endif // THIRD_PARTY_CEL_CPP_EVAL_TESTS_MOCK_CEL_EXPRESION_H_ diff --git a/eval/tests/unknowns_end_to_end_test.cc b/eval/tests/unknowns_end_to_end_test.cc index f37a497e2..1d9a04fdd 100644 --- a/eval/tests/unknowns_end_to_end_test.cc +++ b/eval/tests/unknowns_end_to_end_test.cc @@ -8,8 +8,6 @@ #include "google/protobuf/struct.pb.h" #include "google/protobuf/arena.h" #include "google/protobuf/text_format.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/container/btree_map.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" @@ -26,7 +24,8 @@ #include "eval/public/containers/container_backed_map_impl.h" #include "eval/public/structs/cel_proto_wrapper.h" #include "eval/public/unknown_set.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" +#include "internal/testing.h" namespace google { namespace api { diff --git a/internal/BUILD b/internal/BUILD index 9bacc3b8e..97dba04ea 100644 --- a/internal/BUILD +++ b/internal/BUILD @@ -7,6 +7,30 @@ package(default_visibility = ["//visibility:public"]) licenses(["notice"]) # Apache 2.0 +cc_library( + name = "casts", + hdrs = ["casts.h"], +) + +cc_library( + name = "status_builder", + hdrs = ["status_builder.h"], + deps = [ + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/status", + ], +) + +cc_library( + name = "status_macros", + hdrs = ["status_macros.h"], + deps = [ + ":status_builder", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/status", + ], +) + cc_library( name = "status_util", srcs = ["status_util.cc"], @@ -25,7 +49,7 @@ cc_library( srcs = ["proto_util.cc"], hdrs = ["proto_util.h"], deps = [ - "//base:status_macros", + ":status_macros", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -34,3 +58,22 @@ cc_library( "@com_google_protobuf//:protobuf", ], ) + +cc_library( + name = "testing", + testonly = True, + srcs = [ + "testing.cc", + ], + hdrs = [ + "testing.h", + ], + deps = [ + ":status_builder", + ":status_macros", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/internal/casts.h b/internal/casts.h new file mode 100644 index 000000000..1add49025 --- /dev/null +++ b/internal/casts.h @@ -0,0 +1,36 @@ +#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_CASTS_H_ +#define THIRD_PARTY_CEL_CPP_INTERNAL_CASTS_H_ + +#include +#include +#include + +namespace cel::internal { + +template +To down_cast(From* from) { + static_assert(std::is_pointer_v, "Target type not a pointer."); + static_assert((std::is_base_of_v>), + "Target type not derived from source type."); +#if !defined(__GNUC__) || defined(__GXX_RTTI) + assert(from == nullptr || dynamic_cast(from) != nullptr); +#endif + return static_cast(from); +} + +template +To down_cast(From& from) { + static_assert(std::is_lvalue_reference_v, + "Target type not a lvalue reference."); + static_assert((std::is_base_of_v>), + "Target type not derived from source type."); +#if !defined(__GNUC__) || defined(__GXX_RTTI) + assert(dynamic_cast>>( + std::addressof(from)) != nullptr); +#endif + return static_cast(from); +} + +} // namespace cel::internal + +#endif // THIRD_PARTY_CEL_CPP_INTERNAL_CASTS_H_ diff --git a/internal/proto_util.cc b/internal/proto_util.cc index 436b94115..ce86e3b74 100644 --- a/internal/proto_util.cc +++ b/internal/proto_util.cc @@ -5,7 +5,7 @@ #include "google/protobuf/util/time_util.h" #include "absl/status/status.h" #include "absl/strings/str_cat.h" -#include "base/status_macros.h" +#include "internal/status_macros.h" namespace google { namespace api { @@ -49,7 +49,7 @@ absl::Time DecodeTime(const google::protobuf::Timestamp& proto) { absl::Status EncodeDuration(absl::Duration duration, google::protobuf::Duration* proto) { - RETURN_IF_ERROR(ValidateDuration(duration)); + CEL_RETURN_IF_ERROR(ValidateDuration(duration)); // s and n may both be negative, per the Duration proto spec. const int64_t s = absl::IDivDuration(duration, absl::Seconds(1), &duration); const int64_t n = absl::IDivDuration(duration, absl::Nanoseconds(1), &duration); @@ -68,7 +68,7 @@ absl::StatusOr EncodeDurationToString(absl::Duration duration) { } absl::Status EncodeTime(absl::Time time, google::protobuf::Timestamp* proto) { - RETURN_IF_ERROR(Validate(time)); + CEL_RETURN_IF_ERROR(Validate(time)); const int64_t s = absl::ToUnixSeconds(time); proto->set_seconds(s); proto->set_nanos((time - absl::FromUnixSeconds(s)) / absl::Nanoseconds(1)); diff --git a/internal/status_builder.h b/internal/status_builder.h new file mode 100644 index 000000000..feaa78eb4 --- /dev/null +++ b/internal/status_builder.h @@ -0,0 +1,82 @@ +#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_BUILDER_H_ +#define THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_BUILDER_H_ + +#include +#include + +#include "absl/base/attributes.h" +#include "absl/status/status.h" + +namespace cel::internal { + +class StatusBuilder; + +template +inline constexpr bool kResultMatches = + std::is_same_v>, + Expected>; + +template +using EnableIfStatusBuilder = + std::enable_if_t, + std::invoke_result_t>; + +template +using EnableIfStatus = + std::enable_if_t, + std::invoke_result_t>; + +class StatusBuilder final { + public: + StatusBuilder() = default; + + explicit StatusBuilder(const absl::Status& status) : status_(status) {} + + StatusBuilder(const StatusBuilder&) = default; + + StatusBuilder(StatusBuilder&&) = default; + + ~StatusBuilder() = default; + + StatusBuilder& operator=(const StatusBuilder&) = default; + + StatusBuilder& operator=(StatusBuilder&&) = default; + + bool ok() const { return status_.ok(); } + + absl::StatusCode code() const { return status_.code(); } + + operator absl::Status() const& { return status_; } // NOLINT + + operator absl::Status() && { return std::move(status_); } // NOLINT + + template + auto With( + Adaptor&& adaptor) & -> EnableIfStatusBuilder { + return std::forward(adaptor)(*this); + } + + template + ABSL_MUST_USE_RESULT auto With( + Adaptor&& adaptor) && -> EnableIfStatusBuilder { + return std::forward(adaptor)(std::move(*this)); + } + + template + auto With(Adaptor&& adaptor) & -> EnableIfStatus { + return std::forward(adaptor)(*this); + } + + template + ABSL_MUST_USE_RESULT auto With( + Adaptor&& adaptor) && -> EnableIfStatus { + return std::forward(adaptor)(std::move(*this)); + } + + private: + absl::Status status_; +}; + +} // namespace cel::internal + +#endif // THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_BUILDER_H_ diff --git a/internal/status_macros.h b/internal/status_macros.h new file mode 100644 index 000000000..6f67e6eaf --- /dev/null +++ b/internal/status_macros.h @@ -0,0 +1,154 @@ +/* + * Copyright 2020 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_INTERNAL_STATUS_MACROS_H_ +#define THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_MACROS_H_ + +#include + +#include "absl/base/optimization.h" +#include "absl/status/status.h" +#include "internal/status_builder.h" + +#define CEL_RETURN_IF_ERROR(expr) \ + CEL_INTERNAL_STATUS_MACROS_IMPL_ELSE_BLOCKER_ \ + if (::cel::internal::StatusAdaptor cel_internal_status_macro = {(expr)}) { \ + } else /* NOLINT */ \ + return cel_internal_status_macro.Consume() + +// The GNU compiler historically emitted warnings for obscure usages of +// `if (foo) if (bar) {} else`. This suppresses that. + +// clang-format off +#define CEL_INTERNAL_STATUS_MACROS_IMPL_ELSE_BLOCKER_ \ + switch (0) case 0: default: /* NOLINT */ +// clang-format on + +#define CEL_ASSIGN_OR_RETURN(...) \ + CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_( \ + (__VA_ARGS__, CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_3_, \ + CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_2_)) \ + (__VA_ARGS__) + +// The following are macro magic to select either the 2 arg variant or 3 arg +// variant of CEL_ASSIGN_OR_RETURN. + +#define CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_HELPER_(_1, _2, _3, NAME, ...) \ + NAME +#define CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_(args) \ + CEL_INTERNAL_STATUS_MACROS_GET_VARIADIC_HELPER_ args + +#define CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_2_(lhs, rexpr) \ + CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_( \ + CEL_INTERNAL_STATUS_MACROS_CONCAT(_status_or_value, __LINE__), lhs, \ + rexpr, \ + return absl::Status(std::move(CEL_INTERNAL_STATUS_MACROS_CONCAT( \ + _status_or_value, __LINE__)) \ + .status())) + +#define CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_3_(lhs, rexpr, \ + error_expression) \ + CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_( \ + CEL_INTERNAL_STATUS_MACROS_CONCAT(_status_or_value, __LINE__), lhs, \ + rexpr, \ + ::cel::internal::StatusBuilder _( \ + std::move( \ + CEL_INTERNAL_STATUS_MACROS_CONCAT(_status_or_value, __LINE__)) \ + .status()); \ + (void)_; /* error_expression is allowed to not use this variable */ \ + return (error_expression)) + +// Common implementation of CEL_ASSIGN_OR_RETURN. Both the 2 arg variant and 3 +// arg variant are implemented by this macro. + +#define CEL_INTERNAL_STATUS_MACROS_ASSIGN_OR_RETURN_(statusor, lhs, rexpr, \ + error_expression) \ + auto statusor = (rexpr); \ + if (ABSL_PREDICT_FALSE(!statusor.ok())) { \ + error_expression; \ + } \ + CEL_INTERNAL_STATUS_MACROS_UNPARENTHESIZE_IF_PARENTHESIZED(lhs) = \ + std::move(statusor).value() + +#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER(...) \ + CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_HELPER((__VA_ARGS__, 0, 1)) + +// MSVC historically expands variadic macros incorrectly, so another level of +// indirection is required. +#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_HELPER(args) \ + CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_I args +#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER_I(e0, e1, is_empty, ...) \ + is_empty + +#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY(...) \ + CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_I(__VA_ARGS__) +#define CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_I(...) \ + CEL_INTERNAL_STATUS_MACROS_IS_EMPTY_INNER(_, ##__VA_ARGS__) + +#define CEL_INTERNAL_STATUS_MACROS_IF_1(_Then, _Else) _Then +#define CEL_INTERNAL_STATUS_MACROS_IF_0(_Then, _Else) _Else +#define CEL_INTERNAL_STATUS_MACROS_IF(_Cond, _Then, _Else) \ + CEL_INTERNAL_STATUS_MACROS_CONCAT(CEL_INTERNAL_STATUS_MACROS_IF_, _Cond) \ + (_Then, _Else) + +#define CEL_INTERNAL_STATUS_MACROS_EAT(...) +#define CEL_INTERNAL_STATUS_MACROS_REM(...) __VA_ARGS__ +#define CEL_INTERNAL_STATUS_MACROS_EMPTY() + +// Expands to 1 if the input is surrounded by parenthesis, 0 otherwise. +#define CEL_INTERNAL_STATUS_MACROS_IS_PARENTHESIZED(...) \ + CEL_INTERNAL_STATUS_MACROS_IS_EMPTY( \ + CEL_INTERNAL_STATUS_MACROS_EAT __VA_ARGS__) + +// If the input is surrounded by parenthesis, remove them. Otherwise expand it +// unchanged. +#define CEL_INTERNAL_STATUS_MACROS_UNPARENTHESIZE_IF_PARENTHESIZED(...) \ + CEL_INTERNAL_STATUS_MACROS_IF( \ + CEL_INTERNAL_STATUS_MACROS_IS_PARENTHESIZED(__VA_ARGS__), \ + CEL_INTERNAL_STATUS_MACROS_REM, CEL_INTERNAL_STATUS_MACROS_EMPTY()) \ + __VA_ARGS__ + +#define CEL_INTERNAL_STATUS_MACROS_CONCAT_HELPER(x, y) x##y +#define CEL_INTERNAL_STATUS_MACROS_CONCAT(x, y) \ + CEL_INTERNAL_STATUS_MACROS_CONCAT_HELPER(x, y) + +namespace cel::internal { + +class StatusAdaptor final { + public: + StatusAdaptor() = default; + + StatusAdaptor(const StatusAdaptor&) = delete; + + StatusAdaptor(StatusAdaptor&&) = delete; + + StatusAdaptor(const absl::Status& status) : builder_(status) {} // NOLINT + + StatusAdaptor& operator=(const StatusAdaptor&) = delete; + + StatusAdaptor& operator=(StatusAdaptor&&) = delete; + + StatusBuilder&& Consume() { return std::move(builder_); } + + explicit operator bool() const { return ABSL_PREDICT_TRUE(builder_.ok()); } + + private: + StatusBuilder builder_; +}; + +} // namespace cel::internal + +#endif // THIRD_PARTY_CEL_CPP_INTERNAL_STATUS_MACROS_H_ diff --git a/base/testing.cc b/internal/testing.cc similarity index 67% rename from base/testing.cc rename to internal/testing.cc index a03471e8b..378bcb1d3 100644 --- a/base/testing.cc +++ b/internal/testing.cc @@ -1,7 +1,6 @@ -#include "base/testing.h" +#include "internal/testing.h" -namespace cel_base { -namespace testing { +namespace cel::internal { void StatusIsMatcherCommonImpl::DescribeTo(std::ostream* os) const { *os << ", has a status code that "; @@ -39,5 +38,14 @@ bool StatusIsMatcherCommonImpl::MatchAndExplain( return true; } -} // namespace testing -} // namespace cel_base +void AddFatalFailure(const char* file, int line, absl::string_view expression, + const StatusBuilder& builder) { + GTEST_MESSAGE_AT_(file, line, + absl::StrCat(expression, " returned error: ", + absl::Status(builder).ToString( + absl::StatusToStringMode::kWithEverything)) + .c_str(), + ::testing::TestPartResult::kFatalFailure); +} + +} // namespace cel::internal diff --git a/base/testing.h b/internal/testing.h similarity index 85% rename from base/testing.h rename to internal/testing.h index 15240b79f..024cc67de 100644 --- a/base/testing.h +++ b/internal/testing.h @@ -14,20 +14,36 @@ * limitations under the License. */ -#ifndef THIRD_PARTY_CEL_CPP_BASE_TESTING_H_ -#define THIRD_PARTY_CEL_CPP_BASE_TESTING_H_ +#ifndef THIRD_PARTY_CEL_CPP_INTERNAL_TESTING_H_ +#define THIRD_PARTY_CEL_CPP_INTERNAL_TESTING_H_ #include #include #include #include "gmock/gmock.h" // IWYU pragma: export -#include "gtest/gtest.h" +#include "gtest/gtest.h" // IWYU pragma: export #include "absl/status/status.h" #include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "internal/status_builder.h" +#include "internal/status_macros.h" -namespace cel_base { -namespace testing { +#ifndef ASSERT_OK +#define ASSERT_OK(expr) ASSERT_THAT(expr, ::cel::internal::IsOk()) +#endif + +#ifndef EXPECT_OK +#define EXPECT_OK(expr) EXPECT_THAT(expr, ::cel::internal::IsOk()) +#endif + +#ifndef ASSERT_OK_AND_ASSIGN +#define ASSERT_OK_AND_ASSIGN(lhs, rhs) \ + CEL_ASSIGN_OR_RETURN( \ + lhs, rhs, ::cel::internal::AddFatalFailure(__FILE__, __LINE__, #rhs, _)) +#endif + +namespace cel::internal { inline const absl::Status& GetStatus(const absl::Status& status) { return status; @@ -147,10 +163,12 @@ StatusIsMatcher StatusIs(StatusCodeMatcher&& code_matcher) { return StatusIs(std::forward(code_matcher), ::testing::_); } +void AddFatalFailure(const char* file, int line, absl::string_view expression, + const StatusBuilder& builder); + // Returns a gMock matcher that matches a Status or StatusOr<> which is OK. inline IsOkMatcher IsOk() { return IsOkMatcher(); } -} // namespace testing -} // namespace cel_base +} // namespace cel::internal -#endif // THIRD_PARTY_CEL_CPP_BASE_TESTING_H_ +#endif // THIRD_PARTY_CEL_CPP_INTERNAL_TESTING_H_ diff --git a/parser/BUILD b/parser/BUILD index 717c81f69..1d1f88b79 100644 --- a/parser/BUILD +++ b/parser/BUILD @@ -120,7 +120,7 @@ cc_test( ":options", ":parser", ":source_factory", - "//base:testing", + "//internal:testing", "//testutil:expr_printer", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/strings", diff --git a/parser/parser_test.cc b/parser/parser_test.cc index 61b4be46d..6bf4204a4 100644 --- a/parser/parser_test.cc +++ b/parser/parser_test.cc @@ -7,12 +7,11 @@ #include #include "google/api/expr/v1alpha1/syntax.pb.h" -#include "base/testing.h" -#include "gtest/gtest.h" #include "absl/algorithm/container.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" #include "absl/types/optional.h" +#include "internal/testing.h" #include "parser/options.h" #include "parser/source_factory.h" #include "testutil/expr_printer.h" @@ -26,7 +25,7 @@ namespace { using ::google::api::expr::v1alpha1::Expr; using testing::HasSubstr; using testing::Not; -using cel_base::testing::IsOk; +using cel::internal::IsOk; struct TestInfo { TestInfo(const std::string& I, const std::string& P, diff --git a/testutil/BUILD b/testutil/BUILD index cdfb4ab61..c13f0f150 100644 --- a/testutil/BUILD +++ b/testutil/BUILD @@ -26,7 +26,7 @@ cc_library( "util.h", ], deps = [ - "//base:testing", + "//internal:testing", "@com_google_protobuf//:protobuf", ], ) diff --git a/testutil/util.h b/testutil/util.h index 443869561..7eb62ea85 100644 --- a/testutil/util.h +++ b/testutil/util.h @@ -5,7 +5,7 @@ #include "google/protobuf/message.h" #include "google/protobuf/text_format.h" -#include "base/testing.h" +#include "gmock/gmock.h" namespace google { namespace api { diff --git a/tools/BUILD b/tools/BUILD index b4fd917d4..d418ea720 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -53,9 +53,8 @@ cc_test( ], deps = [ ":flatbuffers_backed_impl", - ":flatbuffers_test_cc", - "//base:status_macros", - "//base:testing", + "//internal:status_macros", + "//internal:testing", "@com_github_google_flatbuffers//:flatbuffers", ], ) diff --git a/tools/flatbuffers_backed_impl_test.cc b/tools/flatbuffers_backed_impl_test.cc index 2e78e33ad..e12865f4e 100644 --- a/tools/flatbuffers_backed_impl_test.cc +++ b/tools/flatbuffers_backed_impl_test.cc @@ -1,10 +1,9 @@ #include "tools/flatbuffers_backed_impl.h" -#include "base/testing.h" -#include "gtest/gtest.h" +#include "internal/status_macros.h" +#include "internal/testing.h" #include "flatbuffers/idl.h" #include "flatbuffers/reflection.h" -#include "base/status_macros.h" namespace google { namespace api {