├── .gitignore ├── README.md ├── UsingLibClang.xcodeproj └── project.pbxproj └── UsingLibClang ├── clang-c ├── BuildSystem.h ├── CXCompilationDatabase.h ├── CXErrorCode.h ├── CXString.h ├── Documentation.h ├── Index.h └── Platform.h └── main.mm /.gitignore: -------------------------------------------------------------------------------- 1 | #project 2 | **/*.xccheckout 3 | **/*.xcscmblueprint 4 | **/contents.xcworkspacedata 5 | **/xcuserdata/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UsingLibClang 2 | A simple demo about using libclang in Xcode 3 | 4 | 你可以看这边博文 [使用 libclang 实现 iOS 代码中的明文加密](https://danleechina.github.io/use-libclang-in-xcode/) 5 | 这个 Demo 主要就是通过一个小例子介绍如何在 Xcode 中使用 libclang 的 C API 6 | -------------------------------------------------------------------------------- /UsingLibClang.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 37E71D781ED27E97007516EB /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37E71D771ED27E97007516EB /* main.mm */; }; 11 | 37E71D801ED27ED9007516EB /* libclang.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 37E71D7F1ED27ED9007516EB /* libclang.dylib */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXCopyFilesBuildPhase section */ 15 | 37E71D721ED27E97007516EB /* CopyFiles */ = { 16 | isa = PBXCopyFilesBuildPhase; 17 | buildActionMask = 2147483647; 18 | dstPath = /usr/share/man/man1/; 19 | dstSubfolderSpec = 0; 20 | files = ( 21 | ); 22 | runOnlyForDeploymentPostprocessing = 1; 23 | }; 24 | /* End PBXCopyFilesBuildPhase section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 37E71D741ED27E97007516EB /* UsingLibClang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = UsingLibClang; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 37E71D771ED27E97007516EB /* main.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = ""; }; 29 | 37E71D7F1ED27ED9007516EB /* libclang.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libclang.dylib; path = Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib; sourceTree = DEVELOPER_DIR; }; 30 | 37E71D8B1ED2801B007516EB /* BuildSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BuildSystem.h; sourceTree = ""; }; 31 | 37E71D8C1ED2801B007516EB /* CXCompilationDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CXCompilationDatabase.h; sourceTree = ""; }; 32 | 37E71D8D1ED2801B007516EB /* CXErrorCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CXErrorCode.h; sourceTree = ""; }; 33 | 37E71D8E1ED2801B007516EB /* CXString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CXString.h; sourceTree = ""; }; 34 | 37E71D8F1ED2801B007516EB /* Documentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Documentation.h; sourceTree = ""; }; 35 | 37E71D901ED2801B007516EB /* Index.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Index.h; sourceTree = ""; }; 36 | 37E71D921ED2801B007516EB /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | 37E71D711ED27E97007516EB /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | 37E71D801ED27ED9007516EB /* libclang.dylib in Frameworks */, 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | 37E71D6B1ED27E97007516EB = { 52 | isa = PBXGroup; 53 | children = ( 54 | 37E71D761ED27E97007516EB /* UsingLibClang */, 55 | 37E71D751ED27E97007516EB /* Products */, 56 | 37E71D7E1ED27ED9007516EB /* Frameworks */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 37E71D751ED27E97007516EB /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 37E71D741ED27E97007516EB /* UsingLibClang */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 37E71D761ED27E97007516EB /* UsingLibClang */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 37E71D8A1ED2801B007516EB /* clang-c */, 72 | 37E71D771ED27E97007516EB /* main.mm */, 73 | ); 74 | path = UsingLibClang; 75 | sourceTree = ""; 76 | }; 77 | 37E71D7E1ED27ED9007516EB /* Frameworks */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 37E71D7F1ED27ED9007516EB /* libclang.dylib */, 81 | ); 82 | name = Frameworks; 83 | sourceTree = ""; 84 | }; 85 | 37E71D8A1ED2801B007516EB /* clang-c */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | 37E71D8B1ED2801B007516EB /* BuildSystem.h */, 89 | 37E71D8C1ED2801B007516EB /* CXCompilationDatabase.h */, 90 | 37E71D8D1ED2801B007516EB /* CXErrorCode.h */, 91 | 37E71D8E1ED2801B007516EB /* CXString.h */, 92 | 37E71D8F1ED2801B007516EB /* Documentation.h */, 93 | 37E71D901ED2801B007516EB /* Index.h */, 94 | 37E71D921ED2801B007516EB /* Platform.h */, 95 | ); 96 | path = "clang-c"; 97 | sourceTree = ""; 98 | }; 99 | /* End PBXGroup section */ 100 | 101 | /* Begin PBXNativeTarget section */ 102 | 37E71D731ED27E97007516EB /* UsingLibClang */ = { 103 | isa = PBXNativeTarget; 104 | buildConfigurationList = 37E71D7B1ED27E97007516EB /* Build configuration list for PBXNativeTarget "UsingLibClang" */; 105 | buildPhases = ( 106 | 37E71D701ED27E97007516EB /* Sources */, 107 | 37E71D711ED27E97007516EB /* Frameworks */, 108 | 37E71D721ED27E97007516EB /* CopyFiles */, 109 | ); 110 | buildRules = ( 111 | ); 112 | dependencies = ( 113 | ); 114 | name = UsingLibClang; 115 | productName = UsingLibClang; 116 | productReference = 37E71D741ED27E97007516EB /* UsingLibClang */; 117 | productType = "com.apple.product-type.tool"; 118 | }; 119 | /* End PBXNativeTarget section */ 120 | 121 | /* Begin PBXProject section */ 122 | 37E71D6C1ED27E97007516EB /* Project object */ = { 123 | isa = PBXProject; 124 | attributes = { 125 | LastUpgradeCheck = 0830; 126 | ORGANIZATIONNAME = "Dan Lee"; 127 | TargetAttributes = { 128 | 37E71D731ED27E97007516EB = { 129 | CreatedOnToolsVersion = 8.3.2; 130 | DevelopmentTeam = VCJVQ6T6G2; 131 | ProvisioningStyle = Automatic; 132 | }; 133 | }; 134 | }; 135 | buildConfigurationList = 37E71D6F1ED27E97007516EB /* Build configuration list for PBXProject "UsingLibClang" */; 136 | compatibilityVersion = "Xcode 3.2"; 137 | developmentRegion = English; 138 | hasScannedForEncodings = 0; 139 | knownRegions = ( 140 | en, 141 | ); 142 | mainGroup = 37E71D6B1ED27E97007516EB; 143 | productRefGroup = 37E71D751ED27E97007516EB /* Products */; 144 | projectDirPath = ""; 145 | projectRoot = ""; 146 | targets = ( 147 | 37E71D731ED27E97007516EB /* UsingLibClang */, 148 | ); 149 | }; 150 | /* End PBXProject section */ 151 | 152 | /* Begin PBXSourcesBuildPhase section */ 153 | 37E71D701ED27E97007516EB /* Sources */ = { 154 | isa = PBXSourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 37E71D781ED27E97007516EB /* main.mm in Sources */, 158 | ); 159 | runOnlyForDeploymentPostprocessing = 0; 160 | }; 161 | /* End PBXSourcesBuildPhase section */ 162 | 163 | /* Begin XCBuildConfiguration section */ 164 | 37E71D791ED27E97007516EB /* Debug */ = { 165 | isa = XCBuildConfiguration; 166 | buildSettings = { 167 | ALWAYS_SEARCH_USER_PATHS = NO; 168 | CLANG_ANALYZER_NONNULL = YES; 169 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 170 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 171 | CLANG_CXX_LIBRARY = "libc++"; 172 | CLANG_ENABLE_MODULES = YES; 173 | CLANG_ENABLE_OBJC_ARC = YES; 174 | CLANG_WARN_BOOL_CONVERSION = YES; 175 | CLANG_WARN_CONSTANT_CONVERSION = YES; 176 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 177 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 178 | CLANG_WARN_EMPTY_BODY = YES; 179 | CLANG_WARN_ENUM_CONVERSION = YES; 180 | CLANG_WARN_INFINITE_RECURSION = YES; 181 | CLANG_WARN_INT_CONVERSION = YES; 182 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 183 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 184 | CLANG_WARN_UNREACHABLE_CODE = YES; 185 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 186 | CODE_SIGN_IDENTITY = "-"; 187 | COPY_PHASE_STRIP = NO; 188 | DEBUG_INFORMATION_FORMAT = dwarf; 189 | ENABLE_STRICT_OBJC_MSGSEND = YES; 190 | ENABLE_TESTABILITY = YES; 191 | GCC_C_LANGUAGE_STANDARD = gnu99; 192 | GCC_DYNAMIC_NO_PIC = NO; 193 | GCC_NO_COMMON_BLOCKS = YES; 194 | GCC_OPTIMIZATION_LEVEL = 0; 195 | GCC_PREPROCESSOR_DEFINITIONS = ( 196 | "DEBUG=1", 197 | "$(inherited)", 198 | ); 199 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 200 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 201 | GCC_WARN_UNDECLARED_SELECTOR = YES; 202 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 203 | GCC_WARN_UNUSED_FUNCTION = YES; 204 | GCC_WARN_UNUSED_VARIABLE = YES; 205 | MACOSX_DEPLOYMENT_TARGET = 10.12; 206 | MTL_ENABLE_DEBUG_INFO = YES; 207 | ONLY_ACTIVE_ARCH = YES; 208 | SDKROOT = macosx; 209 | }; 210 | name = Debug; 211 | }; 212 | 37E71D7A1ED27E97007516EB /* Release */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | ALWAYS_SEARCH_USER_PATHS = NO; 216 | CLANG_ANALYZER_NONNULL = YES; 217 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 219 | CLANG_CXX_LIBRARY = "libc++"; 220 | CLANG_ENABLE_MODULES = YES; 221 | CLANG_ENABLE_OBJC_ARC = YES; 222 | CLANG_WARN_BOOL_CONVERSION = YES; 223 | CLANG_WARN_CONSTANT_CONVERSION = YES; 224 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 225 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 226 | CLANG_WARN_EMPTY_BODY = YES; 227 | CLANG_WARN_ENUM_CONVERSION = YES; 228 | CLANG_WARN_INFINITE_RECURSION = YES; 229 | CLANG_WARN_INT_CONVERSION = YES; 230 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 231 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 232 | CLANG_WARN_UNREACHABLE_CODE = YES; 233 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 234 | CODE_SIGN_IDENTITY = "-"; 235 | COPY_PHASE_STRIP = NO; 236 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 237 | ENABLE_NS_ASSERTIONS = NO; 238 | ENABLE_STRICT_OBJC_MSGSEND = YES; 239 | GCC_C_LANGUAGE_STANDARD = gnu99; 240 | GCC_NO_COMMON_BLOCKS = YES; 241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 243 | GCC_WARN_UNDECLARED_SELECTOR = YES; 244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 245 | GCC_WARN_UNUSED_FUNCTION = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | MACOSX_DEPLOYMENT_TARGET = 10.12; 248 | MTL_ENABLE_DEBUG_INFO = NO; 249 | SDKROOT = macosx; 250 | }; 251 | name = Release; 252 | }; 253 | 37E71D7C1ED27E97007516EB /* Debug */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | CLANG_ENABLE_MODULES = NO; 257 | DEVELOPMENT_TEAM = VCJVQ6T6G2; 258 | HEADER_SEARCH_PATHS = "$(SRCROOT)/UsingLibClang"; 259 | LD_RUNPATH_SEARCH_PATHS = "$(DEVELOPER_DIR)/Toolchains/XcodeDefault.xctoolchain/usr/lib"; 260 | LIBRARY_SEARCH_PATHS = "$(DEVELOPER_DIR)/Toolchains/XcodeDefault.xctoolchain/usr/lib"; 261 | PRODUCT_NAME = "$(TARGET_NAME)"; 262 | }; 263 | name = Debug; 264 | }; 265 | 37E71D7D1ED27E97007516EB /* Release */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | CLANG_ENABLE_MODULES = NO; 269 | DEVELOPMENT_TEAM = VCJVQ6T6G2; 270 | HEADER_SEARCH_PATHS = "$(SRCROOT)/UsingLibClang"; 271 | LD_RUNPATH_SEARCH_PATHS = "$(DEVELOPER_DIR)/Toolchains/XcodeDefault.xctoolchain/usr/lib"; 272 | LIBRARY_SEARCH_PATHS = "$(DEVELOPER_DIR)/Toolchains/XcodeDefault.xctoolchain/usr/lib"; 273 | PRODUCT_NAME = "$(TARGET_NAME)"; 274 | }; 275 | name = Release; 276 | }; 277 | /* End XCBuildConfiguration section */ 278 | 279 | /* Begin XCConfigurationList section */ 280 | 37E71D6F1ED27E97007516EB /* Build configuration list for PBXProject "UsingLibClang" */ = { 281 | isa = XCConfigurationList; 282 | buildConfigurations = ( 283 | 37E71D791ED27E97007516EB /* Debug */, 284 | 37E71D7A1ED27E97007516EB /* Release */, 285 | ); 286 | defaultConfigurationIsVisible = 0; 287 | defaultConfigurationName = Release; 288 | }; 289 | 37E71D7B1ED27E97007516EB /* Build configuration list for PBXNativeTarget "UsingLibClang" */ = { 290 | isa = XCConfigurationList; 291 | buildConfigurations = ( 292 | 37E71D7C1ED27E97007516EB /* Debug */, 293 | 37E71D7D1ED27E97007516EB /* Release */, 294 | ); 295 | defaultConfigurationIsVisible = 0; 296 | }; 297 | /* End XCConfigurationList section */ 298 | }; 299 | rootObject = 37E71D6C1ED27E97007516EB /* Project object */; 300 | } 301 | -------------------------------------------------------------------------------- /UsingLibClang/clang-c/BuildSystem.h: -------------------------------------------------------------------------------- 1 | /*==-- clang-c/BuildSystem.h - Utilities for use by build systems -*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides various utilities for use by build systems. *| 11 | |* *| 12 | \*===----------------------------------------------------------------------===*/ 13 | 14 | #ifndef LLVM_CLANG_C_BUILDSYSTEM_H 15 | #define LLVM_CLANG_C_BUILDSYSTEM_H 16 | 17 | #include "clang-c/Platform.h" 18 | #include "clang-c/CXErrorCode.h" 19 | #include "clang-c/CXString.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * \defgroup BUILD_SYSTEM Build system utilities 27 | * @{ 28 | */ 29 | 30 | /** 31 | * \brief Return the timestamp for use with Clang's 32 | * \c -fbuild-session-timestamp= option. 33 | */ 34 | CINDEX_LINKAGE unsigned long long clang_getBuildSessionTimestamp(void); 35 | 36 | /** 37 | * \brief Object encapsulating information about overlaying virtual 38 | * file/directories over the real file system. 39 | */ 40 | typedef struct CXVirtualFileOverlayImpl *CXVirtualFileOverlay; 41 | 42 | /** 43 | * \brief Create a \c CXVirtualFileOverlay object. 44 | * Must be disposed with \c clang_VirtualFileOverlay_dispose(). 45 | * 46 | * \param options is reserved, always pass 0. 47 | */ 48 | CINDEX_LINKAGE CXVirtualFileOverlay 49 | clang_VirtualFileOverlay_create(unsigned options); 50 | 51 | /** 52 | * \brief Map an absolute virtual file path to an absolute real one. 53 | * The virtual path must be canonicalized (not contain "."/".."). 54 | * \returns 0 for success, non-zero to indicate an error. 55 | */ 56 | CINDEX_LINKAGE enum CXErrorCode 57 | clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay, 58 | const char *virtualPath, 59 | const char *realPath); 60 | 61 | /** 62 | * \brief Set the case sensitivity for the \c CXVirtualFileOverlay object. 63 | * The \c CXVirtualFileOverlay object is case-sensitive by default, this 64 | * option can be used to override the default. 65 | * \returns 0 for success, non-zero to indicate an error. 66 | */ 67 | CINDEX_LINKAGE enum CXErrorCode 68 | clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay, 69 | int caseSensitive); 70 | 71 | /** 72 | * \brief Write out the \c CXVirtualFileOverlay object to a char buffer. 73 | * 74 | * \param options is reserved, always pass 0. 75 | * \param out_buffer_ptr pointer to receive the buffer pointer, which should be 76 | * disposed using \c clang_free(). 77 | * \param out_buffer_size pointer to receive the buffer size. 78 | * \returns 0 for success, non-zero to indicate an error. 79 | */ 80 | CINDEX_LINKAGE enum CXErrorCode 81 | clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, unsigned options, 82 | char **out_buffer_ptr, 83 | unsigned *out_buffer_size); 84 | 85 | /** 86 | * \brief free memory allocated by libclang, such as the buffer returned by 87 | * \c CXVirtualFileOverlay() or \c clang_ModuleMapDescriptor_writeToBuffer(). 88 | * 89 | * \param buffer memory pointer to free. 90 | */ 91 | CINDEX_LINKAGE void clang_free(void *buffer); 92 | 93 | /** 94 | * \brief Dispose a \c CXVirtualFileOverlay object. 95 | */ 96 | CINDEX_LINKAGE void clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay); 97 | 98 | /** 99 | * \brief Object encapsulating information about a module.map file. 100 | */ 101 | typedef struct CXModuleMapDescriptorImpl *CXModuleMapDescriptor; 102 | 103 | /** 104 | * \brief Create a \c CXModuleMapDescriptor object. 105 | * Must be disposed with \c clang_ModuleMapDescriptor_dispose(). 106 | * 107 | * \param options is reserved, always pass 0. 108 | */ 109 | CINDEX_LINKAGE CXModuleMapDescriptor 110 | clang_ModuleMapDescriptor_create(unsigned options); 111 | 112 | /** 113 | * \brief Sets the framework module name that the module.map describes. 114 | * \returns 0 for success, non-zero to indicate an error. 115 | */ 116 | CINDEX_LINKAGE enum CXErrorCode 117 | clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor, 118 | const char *name); 119 | 120 | /** 121 | * \brief Sets the umbrealla header name that the module.map describes. 122 | * \returns 0 for success, non-zero to indicate an error. 123 | */ 124 | CINDEX_LINKAGE enum CXErrorCode 125 | clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor, 126 | const char *name); 127 | 128 | /** 129 | * \brief Write out the \c CXModuleMapDescriptor object to a char buffer. 130 | * 131 | * \param options is reserved, always pass 0. 132 | * \param out_buffer_ptr pointer to receive the buffer pointer, which should be 133 | * disposed using \c clang_free(). 134 | * \param out_buffer_size pointer to receive the buffer size. 135 | * \returns 0 for success, non-zero to indicate an error. 136 | */ 137 | CINDEX_LINKAGE enum CXErrorCode 138 | clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, unsigned options, 139 | char **out_buffer_ptr, 140 | unsigned *out_buffer_size); 141 | 142 | /** 143 | * \brief Dispose a \c CXModuleMapDescriptor object. 144 | */ 145 | CINDEX_LINKAGE void clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor); 146 | 147 | /** 148 | * @} 149 | */ 150 | 151 | #ifdef __cplusplus 152 | } 153 | #endif 154 | 155 | #endif /* CLANG_C_BUILD_SYSTEM_H */ 156 | 157 | -------------------------------------------------------------------------------- /UsingLibClang/clang-c/CXCompilationDatabase.h: -------------------------------------------------------------------------------- 1 | /*===-- clang-c/CXCompilationDatabase.h - Compilation database ---*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides a public inferface to use CompilationDatabase without *| 11 | |* the full Clang C++ API. *| 12 | |* *| 13 | \*===----------------------------------------------------------------------===*/ 14 | 15 | #ifndef LLVM_CLANG_C_CXCOMPILATIONDATABASE_H 16 | #define LLVM_CLANG_C_CXCOMPILATIONDATABASE_H 17 | 18 | #include "clang-c/Platform.h" 19 | #include "clang-c/CXString.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** \defgroup COMPILATIONDB CompilationDatabase functions 26 | * \ingroup CINDEX 27 | * 28 | * @{ 29 | */ 30 | 31 | /** 32 | * A compilation database holds all information used to compile files in a 33 | * project. For each file in the database, it can be queried for the working 34 | * directory or the command line used for the compiler invocation. 35 | * 36 | * Must be freed by \c clang_CompilationDatabase_dispose 37 | */ 38 | typedef void * CXCompilationDatabase; 39 | 40 | /** 41 | * \brief Contains the results of a search in the compilation database 42 | * 43 | * When searching for the compile command for a file, the compilation db can 44 | * return several commands, as the file may have been compiled with 45 | * different options in different places of the project. This choice of compile 46 | * commands is wrapped in this opaque data structure. It must be freed by 47 | * \c clang_CompileCommands_dispose. 48 | */ 49 | typedef void * CXCompileCommands; 50 | 51 | /** 52 | * \brief Represents the command line invocation to compile a specific file. 53 | */ 54 | typedef void * CXCompileCommand; 55 | 56 | /** 57 | * \brief Error codes for Compilation Database 58 | */ 59 | typedef enum { 60 | /* 61 | * \brief No error occurred 62 | */ 63 | CXCompilationDatabase_NoError = 0, 64 | 65 | /* 66 | * \brief Database can not be loaded 67 | */ 68 | CXCompilationDatabase_CanNotLoadDatabase = 1 69 | 70 | } CXCompilationDatabase_Error; 71 | 72 | /** 73 | * \brief Creates a compilation database from the database found in directory 74 | * buildDir. For example, CMake can output a compile_commands.json which can 75 | * be used to build the database. 76 | * 77 | * It must be freed by \c clang_CompilationDatabase_dispose. 78 | */ 79 | CINDEX_LINKAGE CXCompilationDatabase 80 | clang_CompilationDatabase_fromDirectory(const char *BuildDir, 81 | CXCompilationDatabase_Error *ErrorCode); 82 | 83 | /** 84 | * \brief Free the given compilation database 85 | */ 86 | CINDEX_LINKAGE void 87 | clang_CompilationDatabase_dispose(CXCompilationDatabase); 88 | 89 | /** 90 | * \brief Find the compile commands used for a file. The compile commands 91 | * must be freed by \c clang_CompileCommands_dispose. 92 | */ 93 | CINDEX_LINKAGE CXCompileCommands 94 | clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, 95 | const char *CompleteFileName); 96 | 97 | /** 98 | * \brief Get all the compile commands in the given compilation database. 99 | */ 100 | CINDEX_LINKAGE CXCompileCommands 101 | clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase); 102 | 103 | /** 104 | * \brief Free the given CompileCommands 105 | */ 106 | CINDEX_LINKAGE void clang_CompileCommands_dispose(CXCompileCommands); 107 | 108 | /** 109 | * \brief Get the number of CompileCommand we have for a file 110 | */ 111 | CINDEX_LINKAGE unsigned 112 | clang_CompileCommands_getSize(CXCompileCommands); 113 | 114 | /** 115 | * \brief Get the I'th CompileCommand for a file 116 | * 117 | * Note : 0 <= i < clang_CompileCommands_getSize(CXCompileCommands) 118 | */ 119 | CINDEX_LINKAGE CXCompileCommand 120 | clang_CompileCommands_getCommand(CXCompileCommands, unsigned I); 121 | 122 | /** 123 | * \brief Get the working directory where the CompileCommand was executed from 124 | */ 125 | CINDEX_LINKAGE CXString 126 | clang_CompileCommand_getDirectory(CXCompileCommand); 127 | 128 | /** 129 | * \brief Get the filename associated with the CompileCommand. 130 | */ 131 | CINDEX_LINKAGE CXString 132 | clang_CompileCommand_getFilename(CXCompileCommand); 133 | 134 | /** 135 | * \brief Get the number of arguments in the compiler invocation. 136 | * 137 | */ 138 | CINDEX_LINKAGE unsigned 139 | clang_CompileCommand_getNumArgs(CXCompileCommand); 140 | 141 | /** 142 | * \brief Get the I'th argument value in the compiler invocations 143 | * 144 | * Invariant : 145 | * - argument 0 is the compiler executable 146 | */ 147 | CINDEX_LINKAGE CXString 148 | clang_CompileCommand_getArg(CXCompileCommand, unsigned I); 149 | 150 | /** 151 | * \brief Get the number of source mappings for the compiler invocation. 152 | */ 153 | CINDEX_LINKAGE unsigned 154 | clang_CompileCommand_getNumMappedSources(CXCompileCommand); 155 | 156 | /** 157 | * \brief Get the I'th mapped source path for the compiler invocation. 158 | */ 159 | CINDEX_LINKAGE CXString 160 | clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I); 161 | 162 | /** 163 | * \brief Get the I'th mapped source content for the compiler invocation. 164 | */ 165 | CINDEX_LINKAGE CXString 166 | clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I); 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | #endif 176 | 177 | -------------------------------------------------------------------------------- /UsingLibClang/clang-c/CXErrorCode.h: -------------------------------------------------------------------------------- 1 | /*===-- clang-c/CXErrorCode.h - C Index Error Codes --------------*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides the CXErrorCode enumerators. *| 11 | |* *| 12 | \*===----------------------------------------------------------------------===*/ 13 | 14 | #ifndef LLVM_CLANG_C_CXERRORCODE_H 15 | #define LLVM_CLANG_C_CXERRORCODE_H 16 | 17 | #include "clang-c/Platform.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * \brief Error codes returned by libclang routines. 25 | * 26 | * Zero (\c CXError_Success) is the only error code indicating success. Other 27 | * error codes, including not yet assigned non-zero values, indicate errors. 28 | */ 29 | enum CXErrorCode { 30 | /** 31 | * \brief No error. 32 | */ 33 | CXError_Success = 0, 34 | 35 | /** 36 | * \brief A generic error code, no further details are available. 37 | * 38 | * Errors of this kind can get their own specific error codes in future 39 | * libclang versions. 40 | */ 41 | CXError_Failure = 1, 42 | 43 | /** 44 | * \brief libclang crashed while performing the requested operation. 45 | */ 46 | CXError_Crashed = 2, 47 | 48 | /** 49 | * \brief The function detected that the arguments violate the function 50 | * contract. 51 | */ 52 | CXError_InvalidArguments = 3, 53 | 54 | /** 55 | * \brief An AST deserialization error has occurred. 56 | */ 57 | CXError_ASTReadError = 4 58 | }; 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /UsingLibClang/clang-c/CXString.h: -------------------------------------------------------------------------------- 1 | /*===-- clang-c/CXString.h - C Index strings --------------------*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides the interface to C Index strings. *| 11 | |* *| 12 | \*===----------------------------------------------------------------------===*/ 13 | 14 | #ifndef LLVM_CLANG_C_CXSTRING_H 15 | #define LLVM_CLANG_C_CXSTRING_H 16 | 17 | #include "clang-c/Platform.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * \defgroup CINDEX_STRING String manipulation routines 25 | * \ingroup CINDEX 26 | * 27 | * @{ 28 | */ 29 | 30 | /** 31 | * \brief A character string. 32 | * 33 | * The \c CXString type is used to return strings from the interface when 34 | * the ownership of that string might differ from one call to the next. 35 | * Use \c clang_getCString() to retrieve the string data and, once finished 36 | * with the string data, call \c clang_disposeString() to free the string. 37 | */ 38 | typedef struct { 39 | const void *data; 40 | unsigned private_flags; 41 | } CXString; 42 | 43 | typedef struct { 44 | CXString *Strings; 45 | unsigned Count; 46 | } CXStringSet; 47 | 48 | /** 49 | * \brief Retrieve the character data associated with the given string. 50 | */ 51 | CINDEX_LINKAGE const char *clang_getCString(CXString string); 52 | 53 | /** 54 | * \brief Free the given string. 55 | */ 56 | CINDEX_LINKAGE void clang_disposeString(CXString string); 57 | 58 | /** 59 | * \brief Free the given string set. 60 | */ 61 | CINDEX_LINKAGE void clang_disposeStringSet(CXStringSet *set); 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | #endif 71 | 72 | -------------------------------------------------------------------------------- /UsingLibClang/clang-c/Documentation.h: -------------------------------------------------------------------------------- 1 | /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides a supplementary interface for inspecting *| 11 | |* documentation comments. *| 12 | |* *| 13 | \*===----------------------------------------------------------------------===*/ 14 | 15 | #ifndef LLVM_CLANG_C_DOCUMENTATION_H 16 | #define LLVM_CLANG_C_DOCUMENTATION_H 17 | 18 | #include "clang-c/Index.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * \defgroup CINDEX_COMMENT Comment introspection 26 | * 27 | * The routines in this group provide access to information in documentation 28 | * comments. These facilities are distinct from the core and may be subject to 29 | * their own schedule of stability and deprecation. 30 | * 31 | * @{ 32 | */ 33 | 34 | /** 35 | * \brief A parsed comment. 36 | */ 37 | typedef struct { 38 | const void *ASTNode; 39 | CXTranslationUnit TranslationUnit; 40 | } CXComment; 41 | 42 | /** 43 | * \brief Given a cursor that represents a documentable entity (e.g., 44 | * declaration), return the associated parsed comment as a 45 | * \c CXComment_FullComment AST node. 46 | */ 47 | CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C); 48 | 49 | /** 50 | * \brief Describes the type of the comment AST node (\c CXComment). A comment 51 | * node can be considered block content (e. g., paragraph), inline content 52 | * (plain text) or neither (the root AST node). 53 | */ 54 | enum CXCommentKind { 55 | /** 56 | * \brief Null comment. No AST node is constructed at the requested location 57 | * because there is no text or a syntax error. 58 | */ 59 | CXComment_Null = 0, 60 | 61 | /** 62 | * \brief Plain text. Inline content. 63 | */ 64 | CXComment_Text = 1, 65 | 66 | /** 67 | * \brief A command with word-like arguments that is considered inline content. 68 | * 69 | * For example: \\c command. 70 | */ 71 | CXComment_InlineCommand = 2, 72 | 73 | /** 74 | * \brief HTML start tag with attributes (name-value pairs). Considered 75 | * inline content. 76 | * 77 | * For example: 78 | * \verbatim 79 | *

