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
15 changes: 2 additions & 13 deletions checker/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ cc_library(
"type_checker_impl.h",
],
deps = [
":format_type_name",
":namespace_generator",
":proto_type_mask",
":type_check_env",
Expand All @@ -149,6 +148,7 @@ cc_library(
"//common:container",
"//common:decl",
"//common:expr",
"//common:format_type_name",
"//common:standard_definitions",
"//common:type",
"//common:type_kind",
Expand Down Expand Up @@ -243,8 +243,8 @@ cc_library(
srcs = ["type_inference_context.cc"],
hdrs = ["type_inference_context.h"],
deps = [
":format_type_name",
"//common:decl",
"//common:format_type_name",
"//common:standard_definitions",
"//common:type",
"//common:type_kind",
Expand Down Expand Up @@ -275,17 +275,6 @@ cc_test(
],
)

cc_library(
name = "format_type_name",
srcs = ["format_type_name.cc"],
hdrs = ["format_type_name.h"],
deps = [
"//common:type",
"//common:type_kind",
"@com_google_absl//absl/strings",
],
)

cc_library(
name = "descriptor_pool_type_introspector",
srcs = ["descriptor_pool_type_introspector.cc"],
Expand Down
2 changes: 1 addition & 1 deletion checker/internal/type_checker_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "absl/types/optional.h"
#include "absl/types/span.h"
#include "checker/checker_options.h"
#include "checker/internal/format_type_name.h"
#include "checker/internal/namespace_generator.h"
#include "checker/internal/type_check_env.h"
#include "checker/internal/type_checker_builder_impl.h"
Expand All @@ -52,6 +51,7 @@
#include "common/constant.h"
#include "common/decl.h"
#include "common/expr.h"
#include "common/format_type_name.h"
#include "common/standard_definitions.h"
#include "common/type.h"
#include "common/type_kind.h"
Expand Down
18 changes: 9 additions & 9 deletions checker/internal/type_inference_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "absl/types/span.h"
#include "checker/internal/format_type_name.h"
#include "common/decl.h"
#include "common/format_type_name.h"
#include "common/standard_definitions.h"
#include "common/type.h"
#include "common/type_kind.h"
Expand Down Expand Up @@ -657,14 +657,14 @@ bool TypeInferenceContext::AssignabilityContext::IsAssignable(const Type& from,
std::string TypeInferenceContext::DebugString() const {
return absl::StrCat(
"type_parameter_bindings: ",
absl::StrJoin(
type_parameter_bindings_, "\n ",
[](std::string* out, const auto& binding) {
absl::StrAppend(
out, binding.first, " (", binding.second.name, ") -> ",
checker_internal::FormatTypeName(
binding.second.type.value_or(Type(TypeParamType("none")))));
}));
absl::StrJoin(type_parameter_bindings_, "\n ",
[](std::string* out, const auto& binding) {
absl::StrAppend(
out, binding.first, " (", binding.second.name,
") -> ",
cel::FormatTypeName(binding.second.type.value_or(
Type(TypeParamType("none")))));
}));
}

void TypeInferenceContext::AssignabilityContext::
Expand Down
23 changes: 23 additions & 0 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,17 @@ cc_library(
],
)

cc_library(
name = "format_type_name",
srcs = ["format_type_name.cc"],
hdrs = ["format_type_name.h"],
deps = [
":type",
":type_kind",
"@com_google_absl//absl/strings",
],
)

cc_test(
name = "type_test",
srcs = glob([
Expand All @@ -623,6 +634,18 @@ cc_test(
],
)

cc_test(
name = "format_type_name_test",
srcs = ["format_type_name_test.cc"],
deps = [
":format_type_name",
":type",
"//internal:testing",
"@com_google_cel_spec//proto/cel/expr/conformance/proto2:test_all_types_cc_proto",
"@com_google_protobuf//:protobuf",
],
)

cc_library(
name = "value",
srcs = glob(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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 "checker/internal/format_type_name.h"
#include "common/format_type_name.h"

#include <string>
#include <vector>
Expand All @@ -20,7 +20,7 @@
#include "common/type.h"
#include "common/type_kind.h"

namespace cel::checker_internal {
namespace cel {

namespace {
struct FormatImplRecord {
Expand Down Expand Up @@ -177,4 +177,4 @@ std::string FormatTypeName(const Type& type) {
return out;
}

} // namespace cel::checker_internal
} // namespace cel
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.

#ifndef THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_FORMAT_TYPE_NAME_H_
#define THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_FORMAT_TYPE_NAME_H_
#ifndef THIRD_PARTY_CEL_CPP_COMMON_FORMAT_TYPE_NAME_H_
#define THIRD_PARTY_CEL_CPP_COMMON_FORMAT_TYPE_NAME_H_

#include <string>

#include "common/type.h"

namespace cel::checker_internal {
namespace cel {

// Format the type name for presentation in error messages. Matches the
// formatting used in github.com/cel-spec.
std::string FormatTypeName(const Type& type);

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

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

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

#include "common/type.h"
#include "internal/testing.h"
#include "cel/expr/conformance/proto2/test_all_types.pb.h"
#include "google/protobuf/arena.h"

namespace cel::checker_internal {
namespace cel {
namespace {

using ::cel::expr::conformance::proto2::GlobalEnum_descriptor;
Expand Down Expand Up @@ -115,4 +115,4 @@ TEST(FormatTypeNameTest, ArbitraryNesting) {
#endif

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