Add more fundamental types.
This adds boolean, char, and floating point types.
A few notes:
* We can't map any C++ type to Rust `char`, because that type only allows UTF
scalar values, not any integer
* I am not importing `long double`, because Rust has no support for that
* I could have imported `__int128_t` and `__int128_t`, but decided not to,
for now.
* I think we don't need to map the `nullptr` type?
PiperOrigin-RevId: 397685256
diff --git a/rs_bindings_from_cc/ast_visitor.cc b/rs_bindings_from_cc/ast_visitor.cc
index 5d34546..71b45e5 100644
--- a/rs_bindings_from_cc/ast_visitor.cc
+++ b/rs_bindings_from_cc/ast_visitor.cc
@@ -136,17 +136,29 @@
}
} else if (const clang::BuiltinType* builtin_type =
qual_type->getAs<clang::BuiltinType>()) {
- if (builtin_type->isIntegerType()) {
- // TODO(forster): This includes enums, which is incorrect.
- auto size = ctx.getTypeSize(builtin_type);
- if (size == 8 || size == 16 || size == 32 || size == 64) {
- type =
- Type{absl::Substitute(
- "$0$1", builtin_type->isSignedInteger() ? 'i' : 'u', size),
- type_string};
- }
- } else if (builtin_type->isVoidType()) {
- type = Type::Void();
+ switch (builtin_type->getKind()) {
+ case clang::BuiltinType::Bool:
+ type = {"bool", "bool"};
+ break;
+ case clang::BuiltinType::Float:
+ type = {"float", "float"};
+ break;
+ case clang::BuiltinType::Double:
+ type = {"double", "double"};
+ break;
+ case clang::BuiltinType::Void:
+ type = Type::Void();
+ break;
+ default:
+ if (builtin_type->isIntegerType()) {
+ auto size = ctx.getTypeSize(builtin_type);
+ if (size == 8 || size == 16 || size == 32 || size == 64) {
+ type = Type{
+ absl::Substitute(
+ "$0$1", builtin_type->isSignedInteger() ? 'i' : 'u', size),
+ type_string};
+ }
+ }
}
}