Skip to content
Open
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
196 changes: 196 additions & 0 deletions common/typedef/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Copyright 2026 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
#
# https://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.

load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

cc_library(
name = "typedef",
srcs = ["typedef.cc"],
hdrs = ["typedef.h"],
deps = [
"//common:ast",
"//common:constant",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/functional:overload",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
],
)

cc_test(
name = "typedef_test",
srcs = ["typedef_test.cc"],
deps = [
":typedef",
"//common:ast",
"//common:constant",
"//internal:testing",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
],
)

proto_library(
name = "typedef_protos",
srcs = ["typedef.proto"],
deps = [
"@com_google_cel_spec//proto/cel/expr:checked_proto",
"@com_google_cel_spec//proto/cel/expr:syntax_proto",
],
)

cc_proto_library(
name = "typedef_cc_proto",
deps = [":typedef_protos"],
)

cc_library(
name = "aspect_proto",
srcs = ["aspect_proto.cc"],
hdrs = ["aspect_proto.h"],
deps = [
":typedef_cc_proto",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
],
)

cc_test(
name = "aspect_proto_test",
srcs = ["aspect_proto_test.cc"],
deps = [
":aspect_proto",
":typedef_cc_proto",
"//internal:testing",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/strings:string_view",
],
)

cc_library(
name = "typedef_proto",
srcs = ["typedef_proto.cc"],
hdrs = ["typedef_proto.h"],
deps = [
":aspect_proto",
":typedef",
":typedef_cc_proto",
"//common:ast",
"//common:constant",
"//common/ast:constant_proto",
"//internal:status_macros",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/types:span",
"@com_google_absl//absl/types:variant",
"@com_google_cel_spec//proto/cel/expr:checked_cc_proto",
"@com_google_protobuf//:struct_cc_proto",
],
)

cc_library(
name = "proto_schema",
hdrs = ["proto_schema.h"],
deps = [
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/strings:string_view",
],
)

proto_library(
name = "proto_schema_protos",
srcs = ["proto_schema.proto"],
deps = [":typedef_protos"],
)

cc_proto_library(
name = "proto_schema_cc_proto",
deps = [":proto_schema_protos"],
)

cc_library(
name = "proto_schema_proto",
srcs = ["proto_schema_proto.cc"],
hdrs = ["proto_schema_proto.h"],
deps = [
":aspect_proto",
":proto_schema",
":proto_schema_cc_proto",
":typedef_cc_proto",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
],
)

cc_test(
name = "proto_schema_proto_test",
srcs = ["proto_schema_proto_test.cc"],
deps = [
":aspect_proto",
":proto_schema",
":proto_schema_cc_proto",
":proto_schema_proto",
":typedef_cc_proto",
"//internal:testing",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
name = "typedef_proto_test",
srcs = ["typedef_proto_test.cc"],
data = [
"//common/typedef/testdata:typedef_testdata",
],
deps = [
":aspect_proto",
":proto_schema_proto",
":typedef",
":typedef_cc_proto",
":typedef_proto",
"//internal:proto_matchers",
"//internal:runfiles",
"//internal:testing",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
"@com_google_protobuf//:protobuf",
],
)
95 changes: 95 additions & 0 deletions common/typedef/aspect_proto.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2026 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
//
// https://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.

#include "common/typedef/aspect_proto.h"

#include <any>
#include <memory>
#include <utility>
#include <vector>

#include "absl/base/nullability.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "common/typedef/typedef.pb.h"

namespace cel {

absl::StatusOr<std::any> AspectProto::DecodeStructProperties(
const types::Struct& proto) const {
return std::any();
}

absl::StatusOr<std::any> AspectProto::DecodeFieldProperties(
const types::Struct::Field& proto) const {
return std::any();
}

absl::StatusOr<std::any> AspectProto::DecodeEnumProperties(
const types::Enum& proto) const {
return std::any();
}

absl::StatusOr<std::any> AspectProto::DecodeEnumConstantProperties(
const types::Enum::EnumConstant& proto) const {
return std::any();
}

absl::Status AspectProto::EncodeStructProperties(
const std::any& properties, types::Struct* absl_nonnull proto) const {
return absl::UnimplementedError(absl::StrCat(
"Custom struct properties are not supported for aspect '", name(), "'"));
}

absl::Status AspectProto::EncodeFieldProperties(
const std::any& properties,
types::Struct::Field* absl_nonnull proto) const {
return absl::UnimplementedError(absl::StrCat(
"Custom field properties are not supported for aspect '", name(), "'"));
}

absl::Status AspectProto::EncodeEnumProperties(
const std::any& properties, types::Enum* absl_nonnull proto) const {
return absl::UnimplementedError(absl::StrCat(
"Custom enum properties are not supported for aspect '", name(), "'"));
}

absl::Status AspectProto::EncodeEnumConstantProperties(
const std::any& properties,
types::Enum::EnumConstant* absl_nonnull proto) const {
return absl::UnimplementedError(absl::StrCat(
"Custom enum constant properties are not supported for aspect '", name(),
"'"));
}

AspectProtoRegistry::AspectProtoRegistry(
std::vector<std::unique_ptr<const AspectProto>> aspects) {
aspects_.reserve(aspects.size());
for (std::unique_ptr<const AspectProto>& aspect : aspects) {
Add(std::move(aspect));
}
}

const AspectProto* absl_nullable AspectProtoRegistry::Find(
absl::string_view aspect_name) const {
auto it = aspects_.find(aspect_name);
if (it == aspects_.end()) {
return nullptr;
}
return it->second.get();
}

} // namespace cel
Loading
Loading