1 #include "clang-c/CXCompilationDatabase.h"
2 #include "clang/Tooling/CompilationDatabase.h"
6 using namespace clang::tooling;
7 using namespace clang::cxstring;
11 // FIXME: do something more usefull with the error message
13 clang_CompilationDatabase_fromDirectory(const char *BuildDir,
14 CXCompilationDatabase_Error *ErrorCode)
17 CXCompilationDatabase_Error Err = CXCompilationDatabase_NoError;
19 CompilationDatabase *db = CompilationDatabase::loadFromDirectory(BuildDir,
23 fprintf(stderr, "LIBCLANG TOOLING ERROR: %s\n", ErrorMsg.c_str());
24 Err = CXCompilationDatabase_CanNotLoadDatabase;
34 clang_CompilationDatabase_dispose(CXCompilationDatabase CDb)
36 delete static_cast<CompilationDatabase *>(CDb);
39 struct AllocatedCXCompileCommands
41 std::vector<CompileCommand> CCmd;
43 AllocatedCXCompileCommands(const std::vector<CompileCommand>& Cmd)
49 clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase CDb,
50 const char *CompleteFileName)
52 if (CompilationDatabase *db = static_cast<CompilationDatabase *>(CDb)) {
53 const std::vector<CompileCommand>
54 CCmd(db->getCompileCommands(CompleteFileName));
56 return new AllocatedCXCompileCommands( CCmd );
63 clang_CompileCommands_dispose(CXCompileCommands Cmds)
65 delete static_cast<AllocatedCXCompileCommands *>(Cmds);
69 clang_CompileCommands_getSize(CXCompileCommands Cmds)
74 AllocatedCXCompileCommands *ACC =
75 static_cast<AllocatedCXCompileCommands *>(Cmds);
77 return ACC->CCmd.size();
81 clang_CompileCommands_getCommand(CXCompileCommands Cmds, unsigned I)
86 AllocatedCXCompileCommands *ACC =
87 static_cast<AllocatedCXCompileCommands *>(Cmds);
89 if (I >= ACC->CCmd.size())
96 clang_CompileCommand_getDirectory(CXCompileCommand CCmd)
99 return createCXString((const char*)NULL);
101 CompileCommand *cmd = static_cast<CompileCommand *>(CCmd);
102 return createCXString(cmd->Directory);
106 clang_CompileCommand_getNumArgs(CXCompileCommand CCmd)
111 return static_cast<CompileCommand *>(CCmd)->CommandLine.size();
115 clang_CompileCommand_getArg(CXCompileCommand CCmd, unsigned Arg)
118 return createCXString((const char*)NULL);
120 CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
122 if (Arg >= Cmd->CommandLine.size())
123 return createCXString((const char*)NULL);
125 return createCXString(Cmd->CommandLine[Arg]);