[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2020-05-14 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2020-05-13 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added a comment.

I mostly just need to rebase this patch now. I'll try to get to that soon.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2020-05-12 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk added a comment.

@Bigcheese wondering if there are things with respect to testing we can do, to 
help the patch move forward :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2020-01-23 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added a comment.

I was finally able to land the patch this depended on.  Still waiting on review 
for this. In the meantime I've tested this ABI out by building a simple program 
that outputs a ninja file given a command line. It depends on a bunch of 
changes to the Clang side of things, but no changes to this interface.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-12-05 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese updated this revision to Diff 232484.
Bigcheese marked an inline comment as done.
Bigcheese added a comment.
Herald added a subscriber: mgrang.

- Remove duplicate decl
- Add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351

Files:
  clang/include/clang-c/Dependencies.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/Inputs/modules_cdb.json
  clang/test/ClangScanDeps/modules-full.cpp
  clang/test/Index/Core/scan-deps.m
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/c-index-test/core_main.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  clang/tools/libclang/CDependencies.cpp
  clang/tools/libclang/CMakeLists.txt
  clang/tools/libclang/CXString.cpp
  clang/tools/libclang/CXString.h
  clang/tools/libclang/libclang.exports
  llvm/include/llvm/ADT/FunctionExtras.h

Index: llvm/include/llvm/ADT/FunctionExtras.h
===
--- llvm/include/llvm/ADT/FunctionExtras.h
+++ llvm/include/llvm/ADT/FunctionExtras.h
@@ -287,6 +287,37 @@
   }
 };
 
+template  struct FunctionObjectCallback {
+  void *Context;
+  CallTy *Callback;
+};
+
+namespace detail {
+template 
+struct functionObjectToCCallbackRefImpl;
+
+template 
+struct functionObjectToCCallbackRefImpl {
+  static FunctionObjectCallback impl(FuncTy &F) {
+auto Func = +[](void *C, Args... V) -> Ret {
+  return (*reinterpret_cast *>(C))(
+  std::forward(V)...);
+};
+
+return {&F, Func};
+  }
+};
+} // namespace detail
+
+/// Returns a function pointer and context pair suitable for use as a C
+/// callback.
+///
+/// \param F the function object to turn into a C callback. The returned
+///   callback has the same lifetime as F.
+template 
+auto functionObjectToCCallbackRef(FuncTy &F) {
+  return detail::functionObjectToCCallbackRefImpl::impl(F);
+}
 } // end namespace llvm
 
 #endif // LLVM_ADT_FUNCTION_H
Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -157,6 +157,13 @@
 clang_equalRanges
 clang_equalTypes
 clang_executeOnThread
+clang_experimental_DependencyScannerService_create_v0
+clang_experimental_DependencyScannerService_dispose_v0
+clang_experimental_DependencyScannerWorker_create_v0
+clang_experimental_DependencyScannerWorker_dispose_v0
+clang_experimental_DependencyScannerWorker_getFileDependencies_v0
+clang_experimental_FileDependencies_dispose
+clang_experimental_ModuleDependencySet_dispose
 clang_findIncludesInFile
 clang_findIncludesInFileWithBlock
 clang_findReferencesInFile
Index: clang/tools/libclang/CXString.h
===
--- clang/tools/libclang/CXString.h
+++ clang/tools/libclang/CXString.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Compiler.h"
 #include 
 #include 
@@ -69,6 +70,8 @@
 
 CXStringSet *createSet(const std::vector &Strings);
 
+CXStringSet *createSet(const llvm::StringSet<> &Strings);
+
 /// A string pool used for fast allocation/deallocation of strings.
 class CXStringPool {
 public:
Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -119,6 +119,15 @@
   return Set;
 }
 
