Skip to content
Merged
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: 1 addition & 3 deletions checker/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ cc_test(
deps = [
":type_check_issue",
":validation_result",
"//common:ast",
"//common:source",
"//common/ast:ast_impl",
"//internal:testing",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
Expand Down Expand Up @@ -171,7 +171,6 @@ cc_test(
"//common:constant",
"//common:decl",
"//common:type",
"//common/ast:ast_impl",
"//common/ast:expr",
"//internal:testing",
"//internal:testing_descriptor_pool",
Expand Down Expand Up @@ -209,7 +208,6 @@ cc_test(
":type_checker_builder",
":type_checker_builder_factory",
"//checker/internal:test_ast_helpers",
"//common/ast:ast_impl",
"//common/ast:expr",
"//internal:testing",
"//internal:testing_descriptor_pool",
Expand Down
4 changes: 1 addition & 3 deletions checker/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ cc_test(
deps = [
":test_ast_helpers",
"//common:ast",
"//common/ast:ast_impl",
"//internal:testing",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:status_matchers",
Expand Down Expand Up @@ -139,7 +138,6 @@ cc_library(
"//common:source",
"//common:type",
"//common:type_kind",
"//common/ast:ast_impl",
"//common/ast:expr",
"//internal:lexis",
"//internal:status_macros",
Expand Down Expand Up @@ -203,9 +201,9 @@ cc_test(
"//checker:checker_options",
"//checker:type_checker",
"//checker:validation_result",
"//common:ast",
"//common:decl",
"//common:type",
"//common/ast:ast_impl",
"//common/ast:expr",
"//internal:testing",
"//internal:testing_descriptor_pool",
Expand Down
48 changes: 24 additions & 24 deletions checker/internal/type_checker_builder_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "checker/internal/test_ast_helpers.h"
#include "checker/type_checker.h"
#include "checker/validation_result.h"
#include "common/ast/ast_impl.h"
#include "common/ast.h"
#include "common/ast/expr.h"
#include "common/decl.h"
#include "common/type.h"
Expand All @@ -42,11 +42,10 @@ namespace {
using ::absl_testing::IsOk;
using ::absl_testing::StatusIs;

using AstType = cel::ast_internal::Type;

struct ContextDeclsTestCase {
std::string expr;
AstType expected_type;
TypeSpec expected_type;
};

class ContextDeclsFieldsDefinedTest
Expand All @@ -73,50 +72,51 @@ INSTANTIATE_TEST_SUITE_P(
TestAllTypes, ContextDeclsFieldsDefinedTest,
testing::Values(
ContextDeclsTestCase{"single_int64",
AstType(ast_internal::PrimitiveType::kInt64)},
TypeSpec(ast_internal::PrimitiveType::kInt64)},
ContextDeclsTestCase{"single_uint32",
AstType(ast_internal::PrimitiveType::kUint64)},
TypeSpec(ast_internal::PrimitiveType::kUint64)},
ContextDeclsTestCase{"single_double",
AstType(ast_internal::PrimitiveType::kDouble)},
TypeSpec(ast_internal::PrimitiveType::kDouble)},
ContextDeclsTestCase{"single_string",
AstType(ast_internal::PrimitiveType::kString)},
TypeSpec(ast_internal::PrimitiveType::kString)},
ContextDeclsTestCase{"single_any",
AstType(ast_internal::WellKnownType::kAny)},
TypeSpec(ast_internal::WellKnownType::kAny)},
ContextDeclsTestCase{"single_duration",
AstType(ast_internal::WellKnownType::kDuration)},
TypeSpec(ast_internal::WellKnownType::kDuration)},
ContextDeclsTestCase{"single_bool_wrapper",
AstType(ast_internal::PrimitiveTypeWrapper(
TypeSpec(ast_internal::PrimitiveTypeWrapper(
ast_internal::PrimitiveType::kBool))},
ContextDeclsTestCase{
"list_value",
AstType(ast_internal::ListType(
std::make_unique<AstType>(ast_internal::DynamicType())))},
TypeSpec(ast_internal::ListType(
std::make_unique<TypeSpec>(ast_internal::DynamicType())))},
ContextDeclsTestCase{
"standalone_message",
AstType(ast_internal::MessageType(
TypeSpec(ast_internal::MessageType(
"cel.expr.conformance.proto3.TestAllTypes.NestedMessage"))},
ContextDeclsTestCase{"standalone_enum",
AstType(ast_internal::PrimitiveType::kInt64)},
TypeSpec(ast_internal::PrimitiveType::kInt64)},
ContextDeclsTestCase{
"repeated_bytes",
AstType(ast_internal::ListType(std::make_unique<AstType>(
TypeSpec(ast_internal::ListType(std::make_unique<TypeSpec>(
ast_internal::PrimitiveType::kBytes)))},
ContextDeclsTestCase{
"repeated_nested_message",
AstType(ast_internal::ListType(std::make_unique<
AstType>(ast_internal::MessageType(
TypeSpec(ast_internal::ListType(std::make_unique<
TypeSpec>(ast_internal::MessageType(
"cel.expr.conformance.proto3.TestAllTypes.NestedMessage"))))},
ContextDeclsTestCase{
"map_int32_timestamp",
AstType(ast_internal::MapType(
std::make_unique<AstType>(ast_internal::PrimitiveType::kInt64),
std::make_unique<AstType>(
TypeSpec(ast_internal::MapType(
std::make_unique<TypeSpec>(ast_internal::PrimitiveType::kInt64),
std::make_unique<TypeSpec>(
ast_internal::WellKnownType::kTimestamp)))},
ContextDeclsTestCase{
"single_struct",
AstType(ast_internal::MapType(
std::make_unique<AstType>(ast_internal::PrimitiveType::kString),
std::make_unique<AstType>(ast_internal::DynamicType())))}));
TypeSpec(ast_internal::MapType(
std::make_unique<TypeSpec>(
ast_internal::PrimitiveType::kString),
std::make_unique<TypeSpec>(ast_internal::DynamicType())))}));

TEST(ContextDeclsTest, ErrorOnDuplicateContextDeclaration) {
TypeCheckerBuilderImpl builder(internal::GetSharedTestingDescriptorPool(),
Expand Down Expand Up @@ -324,7 +324,7 @@ TEST(TypeCheckerBuilderImplTest, ReplaceVariable) {
const auto& checked_ast = *result.GetAst();

EXPECT_EQ(checked_ast.GetReturnType(),
AstType(ast_internal::PrimitiveType::kString));
TypeSpec(ast_internal::PrimitiveType::kString));
}

} // namespace
Expand Down
1 change: 0 additions & 1 deletion checker/internal/type_checker_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "checker/type_check_issue.h"
#include "checker/validation_result.h"
#include "common/ast.h"
#include "common/ast/ast_impl.h"
#include "common/ast/expr.h"
#include "common/ast_rewrite.h"
#include "common/ast_traverse.h"
Expand Down
1 change: 0 additions & 1 deletion checker/optional_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "checker/type_checker.h"
#include "checker/type_checker_builder.h"
#include "checker/type_checker_builder_factory.h"
#include "common/ast/ast_impl.h"
#include "common/ast/expr.h"
#include "internal/testing.h"
#include "internal/testing_descriptor_pool.h"
Expand Down
5 changes: 2 additions & 3 deletions checker/validation_result_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "absl/status/status.h"
#include "absl/status/status_matchers.h"
#include "checker/type_check_issue.h"
#include "common/ast/ast_impl.h"
#include "common/ast.h"
#include "common/source.h"
#include "internal/testing.h"

Expand All @@ -29,7 +29,6 @@ namespace {

using ::absl_testing::IsOkAndHolds;
using ::absl_testing::StatusIs;
using ::cel::ast_internal::AstImpl;
using ::testing::_;
using ::testing::IsNull;
using ::testing::NotNull;
Expand All @@ -38,7 +37,7 @@ using ::testing::SizeIs;
using Severity = TypeCheckIssue::Severity;

TEST(ValidationResultTest, IsValidWithAst) {
ValidationResult result(std::make_unique<AstImpl>(), {});
ValidationResult result(std::make_unique<Ast>(), {});
EXPECT_TRUE(result.IsValid());
EXPECT_THAT(result.GetAst(), NotNull());
EXPECT_THAT(result.ReleaseAst(), IsOkAndHolds(NotNull()));
Expand Down
14 changes: 11 additions & 3 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ cc_library(
],
)

cc_test(
name = "ast_test",
srcs = ["ast_test.cc"],
deps = [
":ast",
":expr",
"//internal:testing",
"@com_google_absl//absl/container:flat_hash_map",
],
)

cc_library(
name = "expr",
srcs = ["expr.cc"],
Expand Down Expand Up @@ -176,7 +187,6 @@ cc_test(
":ast_rewrite",
":ast_visitor",
":expr",
"//common/ast:ast_impl",
"//common/ast:expr_proto",
"//extensions/protobuf:ast_converters",
"//internal:testing",
Expand Down Expand Up @@ -1031,7 +1041,6 @@ cc_library(
":constant",
":expr",
"//base:ast",
"//common/ast:ast_impl",
"//common/ast:constant_proto",
"//common/ast:expr",
"//common/ast:expr_proto",
Expand Down Expand Up @@ -1062,7 +1071,6 @@ cc_test(
":expr",
":source",
":type",
"//common/ast:ast_impl",
"//common/ast:expr",
"//compiler",
"//compiler:compiler_factory",
Expand Down
13 changes: 0 additions & 13 deletions common/ast/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ cc_library(
":metadata",
"//common:ast",
"//common:expr",
"//internal:casts",
],
)

cc_test(
name = "ast_impl_test",
srcs = ["ast_impl_test.cc"],
deps = [
":ast_impl",
":expr",
"//common:ast",
"//internal:testing",
"@com_google_absl//absl/container:flat_hash_map",
],
)

Expand Down
16 changes: 7 additions & 9 deletions common/ast_proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "absl/status/statusor.h"
#include "absl/types/variant.h"
#include "common/ast.h"
#include "common/ast/ast_impl.h"
#include "common/ast/constant_proto.h"
#include "common/ast/expr.h"
#include "common/ast/expr_proto.h"
Expand All @@ -44,7 +43,6 @@ namespace cel {
namespace {

using ::cel::ast_internal::AbstractType;
using ::cel::ast_internal::AstImpl;
using ::cel::ast_internal::ConstantFromProto;
using ::cel::ast_internal::ConstantToProto;
using ::cel::ast_internal::DynamicType;
Expand Down Expand Up @@ -487,8 +485,8 @@ absl::StatusOr<std::unique_ptr<Ast>> CreateAstFromParsedExpr(
CEL_ASSIGN_OR_RETURN(runtime_source_info,
ConvertProtoSourceInfoToNative(*source_info));
}
return std::make_unique<cel::ast_internal::AstImpl>(
std::move(runtime_expr), std::move(runtime_source_info));
return std::make_unique<Ast>(std::move(runtime_expr),
std::move(runtime_source_info));
}

absl::StatusOr<std::unique_ptr<Ast>> CreateAstFromParsedExpr(
Expand All @@ -513,15 +511,15 @@ absl::StatusOr<std::unique_ptr<Ast>> CreateAstFromCheckedExpr(
CEL_ASSIGN_OR_RETURN(SourceInfo source_info, ConvertProtoSourceInfoToNative(
checked_expr.source_info()));

AstImpl::ReferenceMap reference_map;
Ast::ReferenceMap reference_map;
for (const auto& pair : checked_expr.reference_map()) {
auto native_reference = ConvertProtoReferenceToNative(pair.second);
if (!native_reference.ok()) {
return native_reference.status();
}
reference_map.emplace(pair.first, *(std::move(native_reference)));
}
AstImpl::TypeMap type_map;
Ast::TypeMap type_map;
for (const auto& pair : checked_expr.type_map()) {
auto native_type = ConvertProtoTypeToNative(pair.second);
if (!native_type.ok()) {
Expand All @@ -530,9 +528,9 @@ absl::StatusOr<std::unique_ptr<Ast>> CreateAstFromCheckedExpr(
type_map.emplace(pair.first, *(std::move(native_type)));
}

return std::make_unique<AstImpl>(
std::move(expr), std::move(source_info), std::move(reference_map),
std::move(type_map), checked_expr.expr_version());
return std::make_unique<Ast>(std::move(expr), std::move(source_info),
std::move(reference_map), std::move(type_map),
checked_expr.expr_version());
}

absl::Status AstToCheckedExpr(
Expand Down
2 changes: 0 additions & 2 deletions common/ast_rewrite_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "cel/expr/syntax.pb.h"
#include "absl/status/status_matchers.h"
#include "common/ast.h"
#include "common/ast/ast_impl.h"
#include "common/ast/expr_proto.h"
#include "common/ast_visitor.h"
#include "common/expr.h"
Expand All @@ -35,7 +34,6 @@ namespace cel {
namespace {

using ::absl_testing::IsOk;
using ::cel::ast_internal::AstImpl;
using ::cel::ast_internal::ExprFromProto;
using ::cel::extensions::CreateAstFromParsedExpr;
using ::testing::_;
Expand Down
Loading