1 #include "clang-c/CXCompilationDatabase.h"
3 #include "clang/Tooling/CompilationDatabase.h"
7 using namespace clang::tooling;
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_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase CDb) {
64 if (CompilationDatabase *db = static_cast<CompilationDatabase *>(CDb)) {
65 const std::vector<CompileCommand> CCmd(db->getAllCompileCommands());
67 return new AllocatedCXCompileCommands( CCmd );
74 clang_CompileCommands_dispose(CXCompileCommands Cmds)
76 delete static_cast<AllocatedCXCompileCommands *>(Cmds);
80 clang_CompileCommands_getSize(CXCompileCommands Cmds)
85 AllocatedCXCompileCommands *ACC =
86 static_cast<AllocatedCXCompileCommands *>(Cmds);
88 return ACC->CCmd.size();
92 clang_CompileCommands_getCommand(CXCompileCommands Cmds, unsigned I)
97 AllocatedCXCompileCommands *ACC =
98 static_cast<AllocatedCXCompileCommands *>(Cmds);
100 if (I >= ACC->CCmd.size())
103 return &ACC->CCmd[I];
107 clang_CompileCommand_getDirectory(CXCompileCommand CCmd)
110 return cxstring::createNull();
112 CompileCommand *cmd = static_cast<CompileCommand *>(CCmd);
113 return cxstring::createRef(cmd->Directory.c_str());
117 clang_CompileCommand_getNumArgs(CXCompileCommand CCmd)
122 return static_cast<CompileCommand *>(CCmd)->CommandLine.size();
126 clang_CompileCommand_getArg(CXCompileCommand CCmd, unsigned Arg)
129 return cxstring::createNull();
131 CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
133 if (Arg >= Cmd->CommandLine.size())
134 return cxstring::createNull();
136 return cxstring::createRef(Cmd->CommandLine[Arg].c_str());
140 clang_CompileCommand_getNumMappedSources(CXCompileCommand CCmd)
145 return static_cast<CompileCommand *>(CCmd)->MappedSources.size();
149 clang_CompileCommand_getMappedSourcePath(CXCompileCommand CCmd, unsigned I)
152 return cxstring::createNull();
154 CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
156 if (I >= Cmd->MappedSources.size())
157 return cxstring::createNull();
159 return cxstring::createRef(Cmd->MappedSources[I].first.c_str());
163 clang_CompileCommand_getMappedSourceContent(CXCompileCommand CCmd, unsigned I)
166 return cxstring::createNull();
168 CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
170 if (I >= Cmd->MappedSources.size())
171 return cxstring::createNull();
173 return cxstring::createRef(Cmd->MappedSources[I].second.c_str());