Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-3.5.0",
urls = ["https://github.com/google/protobuf/archive/v3.5.0.zip"],
strip_prefix = "protobuf-3.5.1",
urls = ["https://github.com/google/protobuf/archive/v3.5.1.zip"],
)

http_archive(
Expand Down
38 changes: 38 additions & 0 deletions eval/public/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ licenses(["notice"]) # Apache 2.0

exports_files(["LICENSE"])

cc_library(
name = "cel_value_internal",
hdrs = [
"cel_value_internal.h",
],
visibility = ["//visibility:private"],
deps = [
"@com_google_absl//absl/types:variant",
],
)

cc_library(
name = "cel_builtins",
hdrs = [
"cel_builtins.h",
],
deps = [
],
)

cc_library(
name = "source_position",
srcs = ["source_position.cc"],
Expand Down Expand Up @@ -63,6 +83,24 @@ cc_test(
],
)

cc_test(
name = "activation_bind_helper_test",
size = "small",
srcs = [
"activation_bind_helper_test.cc",
],
tags = ["manual"],
deps = [
":activation",
#":activation_bind_helper",
#"//third_party/cel/cpp/eval/testutil:test_message_protos",
#"//util/gtl:ptr_util",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:arena",
"@com_google_protobuf//:proto2",
],
)

cc_test(
name = "source_position_test",
size = "small",
Expand Down
90 changes: 90 additions & 0 deletions eval/public/cel_value_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_INTERNAL_H_
#define THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_INTERNAL_H_

#include "third_party/absl/types/variant.h"

namespace google {
namespace api {
namespace expr {
namespace runtime {

namespace internal {

// Helper classes needed for IndexOf metafunction implementation.
template <int N, bool>
struct IndexDef {};

// This partial IndexDef type specialization provides additional constant
// "value", associated with the type.
template <int N>
struct IndexDef<N, true> {
static constexpr int value = N;
};

// TypeIndexer is a template class, representing metafunction to find the index
// of a type in a type list.
template <int N, int TYPE_SIZE, class Type, class TypeToTest, class... Types>
struct TypeIndexer
: public TypeIndexer<N + 1, sizeof...(Types), Type, Types...>,
IndexDef<N, std::is_same<Type, TypeToTest>::value> {};

template <int N, class Type, class TypeToTest>
struct TypeIndexer<N, 1, Type, TypeToTest>
: public IndexDef<N, std::is_same<Type, TypeToTest>::value> {};

// ValueHolder class wraps absl::variant, adding IndexOf metafunction to it.
template <class... Args>
class ValueHolder {
public:
template <class T>
explicit ValueHolder(T t) : value_(t) {}

// Metafunction to find the index of a type in a type list.
template <class T>
using IndexOf = TypeIndexer<0, sizeof...(Args), T, Args...>;

template <class T>
const T *get() const {
return absl::get_if<T>(&value_);
}

template <class T>
bool is() const {
return absl::holds_alternative<T>(value_);
}

int index() const { return value_.index(); }

template <class ReturnType, class Op>
ReturnType Visit(Op &&op) const {
return absl::visit(std::forward<Op>(op), value_);
}

private:
absl::variant<Args...> value_;
};

} // namespace internal

} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google

#endif // THIRD_PARTY_CEL_CPP_EVAL_PUBLIC_CEL_VALUE_INTERNAL_H_