1239313Sdim/*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\ 2239313Sdim|* *| 3239313Sdim|* The LLVM Compiler Infrastructure *| 4239313Sdim|* *| 5239313Sdim|* This file is distributed under the University of Illinois Open Source *| 6239313Sdim|* License. See LICENSE.TXT for details. *| 7239313Sdim|* *| 8239313Sdim|*===----------------------------------------------------------------------===*| 9239313Sdim|* *| 10239313Sdim|* This header provides a public inferface to use CompilationDatabase without *| 11239313Sdim|* the full Clang C++ API. *| 12239313Sdim|* *| 13239313Sdim\*===----------------------------------------------------------------------===*/ 14239313Sdim 15239313Sdim#ifndef CLANG_CXCOMPILATIONDATABASE_H 16239313Sdim#define CLANG_CXCOMPILATIONDATABASE_H 17239313Sdim 18239313Sdim#include "clang-c/Platform.h" 19239313Sdim#include "clang-c/CXString.h" 20239313Sdim 21239313Sdim#ifdef __cplusplus 22239313Sdimextern "C" { 23239313Sdim#endif 24239313Sdim 25239313Sdim/** \defgroup COMPILATIONDB CompilationDatabase functions 26239313Sdim * \ingroup CINDEX 27239313Sdim * 28239313Sdim * @{ 29239313Sdim */ 30239313Sdim 31239313Sdim/** 32239313Sdim * A compilation database holds all information used to compile files in a 33239313Sdim * project. For each file in the database, it can be queried for the working 34239313Sdim * directory or the command line used for the compiler invocation. 35239313Sdim * 36239313Sdim * Must be freed by \c clang_CompilationDatabase_dispose 37239313Sdim */ 38239313Sdimtypedef void * CXCompilationDatabase; 39239313Sdim 40239313Sdim/** 41239313Sdim * \brief Contains the results of a search in the compilation database 42239313Sdim * 43239313Sdim * When searching for the compile command for a file, the compilation db can 44239313Sdim * return several commands, as the file may have been compiled with 45239313Sdim * different options in different places of the project. This choice of compile 46239313Sdim * commands is wrapped in this opaque data structure. It must be freed by 47239313Sdim * \c clang_CompileCommands_dispose. 48239313Sdim */ 49239313Sdimtypedef void * CXCompileCommands; 50239313Sdim 51239313Sdim/** 52239313Sdim * \brief Represents the command line invocation to compile a specific file. 53239313Sdim */ 54239313Sdimtypedef void * CXCompileCommand; 55239313Sdim 56239313Sdim/** 57239313Sdim * \brief Error codes for Compilation Database 58239313Sdim */ 59239313Sdimtypedef enum { 60239313Sdim /* 61263508Sdim * \brief No error occurred 62239313Sdim */ 63239313Sdim CXCompilationDatabase_NoError = 0, 64239313Sdim 65239313Sdim /* 66239313Sdim * \brief Database can not be loaded 67239313Sdim */ 68239313Sdim CXCompilationDatabase_CanNotLoadDatabase = 1 69239313Sdim 70239313Sdim} CXCompilationDatabase_Error; 71239313Sdim 72239313Sdim/** 73239313Sdim * \brief Creates a compilation database from the database found in directory 74239313Sdim * buildDir. For example, CMake can output a compile_commands.json which can 75239313Sdim * be used to build the database. 76239313Sdim * 77239313Sdim * It must be freed by \c clang_CompilationDatabase_dispose. 78239313Sdim */ 79239313SdimCINDEX_LINKAGE CXCompilationDatabase 80239313Sdimclang_CompilationDatabase_fromDirectory(const char *BuildDir, 81239313Sdim CXCompilationDatabase_Error *ErrorCode); 82239313Sdim 83239313Sdim/** 84239313Sdim * \brief Free the given compilation database 85239313Sdim */ 86239313SdimCINDEX_LINKAGE void 87239313Sdimclang_CompilationDatabase_dispose(CXCompilationDatabase); 88239313Sdim 89239313Sdim/** 90239313Sdim * \brief Find the compile commands used for a file. The compile commands 91239313Sdim * must be freed by \c clang_CompileCommands_dispose. 92239313Sdim */ 93239313SdimCINDEX_LINKAGE CXCompileCommands 94239313Sdimclang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, 95239313Sdim const char *CompleteFileName); 96239313Sdim 97239313Sdim/** 98249423Sdim * \brief Get all the compile commands in the given compilation database. 99249423Sdim */ 100249423SdimCINDEX_LINKAGE CXCompileCommands 101249423Sdimclang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase); 102249423Sdim 103249423Sdim/** 104239313Sdim * \brief Free the given CompileCommands 105239313Sdim */ 106239313SdimCINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands); 107239313Sdim 108239313Sdim/** 109239313Sdim * \brief Get the number of CompileCommand we have for a file 110239313Sdim */ 111239313SdimCINDEX_LINKAGE unsigned 112239313Sdimclang_CompileCommands_getSize(CXCompileCommands); 113239313Sdim 114239313Sdim/** 115239313Sdim * \brief Get the I'th CompileCommand for a file 116239313Sdim * 117239313Sdim * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands) 118239313Sdim */ 119239313SdimCINDEX_LINKAGE CXCompileCommand 120239313Sdimclang_CompileCommands_getCommand(CXCompileCommands, unsigned I); 121239313Sdim 122239313Sdim/** 123239313Sdim * \brief Get the working directory where the CompileCommand was executed from 124239313Sdim */ 125239313SdimCINDEX_LINKAGE CXString 126239313Sdimclang_CompileCommand_getDirectory(CXCompileCommand); 127239313Sdim 128239313Sdim/** 129239313Sdim * \brief Get the number of arguments in the compiler invocation. 130239313Sdim * 131239313Sdim */ 132239313SdimCINDEX_LINKAGE unsigned 133239313Sdimclang_CompileCommand_getNumArgs(CXCompileCommand); 134239313Sdim 135239313Sdim/** 136239313Sdim * \brief Get the I'th argument value in the compiler invocations 137239313Sdim * 138239313Sdim * Invariant : 139239313Sdim * - argument 0 is the compiler executable 140239313Sdim */ 141239313SdimCINDEX_LINKAGE CXString 142239313Sdimclang_CompileCommand_getArg(CXCompileCommand, unsigned I); 143239313Sdim 144239313Sdim/** 145263508Sdim * \brief Get the number of source mappings for the compiler invocation. 146263508Sdim */ 147263508SdimCINDEX_LINKAGE unsigned 148263508Sdimclang_CompileCommand_getNumMappedSources(CXCompileCommand); 149263508Sdim 150263508Sdim/** 151263508Sdim * \brief Get the I'th mapped source path for the compiler invocation. 152263508Sdim */ 153263508SdimCINDEX_LINKAGE CXString 154263508Sdimclang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I); 155263508Sdim 156263508Sdim/** 157263508Sdim * \brief Get the I'th mapped source content for the compiler invocation. 158263508Sdim */ 159263508SdimCINDEX_LINKAGE CXString 160263508Sdimclang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I); 161263508Sdim 162263508Sdim/** 163239313Sdim * @} 164239313Sdim */ 165239313Sdim 166239313Sdim#ifdef __cplusplus 167239313Sdim} 168239313Sdim#endif 169239313Sdim#endif 170239313Sdim 171