From ad0d5707463cd7875e1ffd50dacd3f900d185aa1 Mon Sep 17 00:00:00 2001 From: Stefanus Du Toit Date: Thu, 8 Aug 2013 17:48:14 +0000 Subject: [PATCH] Add clang_Location_isFromMainFile() to libclang. Also bump the minor version number and update libclang.exports. Reviewed by: Dmitri Gribenko, Doug Gregor git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187994 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang-c/Index.h | 8 +++++++- tools/libclang/CXSourceLocation.cpp | 11 +++++++++++ tools/libclang/libclang.exports | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 1adaa48615..51b1a8c2ee 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 19 +#define CINDEX_VERSION_MINOR 20 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ @@ -413,6 +413,12 @@ CINDEX_LINKAGE CXSourceLocation clang_getLocationForOffset(CXTranslationUnit tu, */ CINDEX_LINKAGE int clang_Location_isInSystemHeader(CXSourceLocation location); +/** + * \brief Returns non-zero if the given source location is in the main file of + * the corresponding translation unit. + */ +CINDEX_LINKAGE int clang_Location_isFromMainFile(CXSourceLocation location); + /** * \brief Retrieve a NULL (invalid) source range. */ diff --git a/tools/libclang/CXSourceLocation.cpp b/tools/libclang/CXSourceLocation.cpp index b7c7622c66..71e425d1f7 100644 --- a/tools/libclang/CXSourceLocation.cpp +++ b/tools/libclang/CXSourceLocation.cpp @@ -209,6 +209,17 @@ int clang_Location_isInSystemHeader(CXSourceLocation location) { return SM.isInSystemHeader(Loc); } +int clang_Location_isFromMainFile(CXSourceLocation location) { + const SourceLocation Loc = + SourceLocation::getFromRawEncoding(location.int_data); + if (Loc.isInvalid()) + return 0; + + const SourceManager &SM = + *static_cast(location.ptr_data[0]); + return SM.isFromMainFile(Loc); +} + void clang_getExpansionLocation(CXSourceLocation location, CXFile *file, unsigned *line, diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index 037f26fcc0..92b060a169 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -255,6 +255,7 @@ clang_isVirtualBase clang_isVolatileQualifiedType clang_loadDiagnostics clang_Location_isInSystemHeader +clang_Location_isFromMainFile clang_parseTranslationUnit clang_remap_dispose clang_remap_getFilenames -- 2.40.0