Merge `TypeMapper` back into `Importer` - part 4/N: `ConvertQualType`.
This CL is one of steps toward merging `TypeMapper` back into
`Importer`. The merge is:
- possible (after https://github.com/google/crubit/commit/16a5610d96eda5720bb57b5f927b00f00635ddf0 which means that there is only 1 instance
of `TypeMapper`, because `ImportFields` doesn't anymore need to
temporarily assume that the containing record can be imported),
- desirable (to support b/228868369 we need to let `ConvertType` call
into `Importer::ConvertTemplateSpecializationType`).
This CL moves the `TypeMapper::ConvertQualType` method into a method of
`Importer`. This requires also moving `ConvertType` and
`ConvertTypeDecl` methods.
PiperOrigin-RevId: 451510529
diff --git a/rs_bindings_from_cc/importer.cc b/rs_bindings_from_cc/importer.cc
index 3d193fd..d132772 100644
--- a/rs_bindings_from_cc/importer.cc
+++ b/rs_bindings_from_cc/importer.cc
@@ -609,12 +609,12 @@
type_string, import_status.message()));
}
- return type_mapper_.ConvertTypeDecl(specialization_decl);
+ return ConvertTypeDecl(specialization_decl);
}
-absl::StatusOr<MappedType> TypeMapper::ConvertTypeDecl(
+absl::StatusOr<MappedType> Importer::ConvertTypeDecl(
const clang::TypeDecl* decl) const {
- if (!known_type_decls_.contains(decl)) {
+ if (!HasBeenAlreadySuccessfullyImported(decl)) {
return absl::NotFoundError(absl::Substitute(
"No generated bindings found for '$0'", decl->getNameAsString()));
}
@@ -623,14 +623,14 @@
return MappedType::WithDeclId(decl_id);
}
-absl::StatusOr<MappedType> TypeMapper::ConvertType(
+absl::StatusOr<MappedType> Importer::ConvertType(
const clang::Type* type,
std::optional<clang::tidy::lifetimes::ValueLifetimes>& lifetimes,
bool nullable) const {
// Qualifiers are handled separately in ConvertQualType().
std::string type_string = clang::QualType(type, 0).getAsString();
- if (auto maybe_mapped_type = MapKnownCcTypeToRsType(type_string);
+ if (auto maybe_mapped_type = type_mapper_.MapKnownCcTypeToRsType(type_string);
maybe_mapped_type.has_value()) {
return MappedType::Simple(std::string(*maybe_mapped_type), type_string);
} else if (type->isPointerType() || type->isLValueReferenceType() ||
@@ -717,7 +717,7 @@
break;
default:
if (builtin_type->isIntegerType()) {
- auto size = ctx_->getTypeSize(builtin_type);
+ auto size = ctx_.getTypeSize(builtin_type);
if (size == 8 || size == 16 || size == 32 || size == 64) {
return MappedType::Simple(
absl::Substitute(
@@ -745,7 +745,7 @@
"Unsupported clang::Type class '", type->getTypeClassName(), "'"));
}
-absl::StatusOr<MappedType> TypeMapper::ConvertQualType(
+absl::StatusOr<MappedType> Importer::ConvertQualType(
clang::QualType qual_type,
std::optional<clang::tidy::lifetimes::ValueLifetimes>& lifetimes,
bool nullable) const {