Skip to content

Commit c0e4307

Browse files
jnthntatumcopybara-github
authored andcommitted
refactor: Move type formatter to common.
PiperOrigin-RevId: 930639404
1 parent 6975536 commit c0e4307

7 files changed

Lines changed: 46 additions & 34 deletions

File tree

checker/internal/BUILD

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ cc_library(
130130
"type_checker_impl.h",
131131
],
132132
deps = [
133-
":format_type_name",
134133
":namespace_generator",
135134
":proto_type_mask",
136135
":type_check_env",
@@ -149,6 +148,7 @@ cc_library(
149148
"//common:container",
150149
"//common:decl",
151150
"//common:expr",
151+
"//common:format_type_name",
152152
"//common:standard_definitions",
153153
"//common:type",
154154
"//common:type_kind",
@@ -243,8 +243,8 @@ cc_library(
243243
srcs = ["type_inference_context.cc"],
244244
hdrs = ["type_inference_context.h"],
245245
deps = [
246-
":format_type_name",
247246
"//common:decl",
247+
"//common:format_type_name",
248248
"//common:standard_definitions",
249249
"//common:type",
250250
"//common:type_kind",
@@ -275,17 +275,6 @@ cc_test(
275275
],
276276
)
277277

278-
cc_library(
279-
name = "format_type_name",
280-
srcs = ["format_type_name.cc"],
281-
hdrs = ["format_type_name.h"],
282-
deps = [
283-
"//common:type",
284-
"//common:type_kind",
285-
"@com_google_absl//absl/strings",
286-
],
287-
)
288-
289278
cc_library(
290279
name = "descriptor_pool_type_introspector",
291280
srcs = ["descriptor_pool_type_introspector.cc"],

checker/internal/type_checker_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "absl/types/optional.h"
3737
#include "absl/types/span.h"
3838
#include "checker/checker_options.h"
39-
#include "checker/internal/format_type_name.h"
4039
#include "checker/internal/namespace_generator.h"
4140
#include "checker/internal/type_check_env.h"
4241
#include "checker/internal/type_checker_builder_impl.h"
@@ -52,6 +51,7 @@
5251
#include "common/constant.h"
5352
#include "common/decl.h"
5453
#include "common/expr.h"
54+
#include "common/format_type_name.h"
5555
#include "common/standard_definitions.h"
5656
#include "common/type.h"
5757
#include "common/type_kind.h"

checker/internal/type_inference_context.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include "absl/strings/string_view.h"
2929
#include "absl/types/optional.h"
3030
#include "absl/types/span.h"
31-
#include "checker/internal/format_type_name.h"
3231
#include "common/decl.h"
32+
#include "common/format_type_name.h"
3333
#include "common/standard_definitions.h"
3434
#include "common/type.h"
3535
#include "common/type_kind.h"
@@ -657,14 +657,14 @@ bool TypeInferenceContext::AssignabilityContext::IsAssignable(const Type& from,
657657
std::string TypeInferenceContext::DebugString() const {
658658
return absl::StrCat(
659659
"type_parameter_bindings: ",
660-
absl::StrJoin(
661-
type_parameter_bindings_, "\n ",
662-
[](std::string* out, const auto& binding) {
663-
absl::StrAppend(
664-
out, binding.first, " (", binding.second.name, ") -> ",
665-
checker_internal::FormatTypeName(
666-
binding.second.type.value_or(Type(TypeParamType("none")))));
667-
}));
660+
absl::StrJoin(type_parameter_bindings_, "\n ",
661+
[](std::string* out, const auto& binding) {
662+
absl::StrAppend(
663+
out, binding.first, " (", binding.second.name,
664+
") -> ",
665+
cel::FormatTypeName(binding.second.type.value_or(
666+
Type(TypeParamType("none")))));
667+
}));
668668
}
669669

670670
void TypeInferenceContext::AssignabilityContext::

common/BUILD

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,17 @@ cc_library(
601601
],
602602
)
603603

604+
cc_library(
605+
name = "format_type_name",
606+
srcs = ["format_type_name.cc"],
607+
hdrs = ["format_type_name.h"],
608+
deps = [
609+
":type",
610+
":type_kind",
611+
"@com_google_absl//absl/strings",
612+
],
613+
)
614+
604615
cc_test(
605616
name = "type_test",
606617
srcs = glob([
@@ -623,6 +634,18 @@ cc_test(
623634
],
624635
)
625636

637+
cc_test(
638+
name = "format_type_name_test",
639+
srcs = ["format_type_name_test.cc"],
640+
deps = [
641+
":format_type_name",
642+
":type",
643+
"//internal:testing",
644+
"@com_google_cel_spec//proto/cel/expr/conformance/proto2:test_all_types_cc_proto",
645+
"@com_google_protobuf//:protobuf",
646+
],
647+
)
648+
626649
cc_library(
627650
name = "value",
628651
srcs = glob(
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#include "checker/internal/format_type_name.h"
14+
#include "common/format_type_name.h"
1515

1616
#include <string>
1717
#include <vector>
@@ -20,7 +20,7 @@
2020
#include "common/type.h"
2121
#include "common/type_kind.h"
2222

23-
namespace cel::checker_internal {
23+
namespace cel {
2424

2525
namespace {
2626
struct FormatImplRecord {
@@ -177,4 +177,4 @@ std::string FormatTypeName(const Type& type) {
177177
return out;
178178
}
179179

180-
} // namespace cel::checker_internal
180+
} // namespace cel
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_FORMAT_TYPE_NAME_H_
16-
#define THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_FORMAT_TYPE_NAME_H_
15+
#ifndef THIRD_PARTY_CEL_CPP_COMMON_FORMAT_TYPE_NAME_H_
16+
#define THIRD_PARTY_CEL_CPP_COMMON_FORMAT_TYPE_NAME_H_
1717

1818
#include <string>
1919

2020
#include "common/type.h"
2121

22-
namespace cel::checker_internal {
22+
namespace cel {
2323

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

28-
} // namespace cel::checker_internal
28+
} // namespace cel
2929

30-
#endif // THIRD_PARTY_CEL_CPP_CHECKER_INTERNAL_FORMAT_TYPE_NAME_H_
30+
#endif // THIRD_PARTY_CEL_CPP_COMMON_FORMAT_TYPE_NAME_H_
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "checker/internal/format_type_name.h"
15+
#include "common/format_type_name.h"
1616

1717
#include "common/type.h"
1818
#include "internal/testing.h"
1919
#include "cel/expr/conformance/proto2/test_all_types.pb.h"
2020
#include "google/protobuf/arena.h"
2121

22-
namespace cel::checker_internal {
22+
namespace cel {
2323
namespace {
2424

2525
using ::cel::expr::conformance::proto2::GlobalEnum_descriptor;
@@ -115,4 +115,4 @@ TEST(FormatTypeNameTest, ArbitraryNesting) {
115115
#endif
116116

117117
} // namespace
118-
} // namespace cel::checker_internal
118+
} // namespace cel

0 commit comments

Comments
 (0)