From 58828cc308e0a6030d0418573376624d01baa7d3 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Tue, 27 Nov 2018 12:02:39 +0000 Subject: [PATCH] [libclang] Fix clang_Cursor_getNumArguments and clang_Cursor_getArgument for CXXConstructExpr Constructors have the same methods for arguments as call expressions. Let's provide a way to get their arguments the same way. Differential Revision: https://reviews.llvm.org/D54934 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347654 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Index/print-type.cpp | 3 +++ tools/libclang/CXCursor.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/test/Index/print-type.cpp b/test/Index/print-type.cpp index 3c76c97cca..654b456239 100644 --- a/test/Index/print-type.cpp +++ b/test/Index/print-type.cpp @@ -77,6 +77,8 @@ using baz = C>; auto autoTemplPointer = &autoTemplRefParam; +outer::Foo parameter; +outer::inner::Bar construct(¶meter); // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0] @@ -185,3 +187,4 @@ auto autoTemplPointer = &autoTemplRefParam; // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization &>] [typekind=Unexposed] [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1] // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0] // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) [type=Specialization &> *] [typekind=Auto] [canonicaltype=Specialization &> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=Specialization &>] [pointeekind=Record] +// CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] [canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= [outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3] diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 7e14b5f893..b8c2529169 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -1164,6 +1164,9 @@ int clang_Cursor_getNumArguments(CXCursor C) { if (const CallExpr *CE = dyn_cast(E)) { return CE->getNumArgs(); } + if (const CXXConstructExpr *CE = dyn_cast(E)) { + return CE->getNumArgs(); + } } return -1; @@ -1192,6 +1195,13 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { cxcursor::getCursorTU(C)); } } + if (const CXXConstructExpr *CE = dyn_cast(E)) { + if (i < CE->getNumArgs()) { + return cxcursor::MakeCXCursor(CE->getArg(i), + getCursorDecl(C), + cxcursor::getCursorTU(C)); + } + } } return clang_getNullCursor(); -- 2.40.0