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
35 changes: 1 addition & 34 deletions checker/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ cc_library(
srcs = ["type_check_env.cc"],
hdrs = ["type_check_env.h"],
deps = [
":descriptor_pool_type_introspector",
":proto_type_mask",
":proto_type_mask_registry",
"//common:constant",
"//common:container",
"//common:decl",
"//common:descriptor_pool_type_introspector",
"//common:type",
"//internal:status_macros",
"@com_google_absl//absl/base:core_headers",
Expand Down Expand Up @@ -275,39 +275,6 @@ cc_test(
],
)

cc_library(
name = "descriptor_pool_type_introspector",
srcs = ["descriptor_pool_type_introspector.cc"],
hdrs = ["descriptor_pool_type_introspector.h"],
deps = [
"//common:type",
"@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/log:absl_check",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:span",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
name = "descriptor_pool_type_introspector_test",
srcs = ["descriptor_pool_type_introspector_test.cc"],
deps = [
":descriptor_pool_type_introspector",
"//common:type",
"//internal:testing",
"//internal:testing_descriptor_pool",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/types:optional",
],
)

cc_library(
name = "field_path",
srcs = ["field_path.cc"],
Expand Down
2 changes: 1 addition & 1 deletion checker/internal/type_check_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "absl/types/span.h"
#include "checker/internal/descriptor_pool_type_introspector.h"
#include "checker/internal/proto_type_mask.h"
#include "checker/internal/proto_type_mask_registry.h"
#include "common/constant.h"
#include "common/container.h"
#include "common/decl.h"
#include "common/descriptor_pool_type_introspector.h"
#include "common/type.h"
#include "common/type_introspector.h"
#include "internal/status_macros.h"
Expand Down
35 changes: 35 additions & 0 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ cc_library(
hdrs = ["type_spec_resolver.h"],
deps = [
":ast",
":descriptor_pool_type_introspector",
":type",
":type_kind",
"//internal:status_macros",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_google_protobuf//:protobuf",
],
)
Expand All @@ -79,6 +81,39 @@ cc_test(
],
)

cc_library(
name = "descriptor_pool_type_introspector",
srcs = ["descriptor_pool_type_introspector.cc"],
hdrs = ["descriptor_pool_type_introspector.h"],
deps = [
":type",
"@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/log:absl_check",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/types:optional",
"@com_google_absl//absl/types:span",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
name = "descriptor_pool_type_introspector_test",
srcs = ["descriptor_pool_type_introspector_test.cc"],
deps = [
":descriptor_pool_type_introspector",
":type",
"//internal:testing",
"//internal:testing_descriptor_pool",
"@com_google_absl//absl/status:status_matchers",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/types:optional",
],
)

cc_library(
name = "signature",
srcs = ["signature.cc"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "checker/internal/descriptor_pool_type_introspector.h"
#include "common/descriptor_pool_type_introspector.h"

#include <memory>
#include <optional>
#include <utility>
#include <vector>

Expand All @@ -24,13 +25,12 @@
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/types/optional.h"
#include "absl/types/span.h"
#include "common/type.h"
#include "common/type_introspector.h"
#include "google/protobuf/descriptor.h"

namespace cel::checker_internal {
namespace cel {
namespace {

// Standard implementation for field lookups.
Expand Down Expand Up @@ -242,4 +242,4 @@ DescriptorPoolTypeIntrospector::CreateFieldTable(
return result;
}

} // namespace cel::checker_internal
} // namespace cel
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_DESCRIPTOR_POOL_TYPE_INTROSPECTOR_H_
#define THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_DESCRIPTOR_POOL_TYPE_INTROSPECTOR_H_
#ifndef THIRD_PARTY_CEL_CPP_COMMON_DESCRIPTOR_POOL_TYPE_INTROSPECTOR_H_
#define THIRD_PARTY_CEL_CPP_COMMON_DESCRIPTOR_POOL_TYPE_INTROSPECTOR_H_

#include <memory>
#include <vector>
Expand All @@ -30,14 +30,15 @@
#include "common/type_introspector.h"
#include "google/protobuf/descriptor.h"

namespace cel::checker_internal {
namespace cel {

// Implementation of `TypeIntrospector` that uses a `google::protobuf::DescriptorPool`.
//
// This is used by the type checker to resolve protobuf types and their fields
// and apply any options like using JSON names.
//
// Neither copyable nor movable. Should be managed by a TypeCheckEnv.
// Neither copyable nor movable. Should be managed by a TypeCheckEnv or a
// runtime Environment.
class DescriptorPoolTypeIntrospector : public TypeIntrospector {
public:
struct Field {
Expand Down Expand Up @@ -100,6 +101,6 @@ class DescriptorPoolTypeIntrospector : public TypeIntrospector {
const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool_;
};

} // namespace cel::checker_internal
} // namespace cel

#endif // THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_DESCRIPTOR_POOL_TYPE_INTROSPECTOR_H_
#endif // THIRD_PARTY_CEL_CPP_COMMON_DESCRIPTOR_POOL_TYPE_INTROSPECTOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "checker/internal/descriptor_pool_type_introspector.h"
#include "common/descriptor_pool_type_introspector.h"

#include <optional>
#include <vector>

#include "absl/status/status_matchers.h"
#include "absl/status/statusor.h"
#include "absl/types/optional.h"
#include "common/type.h"
#include "common/type_introspector.h"
#include "internal/testing.h"
#include "internal/testing_descriptor_pool.h"

namespace cel::checker_internal {
namespace cel {
namespace {

using ::absl_testing::IsOkAndHolds;
Expand Down Expand Up @@ -172,4 +172,4 @@ TEST(DescriptorPoolTypeIntrospectorTest, ListFieldsForStructTypeNotFound) {
}

} // namespace
} // namespace cel::checker_internal
} // namespace cel
2 changes: 1 addition & 1 deletion common/signature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ absl::StatusOr<TypeSpec> ParseTypeSpec(std::string_view signature) {
absl::StatusOr<Type> ParseType(std::string_view signature, google::protobuf::Arena* arena,
const google::protobuf::DescriptorPool& pool) {
CEL_ASSIGN_OR_RETURN(auto type_spec, ParseTypeSpec(signature));
return cel::ConvertTypeSpecToType(type_spec, arena, pool);
return cel::ConvertTypeSpecToType(type_spec, pool, arena);
}

} // namespace cel
9 changes: 5 additions & 4 deletions common/signature_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ TEST_P(TypeSignatureTest, TypeSignature) {
EXPECT_THAT(signature, IsOkAndHolds(param.expected_signature));

absl::StatusOr<Type> type = ConvertTypeSpecToType(
param.type, GetTestArena(), *GetTestingDescriptorPool());
param.type, *GetTestingDescriptorPool(), GetTestArena());
ASSERT_THAT(type, ::absl_testing::IsOk());
EXPECT_THAT(MakeTypeSignature(*type),
IsOkAndHolds(param.expected_signature));
Expand Down Expand Up @@ -285,9 +285,10 @@ TEST_P(TypeSignatureTest, ParseTypeCheck) {
auto parsed = ParseType(param.expected_signature, GetTestArena(),
*GetTestingDescriptorPool());
ASSERT_THAT(parsed, ::absl_testing::IsOk());
ASSERT_OK_AND_ASSIGN(auto expected_type,
ConvertTypeSpecToType(param.type, GetTestArena(),
*GetTestingDescriptorPool()));
ASSERT_OK_AND_ASSIGN(
auto expected_type,
ConvertTypeSpecToType(param.type, *GetTestingDescriptorPool(),
GetTestArena()));
VerifyTypesEqual(*parsed, expected_type);
}
}
Expand Down
5 changes: 5 additions & 0 deletions common/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ absl::optional<MessageTypeField> StructTypeField::AsMessage() const {
return std::nullopt;
}

MessageTypeField StructTypeField::GetMessage() const {
ABSL_DCHECK(IsMessage());
return absl::get<MessageTypeField>(variant_);
}

StructTypeField::operator MessageTypeField() const {
ABSL_DCHECK(IsMessage());
return absl::get<MessageTypeField>(variant_);
Expand Down
1 change: 1 addition & 0 deletions common/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ class StructTypeField final {
}

absl::optional<MessageTypeField> AsMessage() const;
MessageTypeField GetMessage() const;

explicit operator MessageTypeField() const;

Expand Down
Loading
Loading