clang API Documentation

CXCompilationDatabase.h
Go to the documentation of this file.
00001 /*===-- clang-c/CXCompilationDatabase.h - Compilation database  ---*- C -*-===*\
00002 |*                                                                            *|
00003 |*                     The LLVM Compiler Infrastructure                       *|
00004 |*                                                                            *|
00005 |* This file is distributed under the University of Illinois Open Source      *|
00006 |* License. See LICENSE.TXT for details.                                      *|
00007 |*                                                                            *|
00008 |*===----------------------------------------------------------------------===*|
00009 |*                                                                            *|
00010 |* This header provides a public inferface to use CompilationDatabase without *|
00011 |* the full Clang C++ API.                                                    *|
00012 |*                                                                            *|
00013 \*===----------------------------------------------------------------------===*/
00014 
00015 #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
00016 #define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H
00017 
00018 #include "clang-c/Platform.h"
00019 #include "clang-c/CXString.h"
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 /** \defgroup COMPILATIONDB CompilationDatabase functions
00026  * \ingroup CINDEX
00027  *
00028  * @{
00029  */
00030 
00031 /**
00032  * A compilation database holds all information used to compile files in a
00033  * project. For each file in the database, it can be queried for the working
00034  * directory or the command line used for the compiler invocation.
00035  *
00036  * Must be freed by \c clang_CompilationDatabase_dispose
00037  */
00038 typedef void * CXCompilationDatabase;
00039 
00040 /**
00041  * \brief Contains the results of a search in the compilation database
00042  *
00043  * When searching for the compile command for a file, the compilation db can
00044  * return several commands, as the file may have been compiled with
00045  * different options in different places of the project. This choice of compile
00046  * commands is wrapped in this opaque data structure. It must be freed by
00047  * \c clang_CompileCommands_dispose.
00048  */
00049 typedef void * CXCompileCommands;
00050 
00051 /**
00052  * \brief Represents the command line invocation to compile a specific file.
00053  */
00054 typedef void * CXCompileCommand;
00055 
00056 /**
00057  * \brief Error codes for Compilation Database
00058  */
00059 typedef enum  {
00060   /*
00061    * \brief No error occurred
00062    */
00063   CXCompilationDatabase_NoError = 0,
00064 
00065   /*
00066    * \brief Database can not be loaded
00067    */
00068   CXCompilationDatabase_CanNotLoadDatabase = 1
00069 
00070 } CXCompilationDatabase_Error;
00071 
00072 /**
00073  * \brief Creates a compilation database from the database found in directory
00074  * buildDir. For example, CMake can output a compile_commands.json which can
00075  * be used to build the database.
00076  *
00077  * It must be freed by \c clang_CompilationDatabase_dispose.
00078  */
00079 CINDEX_LINKAGE CXCompilationDatabase
00080 clang_CompilationDatabase_fromDirectory(const char *BuildDir,
00081                                         CXCompilationDatabase_Error *ErrorCode);
00082 
00083 /**
00084  * \brief Free the given compilation database
00085  */
00086 CINDEX_LINKAGE void
00087 clang_CompilationDatabase_dispose(CXCompilationDatabase);
00088 
00089 /**
00090  * \brief Find the compile commands used for a file. The compile commands
00091  * must be freed by \c clang_CompileCommands_dispose.
00092  */
00093 CINDEX_LINKAGE CXCompileCommands
00094 clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase,
00095                                              const char *CompleteFileName);
00096 
00097 /**
00098  * \brief Get all the compile commands in the given compilation database.
00099  */
00100 CINDEX_LINKAGE CXCompileCommands
00101 clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase);
00102 
00103 /**
00104  * \brief Free the given CompileCommands
00105  */
00106 CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands);
00107 
00108 /**
00109  * \brief Get the number of CompileCommand we have for a file
00110  */
00111 CINDEX_LINKAGE unsigned
00112 clang_CompileCommands_getSize(CXCompileCommands);
00113 
00114 /**
00115  * \brief Get the I'th CompileCommand for a file
00116  *
00117  * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands)
00118  */
00119 CINDEX_LINKAGE CXCompileCommand
00120 clang_CompileCommands_getCommand(CXCompileCommands, unsigned I);
00121 
00122 /**
00123  * \brief Get the working directory where the CompileCommand was executed from
00124  */
00125 CINDEX_LINKAGE CXString
00126 clang_CompileCommand_getDirectory(CXCompileCommand);
00127 
00128 /**
00129  * \brief Get the number of arguments in the compiler invocation.
00130  *
00131  */
00132 CINDEX_LINKAGE unsigned
00133 clang_CompileCommand_getNumArgs(CXCompileCommand);
00134 
00135 /**
00136  * \brief Get the I'th argument value in the compiler invocations
00137  *
00138  * Invariant :
00139  *  - argument 0 is the compiler executable
00140  */
00141 CINDEX_LINKAGE CXString
00142 clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
00143 
00144 /**
00145  * \brief Get the number of source mappings for the compiler invocation.
00146  */
00147 CINDEX_LINKAGE unsigned
00148 clang_CompileCommand_getNumMappedSources(CXCompileCommand);
00149 
00150 /**
00151  * \brief Get the I'th mapped source path for the compiler invocation.
00152  */
00153 CINDEX_LINKAGE CXString
00154 clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
00155 
00156 /**
00157  * \brief Get the I'th mapped source content for the compiler invocation.
00158  */
00159 CINDEX_LINKAGE CXString
00160 clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
00161 
00162 /**
00163  * @}
00164  */
00165 
00166 #ifdef __cplusplus
00167 }
00168 #endif
00169 #endif
00170