Skip to content

Commit bb03a5f

Browse files
authored
Merge pull request #106 from google/cpp-sync
internal changes (some fixes might be in older sync) Fixes #88 Fixes #83 Fixes #82 Fixes #66 Fixes #57 Fixes #21 Fixes #15
2 parents 9841e3e + f029e3e commit bb03a5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1779
-660
lines changed

base/BUILD

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ cc_library(
1010
"status_macros.h",
1111
],
1212
)
13+
14+
cc_library(
15+
name = "unilib",
16+
srcs = [
17+
"unilib.cc",
18+
],
19+
hdrs = [
20+
"unilib.h",
21+
],
22+
deps = [
23+
"@com_github_google_flatbuffers//:flatbuffers",
24+
"@com_google_absl//absl/strings",
25+
],
26+
)

base/unilib.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "base/unilib.h"
2+
3+
#include "flatbuffers/util.h"
4+
5+
namespace UniLib {
6+
7+
// Detects whether a string is valid UTF-8.
8+
bool IsStructurallyValid(absl::string_view str) {
9+
const char *s = &str[0];
10+
const char *const sEnd = s + str.length();
11+
while (s < sEnd) {
12+
if (flatbuffers::FromUTF8(&s) < 0) {
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
18+
19+
} // namespace UniLib

base/unilib.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef THIRD_PARTY_CEL_CPP_BASE_UNILIB_H_
18+
#define THIRD_PARTY_CEL_CPP_BASE_UNILIB_H_
19+
20+
#include "absl/strings/string_view.h"
21+
22+
namespace UniLib {
23+
24+
// Detects whether a string is valid UTF-8.
25+
bool IsStructurallyValid(absl::string_view str);
26+
27+
} // namespace UniLib
28+
29+
#endif // THIRD_PARTY_CEL_CPP_BASE_UNILIB_H_

common/type.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ UnrecognizedType::UnrecognizedType(absl::string_view full_name)
7272
: string_rep_(absl::StrCat("type(\"", full_name, "\")")),
7373
hash_code_(internal::Hash(full_name)) {
7474
assert(google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName(
75-
std::string(full_name)) == nullptr);
75+
full_name.data()) == nullptr);
7676
}
7777

7878
absl::string_view UnrecognizedType::full_name() const {
@@ -89,7 +89,7 @@ Type::Type(const std::string& full_name)
8989

9090
auto obj_desc =
9191
google::protobuf::DescriptorPool::generated_pool()->FindMessageTypeByName(
92-
full_name);
92+
full_name.data());
9393
if (obj_desc != nullptr) {
9494
data_ = ObjectType(obj_desc);
9595
return;

common/value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class Container : public SharedValue {
330330
}
331331
template <Value::Kind ValueKind, typename V>
332332
static Value GetValue(V&& value) {
333-
return Value::From<ValueKind>(std::move(value));
333+
return Value::From<ValueKind>(std::forward<V>(value));
334334
}
335335

336336
private:

conformance/BUILD

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ ALL_TESTS = [
1919
"@com_google_cel_spec//tests/simple:testdata/macros.textproto",
2020
"@com_google_cel_spec//tests/simple:testdata/namespace.textproto",
2121
"@com_google_cel_spec//tests/simple:testdata/plumbing.textproto",
22-
# TODO(issues/92): Support for parse-only proto message creation within a container.
23-
# "@com_google_cel_spec//tests/simple:testdata/proto2.textproto",
24-
# "@com_google_cel_spec//tests/simple:testdata/proto3.textproto",
22+
"@com_google_cel_spec//tests/simple:testdata/proto2.textproto",
23+
"@com_google_cel_spec//tests/simple:testdata/proto3.textproto",
2524
"@com_google_cel_spec//tests/simple:testdata/string.textproto",
2625
"@com_google_cel_spec//tests/simple:testdata/timestamps.textproto",
2726
"@com_google_cel_spec//tests/simple:testdata/unknowns.textproto",
@@ -91,18 +90,11 @@ cc_binary(
9190
# uncommented when the spec changes to truncation rather than rounding.
9291
"--skip_test=conversions/int/double_nearest,double_nearest_neg,double_half_away_neg,double_half_away_pos",
9392
"--skip_test=conversions/uint/double_nearest,double_nearest_int,double_half_away",
94-
# TODO(issues/82): Unexpected behavior when converting invalid bytes to string.
95-
"--skip_test=conversions/string/bytes_invalid",
96-
# TODO(issues/83): Missing type() conversion functions
97-
"--skip_test=conversions/type",
9893
# TODO(issues/96): Well-known type conversion support.
9994
"--skip_test=proto2/literal_wellknown",
10095
"--skip_test=proto3/literal_wellknown",
10196
"--skip_test=proto2/empty_field/wkt",
10297
"--skip_test=proto3/empty_field/wkt",
103-
# TODO(issues/92): Support for parse-only proto message creation within a container.
104-
"--skip_test=proto2/has/undefined",
105-
"--skip_test=proto3/has/undefined",
10698
# Requires container support
10799
"--skip_test=namespace/namespace/self_eval_container_lookup_unchecked",
108100
"--skip_test=basic/self_eval_nonzeroish/self_eval_bytes_invalid_utf8",

conformance/server.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "proto/test/v1/proto3/test_all_types.pb.h"
2626

2727

28-
using absl::Status;
29-
using absl::StatusCode;
3028
using ::google::protobuf::Arena;
3129
using ::google::protobuf::util::JsonStringToMessage;
3230
using ::google::protobuf::util::MessageToJsonString;
@@ -42,10 +40,10 @@ class ConformanceServiceImpl {
4240
public:
4341
explicit ConformanceServiceImpl(std::unique_ptr<CelExpressionBuilder> builder)
4442
: builder_(std::move(builder)),
45-
proto2Tests_(&google::api::expr::test::v1::proto2::TestAllTypes::
46-
default_instance()),
47-
proto3Tests_(&google::api::expr::test::v1::proto3::TestAllTypes::
48-
default_instance()) {}
43+
proto2_tests_(&google::api::expr::test::v1::proto2::TestAllTypes::
44+
default_instance()),
45+
proto3_tests_(&google::api::expr::test::v1::proto3::TestAllTypes::
46+
default_instance()) {}
4947

5048
void Parse(const v1alpha1::ParseRequest* request,
5149
v1alpha1::ParseResponse* response) {
@@ -63,7 +61,7 @@ class ConformanceServiceImpl {
6361
} else {
6462
google::api::expr::v1alpha1::ParsedExpr out;
6563
(out).MergeFrom(parse_status.value());
66-
response->mutable_parsed_expr()->CopyFrom(out);
64+
*response->mutable_parsed_expr() = out;
6765
}
6866
}
6967

@@ -87,6 +85,7 @@ class ConformanceServiceImpl {
8785
google::api::expr::v1alpha1::SourceInfo source_info;
8886
google::api::expr::v1alpha1::Expr out;
8987
(out).MergeFrom(*expr);
88+
builder_->set_container(request->container());
9089
auto cel_expression_status = builder_->CreateExpression(&out, &source_info);
9190

9291
if (!cel_expression_status.ok()) {
@@ -144,13 +143,14 @@ class ConformanceServiceImpl {
144143

145144
private:
146145
std::unique_ptr<CelExpressionBuilder> builder_;
147-
const google::api::expr::test::v1::proto2::TestAllTypes* proto2Tests_;
148-
const google::api::expr::test::v1::proto3::TestAllTypes* proto3Tests_;
146+
const google::api::expr::test::v1::proto2::TestAllTypes* proto2_tests_;
147+
const google::api::expr::test::v1::proto3::TestAllTypes* proto3_tests_;
149148
};
150149

151150
int RunServer(bool optimize) {
152151
google::protobuf::Arena arena;
153152
InterpreterOptions options;
153+
options.enable_qualified_type_identifiers = true;
154154

155155
if (optimize) {
156156
std::cerr << "Enabling optimizations" << std::endl;
@@ -160,14 +160,15 @@ int RunServer(bool optimize) {
160160

161161
std::unique_ptr<CelExpressionBuilder> builder =
162162
CreateCelExpressionBuilder(options);
163-
builder->AddResolvableEnum(
163+
auto type_registry = builder->GetTypeRegistry();
164+
type_registry->Register(
164165
google::api::expr::test::v1::proto2::GlobalEnum_descriptor());
165-
builder->AddResolvableEnum(
166+
type_registry->Register(
166167
google::api::expr::test::v1::proto3::GlobalEnum_descriptor());
167-
builder->AddResolvableEnum(google::api::expr::test::v1::proto2::TestAllTypes::
168-
NestedEnum_descriptor());
169-
builder->AddResolvableEnum(google::api::expr::test::v1::proto3::TestAllTypes::
170-
NestedEnum_descriptor());
168+
type_registry->Register(google::api::expr::test::v1::proto2::TestAllTypes::
169+
NestedEnum_descriptor());
170+
type_registry->Register(google::api::expr::test::v1::proto3::TestAllTypes::
171+
NestedEnum_descriptor());
171172
auto register_status = RegisterBuiltinFunctions(builder->GetRegistry());
172173
if (!register_status.ok()) {
173174
std::cerr << "Failed to initialize: " << register_status.ToString()

eval/compiler/BUILD

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cc_library(
1717
deps = [
1818
":constant_folding",
1919
":qualified_reference_resolver",
20+
":resolver",
2021
"//base:status_macros",
2122
"//eval/eval:comprehension_step",
2223
"//eval/eval:const_value_step",
@@ -30,6 +31,7 @@ cc_library(
3031
"//eval/eval:jump_step",
3132
"//eval/eval:logic_step",
3233
"//eval/eval:select_step",
34+
"//eval/eval:shadowable_value_step",
3335
"//eval/eval:ternary_step",
3436
"//eval/public:ast_traverse",
3537
"//eval/public:ast_visitor",
@@ -147,6 +149,7 @@ cc_library(
147149
"qualified_reference_resolver.h",
148150
],
149151
deps = [
152+
":resolver",
150153
"//base:status_macros",
151154
"//eval/eval:const_value_step",
152155
"//eval/eval:expression_build_warning",
@@ -162,6 +165,21 @@ cc_library(
162165
],
163166
)
164167

168+
cc_library(
169+
name = "resolver",
170+
srcs = ["resolver.cc"],
171+
hdrs = ["resolver.h"],
172+
deps = [
173+
"//eval/public:cel_builtins",
174+
"//eval/public:cel_function_registry",
175+
"//eval/public:cel_type_registry",
176+
"//eval/public:cel_value",
177+
"@com_google_absl//absl/strings",
178+
"@com_google_absl//absl/types:optional",
179+
"@com_google_protobuf//:protobuf",
180+
],
181+
)
182+
165183
cc_test(
166184
name = "qualified_reference_resolver_test",
167185
srcs = [
@@ -174,6 +192,7 @@ cc_test(
174192
"//eval/public:cel_builtins",
175193
"//eval/public:cel_function",
176194
"//eval/public:cel_function_registry",
195+
"//eval/public:cel_type_registry",
177196
"//testutil:util",
178197
"@com_google_absl//absl/status",
179198
"@com_google_absl//absl/types:optional",
@@ -203,3 +222,19 @@ cc_test(
203222
"@com_google_protobuf//:protobuf",
204223
],
205224
)
225+
226+
cc_test(
227+
name = "resolver_test",
228+
size = "small",
229+
srcs = ["resolver_test.cc"],
230+
deps = [
231+
":resolver",
232+
"//base:status_macros",
233+
"//eval/public:cel_function",
234+
"//eval/public:cel_function_registry",
235+
"//eval/public:cel_type_registry",
236+
"//eval/testutil:test_message_cc_proto",
237+
"@com_google_absl//absl/status",
238+
"@com_google_googletest//:gtest_main",
239+
],
240+
)

0 commit comments

Comments
 (0)