r347654 - [libclang] Fix clang_Cursor_getNumArguments and clang_Cursor_getArgument for CXXConstructExpr

Ivan Donchevskii via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 27 04:02:39 PST 2018


Author: yvvan
Date: Tue Nov 27 04:02:39 2018
New Revision: 347654

URL: http://llvm.org/viewvc/llvm-project?rev=347654&view=rev
Log:
[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

Modified:
    cfe/trunk/test/Index/print-type.cpp
    cfe/trunk/tools/libclang/CXCursor.cpp

Modified: cfe/trunk/test/Index/print-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.cpp?rev=347654&r1=347653&r2=347654&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-type.cpp (original)
+++ cfe/trunk/test/Index/print-type.cpp Tue Nov 27 04:02:39 2018
@@ -77,6 +77,8 @@ using baz = C<A<void>>;
 
 auto autoTemplPointer = &autoTemplRefParam;
 
+outer::Foo<bool> parameter;
+outer::inner::Bar construct(&parameter);
 // 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 = &autoTemplRefPar
 // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization<Specialization<bool> &>] [typekind=Unexposed] [templateargs/1= [type=Specialization<bool> &] [typekind=LValueReference]] [canonicaltype=Specialization<Specialization<bool> &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization<bool> &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A<void>] [typekind=Unexposed]] [canonicaltype=A<void>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) [type=Specialization<Specialization<bool> &> *] [typekind=Auto] [canonicaltype=Specialization<Specialization<bool> &> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=Specialization<Specialization<bool> &>] [pointeekind=Record]
+// CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] [canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= [outer::Foo<bool> *] [Pointer]] [isPOD=0] [nbFields=3]

Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=347654&r1=347653&r2=347654&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Tue Nov 27 04:02:39 2018
@@ -1164,6 +1164,9 @@ int clang_Cursor_getNumArguments(CXCurso
     if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
       return CE->getNumArgs();
     }
+    if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) {
+      return CE->getNumArgs();
+    }
   }
 
   return -1;
@@ -1189,6 +1192,13 @@ CXCursor clang_Cursor_getArgument(CXCurs
       if (i < CE->getNumArgs()) {
         return cxcursor::MakeCXCursor(CE->getArg(i),
                                       getCursorDecl(C),
+                                      cxcursor::getCursorTU(C));
+      }
+    }
+    if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) {
+      if (i < CE->getNumArgs()) {
+        return cxcursor::MakeCXCursor(CE->getArg(i),
+                                      getCursorDecl(C),
                                       cxcursor::getCursorTU(C));
       }
     }




More information about the cfe-commits mailing list