80 | * \endverbatim 81 | */ 82 | CXComment_HTMLStartTag = 3, 83 | 84 | /** 85 | * \brief HTML end tag. Considered inline content. 86 | * 87 | * For example: 88 | * \verbatim 89 | * 90 | * \endverbatim 91 | */ 92 | CXComment_HTMLEndTag = 4, 93 | 94 | /** 95 | * \brief A paragraph, contains inline comment. The paragraph itself is 96 | * block content. 97 | */ 98 | CXComment_Paragraph = 5, 99 | 100 | /** 101 | * \brief A command that has zero or more word-like arguments (number of 102 | * word-like arguments depends on command name) and a paragraph as an 103 | * argument. Block command is block content. 104 | * 105 | * Paragraph argument is also a child of the block command. 106 | * 107 | * For example: \\brief has 0 word-like arguments and a paragraph argument. 108 | * 109 | * AST nodes of special kinds that parser knows about (e. g., \\param 110 | * command) have their own node kinds. 111 | */ 112 | CXComment_BlockCommand = 6, 113 | 114 | /** 115 | * \brief A \\param or \\arg command that describes the function parameter 116 | * (name, passing direction, description). 117 | * 118 | * For example: \\param [in] ParamName description. 119 | */ 120 | CXComment_ParamCommand = 7, 121 | 122 | /** 123 | * \brief A \\tparam command that describes a template parameter (name and 124 | * description). 125 | * 126 | * For example: \\tparam T description. 127 | */ 128 | CXComment_TParamCommand = 8, 129 | 130 | /** 131 | * \brief A verbatim block command (e. g., preformatted code). Verbatim 132 | * block has an opening and a closing command and contains multiple lines of 133 | * text (\c CXComment_VerbatimBlockLine child nodes). 134 | * 135 | * For example: 136 | * \\verbatim 137 | * aaa 138 | * \\endverbatim 139 | */ 140 | CXComment_VerbatimBlockCommand = 9, 141 | 142 | /** 143 | * \brief A line of text that is contained within a 144 | * CXComment_VerbatimBlockCommand node. 145 | */ 146 | CXComment_VerbatimBlockLine = 10, 147 | 148 | /** 149 | * \brief A verbatim line command. Verbatim line has an opening command, 150 | * a single line of text (up to the newline after the opening command) and 151 | * has no closing command. 152 | */ 153 | CXComment_VerbatimLine = 11, 154 | 155 | /** 156 | * \brief A full comment attached to a declaration, contains block content. 157 | */ 158 | CXComment_FullComment = 12 159 | }; 160 | 161 | /** 162 | * \brief The most appropriate rendering mode for an inline command, chosen on 163 | * command semantics in Doxygen. 164 | */ 165 | enum CXCommentInlineCommandRenderKind { 166 | /** 167 | * \brief Command argument should be rendered in a normal font. 168 | */ 169 | CXCommentInlineCommandRenderKind_Normal, 170 | 171 | /** 172 | * \brief Command argument should be rendered in a bold font. 173 | */ 174 | CXCommentInlineCommandRenderKind_Bold, 175 | 176 | /** 177 | * \brief Command argument should be rendered in a monospaced font. 178 | */ 179 | CXCommentInlineCommandRenderKind_Monospaced, 180 | 181 | /** 182 | * \brief Command argument should be rendered emphasized (typically italic 183 | * font). 184 | */ 185 | CXCommentInlineCommandRenderKind_Emphasized 186 | }; 187 | 188 | /** 189 | * \brief Describes parameter passing direction for \\param or \\arg command. 190 | */ 191 | enum CXCommentParamPassDirection { 192 | /** 193 | * \brief The parameter is an input parameter. 194 | */ 195 | CXCommentParamPassDirection_In, 196 | 197 | /** 198 | * \brief The parameter is an output parameter. 199 | */ 200 | CXCommentParamPassDirection_Out, 201 | 202 | /** 203 | * \brief The parameter is an input and output parameter. 204 | */ 205 | CXCommentParamPassDirection_InOut 206 | }; 207 | 208 | /** 209 | * \param Comment AST node of any kind. 210 | * 211 | * \returns the type of the AST node. 212 | */ 213 | CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment); 214 | 215 | /** 216 | * \param Comment AST node of any kind. 217 | * 218 | * \returns number of children of the AST node. 219 | */ 220 | CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment); 221 | 222 | /** 223 | * \param Comment AST node of any kind. 224 | * 225 | * \param ChildIdx child index (zero-based). 226 | * 227 | * \returns the specified child of the AST node. 228 | */ 229 | CINDEX_LINKAGE 230 | CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx); 231 | 232 | /** 233 | * \brief A \c CXComment_Paragraph node is considered whitespace if it contains 234 | * only \c CXComment_Text nodes that are empty or whitespace. 235 | * 236 | * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are 237 | * never considered whitespace. 238 | * 239 | * \returns non-zero if \c Comment is whitespace. 240 | */ 241 | CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment); 242 | 243 | /** 244 | * \returns non-zero if \c Comment is inline content and has a newline 245 | * immediately following it in the comment text. Newlines between paragraphs 246 | * do not count. 247 | */ 248 | CINDEX_LINKAGE 249 | unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment); 250 | 251 | /** 252 | * \param Comment a \c CXComment_Text AST node. 253 | * 254 | * \returns text contained in the AST node. 255 | */ 256 | CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment); 257 | 258 | /** 259 | * \param Comment a \c CXComment_InlineCommand AST node. 260 | * 261 | * \returns name of the inline command. 262 | */ 263 | CINDEX_LINKAGE 264 | CXString clang_InlineCommandComment_getCommandName(CXComment Comment); 265 | 266 | /** 267 | * \param Comment a \c CXComment_InlineCommand AST node. 268 | * 269 | * \returns the most appropriate rendering mode, chosen on command 270 | * semantics in Doxygen. 271 | */ 272 | CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind 273 | clang_InlineCommandComment_getRenderKind(CXComment Comment); 274 | 275 | /** 276 | * \param Comment a \c CXComment_InlineCommand AST node. 277 | * 278 | * \returns number of command arguments. 279 | */ 280 | CINDEX_LINKAGE 281 | unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment); 282 | 283 | /** 284 | * \param Comment a \c CXComment_InlineCommand AST node. 285 | * 286 | * \param ArgIdx argument index (zero-based). 287 | * 288 | * \returns text of the specified argument. 289 | */ 290 | CINDEX_LINKAGE 291 | CXString clang_InlineCommandComment_getArgText(CXComment Comment, 292 | unsigned ArgIdx); 293 | 294 | /** 295 | * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST 296 | * node. 297 | * 298 | * \returns HTML tag name. 299 | */ 300 | CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment); 301 | 302 | /** 303 | * \param Comment a \c CXComment_HTMLStartTag AST node. 304 | * 305 | * \returns non-zero if tag is self-closing (for example, <br />). 306 | */ 307 | CINDEX_LINKAGE 308 | unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment); 309 | 310 | /** 311 | * \param Comment a \c CXComment_HTMLStartTag AST node. 312 | * 313 | * \returns number of attributes (name-value pairs) attached to the start tag. 314 | */ 315 | CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment); 316 | 317 | /** 318 | * \param Comment a \c CXComment_HTMLStartTag AST node. 319 | * 320 | * \param AttrIdx attribute index (zero-based). 321 | * 322 | * \returns name of the specified attribute. 323 | */ 324 | CINDEX_LINKAGE 325 | CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx); 326 | 327 | /** 328 | * \param Comment a \c CXComment_HTMLStartTag AST node. 329 | * 330 | * \param AttrIdx attribute index (zero-based). 331 | * 332 | * \returns value of the specified attribute. 333 | */ 334 | CINDEX_LINKAGE 335 | CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx); 336 | 337 | /** 338 | * \param Comment a \c CXComment_BlockCommand AST node. 339 | * 340 | * \returns name of the block command. 341 | */ 342 | CINDEX_LINKAGE 343 | CXString clang_BlockCommandComment_getCommandName(CXComment Comment); 344 | 345 | /** 346 | * \param Comment a \c CXComment_BlockCommand AST node. 347 | * 348 | * \returns number of word-like arguments. 349 | */ 350 | CINDEX_LINKAGE 351 | unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment); 352 | 353 | /** 354 | * \param Comment a \c CXComment_BlockCommand AST node. 355 | * 356 | * \param ArgIdx argument index (zero-based). 357 | * 358 | * \returns text of the specified word-like argument. 359 | */ 360 | CINDEX_LINKAGE 361 | CXString clang_BlockCommandComment_getArgText(CXComment Comment, 362 | unsigned ArgIdx); 363 | 364 | /** 365 | * \param Comment a \c CXComment_BlockCommand or 366 | * \c CXComment_VerbatimBlockCommand AST node. 367 | * 368 | * \returns paragraph argument of the block command. 369 | */ 370 | CINDEX_LINKAGE 371 | CXComment clang_BlockCommandComment_getParagraph(CXComment Comment); 372 | 373 | /** 374 | * \param Comment a \c CXComment_ParamCommand AST node. 375 | * 376 | * \returns parameter name. 377 | */ 378 | CINDEX_LINKAGE 379 | CXString clang_ParamCommandComment_getParamName(CXComment Comment); 380 | 381 | /** 382 | * \param Comment a \c CXComment_ParamCommand AST node. 383 | * 384 | * \returns non-zero if the parameter that this AST node represents was found 385 | * in the function prototype and \c clang_ParamCommandComment_getParamIndex 386 | * function will return a meaningful value. 387 | */ 388 | CINDEX_LINKAGE 389 | unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment); 390 | 391 | /** 392 | * \param Comment a \c CXComment_ParamCommand AST node. 393 | * 394 | * \returns zero-based parameter index in function prototype. 395 | */ 396 | CINDEX_LINKAGE 397 | unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment); 398 | 399 | /** 400 | * \param Comment a \c CXComment_ParamCommand AST node. 401 | * 402 | * \returns non-zero if parameter passing direction was specified explicitly in 403 | * the comment. 404 | */ 405 | CINDEX_LINKAGE 406 | unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment); 407 | 408 | /** 409 | * \param Comment a \c CXComment_ParamCommand AST node. 410 | * 411 | * \returns parameter passing direction. 412 | */ 413 | CINDEX_LINKAGE 414 | enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection( 415 | CXComment Comment); 416 | 417 | /** 418 | * \param Comment a \c CXComment_TParamCommand AST node. 419 | * 420 | * \returns template parameter name. 421 | */ 422 | CINDEX_LINKAGE 423 | CXString clang_TParamCommandComment_getParamName(CXComment Comment); 424 | 425 | /** 426 | * \param Comment a \c CXComment_TParamCommand AST node. 427 | * 428 | * \returns non-zero if the parameter that this AST node represents was found 429 | * in the template parameter list and 430 | * \c clang_TParamCommandComment_getDepth and 431 | * \c clang_TParamCommandComment_getIndex functions will return a meaningful 432 | * value. 433 | */ 434 | CINDEX_LINKAGE 435 | unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment); 436 | 437 | /** 438 | * \param Comment a \c CXComment_TParamCommand AST node. 439 | * 440 | * \returns zero-based nesting depth of this parameter in the template parameter list. 441 | * 442 | * For example, 443 | * \verbatim 444 | * template class TT> 445 | * void test(TT aaa); 446 | * \endverbatim 447 | * for C and TT nesting depth is 0, 448 | * for T nesting depth is 1. 449 | */ 450 | CINDEX_LINKAGE 451 | unsigned clang_TParamCommandComment_getDepth(CXComment Comment); 452 | 453 | /** 454 | * \param Comment a \c CXComment_TParamCommand AST node. 455 | * 456 | * \returns zero-based parameter index in the template parameter list at a 457 | * given nesting depth. 458 | * 459 | * For example, 460 | * \verbatim 461 | * template class TT> 462 | * void test(TT aaa); 463 | * \endverbatim 464 | * for C and TT nesting depth is 0, so we can ask for index at depth 0: 465 | * at depth 0 C's index is 0, TT's index is 1. 466 | * 467 | * For T nesting depth is 1, so we can ask for index at depth 0 and 1: 468 | * at depth 0 T's index is 1 (same as TT's), 469 | * at depth 1 T's index is 0. 470 | */ 471 | CINDEX_LINKAGE 472 | unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth); 473 | 474 | /** 475 | * \param Comment a \c CXComment_VerbatimBlockLine AST node. 476 | * 477 | * \returns text contained in the AST node. 478 | */ 479 | CINDEX_LINKAGE 480 | CXString clang_VerbatimBlockLineComment_getText(CXComment Comment); 481 | 482 | /** 483 | * \param Comment a \c CXComment_VerbatimLine AST node. 484 | * 485 | * \returns text contained in the AST node. 486 | */ 487 | CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment); 488 | 489 | /** 490 | * \brief Convert an HTML tag AST node to string. 491 | * 492 | * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST 493 | * node. 494 | * 495 | * \returns string containing an HTML tag. 496 | */ 497 | CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment); 498 | 499 | /** 500 | * \brief Convert a given full parsed comment to an HTML fragment. 501 | * 502 | * Specific details of HTML layout are subject to change. Don't try to parse 503 | * this HTML back into an AST, use other APIs instead. 504 | * 505 | * Currently the following CSS classes are used: 506 | * \li "para-brief" for \\brief paragraph and equivalent commands; 507 | * \li "para-returns" for \\returns paragraph and equivalent commands; 508 | * \li "word-returns" for the "Returns" word in \\returns paragraph. 509 | * 510 | * Function argument documentation is rendered as a \ list with arguments 511 | * sorted in function prototype order. CSS classes used: 512 | * \li "param-name-index-NUMBER" for parameter name (\); 513 | * \li "param-descr-index-NUMBER" for parameter description (\); 514 | * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if 515 | * parameter index is invalid. 516 | * 517 | * Template parameter documentation is rendered as a \ list with 518 | * parameters sorted in template parameter list order. CSS classes used: 519 | * \li "tparam-name-index-NUMBER" for parameter name (\); 520 | * \li "tparam-descr-index-NUMBER" for parameter description (\); 521 | * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for 522 | * names inside template template parameters; 523 | * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if 524 | * parameter position is invalid. 525 | * 526 | * \param Comment a \c CXComment_FullComment AST node. 527 | * 528 | * \returns string containing an HTML fragment. 529 | */ 530 | CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment); 531 | 532 | /** 533 | * \brief Convert a given full parsed comment to an XML document. 534 | * 535 | * A Relax NG schema for the XML can be found in comment-xml-schema.rng file 536 | * inside clang source tree. 537 | * 538 | * \param Comment a \c CXComment_FullComment AST node. 539 | * 540 | * \returns string containing an XML document. 541 | */ 542 | CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment); 543 | 544 | /** 545 | * @} 546 | */ 547 | 548 | 549 | #ifdef __cplusplus 550 | } 551 | #endif 552 | 553 | #endif /* CLANG_C_DOCUMENTATION_H */ 554 | 555 | -------------------------------------------------------------------------------- /UsingLibClang/clang-c/Platform.h: -------------------------------------------------------------------------------- 1 | /*===-- clang-c/Platform.h - C Index platform decls -------------*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides platform specific macros (dllimport, deprecated, ...) *| 11 | |* *| 12 | \*===----------------------------------------------------------------------===*/ 13 | 14 | #ifndef LLVM_CLANG_C_PLATFORM_H 15 | #define LLVM_CLANG_C_PLATFORM_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* MSVC DLL import/export. */ 22 | #ifdef _MSC_VER 23 | #ifdef _CINDEX_LIB_ 24 | #define CINDEX_LINKAGE __declspec(dllexport) 25 | #else 26 | #define CINDEX_LINKAGE __declspec(dllimport) 27 | #endif 28 | #else 29 | #define CINDEX_LINKAGE 30 | #endif 31 | 32 | #ifdef __GNUC__ 33 | #define CINDEX_DEPRECATED __attribute__((deprecated)) 34 | #else 35 | #ifdef _MSC_VER 36 | #define CINDEX_DEPRECATED __declspec(deprecated) 37 | #else 38 | #define CINDEX_DEPRECATED 39 | #endif 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /UsingLibClang/main.mm: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UsingLibClang 4 | // 5 | // Created by Dan.Lee on 2017/5/22. 6 | // Copyright © 2017年 Dan Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #include 11 | #include 12 | #include 13 | #include "clang-c/Index.h" 14 | 15 | 16 | int main(int argc, const char * argv[]) { 17 | @autoreleasepool { 18 | CXTranslationUnit tu; 19 | CXIndex index = clang_createIndex(1, 1); 20 | const char *filePath = "/Users/ios/NO2/iPhoneLoan/WMPayDayLoan/Modules/HomeModule/ViewController/PDLHomeViewController.m"; 21 | tu = clang_parseTranslationUnit(index, filePath, NULL, 0, nullptr, 0, CXTranslationUnit_Incomplete); 22 | if (!tu) { 23 | printf("Couldn't create translation unit"); 24 | return 1; 25 | } 26 | 27 | CXCursor rootCursor = clang_getTranslationUnitCursor(tu); 28 | CXToken *tokens; 29 | unsigned int numTokens; 30 | CXCursor *cursors = 0; 31 | CXSourceRange range = clang_getCursorExtent(rootCursor); 32 | clang_tokenize(tu, range, &tokens, &numTokens); 33 | cursors = (CXCursor *)malloc(numTokens * sizeof(CXCursor)); 34 | clang_annotateTokens(tu, tokens, numTokens, cursors); 35 | 36 | for(int i=0; i < numTokens; i++) { 37 | CXToken token = tokens[i]; 38 | CXCursor cursor = cursors[i]; 39 | CXString tokenSpelling = clang_getTokenSpelling(tu, token); 40 | CXString cursorSpelling = clang_getCursorSpelling(cursor); 41 | const char *tokenName = clang_getCString(tokenSpelling); 42 | if (CXToken_Literal == clang_getTokenKind(token) 43 | && CXCursor_PreprocessingDirective != cursor.kind 44 | && strlen(tokenName) >= 2 45 | && tokenName[0] == '\"' 46 | && tokenName[strlen(tokenName) - 1] == '\"' ) { 47 | // Do some replacing. 48 | NSData *content = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithUTF8String:filePath]]; 49 | NSString *contentString = [[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding]; 50 | NSString *stringToBeResplaced = [NSString stringWithUTF8String:tokenName]; 51 | NSString *stringToBePutted = @"\"Hello\""; 52 | contentString = [contentString stringByReplacingOccurrencesOfString:stringToBeResplaced withString:stringToBePutted]; 53 | [contentString writeToFile:[NSString stringWithUTF8String:filePath] atomically:YES encoding:NSUTF8StringEncoding error:nil]; 54 | printf("\t%d\t%s\n", cursor.kind, tokenName); 55 | } 56 | clang_disposeString(tokenSpelling); 57 | clang_disposeString(cursorSpelling); 58 | } 59 | clang_disposeTokens(tu, tokens, numTokens); 60 | clang_disposeIndex(index); 61 | clang_disposeTranslationUnit(tu); 62 | free(cursors); 63 | } 64 | return 0; 65 | } 66 | --------------------------------------------------------------------------------