@@ -65,9 +65,9 @@ bool Converter::Convert(clang::QualType qual_type) {
6565 return false ;
6666 }
6767
68- if (Mapper::Contains (qual_type) &&
69- Mapper::Map (qual_type) != ignore_rule_type_) {
70- StrCat (Mapper::Map (qual_type) );
68+ if (auto mapped = Mapper::Map (qual_type);
69+ mapped && *mapped != ignore_rule_type_) {
70+ StrCat (*mapped );
7171 return false ;
7272 }
7373
@@ -76,7 +76,7 @@ bool Converter::Convert(clang::QualType qual_type) {
7676}
7777
7878bool Converter::ConvertMappedType (clang::QualType qual_type) {
79- std::string type_as_string = Mapper::Map (qual_type);
79+ std::string type_as_string = Mapper::Map (qual_type). value_or (std::string{}) ;
8080 if (type_as_string == ignore_rule_type_) {
8181 return false ;
8282 }
@@ -551,7 +551,7 @@ static bool recordDerivesCopy(const clang::RecordDecl *decl) {
551551 for (auto f : decl->fields ()) {
552552 // Records that contain std::vector, std::array, std::string or anything
553553 // that is translated to Vec<>, do not derive Copy
554- auto mapped = Mapper::Map (f->getType ());
554+ auto mapped = Mapper::Map (f->getType ()). value_or (std::string{}) ;
555555 if (mapped.starts_with (" Vec<" )) {
556556 return false ;
557557 }
@@ -1105,7 +1105,7 @@ bool Converter::VisitCXXForRangeStmtMap(clang::CXXForRangeStmt *stmt) {
11051105 auto loop_var_name = GetNamedDeclAsString (loop_var);
11061106
11071107 StrCat (" 'loop_:" );
1108- auto map_type = Mapper::Map (stmt->getRangeInit ()->getType ());
1108+ auto map_type = Mapper::Map (stmt->getRangeInit ()->getType ()). value_or (std::string{}) ;
11091109 StrCat (keyword::kFor , loop_var_name, keyword::kIn ,
11101110 " UnsafeMapIterator::begin(&" );
11111111 Convert (stmt->getRangeInit ());
@@ -1234,7 +1234,7 @@ bool Converter::GetFmtArg(clang::Expr *arg, std::string &fmt,
12341234 fmt_width.erase (0 , fmt_width.find_first_not_of (' ' ));
12351235 fmt_width.erase (fmt_width.find_last_not_of (' ' ) + 1 );
12361236 } else if (!arg->getType ()->isCharType () &&
1237- Mapper::Map (arg->getType ()) != " Vec<u8>" ) {
1237+ Mapper::Map (arg->getType ()). value_or (std::string{}) != " Vec<u8>" ) {
12381238 fmt += (" {:" + fmt_width + fmt_trait + " }" );
12391239 fmt_width.clear (); // Reset setw after first usage
12401240 arg_str = ToString (arg);
@@ -1251,7 +1251,7 @@ bool Converter::GetFmtArg(clang::Expr *arg, std::string &fmt,
12511251bool Converter::GetRawArg (clang::Expr *arg, std::string &raw_args) {
12521252 if (arg->getType ()->isCharType ()) {
12531253 raw_args += " (&[" + ToString (arg) + " ]" ;
1254- } else if (Mapper::Map (arg->getType ()) == " Vec<u8>" ) {
1254+ } else if (Mapper::Map (arg->getType ()). value_or (std::string{}) == " Vec<u8>" ) {
12551255 PushExprKind push (*this , ExprKind::RValue);
12561256 std::string str = ToString (arg);
12571257 raw_args += " (&(" + str + " )[..(" + str + " ).len() - 1]" ;
@@ -1630,7 +1630,7 @@ std::string Converter::getIntegerLiteral(clang::IntegerLiteral *expr,
16301630}
16311631
16321632bool Converter::VisitIntegerLiteral (clang::IntegerLiteral *expr) {
1633- StrCat (getIntegerLiteral (expr, Mapper::Map (expr->getType ()) != " i32" ));
1633+ StrCat (getIntegerLiteral (expr, Mapper::Map (expr->getType ()). value_or (std::string{}) != " i32" ));
16341634 computed_expr_type_ = ComputedExprType::FreshValue;
16351635 return false ;
16361636}
@@ -2672,7 +2672,7 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
26722672 }
26732673 Mapper::AddRuleForUserDefinedType (decl);
26742674 StrCat (" #[derive(Clone, Copy, PartialEq, Debug, Default)]" );
2675- StrCat (std::format (" enum {}" , Mapper::Map (ctx_.getCanonicalTagType (decl))));
2675+ StrCat (std::format (" enum {}" , Mapper::Map (ctx_.getCanonicalTagType (decl)). value_or (std::string{}) ));
26762676 StrCat (" {" );
26772677 bool first_enumerator = true ;
26782678 for (auto e : decl->enumerators ()) {
@@ -3055,9 +3055,11 @@ void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) {
30553055void Converter::ConvertUnsignedArithOperand (clang::Expr *expr,
30563056 clang::QualType type) {
30573057 Convert (expr);
3058+ auto expr_mapped = Mapper::Map (expr->getType ()).value_or (std::string{});
3059+ auto type_mapped = Mapper::Map (type).value_or (std::string{});
30583060 if ((expr->isIntegerConstantExpr (ctx_) &&
30593061 !clang::isa<clang::ImplicitCastExpr>(expr)) ||
3060- Mapper::Map (expr-> getType ()) != Mapper::Map (type) ) {
3062+ expr_mapped != type_mapped ) {
30613063 ConvertCast (type);
30623064 }
30633065}
0 commit comments