Added a temporary hack to allow casting of Objective-C
method results to int.  This will only last until we
get accurate type information for Objective-C methods
or some way of making their types inferred by the
parser.


git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@117178 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangUserExpression.cpp b/source/Expression/ClangUserExpression.cpp
index 0e454a7..d2b35ba 100644
--- a/source/Expression/ClangUserExpression.cpp
+++ b/source/Expression/ClangUserExpression.cpp
@@ -72,7 +72,26 @@
         m_objectivec = true;
 }
 
-bool 
+// This is a really nasty hack, meant to fix Objective-C expressions of the form
+// (int)[myArray count].  Right now, because the type information for 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)["
+
+    size_t from_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
+}
+
+bool
 ClangUserExpression::Parse (Stream &error_stream, ExecutionContext &exe_ctx)
 {
     Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
@@ -84,11 +103,13 @@
     ////////////////////////////////////
     // Generate the expression
     //
+    
+    ApplyObjcCastHack(m_expr_text);
 
     if (m_cplusplus)
     {
         m_transformed_stream.Printf("void                                   \n"
-                                    "$__lldb_class::%s(void *$__lldb_arg) \n"
+                                    "$__lldb_class::%s(void *$__lldb_arg)   \n"
                                     "{                                      \n"
                                     "    %s;                                \n" 
                                     "}                                      \n",
@@ -100,7 +121,7 @@
     else
     {
         m_transformed_stream.Printf("void                           \n"
-                                    "%s(void *$__lldb_arg)         \n"
+                                    "%s(void *$__lldb_arg)          \n"
                                     "{                              \n"
                                     "    %s;                        \n" 
                                     "}                              \n",