Added the ability to get function return and argument types to SBType():
authorGreg Clayton <gclayton@apple.com>
Tue, 30 Oct 2012 16:57:17 +0000 (16:57 +0000)
committerGreg Clayton <gclayton@apple.com>
Tue, 30 Oct 2012 16:57:17 +0000 (16:57 +0000)
     bool
     SBType::IsFunctionType ();

     lldb::SBType
     SBType::GetFunctionReturnType ();

     lldb::SBTypeList
     SBType::GetFunctionArgumentTypes ();

llvm-svn: 167023

lldb/include/lldb/API/SBType.h
lldb/scripts/Python/interface/SBType.i
lldb/source/API/SBType.cpp

index 85dfcf4..14ee24d 100644 (file)
@@ -90,6 +90,9 @@ public:
     bool
     IsReferenceType();
     
+    bool
+    IsFunctionType ();
+    
     lldb::SBType
     GetPointerType();
     
@@ -141,6 +144,12 @@ public:
     lldb::TemplateArgumentKind
     GetTemplateArgumentKind (uint32_t idx);
 
+    lldb::SBType
+    GetFunctionReturnType ();
+
+    lldb::SBTypeList
+    GetFunctionArgumentTypes ();
+
     const char*
     GetName();
     
index 76fdfc9..82dff14 100644 (file)
@@ -161,6 +161,9 @@ public:
 
     bool
     IsReferenceType();
+    
+    bool
+    IsFunctionType ();
 
     lldb::SBType
     GetPointerType();
@@ -216,6 +219,12 @@ public:
     lldb::TemplateArgumentKind
     GetTemplateArgumentKind (uint32_t idx);
     
+    lldb::SBType
+    GetFunctionReturnType ();
+    
+    lldb::SBTypeList
+    GetFunctionArgumentTypes ();
+
     bool
     IsTypeComplete ();
 
@@ -240,7 +249,10 @@ public:
         
         __swig_getmethods__["is_reference"] = IsReferenceType
         if _newclass: is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a reference type.''')
-
+        
+        __swig_getmethods__["is_function"] = IsFunctionType
+        if _newclass: is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a function type.''')
+        
         __swig_getmethods__["num_fields"] = GetNumberOfFields
         if _newclass: num_fields = property(GetNumberOfFields, None, doc='''A read only property that returns number of fields in this type as an integer.''')
         
index 3e6d8f5..7387ed3 100644 (file)
@@ -219,6 +219,51 @@ SBType::GetDereferencedType()
     return SBType(ClangASTType(m_opaque_sp->GetASTContext(),qt.getNonReferenceType().getAsOpaquePtr()));
 }
 
+bool 
+SBType::IsFunctionType ()
+{
+    if (IsValid())
+    {
+        QualType qual_type(QualType::getFromOpaquePtr(m_opaque_sp->GetOpaqueQualType()));
+        const FunctionProtoType* func = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
+        return func != NULL;
+    }
+    return false;
+}
+
+lldb::SBType
+SBType::GetFunctionReturnType ()
+{
+    if (IsValid())
+    {
+        QualType qual_type(QualType::getFromOpaquePtr(m_opaque_sp->GetOpaqueQualType()));
+        const FunctionProtoType* func = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
+        
+        if (func)
+            return SBType(ClangASTType(m_opaque_sp->GetASTContext(),
+                                       func->getResultType().getAsOpaquePtr()));
+    }
+    return lldb::SBType();
+}
+
+lldb::SBTypeList
+SBType::GetFunctionArgumentTypes ()
+{
+    SBTypeList sb_type_list;
+    if (IsValid())
+    {
+        QualType qual_type(QualType::getFromOpaquePtr(m_opaque_sp->GetOpaqueQualType()));
+        const FunctionProtoType* func = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
+        if (func)
+        {
+            const uint32_t num_args = func->getNumArgs();
+            for (uint32_t i=0; i<num_args; ++i)
+                sb_type_list.Append (SBType(ClangASTType(m_opaque_sp->GetASTContext(), func->getArgType(i).getAsOpaquePtr())));
+        }
+    }
+    return sb_type_list;
+}
+
 lldb::SBType
 SBType::GetUnqualifiedType()
 {