diff options
author | Arnaud A. de Grandmaison <arnaud.adegm@gmail.com> | 2012-06-30 20:43:43 +0000 |
---|---|---|
committer | Arnaud A. de Grandmaison <arnaud.adegm@gmail.com> | 2012-06-30 20:43:43 +0000 |
commit | 685d78d0da52f611b09e728f73e83999fabaa463 (patch) | |
tree | de6f01348920eb02397bad95c0691663c2a961dd /tools/libclang/CXCompilationDatabase.cpp | |
parent | 4439478c38222bb56d42a9afe4c6c51cb8b593d2 (diff) |
[libclang] Make implementation filename match the header's name for CXCompilationDatabase
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159493 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CXCompilationDatabase.cpp')
-rw-r--r-- | tools/libclang/CXCompilationDatabase.cpp | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/tools/libclang/CXCompilationDatabase.cpp b/tools/libclang/CXCompilationDatabase.cpp new file mode 100644 index 0000000000..a537c9d6f9 --- /dev/null +++ b/tools/libclang/CXCompilationDatabase.cpp @@ -0,0 +1,130 @@ +#include "clang-c/CXCompilationDatabase.h" +#include "clang/Tooling/CompilationDatabase.h" +#include "CXString.h" + +using namespace clang; +using namespace clang::tooling; +using namespace clang::cxstring; + +extern "C" { + +// FIXME: do something more usefull with the error message +CXCompilationDatabase +clang_tooling_CompilationDatabase_fromDirectory( + const char *BuildDir, + CXCompilationDatabase_Error *ErrorCode) +{ + std::string ErrorMsg; + CXCompilationDatabase_Error Err = CXCompilationDatabase_NoError; + + CompilationDatabase *db = CompilationDatabase::loadFromDirectory(BuildDir, + ErrorMsg); + + if (!db) { + fprintf(stderr, "LIBCLANG TOOLING ERROR: %s\n", ErrorMsg.c_str()); + Err = CXCompilationDatabase_CanNotLoadDatabase; + } + + if (ErrorCode) + *ErrorCode = Err; + + return db; +} + +void +clang_tooling_CompilationDatabase_dispose(CXCompilationDatabase CDb) +{ + delete static_cast<CompilationDatabase *>(CDb); +} + +struct AllocatedCXCompileCommands +{ + std::vector<CompileCommand> CCmd; + + AllocatedCXCompileCommands(const std::vector<CompileCommand>& Cmd) + : CCmd(Cmd) + { } +}; + +CXCompileCommands +clang_tooling_CompilationDatabase_getCompileCommands(CXCompilationDatabase CDb, + const char *CompleteFileName) +{ + if (CompilationDatabase *db = static_cast<CompilationDatabase *>(CDb)) { + const std::vector<CompileCommand> + CCmd(db->getCompileCommands(CompleteFileName)); + if (!CCmd.empty()) + return new AllocatedCXCompileCommands( CCmd ); + } + + return 0; +} + +void +clang_tooling_CompileCommands_dispose(CXCompileCommands Cmds) +{ + delete static_cast<AllocatedCXCompileCommands *>(Cmds); +} + +unsigned +clang_tooling_CompileCommands_getSize(CXCompileCommands Cmds) +{ + if (!Cmds) + return 0; + + AllocatedCXCompileCommands *ACC = + static_cast<AllocatedCXCompileCommands *>(Cmds); + + return ACC->CCmd.size(); +} + +CXCompileCommand +clang_tooling_CompileCommands_getCommand(CXCompileCommands Cmds, unsigned I) +{ + if (!Cmds) + return 0; + + AllocatedCXCompileCommands *ACC = + static_cast<AllocatedCXCompileCommands *>(Cmds); + + if (I >= ACC->CCmd.size()) + return 0; + + return &ACC->CCmd[I]; +} + +CXString +clang_tooling_CompileCommand_getDirectory(CXCompileCommand CCmd) +{ + if (!CCmd) + return createCXString((const char*)NULL); + + CompileCommand *cmd = static_cast<CompileCommand *>(CCmd); + return createCXString(cmd->Directory); +} + +unsigned +clang_tooling_CompileCommand_getNumArgs(CXCompileCommand CCmd) +{ + if (!CCmd) + return 0; + + return static_cast<CompileCommand *>(CCmd)->CommandLine.size(); +} + +CXString +clang_tooling_CompileCommand_getArg(CXCompileCommand CCmd, unsigned Arg) +{ + if (!CCmd) + return createCXString((const char*)NULL); + + CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd); + + if (Arg >= Cmd->CommandLine.size()) + return createCXString((const char*)NULL); + + return createCXString(Cmd->CommandLine[Arg]); +} + + +} // end: extern "C" |