[Lldb-commits] [lldb] r117178 - /lldb/trunk/source/Expression/ClangUserExpression.cpp

Sean Callanan scallanan at apple.com
Fri Oct 22 16:25:16 PDT 2010


Author: spyffe
Date: Fri Oct 22 18:25:16 2010
New Revision: 117178

URL: http://llvm.org/viewvc/llvm-project?rev=117178&view=rev
Log:
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.

Modified:
    lldb/trunk/source/Expression/ClangUserExpression.cpp

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=117178&r1=117177&r2=117178&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Fri Oct 22 18:25:16 2010
@@ -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",





More information about the lldb-commits mailing list