1 #include "clang-c/CXCompilationDatabase.h"
3 #include "clang/Tooling/CompilationDatabase.h"
6 using namespace clang::tooling;
10 // FIXME: do something more usefull with the error message
12 clang_CompilationDatabase_fromDirectory(const char *BuildDir,
13 CXCompilationDatabase_Error *ErrorCode)
16 CXCompilationDatabase_Error Err = CXCompilationDatabase_NoError;
18 CompilationDatabase *db = CompilationDatabase::loadFromDirectory(BuildDir,
22 fprintf(stderr, "LIBCLANG TOOLING ERROR: %s\n", ErrorMsg.c_str());
23 Err = CXCompilationDatabase_CanNotLoadDatabase;
33 clang_CompilationDatabase_dispose(CXCompilationDatabase CDb)
35 delete static_cast<CompilationDatabase *>(CDb);
38 struct AllocatedCXCompileCommands
40 std::vector<CompileCommand> CCmd;
42 AllocatedCXCompileCommands(const std::vector<CompileCommand>& Cmd)
48 clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase CDb,
49 const char *CompleteFileName)
51 if (CompilationDatabase *db = static_cast<CompilationDatabase *>(CDb)) {
52 const std::vector<CompileCommand>
53 CCmd(db->getCompileCommands(CompleteFileName));
55 return new AllocatedCXCompileCommands( CCmd );
62 clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase CDb) {
63 if (CompilationDatabase *db = static_cast<CompilationDatabase *>(CDb)) {
64 const std::vector<CompileCommand> CCmd(db->getAllCompileCommands());
66 return new AllocatedCXCompileCommands( CCmd );
73 clang_CompileCommands_dispose(CXCompileCommands Cmds)
75 delete static_cast<AllocatedCXCompileCommands *>(Cmds);
79 clang_CompileCommands_getSize(CXCompileCommands Cmds)
84 AllocatedCXCompileCommands *ACC =
85 static_cast<AllocatedCXCompileCommands *>(Cmds);
87 return ACC->CCmd.size();
91 clang_CompileCommands_getCommand(CXCompileCommands Cmds, unsigned I)
96 AllocatedCXCompileCommands *ACC =
97 static_cast<AllocatedCXCompileCommands *>(Cmds);
99 if (I >= ACC->CCmd.size())
102 return &ACC->CCmd[I];
106 clang_CompileCommand_getDirectory(CXCompileCommand CCmd)
109 return cxstring::createNull();
111 CompileCommand *cmd = static_cast<CompileCommand *>(CCmd);
112 return cxstring::createRef(cmd->Directory.c_str());
116 clang_CompileCommand_getNumArgs(CXCompileCommand CCmd)
121 return static_cast<CompileCommand *>(CCmd)->CommandLine.size();
125 clang_CompileCommand_getArg(CXCompileCommand CCmd, unsigned Arg)
128 return cxstring::createNull();
130 CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
132 if (Arg >= Cmd->CommandLine.size())
133 return cxstring::createNull();
135 return cxstring::createRef(Cmd->CommandLine[Arg].c_str());