yvvan created this revision.
yvvan added reviewers: nik, marcobubke.
Herald added a subscriber: arphaman.

Constructors have the same methods for arguments as call expressions. Let's 
provide a way to get their arguments the same way.


https://reviews.llvm.org/D54934

Files:
  test/Index/print-type.cpp
  tools/libclang/CXCursor.cpp


Index: tools/libclang/CXCursor.cpp
===================================================================
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -1146,6 +1146,9 @@
     if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
       return CE->getNumArgs();
     }
+    if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) {
+      return CE->getNumArgs();
+    }
   }
 
   return -1;
@@ -1174,6 +1177,13 @@
                                       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));
+      }
+    }
   }
 
   return clang_getNullCursor();
Index: test/Index/print-type.cpp
===================================================================
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -77,6 +77,8 @@
 
 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 @@
 // 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]


Index: tools/libclang/CXCursor.cpp
===================================================================
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -1146,6 +1146,9 @@
     if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
       return CE->getNumArgs();
     }
+    if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) {
+      return CE->getNumArgs();
+    }
   }
 
   return -1;
@@ -1174,6 +1177,13 @@
                                       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));
+      }
+    }
   }
 
   return clang_getNullCursor();
Index: test/Index/print-type.cpp
===================================================================
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -77,6 +77,8 @@
 
 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 @@
 // 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]
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D54934: [libclang... Ivan Donchevskii via Phabricator via cfe-commits

Reply via email to