[Lldb-commits] [lldb] r120606 - in /lldb/trunk: include/lldb/Expression/ClangUserExpression.h include/lldb/Symbol/ClangASTType.h source/Expression/ClangUserExpression.cpp source/Symbol/ClangASTType.cpp

Sean Callanan scallanan at apple.com
Wed Dec 1 13:35:54 PST 2010


Author: spyffe
Date: Wed Dec  1 15:35:54 2010
New Revision: 120606

URL: http://llvm.org/viewvc/llvm-project?rev=120606&view=rev
Log:
Fixed ClangUserExpression's wrapping of expressions
in C++ methods.  There were two fixes involved:

 - For an object whose contents are not known, the
   expression should be treated as a non-member, and
   "this" should have no meaning.

 - For a const object, the method should be declared
   const as well.

Modified:
    lldb/trunk/include/lldb/Expression/ClangUserExpression.h
    lldb/trunk/include/lldb/Symbol/ClangASTType.h
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Symbol/ClangASTType.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=120606&r1=120605&r2=120606&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Wed Dec  1 15:35:54 2010
@@ -272,6 +272,7 @@
     bool                                        m_cplusplus;            ///< True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was in a C++ method).
     bool                                        m_objectivec;           ///< True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was in an Objective-C method).
     bool                                        m_needs_object_ptr;     ///< True if "this" or "self" must be looked up and passed in.  False if the expression doesn't really use them and they can be NULL.
+    bool                                        m_const_object;         ///< True if "this" is const.
 };
     
 } // namespace lldb_private

Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=120606&r1=120605&r2=120606&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Wed Dec  1 15:35:54 2010
@@ -197,6 +197,12 @@
     IsDefined (lldb::clang_type_t opaque_clang_qual_type);
 
     bool
+    IsConst();
+    
+    static bool
+    IsConst (lldb::clang_type_t opaque_clang_qual_type);
+    
+    bool
     SetValueFromScalar (const Scalar &value,
                         Stream &strm);
 

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=120606&r1=120605&r2=120606&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Wed Dec  1 15:35:54 2010
@@ -47,6 +47,7 @@
     m_cplusplus(false),
     m_objectivec(false),
     m_needs_object_ptr(false),
+    m_const_object(false),
     m_desired_type(NULL, NULL)
 {
 }
@@ -73,10 +74,31 @@
     if (!vars)
         return;
     
-    if (vars->FindVariable(ConstString("this")).get())
-        m_cplusplus = true;
-    else if (vars->FindVariable(ConstString("self")).get())
+    lldb::VariableSP this_var(vars->FindVariable(ConstString("this")));
+    lldb::VariableSP self_var(vars->FindVariable(ConstString("self")));
+    
+    if (this_var.get())
+    {
+        Type *this_type = this_var->GetType();
+        
+        lldb::clang_type_t pointer_target_type;
+        
+        if (ClangASTContext::IsPointerType(this_type->GetClangType(),
+                                           &pointer_target_type))
+        {
+            TypeFromUser target_ast_type(pointer_target_type, this_type->GetClangAST());
+            
+            if (target_ast_type.IsDefined())
+                m_cplusplus = true;
+            
+            if (target_ast_type.IsConst())
+                m_const_object = true;
+        }
+    }
+    else if (self_var.get())
+    {
         m_objectivec = true;
+    }
 }
 
 // This is a really nasty hack, meant to fix Objective-C expressions of the form
@@ -141,12 +163,13 @@
         m_transformed_stream.Printf("%s                                     \n"
                                     "typedef unsigned short unichar;        \n"
                                     "void                                   \n"
-                                    "$__lldb_class::%s(void *$__lldb_arg)   \n"
+                                    "$__lldb_class::%s(void *$__lldb_arg) %s\n"
                                     "{                                      \n"
                                     "    %s;                                \n" 
                                     "}                                      \n",
                                     m_expr_prefix.c_str(),
                                     FunctionName(),
+                                    (m_const_object ? "const" : ""),
                                     m_expr_text.c_str());
         
         m_needs_object_ptr = true;

Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=120606&r1=120605&r2=120606&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Wed Dec  1 15:35:54 2010
@@ -812,7 +812,6 @@
     return ClangASTType::IsDefined (m_type);
 }
 
-
 bool
 ClangASTType::IsDefined (clang_type_t clang_type)
 {
@@ -838,6 +837,20 @@
     return true;
 }
 
+bool
+ClangASTType::IsConst()
+{
+    return ClangASTType::IsConst (m_type);
+}
+
+bool
+ClangASTType::IsConst (lldb::clang_type_t clang_type)
+{
+    clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
+    
+    return qual_type.isConstQualified();
+}
+
 void
 ClangASTType::DumpTypeDescription (Stream *s)
 {





More information about the lldb-commits mailing list