[Lldb-commits] [lldb] r115290 - in /lldb/trunk: source/Symbol/ClangASTContext.cpp test/class_types/main.cpp

Greg Clayton gclayton at apple.com
Thu Sep 30 20:45:20 PDT 2010


Author: gclayton
Date: Thu Sep 30 22:45:20 2010
New Revision: 115290

URL: http://llvm.org/viewvc/llvm-project?rev=115290&view=rev
Log:
Added correct C++ method declarations for destructors and for conversion
operators.


Modified:
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/test/class_types/main.cpp

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=115290&r1=115289&r2=115290&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Sep 30 22:45:20 2010
@@ -853,13 +853,36 @@
     CXXMethodDecl *cxx_method_decl = NULL;
     
     DeclarationName decl_name (&identifier_table->get(name));
+
+    DeclarationNameInfo decl_name_info (decl_name, SourceLocation());
+    const bool is_implicitly_declared = false;
+    
+    clang::Type *method_type(method_qual_type.getTypePtr());
+    
+    if (method_type == NULL)
+        return NULL;
+
+    FunctionProtoType *method_function_prototype (dyn_cast<FunctionProtoType>(method_type));
     
-    if (name[0] == '~' || decl_name == record_decl->getDeclName())
+    if (!method_function_prototype)
+        return NULL;
+    
+    unsigned int num_params = method_function_prototype->getNumArgs();
+    
+    if (name[0] == '~')
+    {
+        cxx_method_decl = CXXDestructorDecl::Create (*ast_context,
+                                                     cxx_record_decl,
+                                                     decl_name_info,
+                                                     method_qual_type,
+                                                     is_inline,
+                                                     is_implicitly_declared);
+    }
+    else if (decl_name == record_decl->getDeclName())
     {
-        bool is_implicitly_declared = false;
         cxx_method_decl = CXXConstructorDecl::Create (*ast_context,
                                                       cxx_record_decl,
-                                                      DeclarationNameInfo (decl_name, SourceLocation()),
+                                                      decl_name_info,
                                                       method_qual_type,
                                                       NULL, // TypeSourceInfo *
                                                       is_explicit, 
@@ -867,15 +890,33 @@
                                                       is_implicitly_declared);
     }
     else
-    {    
-        cxx_method_decl = CXXMethodDecl::Create (*ast_context,
-                                                 cxx_record_decl,
-                                                 DeclarationNameInfo (decl_name, SourceLocation()),
-                                                 method_qual_type,
-                                                 NULL, // TypeSourceInfo *
-                                                 is_static,
-                                                 SC_None,
-                                                 is_inline);
+    {   
+        // TODO: verify this is an ok way to see if this is a C++ conversion
+        // operator. I am currently checking for "operator " following by a valid
+        // first character of a type name (A-Z, a-z, or _)...
+        if ((num_params == 0) && 
+            (::strstr(name, "operator ") == name) &&
+            (::isalpha(name[9]) || name[9] == '_'))
+        {
+            cxx_method_decl = CXXConversionDecl::Create (*ast_context,
+                                                         cxx_record_decl,
+                                                         decl_name_info,
+                                                         method_qual_type,
+                                                         NULL, // TypeSourceInfo *
+                                                         is_inline,
+                                                         is_explicit);
+        }
+        else
+        {
+            cxx_method_decl = CXXMethodDecl::Create (*ast_context,
+                                                     cxx_record_decl,
+                                                     decl_name_info,
+                                                     method_qual_type,
+                                                     NULL, // TypeSourceInfo *
+                                                     is_static,
+                                                     SC_None,
+                                                     is_inline);
+        }
     }
         
     
@@ -885,17 +926,6 @@
     cxx_method_decl->setVirtualAsWritten (is_virtual);
     
     // Populate the method decl with parameter decls
-    clang::Type *method_type(method_qual_type.getTypePtr());
-    
-    if (method_type == NULL)
-        return NULL;
-    
-    FunctionProtoType *method_function_prototype (dyn_cast<FunctionProtoType>(method_type));
-    
-    if (!method_function_prototype)
-        return NULL;
-    
-    unsigned int num_params = method_function_prototype->getNumArgs();
     
     ParmVarDecl *params[num_params];
     

Modified: lldb/trunk/test/class_types/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/main.cpp?rev=115290&r1=115289&r2=115290&view=diff
==============================================================================
--- lldb/trunk/test/class_types/main.cpp (original)
+++ lldb/trunk/test/class_types/main.cpp Thu Sep 30 22:45:20 2010
@@ -7,6 +7,22 @@
 //
 //===----------------------------------------------------------------------===//
 
+class Conversion
+{
+public:
+    Conversion (int i) :
+      m_i (i)
+      {}
+
+    operator bool()
+    {
+        return m_i != 0;
+    }
+    
+private:
+    int m_i;
+};
+
 class A
 {
 public:
@@ -103,5 +119,8 @@
     A a(12);
     B b(22,33);
     C c(44,55,66);
-    return b.GetIntegerB() - a.GetInteger() + c.GetInteger();
+    Conversion conv(1);
+    if (conv)
+        return b.GetIntegerB() - a.GetInteger() + c.GetInteger();
+    return 0;
 }





More information about the lldb-commits mailing list