Skip to content

Commit ac2f3b2

Browse files
committed
OSS export.
PiperOrigin-RevId: 453225470
1 parent 23cd804 commit ac2f3b2

36 files changed

Lines changed: 323 additions & 269 deletions

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build --cxxopt=-std=c++17
2+
build --cxxopt=-fsized-deallocation
23

34
# Enable matchers in googletest
45
build --define absl=1

base/type.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ class Type : public base_internal::Resource {
9292

9393
virtual std::string DebugString() const;
9494

95+
// Called by base_internal::TypeHandleBase.
96+
// Note GCC does not consider a friend member as a member of a friend.
97+
virtual bool Equals(const Type& other) const;
98+
99+
// Called by base_internal::TypeHandleBase.
100+
// Note GCC does not consider a friend member as a member of a friend.
101+
virtual void HashValue(absl::HashState state) const;
102+
95103
private:
96104
friend class NullType;
97105
friend class ErrorType;
@@ -126,12 +134,6 @@ class Type : public base_internal::Resource {
126134

127135
using base_internal::Resource::Ref;
128136
using base_internal::Resource::Unref;
129-
130-
// Called by base_internal::TypeHandleBase.
131-
virtual bool Equals(const Type& other) const;
132-
133-
// Called by base_internal::TypeHandleBase.
134-
virtual void HashValue(absl::HashState state) const;
135137
};
136138

137139
class NullType final : public Type {
@@ -140,6 +142,9 @@ class NullType final : public Type {
140142

141143
absl::string_view name() const override { return "null_type"; }
142144

145+
// Note GCC does not consider a friend member as a member of a friend.
146+
ABSL_ATTRIBUTE_PURE_FUNCTION static const NullType& Get();
147+
143148
private:
144149
friend class NullValue;
145150
friend class TypeFactory;
@@ -151,8 +156,6 @@ class NullType final : public Type {
151156
// Persistent.
152157
static bool Is(const Type& type) { return type.kind() == Kind::kNullType; }
153158

154-
ABSL_ATTRIBUTE_PURE_FUNCTION static const NullType& Get();
155-
156159
NullType() = default;
157160

158161
NullType(const NullType&) = delete;

base/value.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,6 @@ struct BytesValueDebugStringVisitor final {
407407
}
408408

409409
std::string operator()(const absl::Cord& value) const {
410-
absl::string_view flat;
411-
if (value.GetFlat(&flat)) {
412-
return internal::FormatBytesLiteral(flat);
413-
}
414410
return internal::FormatBytesLiteral(static_cast<std::string>(value));
415411
}
416412
};
@@ -421,10 +417,6 @@ struct StringValueDebugStringVisitor final {
421417
}
422418

423419
std::string operator()(const absl::Cord& value) const {
424-
absl::string_view flat;
425-
if (value.GetFlat(&flat)) {
426-
return internal::FormatStringLiteral(flat);
427-
}
428420
return internal::FormatStringLiteral(static_cast<std::string>(value));
429421
}
430422
};

base/value.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ class Value : public base_internal::Resource {
8484

8585
virtual std::string DebugString() const = 0;
8686

87+
// Called by base_internal::ValueHandleBase.
88+
// Note GCC does not consider a friend member as a member of a friend.
89+
virtual bool Equals(const Value& other) const = 0;
90+
91+
// Called by base_internal::ValueHandleBase.
92+
// Note GCC does not consider a friend member as a member of a friend.
93+
virtual void HashValue(absl::HashState state) const = 0;
94+
8795
private:
8896
friend class NullValue;
8997
friend class ErrorValue;
@@ -127,12 +135,6 @@ class Value : public base_internal::Resource {
127135

128136
// Called by base_internal::ValueHandleBase for inlined values.
129137
virtual void MoveTo(Value& address);
130-
131-
// Called by base_internal::ValueHandleBase.
132-
virtual bool Equals(const Value& other) const = 0;
133-
134-
// Called by base_internal::ValueHandleBase.
135-
virtual void HashValue(absl::HashState state) const = 0;
136138
};
137139

138140
class NullValue final : public Value, public base_internal::ResourceInlined {
@@ -145,6 +147,9 @@ class NullValue final : public Value, public base_internal::ResourceInlined {
145147

146148
std::string DebugString() const override;
147149

150+
// Note GCC does not consider a friend member as a member of a friend.
151+
ABSL_ATTRIBUTE_PURE_FUNCTION static const NullValue& Get();
152+
148153
private:
149154
friend class ValueFactory;
150155
template <typename T>
@@ -157,8 +162,6 @@ class NullValue final : public Value, public base_internal::ResourceInlined {
157162
// Persistent.
158163
static bool Is(const Value& value) { return value.kind() == Kind::kNullType; }
159164

160-
ABSL_ATTRIBUTE_PURE_FUNCTION static const NullValue& Get();
161-
162165
NullValue() = default;
163166
NullValue(const NullValue&) = default;
164167
NullValue(NullValue&&) = default;

bazel/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
load("@rules_java//java:defs.bzl", "java_binary")
2+
13
package(default_visibility = ["//visibility:public"])
4+
5+
java_binary(
6+
name = "antlr4_tool",
7+
main_class = "org.antlr.v4.Tool",
8+
runtime_deps = ["@antlr4_jar//jar"],
9+
)

bazel/antlr.bzl

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,17 @@
1616
Generate C++ parser and lexer from a grammar file.
1717
"""
1818

19-
load("@rules_antlr//antlr:antlr4.bzl", "antlr")
20-
21-
def antlr_cc_library(name, src, package = None, listener = False, visitor = True):
19+
def antlr_cc_library(name, src, package):
2220
"""Creates a C++ lexer and parser from a source grammar.
23-
2421
Args:
2522
name: Base name for the lexer and the parser rules.
2623
src: source ANTLR grammar file
2724
package: The namespace for the generated code
28-
listener: generate ANTLR listener (default: False)
29-
visitor: generate ANTLR visitor (default: True)
3025
"""
3126
generated = name + "_grammar"
32-
antlr(
27+
antlr_library(
3328
name = generated,
34-
srcs = [src],
35-
language = "Cpp",
36-
listener = listener,
37-
visitor = visitor,
29+
src = src,
3830
package = package,
3931
)
4032
native.cc_library(
@@ -46,3 +38,65 @@ def antlr_cc_library(name, src, package = None, listener = False, visitor = True
4638
],
4739
linkstatic = 1,
4840
)
41+
42+
def _antlr_library(ctx):
43+
output = ctx.actions.declare_directory(ctx.attr.name)
44+
45+
antlr_args = ctx.actions.args()
46+
antlr_args.add("-Dlanguage=Cpp")
47+
antlr_args.add("-no-listener")
48+
antlr_args.add("-visitor")
49+
antlr_args.add("-o", output.path)
50+
antlr_args.add("-package", ctx.attr.package)
51+
antlr_args.add(ctx.file.src)
52+
53+
# Strip ".g4" extension.
54+
basename = ctx.file.src.basename[:-3]
55+
56+
suffixes = ["Lexer", "Parser", "BaseVisitor", "Visitor"]
57+
58+
ctx.actions.run(
59+
arguments = [antlr_args],
60+
inputs = [ctx.file.src],
61+
outputs = [output],
62+
executable = ctx.executable._tool,
63+
progress_message = "Processing ANTLR grammar",
64+
)
65+
66+
files = []
67+
for suffix in suffixes:
68+
header = ctx.actions.declare_file(basename + suffix + ".h")
69+
source = ctx.actions.declare_file(basename + suffix + ".cpp")
70+
generated = output.path + "/" + ctx.file.src.path[:-3] + suffix
71+
72+
ctx.actions.run_shell(
73+
mnemonic = "CopyHeader" + suffix,
74+
inputs = [output],
75+
outputs = [header],
76+
command = 'cp "{generated}" "{out}"'.format(generated = generated + ".h", out = header.path),
77+
)
78+
ctx.actions.run_shell(
79+
mnemonic = "CopySource" + suffix,
80+
inputs = [output],
81+
outputs = [source],
82+
command = 'cp "{generated}" "{out}"'.format(generated = generated + ".cpp", out = source.path),
83+
)
84+
85+
files.append(header)
86+
files.append(source)
87+
88+
compilation_context = cc_common.create_compilation_context(headers = depset(files))
89+
return [DefaultInfo(files = depset(files)), CcInfo(compilation_context = compilation_context)]
90+
91+
antlr_library = rule(
92+
implementation = _antlr_library,
93+
attrs = {
94+
"src": attr.label(allow_single_file = [".g4"], mandatory = True),
95+
"package": attr.string(),
96+
"_tool": attr.label(
97+
executable = True,
98+
cfg = "host", # buildifier: disable=attr-cfg
99+
default = Label("//bazel:antlr4_tool"),
100+
),
101+
},
102+
)

bazel/deps.bzl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Main dependencies of cel-cpp.
33
"""
44

5-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_jar")
66

77
def base_deps():
88
"""Base evaluator and test dependencies."""
@@ -49,17 +49,17 @@ def base_deps():
4949
sha256 = RE2_SHA256,
5050
)
5151

52-
PROTOBUF_VERSION = "3.19.2"
53-
PROTOBUF_SHA = "4dd35e788944b7686aac898f77df4e9a54da0ca694b8801bd6b2a9ffc1b3085e"
52+
PROTOBUF_VERSION = "3.21.1"
53+
PROTOBUF_SHA = "a295dd3b9551d3e2749a9969583dea110c6cdcc39d02088f7c7bb1100077e081"
5454
http_archive(
5555
name = "com_google_protobuf",
5656
sha256 = PROTOBUF_SHA,
5757
strip_prefix = "protobuf-" + PROTOBUF_VERSION,
5858
urls = ["https://github.com/protocolbuffers/protobuf/archive/v" + PROTOBUF_VERSION + ".tar.gz"],
5959
)
6060

61-
GOOGLEAPIS_GIT_SHA = "77066268d1fd5d72278afc2aef1ebc1d2112cca6" # Oct 01, 2021
62-
GOOGLEAPIS_SHA = "dca75efd11a6295618dba919ad52fe551ba8bb85778d331a38c2bca282234296"
61+
GOOGLEAPIS_GIT_SHA = "f19049fdd8dfc8b6eba387f4ef6d1d8b4d0103e7" # May 31, 2022
62+
GOOGLEAPIS_SHA = "cbda1073fe2eb3b7a5a41fd940a592cfe1861895580c13bf25066896f9e9bede"
6363
http_archive(
6464
name = "com_google_googleapis",
6565
sha256 = GOOGLEAPIS_SHA,
@@ -69,15 +69,10 @@ def base_deps():
6969

7070
def parser_deps():
7171
"""ANTLR dependency for the parser."""
72-
http_archive(
73-
name = "rules_antlr",
74-
sha256 = "26e6a83c665cf6c1093b628b3a749071322f0f70305d12ede30909695ed85591",
75-
strip_prefix = "rules_antlr-0.5.0",
76-
urls = ["https://github.com/marcohu/rules_antlr/archive/0.5.0.tar.gz"],
77-
)
7872

79-
ANTLR4_RUNTIME_GIT_SHA = "70b2edcf98eb612a92d3dbaedb2ce0b69533b0cb" # Dec 7, 2021
80-
ANTLR4_RUNTIME_SHA = "fae73909f95e1320701e29ac03bab9233293fb5b90d3ce857279f1b46b614c83"
73+
# Apr 15, 2022
74+
ANTLR4_VERSION = "4.10.1"
75+
8176
http_archive(
8277
name = "antlr4_runtimes",
8378
build_file_content = """
@@ -89,9 +84,14 @@ cc_library(
8984
includes = ["runtime/Cpp/runtime/src"],
9085
)
9186
""",
92-
sha256 = ANTLR4_RUNTIME_SHA,
93-
strip_prefix = "antlr4-" + ANTLR4_RUNTIME_GIT_SHA,
94-
urls = ["https://github.com/antlr/antlr4/archive/" + ANTLR4_RUNTIME_GIT_SHA + ".tar.gz"],
87+
sha256 = "a320568b738e42735946bebc5d9d333170e14a251c5734e8b852ad1502efa8a2",
88+
strip_prefix = "antlr4-" + ANTLR4_VERSION,
89+
urls = ["https://github.com/antlr/antlr4/archive/v" + ANTLR4_VERSION + ".tar.gz"],
90+
)
91+
http_jar(
92+
name = "antlr4_jar",
93+
urls = ["https://www.antlr.org/download/antlr-" + ANTLR4_VERSION + "-complete.jar"],
94+
sha256 = "41949d41f20d31d5b8277187735dd755108df52b38db6c865108d3382040f918",
9595
)
9696

9797
def flatbuffers_deps():
@@ -124,10 +124,10 @@ def cel_spec_deps():
124124
],
125125
)
126126

127-
CEL_SPEC_GIT_SHA = "c9ae91b24fdaf869d7c59a9f64863249a6a2905e" # 9/22/2021
127+
CEL_SPEC_GIT_SHA = "6040c0a6df9601751e628405706bac18948b8eb3" # 3/31/2022
128128
http_archive(
129129
name = "com_google_cel_spec",
130-
sha256 = "a911c4a5c5cea1c29dc57463cfea5614025654e6bb67a6aeebc57af3d132c8e4",
130+
sha256 = "6b4ca28de8d8a3038a96c393774c2ab65abd6a57cb50295dddea406b2eeafc9e",
131131
strip_prefix = "cel-spec-" + CEL_SPEC_GIT_SHA,
132132
urls = ["https://github.com/google/cel-spec/archive/" + CEL_SPEC_GIT_SHA + ".zip"],
133133
)

bazel/deps_extra.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Transitive dependencies.
44

55
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
66
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
7-
load("@rules_antlr//antlr:repositories.bzl", "rules_antlr_dependencies")
87
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
98
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
109

@@ -50,5 +49,4 @@ def cel_cpp_deps_extra():
5049
cc = True,
5150
go = True, # cel-spec requirement
5251
)
53-
rules_antlr_dependencies("4.8")
5452
cel_spec_deps_extra()

eval/compiler/flat_expr_builder_test.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ namespace google::api::expr::runtime {
6363

6464
namespace {
6565

66+
using ::google::api::expr::v1alpha1::CheckedExpr;
67+
using ::google::api::expr::v1alpha1::Expr;
68+
using ::google::api::expr::v1alpha1::ParsedExpr;
69+
using ::google::api::expr::v1alpha1::SourceInfo;
6670
using testing::Eq;
6771
using testing::HasSubstr;
6872
using cel::internal::StatusIs;
@@ -75,7 +79,7 @@ template <class MessageClass>
7579
absl::Status ReadBinaryProtoFromDisk(absl::string_view file_name,
7680
MessageClass& message) {
7781
std::ifstream file;
78-
file.open(file_name, std::fstream::in);
82+
file.open(std::string(file_name), std::fstream::in);
7983
if (!file.is_open()) {
8084
return absl::NotFoundError(absl::StrFormat("Failed to open file '%s': %s",
8185
file_name, strerror(errno)));
@@ -1890,9 +1894,8 @@ TEST(FlatExprBuilderTest, CustomDescriptorPoolForSelect) {
18901894

18911895
std::pair<google::protobuf::Message*, const google::protobuf::Reflection*> CreateTestMessage(
18921896
const google::protobuf::DescriptorPool& descriptor_pool,
1893-
google::protobuf::MessageFactory& message_factory, absl::string_view message_type) {
1894-
const google::protobuf::Descriptor* desc =
1895-
descriptor_pool.FindMessageTypeByName(message_type);
1897+
google::protobuf::MessageFactory& message_factory, absl::string_view name) {
1898+
const google::protobuf::Descriptor* desc = descriptor_pool.FindMessageTypeByName(name.data());
18961899
const google::protobuf::Message* message_prototype = message_factory.GetPrototype(desc);
18971900
google::protobuf::Message* message = message_prototype->New();
18981901
const google::protobuf::Reflection* refl = message->GetReflection();

eval/compiler/qualified_reference_resolver.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace {
2828
using ::google::api::expr::v1alpha1::Constant;
2929
using ::google::api::expr::v1alpha1::Expr;
3030
using ::google::api::expr::v1alpha1::Reference;
31+
using ::google::api::expr::v1alpha1::SourceInfo;
3132

3233
// Determines if function is implemented with custom evaluation step instead of
3334
// registered.

0 commit comments

Comments
 (0)