@@ -86,6 +86,19 @@ bool Converter::ConvertMappedType(clang::QualType qual_type) {
8686 return true ;
8787}
8888
89+ std::string Converter::ConvertPointeeType (clang::QualType ptr_type) {
90+ assert (!ptr_type.isNull () && ptr_type->isPointerType ());
91+ auto pointee = ptr_type->getPointeeType ();
92+ if (!pointee->isRecordType ()) {
93+ return ToString (pointee);
94+ }
95+
96+ auto str = ToString (ptr_type);
97+ Unwrap (str, " *mut " , " " );
98+ Unwrap (str, " *const " , " " );
99+ return str;
100+ }
101+
89102bool Converter::VisitBuiltinType (clang::BuiltinType *type) {
90103 switch (type->getKind ()) {
91104 case clang::BuiltinType::Bool:
@@ -216,9 +229,8 @@ bool Converter::VisitIncompleteArrayType(clang::IncompleteArrayType *type) {
216229}
217230
218231bool Converter::VisitLValueReferenceType (clang::LValueReferenceType *type) {
219- StrCat (token::kStar );
220232 auto pointee_type = type->getPointeeType ();
221- StrCat (pointee_type.isConstQualified () ? keyword:: kConst : keyword_mut_ );
233+ StrCat (pointee_type.isConstQualified () ? " *const " : " *mut " );
222234 return Convert (pointee_type);
223235}
224236
@@ -250,9 +262,8 @@ bool Converter::VisitPointerType(clang::PointerType *type) {
250262 return false ;
251263 }
252264
253- StrCat (token::kStar );
254265 auto pointee_type = type->getPointeeType ();
255- StrCat (pointee_type.isConstQualified () ? keyword:: kConst : keyword_mut_ );
266+ StrCat (pointee_type.isConstQualified () ? " *const " : " *mut " );
256267 if (pointee_type->isRecordType () &&
257268 abstract_structs_.contains (GetID (pointee_type->getAsRecordDecl ()))) {
258269 StrCat (keyword::kDyn );
@@ -1850,7 +1861,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
18501861 if (type->isVoidPointerType ()) {
18511862 StrCat (keyword::kAs ,
18521863 type->getPointeeType ().isConstQualified () ? " *const" : " *mut" );
1853- Convert ( sub_expr->getType ()-> getPointeeType ( ));
1864+ StrCat ( ConvertPointeeType ( sub_expr->getType ()));
18541865 }
18551866 ConvertCast (type);
18561867 break ;
@@ -2109,7 +2120,7 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) {
21092120 StrCat (keyword::kAs , " usize" );
21102121 }
21112122 StrCat (token::kDiv );
2112- auto pointee_type_as_string = ToString (lhs_type-> getPointeeType () );
2123+ auto pointee_type_as_string = ConvertPointeeType (lhs_type);
21132124 auto size_of_as_string =
21142125 std::format (" ::std::mem::size_of::<{}>()" , pointee_type_as_string);
21152126 StrCat (size_of_as_string);
0 commit comments