From: Argyrios Kyrtzidis Date: Thu, 18 Apr 2013 16:41:15 +0000 (+0000) Subject: [libclang] Report parameter array types as written in source, not decayed to pointer... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7717914639ed8a186fe8b781c9c220594e8dcf30;p=clang [libclang] Report parameter array types as written in source, not decayed to pointer types. Patch by Doug. rdar://13684618 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179769 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/print-type.c b/test/Index/print-type.c index 8594994e77..4805f59f3f 100644 --- a/test/Index/print-type.c +++ b/test/Index/print-type.c @@ -11,12 +11,12 @@ int __attribute__((vector_size(16))) x; typedef int __attribute__((vector_size(16))) int4_t; // RUN: c-index-test -test-print-type %s | FileCheck %s -// CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int *] [Pointer] [void (*)(int)] [Pointer]] [isPOD=0] +// CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0] // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] // CHECK: ParmDecl=x:3:22 (Definition) [type=char *] [typekind=Pointer] [isPOD=1] // CHECK: ParmDecl=z:3:33 (Definition) [type=FooType] [typekind=Typedef] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] // CHECK: TypeRef=FooType:1:13 [type=FooType] [typekind=Typedef] [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1] -// CHECK: ParmDecl=arr:3:40 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] +// CHECK: ParmDecl=arr:3:40 (Definition) [type=int [5]] [typekind=ConstantArray] [isPOD=1] // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1] // CHECK: ParmDecl=fn:3:55 (Definition) [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1] // CHECK: ParmDecl=:3:62 (Definition) [type=int] [typekind=Int] [isPOD=1] diff --git a/test/Index/print-type.cpp b/test/Index/print-type.cpp index b99d1cb02b..49a05fbbdb 100644 --- a/test/Index/print-type.cpp +++ b/test/Index/print-type.cpp @@ -26,6 +26,9 @@ struct Bar { template T tbar(int); +template +T tbar(int[5]); + // RUN: c-index-test -test-print-type %s | FileCheck %s // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0] @@ -59,3 +62,5 @@ T tbar(int); // CHECK: TypedefDecl=ArrayType:20:15 (Definition) [type=ArrayType] [typekind=Typedef] [canonicaltype=int [5]] [canonicaltypekind=ConstantArray] [isPOD=1] // CHECK: FunctionTemplate=tbar:27:3 [type=T (int)] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0] // CHECK: TemplateTypeParameter=T:26:20 (Definition) [type=T] [typekind=Unexposed] [canonicaltype=type-parameter-0-0] [canonicaltypekind=Unexposed] [isPOD=0] +// CHECK: FunctionTemplate=tbar:30:3 [type=T (int *)] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int *)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0] +// CHECK: ParmDecl=:30:11 (Definition) [type=int [5]] [typekind=ConstantArray] [isPOD=1] diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 16009bf47a..148241597a 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -149,14 +149,20 @@ CXType clang_getCursorType(CXCursor C) { return MakeCXType(Context.getTypeDeclType(TD), TU); if (const ObjCInterfaceDecl *ID = dyn_cast(D)) return MakeCXType(Context.getObjCInterfaceType(ID), TU); + if (const DeclaratorDecl *DD = dyn_cast(D)) { + if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo()) + return MakeCXType(TSInfo->getType(), TU); + return MakeCXType(DD->getType(), TU); + } if (const ValueDecl *VD = dyn_cast(D)) return MakeCXType(VD->getType(), TU); if (const ObjCPropertyDecl *PD = dyn_cast(D)) return MakeCXType(PD->getType(), TU); - if (const FunctionDecl *FD = dyn_cast(D)) - return MakeCXType(FD->getType(), TU); - if (const FunctionTemplateDecl *FTD = dyn_cast(D)) + if (const FunctionTemplateDecl *FTD = dyn_cast(D)) { + if (TypeSourceInfo *TSInfo = FTD->getTemplatedDecl()->getTypeSourceInfo()) + return MakeCXType(TSInfo->getType(), TU); return MakeCXType(FTD->getTemplatedDecl()->getType(), TU); + } return MakeCXType(QualType(), TU); }