From 76a434840a2d6088f9e6b897e6ff515db9b36b04 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 20 May 2010 02:59:19 +0000 Subject: [PATCH] Add libclang function 'clang_isFromMainFile()' (which just wraps SourceManager::isFromMainFile()). llvm-svn: 104208 --- clang/include/clang-c/Index.h | 6 ++++++ clang/tools/libclang/CIndex.cpp | 7 +++++++ clang/tools/libclang/libclang.darwin.exports | 1 + clang/tools/libclang/libclang.exports | 1 + 4 files changed, 15 insertions(+) diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 663737a0f36b..5fd5cbd1f0a4 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -342,6 +342,12 @@ CINDEX_LINKAGE CXSourceLocation clang_getRangeStart(CXSourceRange range); */ CINDEX_LINKAGE CXSourceLocation clang_getRangeEnd(CXSourceRange range); +/** + * \brief Determine if the source location occurs within the main file + * of the translation unit (as opposed to an included header). + */ +CINDEX_LINKAGE unsigned clang_isFromMainFile(CXSourceLocation loc); + /** * @} */ diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 945d05bf23e0..d0773565a953 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -1479,6 +1479,13 @@ CXSourceLocation clang_getRangeEnd(CXSourceRange range) { return Result; } +unsigned clang_isFromMainFile(CXSourceLocation loc) { + SourceLocation Loc = SourceLocation::getFromRawEncoding(loc.int_data); + const SourceManager &SM = + *static_cast(loc.ptr_data[0]); + return SM.isFromMainFile(Loc) ? 1 : 0; +} + } // end: extern "C" //===----------------------------------------------------------------------===// diff --git a/clang/tools/libclang/libclang.darwin.exports b/clang/tools/libclang/libclang.darwin.exports index 4b61bd34cbd3..59888f173b00 100644 --- a/clang/tools/libclang/libclang.darwin.exports +++ b/clang/tools/libclang/libclang.darwin.exports @@ -77,6 +77,7 @@ _clang_getTypeKindSpelling _clang_isCursorDefinition _clang_isDeclaration _clang_isExpression +_clang_isFromMainFile _clang_isInvalid _clang_isPreprocessing _clang_isReference diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 744ba7143608..12062470f22d 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -77,6 +77,7 @@ clang_getTypeKindSpelling clang_isCursorDefinition clang_isDeclaration clang_isExpression +clang_isFromMainFile clang_isInvalid clang_isPreprocessing clang_isReference