diff options
| -rw-r--r-- | clang/include/clang-c/Index.h | 31 | ||||
| -rw-r--r-- | clang/tools/libclang/CXSourceLocation.cpp | 39 | ||||
| -rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
3 files changed, 69 insertions, 2 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 94c896ec6e2..011588efc88 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/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 9 +#define CINDEX_VERSION_MINOR 10 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ @@ -531,6 +531,35 @@ CINDEX_LINKAGE void clang_getSpellingLocation(CXSourceLocation location, unsigned *offset); /** + * \brief Retrieve the file, line, column, and offset represented by + * the given source location. + * + * If the location refers into a macro expansion, return where the macro was + * expanded or where the macro argument was written, if the location points at + * a macro argument. + * + * \param location the location within a source file that will be decomposed + * into its parts. + * + * \param file [out] if non-NULL, will be set to the file to which the given + * source location points. + * + * \param line [out] if non-NULL, will be set to the line to which the given + * source location points. + * + * \param column [out] if non-NULL, will be set to the column to which the given + * source location points. + * + * \param offset [out] if non-NULL, will be set to the offset into the + * buffer to which the given source location points. + */ +CINDEX_LINKAGE void clang_getFileLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** * \brief Retrieve a source location representing the first character within a * source range. */ diff --git a/clang/tools/libclang/CXSourceLocation.cpp b/clang/tools/libclang/CXSourceLocation.cpp index 5d49f42a4a5..8d88a116e04 100644 --- a/clang/tools/libclang/CXSourceLocation.cpp +++ b/clang/tools/libclang/CXSourceLocation.cpp @@ -294,6 +294,7 @@ void clang_getSpellingLocation(CXSourceLocation location, const SourceManager &SM = *static_cast<const SourceManager*>(location.ptr_data[0]); + // FIXME: This should call SourceManager::getSpellingLoc(). SourceLocation SpellLoc = SM.getFileLoc(Loc); std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SpellLoc); FileID FID = LocInfo.first; @@ -312,5 +313,41 @@ void clang_getSpellingLocation(CXSourceLocation location, *offset = FileOffset; } -} // end extern "C" +void clang_getFileLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset) { + + if (!isASTUnitSourceLocation(location)) { + CXLoadedDiagnostic::decodeLocation(location, file, line, + column, offset); + return; + } + + SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); + + if (!location.ptr_data[0] || Loc.isInvalid()) + return createNullLocation(file, line, column, offset); + const SourceManager &SM = + *static_cast<const SourceManager*>(location.ptr_data[0]); + SourceLocation FileLoc = SM.getFileLoc(Loc); + std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(FileLoc); + FileID FID = LocInfo.first; + unsigned FileOffset = LocInfo.second; + + if (FID.isInvalid()) + return createNullLocation(file, line, column, offset); + + if (file) + *file = (void *)SM.getFileEntryForID(FID); + if (line) + *line = SM.getLineNumber(FID, FileOffset); + if (column) + *column = SM.getColumnNumber(FID, FileOffset); + if (offset) + *offset = FileOffset; +} + +} // end extern "C" diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 68bfb71f18f..8f3c86318c7 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -163,6 +163,7 @@ clang_getEnumDeclIntegerType clang_getFieldDeclBitWidth clang_getExpansionLocation clang_getFile +clang_getFileLocation clang_getFileName clang_getFileTime clang_getFunctionTypeCallingConv |

