@@ -1731,6 +1731,16 @@ bool Converter::VisitCXXBoolLiteralExpr(clang::CXXBoolLiteralExpr *expr) {
17311731 return false ;
17321732}
17331733
1734+ void Converter::ConvertIntegerToEnumeralCast (clang::Expr *to,
1735+ clang::Expr *from) {
1736+ StrCat (GetUnsafeTypeAsString (to->getType ()), " ::from" );
1737+ PushParen paren (*this );
1738+ Convert (from);
1739+ if (!from->getType ()->isSpecificBuiltinType (clang::BuiltinType::Int)) {
1740+ StrCat (keyword::kAs , " i32" );
1741+ }
1742+ }
1743+
17341744bool Converter::VisitImplicitCastExpr (clang::ImplicitCastExpr *expr) {
17351745 auto *sub_expr = expr->getSubExpr ();
17361746 auto type = expr->getType ();
@@ -1847,10 +1857,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) {
18471857 break ;
18481858 }
18491859 if (type->isEnumeralType () && !sub_expr->getType ()->isEnumeralType ()) {
1850- StrCat (std::format (" {}::from" , GetUnsafeTypeAsString (type)));
1851- PushParen paren (*this );
1852- Convert (sub_expr);
1853- StrCat (keyword::kAs , " i32" );
1860+ ConvertIntegerToEnumeralCast (expr, sub_expr);
18541861 break ;
18551862 }
18561863 {
@@ -1898,10 +1905,7 @@ bool Converter::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
18981905 return false ;
18991906 }
19001907 if (type->isEnumeralType () && !sub_expr->getType ()->isEnumeralType ()) {
1901- StrCat (std::format (" {}::from" , GetUnsafeTypeAsString (type)));
1902- PushParen paren (*this );
1903- Convert (sub_expr);
1904- StrCat (keyword::kAs , " i32" );
1908+ ConvertIntegerToEnumeralCast (expr, sub_expr);
19051909 return false ;
19061910 }
19071911 {
0 commit comments