On Thu, Sep 12, 2013 at 09:45:35AM -0700, Argyrios Kyrtzidis wrote:
> Since libclang is supposed to be somewhat higher level and closer to the 
> source, could we just report a DecayedType as the original (as written) one ?
> Or do you have a specific use case where you need to know that it is a 
> DecayedType ?

Not really. So something like attached patch instead?

thanks
commit af7e84d9e7596054b1298f6f45228f1c96618b6c
Author: Anders Waldenborg <[email protected]>
Date:   Fri Sep 13 09:46:56 2013 +0200

    [libclang] Handle decayed type as the original type

diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py
index ed3d65c..62968d6 100644
--- a/bindings/python/tests/cindex/test_type.py
+++ b/bindings/python/tests/cindex/test_type.py
@@ -369,3 +369,13 @@ struct Test {
         assert teststruct.type.get_offset("bar") == bar
 
 
+def test_decay():
+    """Ensure decayed types are handled as the original type"""
+
+    tu = get_tu("void foo(int a[]);")
+    foo = get_cursor(tu, 'foo')
+    a = foo.type.argument_types()[0]
+
+    assert a.kind == TypeKind.INCOMPLETEARRAY
+    assert a.element_type.kind == TypeKind.INT
+    assert a.get_canonical().kind == TypeKind.INCOMPLETEARRAY
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index dcf69b5..a7d6386 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -110,6 +110,11 @@ CXType cxtype::MakeCXType(QualType T, CXTranslationUnit TU) {
       else if (Ctx.isObjCSelType(UnqualT))
         TK = CXType_ObjCSel;
     }
+
+    /* Handle decayed types as the original type */
+    if (const DecayedType *DT = T->getAs<DecayedType>()) {
+      return MakeCXType(DT->getOriginalType(), TU);
+    }
   }
   if (TK == CXType_Invalid)
     TK = GetTypeKind(T);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to