@@ -86,19 +86,6 @@ void ConverterRefCount::PendingDeref::set_unchecked(std::string str, bool fresh,
8686 type = ComputedExprType::Pending;
8787}
8888
89- std::string
90- ConverterRefCount::GetStringLiteralCodeUnit (const clang::Expr *expr) {
91- const auto *literal = clang::dyn_cast<clang::StringLiteral>(
92- expr->IgnoreParens ()->IgnoreImplicit ());
93- if (literal == nullptr ||
94- (literal->getCharByteWidth () == 1 &&
95- literal->getKind () != clang::StringLiteralKind::UTF8 )) {
96- return " u8" ;
97- }
98- return ToStringBase (
99- ctx_.getAsArrayType (literal->getType ())->getElementType ());
100- }
101-
10289std::string ConverterRefCount::GetInnerType (clang::QualType type) {
10390 PushConversionKind push (*this , ConversionKind::Unboxed);
10491 auto str = ToString (type);
@@ -1192,23 +1179,15 @@ bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) {
11921179}
11931180
11941181bool ConverterRefCount::VisitStringLiteral (clang::StringLiteral *expr) {
1195- if (expr->getCharByteWidth () != 1 ||
1196- expr->getKind () == clang::StringLiteralKind::UTF8 ) {
1197- uint64_t pad = 1 ;
1198- if (!curr_init_type_.empty () && curr_init_type_.back ()->isArrayType ()) {
1199- if (auto *arr_ty = ctx_.getAsConstantArrayType (curr_init_type_.back ())) {
1200- uint64_t arr_size = arr_ty->getSize ().getZExtValue ();
1201- pad = arr_size > expr->getLength () ? arr_size - expr->getLength () : 0 ;
1202- }
1203- StrCat (std::format (" Box::from({})" , GetCodeUnitArrayLiteral (expr, pad)));
1204- } else {
1205- StrCat (std::format (" &{}" , GetCodeUnitArrayLiteral (expr, pad)));
1206- }
1182+ if (IsCodeUnitStringLiteral (expr)) {
1183+ auto arr = GetCodeUnitArrayLiteral (expr);
1184+ StrCat (IsArrayInitContext () ? std::format (" Box::from({})" , arr)
1185+ : ' &' + arr);
12071186 computed_expr_type_ = ComputedExprType::FreshValue;
12081187 return false ;
12091188 }
12101189
1211- if (!curr_init_type_. empty () && curr_init_type_. back ()-> isArrayType ()) {
1190+ if (IsArrayInitContext ()) {
12121191 uint64_t pad = 1 ;
12131192 if (auto *arr_ty = ctx_.getAsConstantArrayType (curr_init_type_.back ())) {
12141193 uint64_t arr_size = arr_ty->getSize ().getZExtValue ();
@@ -1301,7 +1280,10 @@ bool ConverterRefCount::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
13011280 return false ;
13021281 }
13031282 if (IsStringLiteralExpr (sub_expr)) {
1304- auto code_unit = GetStringLiteralCodeUnit (sub_expr);
1283+ auto code_unit = ToStringBase (
1284+ ctx_.getAsArrayType (
1285+ sub_expr->IgnoreParens ()->IgnoreImplicit ()->getType ())
1286+ ->getElementType ());
13051287 StrCat (std::format (" Ptr::<{}>::from_string_literal({})" , code_unit,
13061288 ToString (sub_expr->IgnoreParens ())));
13071289 computed_expr_type_ = ComputedExprType::FreshPointer;
@@ -2174,7 +2156,10 @@ std::string ConverterRefCount::ConvertVarInitValue(clang::QualType qual_type,
21742156 }
21752157 if (qual_type.getNonReferenceType ()->isArrayType ()) {
21762158 if (IsStringLiteralExpr (expr)) {
2177- auto code_unit = GetStringLiteralCodeUnit (expr);
2159+ auto code_unit = ToStringBase (
2160+ ctx_.getAsArrayType (
2161+ expr->IgnoreParens ()->IgnoreImplicit ()->getType ())
2162+ ->getElementType ());
21782163 return std::format (" Ptr::<Box<[{}]>>::from_string_literal_array({})" ,
21792164 code_unit,
21802165 ToString (expr->IgnoreParens ()->IgnoreImplicit ()));
@@ -2446,7 +2431,10 @@ void ConverterRefCount::ConvertArraySubscript(clang::Expr *base,
24462431 {
24472432 PushParen paren (*this , is_inner_boxed);
24482433 if (IsStringLiteralExpr (base)) {
2449- auto code_unit = GetStringLiteralCodeUnit (base);
2434+ auto code_unit = ToStringBase (
2435+ ctx_.getAsArrayType (
2436+ base->IgnoreParens ()->IgnoreImplicit ()->getType ())
2437+ ->getElementType ());
24502438 StrCat (std::format (" Ptr::<{}>::from_string_literal({}).offset({})" ,
24512439 code_unit,
24522440 ToString (base->IgnoreParens ()->IgnoreImplicit ()),
0 commit comments