r202681 - [libclang] Introduce APIs that assist in constructing a simple module.map file for a user framework.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Sun Mar 2 23:41:46 PST 2014
Author: akirtzidis
Date: Mon Mar 3 01:41:45 2014
New Revision: 202681
URL: http://llvm.org/viewvc/llvm-project?rev=202681&view=rev
Log:
[libclang] Introduce APIs that assist in constructing a simple module.map file for a user framework.
rdar://16092858
Modified:
cfe/trunk/include/clang-c/BuildSystem.h
cfe/trunk/tools/libclang/BuildSystem.cpp
cfe/trunk/tools/libclang/libclang.exports
cfe/trunk/unittests/libclang/LibclangTest.cpp
Modified: cfe/trunk/include/clang-c/BuildSystem.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/BuildSystem.h?rev=202681&r1=202680&r2=202681&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/BuildSystem.h (original)
+++ cfe/trunk/include/clang-c/BuildSystem.h Mon Mar 3 01:41:45 2014
@@ -78,6 +78,55 @@ clang_VirtualFileOverlay_writeToBuffer(C
CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay);
/**
+ * \brief Object encapsulating information about a module.map file.
+ */
+typedef struct CXModuleMapDescriptorImpl *CXModuleMapDescriptor;
+
+/**
+ * \brief Create a \c CXModuleMapDescriptor object.
+ * Must be disposed with \c clang_ModuleMapDescriptor_dispose().
+ *
+ * \param options is reserved, always pass 0.
+ */
+CINDEX_LINKAGE CXModuleMapDescriptor
+clang_ModuleMapDescriptor_create(unsigned options);
+
+/**
+ * \brief Sets the framework module name that the module.map describes.
+ * \returns 0 for success, non-zero to indicate an error.
+ */
+CINDEX_LINKAGE enum CXErrorCode
+clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor,
+ const char *name);
+
+/**
+ * \brief Sets the umbrealla header name that the module.map describes.
+ * \returns 0 for success, non-zero to indicate an error.
+ */
+CINDEX_LINKAGE enum CXErrorCode
+clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor,
+ const char *name);
+
+/**
+ * \brief Write out the \c CXModuleMapDescriptor object to a char buffer.
+ *
+ * \param options is reserved, always pass 0.
+ * \param out_buffer_ptr pointer to receive the buffer pointer, which should be
+ * disposed using \c free().
+ * \param out_buffer_size pointer to receive the buffer size.
+ * \returns 0 for success, non-zero to indicate an error.
+ */
+CINDEX_LINKAGE enum CXErrorCode
+clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, unsigned options,
+ char **out_buffer_ptr,
+ unsigned *out_buffer_size);
+
+/**
+ * \brief Dispose a \c CXModuleMapDescriptor object.
+ */
+CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor);
+
+/**
* @}
*/
Modified: cfe/trunk/tools/libclang/BuildSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/BuildSystem.cpp?rev=202681&r1=202680&r2=202681&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/BuildSystem.cpp (original)
+++ cfe/trunk/tools/libclang/BuildSystem.cpp Mon Mar 3 01:41:45 2014
@@ -197,3 +197,61 @@ clang_VirtualFileOverlay_writeToBuffer(C
void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay VFO) {
delete VFO;
}
+
+
+struct CXModuleMapDescriptorImpl {
+ std::string ModuleName;
+ std::string UmbrellaHeader;
+};
+
+CXModuleMapDescriptor clang_ModuleMapDescriptor_create(unsigned) {
+ return new CXModuleMapDescriptorImpl();
+}
+
+enum CXErrorCode
+clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor MMD,
+ const char *name) {
+ if (!MMD || !name)
+ return CXError_InvalidArguments;
+
+ MMD->ModuleName = name;
+ return CXError_Success;
+}
+
+enum CXErrorCode
+clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor MMD,
+ const char *name) {
+ if (!MMD || !name)
+ return CXError_InvalidArguments;
+
+ MMD->UmbrellaHeader = name;
+ return CXError_Success;
+}
+
+enum CXErrorCode
+clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor MMD, unsigned,
+ char **out_buffer_ptr,
+ unsigned *out_buffer_size) {
+ if (!MMD || !out_buffer_ptr || !out_buffer_size)
+ return CXError_InvalidArguments;
+
+ llvm::SmallString<256> Buf;
+ llvm::raw_svector_ostream OS(Buf);
+ OS << "framework module " << MMD->ModuleName << " {\n";
+ OS << " umbrella header \"";
+ OS.write_escaped(MMD->UmbrellaHeader) << "\"\n";
+ OS << '\n';
+ OS << " export *\n";
+ OS << " module * { export * }\n";
+ OS << "}\n";
+
+ StringRef Data = OS.str();
+ *out_buffer_ptr = (char*)malloc(Data.size());
+ *out_buffer_size = Data.size();
+ memcpy(*out_buffer_ptr, Data.data(), Data.size());
+ return CXError_Success;
+}
+
+void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor MMD) {
+ delete MMD;
+}
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=202681&r1=202680&r2=202681&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Mon Mar 3 01:41:45 2014
@@ -286,6 +286,11 @@ clang_CompileCommand_getNumArgs
clang_CompileCommand_getArg
clang_visitChildren
clang_visitChildrenWithBlock
+clang_ModuleMapDescriptor_create
+clang_ModuleMapDescriptor_dispose
+clang_ModuleMapDescriptor_setFrameworkModuleName
+clang_ModuleMapDescriptor_setUmbrellaHeader
+clang_ModuleMapDescriptor_writeToBuffer
clang_VirtualFileOverlay_addFileMapping
clang_VirtualFileOverlay_create
clang_VirtualFileOverlay_dispose
Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=202681&r1=202680&r2=202681&view=diff
==============================================================================
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Mon Mar 3 01:41:45 2014
@@ -141,3 +141,26 @@ TEST(libclang, VirtualFileOverlay) {
T.map("/path/virtual/dir/in/subdir/foo4.h", "/real/foo4.h");
}
}
+
+TEST(libclang, ModuleMapDescriptor) {
+ const char *Contents =
+ "framework module TestFrame {\n"
+ " umbrella header \"TestFrame.h\"\n"
+ "\n"
+ " export *\n"
+ " module * { export * }\n"
+ "}\n";
+
+ CXModuleMapDescriptor MMD = clang_ModuleMapDescriptor_create(0);
+
+ clang_ModuleMapDescriptor_setFrameworkModuleName(MMD, "TestFrame");
+ clang_ModuleMapDescriptor_setUmbrellaHeader(MMD, "TestFrame.h");
+
+ char *BufPtr;
+ unsigned BufSize;
+ clang_ModuleMapDescriptor_writeToBuffer(MMD, 0, &BufPtr, &BufSize);
+ std::string BufStr(BufPtr, BufSize);
+ EXPECT_STREQ(Contents, BufStr.c_str());
+ free(BufPtr);
+ clang_ModuleMapDescriptor_dispose(MMD);
+}
More information about the cfe-commits
mailing list