Reland "[lldb][NFC] Make ApplyObjcCastHack less scary"
authorRaphael Isemann <teemperor@gmail.com>
Tue, 17 Sep 2019 07:58:01 +0000 (07:58 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Tue, 17 Sep 2019 07:58:01 +0000 (07:58 +0000)
First version had a typo.

llvm-svn: 372077

lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp

index 57bf654..40667c6 100644 (file)
@@ -313,17 +313,13 @@ void ClangUserExpression::ScanContext(ExecutionContext &exe_ctx, Status &err) {
 // count is not available, [myArray count] returns id, which can't be directly
 // cast to int without causing a clang error.
 static void ApplyObjcCastHack(std::string &expr) {
-#define OBJC_CAST_HACK_FROM "(int)["
-#define OBJC_CAST_HACK_TO "(int)(long long)["
+  const std::string from = "(int)[";
+  const std::string to = "(int)(long long)[";
 
-  size_t from_offset;
+  size_t offset;
 
-  while ((from_offset = expr.find(OBJC_CAST_HACK_FROM)) != expr.npos)
-    expr.replace(from_offset, sizeof(OBJC_CAST_HACK_FROM) - 1,
-                 OBJC_CAST_HACK_TO);
-
-#undef OBJC_CAST_HACK_TO
-#undef OBJC_CAST_HACK_FROM
+  while ((offset = expr.find(from)) != expr.npos)
+    expr.replace(offset, from.size(), to);
 }
 
 bool ClangUserExpression::SetupPersistentState(DiagnosticManager &diagnostic_manager,