+CXStringSet *createSet(const llvm::StringSet<> &Strings) {
+  CXStringSet *Set = new CXStringSet;
+  Set->Count = Strings.size();
+  Set->Strings = new CXString[Set->Count];
+  int I = 0;
+  for (auto SI = Strings.begin(), SE = Strings.end(); SI != SE; ++SI)
+Set->Strings[I++] = createDup(SI->getKey());
+  return Set;
+}
 
 //===--===//
 // String pools.
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(SOURCES
   ARCMigrate.cpp
   BuildSystem.cpp
+  CDependencies.cpp
   CIndex.cpp
   CIndexCXX.cpp
   CIndexCodeCompletion.cpp
@@ -37,6 +38,7 @@
 set(LIBS
   clangAST
   clangBasic
+  clangDependencyScanning
   clangDriver
   clangFrontend
   clangIndex
Index: clang/tools/libclang/CDependencies.cpp
===
--- /dev/null
+++ clang/too

[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-22 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese marked an inline comment as done.
Bigcheese added inline comments.



Comment at: clang/include/clang-c/Dependencies.h:146
+ */
+typedef struct CXOpaqueDependencyScannerWorker *CXDependencyScannerWorker;
+

kousikk wrote:
> It would be simpler if the clients didn't have to worry about the worker?
> As far as a user of this lib is concerned, they need to create a shared 
> cache, then call scanDeps() in some form with the shared cache and other 
> inputs.
> 
> Can we hide the worker inside the implementation? So essentially we create a 
> new worker for every invocation (that's assuming worker setup is cheap).
A lot of caching is per-worker. It would be pretty bad to spawn a new worker 
for every scan.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-21 Thread Kousik Kumar via Phabricator via cfe-commits
kousikk added inline comments.



Comment at: clang/include/clang-c/Dependencies.h:146
+ */
+typedef struct CXOpaqueDependencyScannerWorker *CXDependencyScannerWorker;
+

It would be simpler if the clients didn't have to worry about the worker?
As far as a user of this lib is concerned, they need to create a shared cache, 
then call scanDeps() in some form with the shared cache and other inputs.

Can we hide the worker inside the implementation? So essentially we create a 
new worker for every invocation (that's assuming worker setup is cheap).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-21 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: clang/include/clang-c/Dependencies.h:205
+ */
+CINDEX_LINKAGE void clang_experimental_DependencyScannerWorker_dispose_v0(
+CXDependencyScannerWorker);

Looks like you have a duplicate declaration of this function, and the prototype 
above is missing the comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-21 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

I think this patch is missing tests for the C api that use c-index-test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-20 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese added a comment.

In D70351#1754276 , @arphaman wrote:

> Adding experimental APIs is something that we haven't done before, but it be 
> useful for this case.


Yep, I'm currently aware of two other people who care about this interface, so 
I thought it would make sense to do the development of the API upstream.

> I have a couple of questions about the API:
> 
> - Should types be prefixed / suffixed with experimental / v0 in case we need 
> to extend the information passed to the client?

I don't think the type names matter unless someone plans to write a user of 
this API that can handle multiple versions at the same time (which means they 
aren't using this header). The function names matter as that's what shows up in 
the symbol table.

> - The types look to be more geared towards Clang modules (like the addition 
> of a module map path). Do you think the same types could be used for C++ 20 
> modules as well, or should C++ 20 modules have a completely separate API?

C++20 modules will need to use the same API as we intend to support mixing 
Clang modules and C++20 modules. The types will need to be modified slightly to 
work for C++20 modules, I just haven't gotten to that yet. C++20 module 
interfaces don't need a module-map or equivalent, and C++20 header units will 
just need to know the header file they are for.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Adding experimental APIs is something that we haven't done before, but it be 
useful for this case.
I have a couple of questions about the API:

- Should types be prefixed / suffixed with experimental / v0 in case we need to 
extend the information passed to the client?
- The types look to be more geared towards Clang modules (like the addition of 
a module map path). Do you think the same types could be used for C++ 20 
modules as well, or should C++ 20 modules have a completely separate API?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70351/new/

https://reviews.llvm.org/D70351



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70351: [clang][WIP][clang-scan-deps] Add an experimental C API.

2019-11-16 Thread Michael Spencer via Phabricator via cfe-commits
Bigcheese created this revision.
Bigcheese added reviewers: arphaman, kousikk.
Herald added subscribers: llvm-commits, cfe-commits, tschuett, dexonsmith, 
mgorny.
Herald added projects: clang, LLVM.
Bigcheese added a parent revision: D70268: [clang][clang-scan-deps] Aggregate 
the full dependency information..

This adds an experimental C API for clang-scan-deps. It provides both
the full module dependency graph along with a flattened list of
dependencies.

See clang/include/clang-c/Dependencies.h for the API and documentation.

You can test it out using:
c-index-test core --scan-deps  -- clang --cc1 

This will output a list of modules and then the direct dependencies of
the main translation unit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70351

Files:
  clang/include/clang-c/Dependencies.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/c-index-test/core_main.cpp
  clang/tools/libclang/CDependencies.cpp
  clang/tools/libclang/CMakeLists.txt
  clang/tools/libclang/CXString.cpp
  clang/tools/libclang/CXString.h
  clang/tools/libclang/libclang.exports
  llvm/include/llvm/ADT/FunctionExtras.h

Index: llvm/include/llvm/ADT/FunctionExtras.h
===
--- llvm/include/llvm/ADT/FunctionExtras.h
+++ llvm/include/llvm/ADT/FunctionExtras.h
@@ -287,6 +287,37 @@
   }
 };
 
+template  struct FunctionObjectCallback {
+  void *Context;
+  CallTy *Callback;
+};
+
+namespace detail {
+template 
+struct functionObjectToCCallbackRefImpl;
+
+template 
+struct functionObjectToCCallbackRefImpl {
+  static FunctionObjectCallback impl(FuncTy &F) {
+auto Func = +[](void *C, Args... V) -> Ret {
+  return (*reinterpret_cast *>(C))(
+  std::forward(V)...);
+};
+
+return {&F, Func};
+  }
+};
+} // namespace detail
+
+/// Returns a function pointer and context pair suitable for use as a C
+/// callback.
+///
+/// \param F the function object to turn into a C callback. The returned
+///   callback has the same lifetime as F.
+template 
+auto functionObjectToCCallbackRef(FuncTy &F) {
+  return detail::functionObjectToCCallbackRefImpl::impl(F);
+}
 } // end namespace llvm
 
 #endif // LLVM_ADT_FUNCTION_H
Index: clang/tools/libclang/libclang.exports
===
--- clang/tools/libclang/libclang.exports
+++ clang/tools/libclang/libclang.exports
@@ -157,6 +157,13 @@
 clang_equalRanges
 clang_equalTypes
 clang_executeOnThread
+clang_experimental_DependencyScannerService_create_v0
+clang_experimental_DependencyScannerService_dispose_v0
+clang_experimental_DependencyScannerWorker_create_v0
+clang_experimental_DependencyScannerWorker_dispose_v0
+clang_experimental_DependencyScannerWorker_getFileDependencies_v0
+clang_experimental_FileDependencies_dispose
+clang_experimental_ModuleDependencySet_dispose
 clang_findIncludesInFile
 clang_findIncludesInFileWithBlock
 clang_findReferencesInFile
Index: clang/tools/libclang/CXString.h
===
--- clang/tools/libclang/CXString.h
+++ clang/tools/libclang/CXString.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Compiler.h"
 #include 
 #include 
@@ -69,6 +70,8 @@
 
 CXStringSet *createSet(const std::vector &Strings);
 
+CXStringSet *createSet(const llvm::StringSet<> &Strings);
+
 /// A string pool used for fast allocation/deallocation of strings.
 class CXStringPool {
 public:
Index: clang/tools/libclang/CXString.cpp
===
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -119,6 +119,15 @@
   return Set;
 }
 
+CXStringSet *createSet(const llvm::StringSet<> &Strings) {
+  CXStringSet *Set = new CXStringSet;
+  Set->Count = Strings.size();
+  Set->Strings = new CXString[Set->Count];
+  int I = 0;
+  for (auto SI = Strings.begin(), SE = Strings.end(); SI != SE; ++SI)
+Set->Strings[I++] = createDup(SI->getKey());
+  return Set;
+}
 
 //===--===//
 // String pools.
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(SOURCES
   ARCMigrate.cpp
   BuildSystem.cpp
+  CDependencies.cpp
   CIndex.cpp
   CIndexCXX.cpp
   CIndexCodeCompletion.cpp
@@ -37,6 +38,7 @@
 set(LIBS
   clangAST
   clangBasic
+  clangDependencyScanning
   clangDriver
   clangFrontend
   clangIndex
Index: clang/tools/libclang/CDependencies.cpp
===
--- /dev/null
+++ clang/to