From d1ea3f0d29dd9e18c42d17ef281c744b5bea6b92 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 9 Nov 2010 05:28:47 +0000 Subject: Introduce clang_getSpellingLocation() into libclang, to provide the location where we're spelling a token even within a macro. clang_getInstantiationLocation() tells where we instantiated the macro. I'm still not thrilled with the CXSourceLocation/CXSourceRange APIs, since they gloss over macro-instantiation information. llvm-svn: 118492 --- clang/include/clang-c/Index.h | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'clang/include/clang-c') diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index b193600d9d6..f3ba9974eb2 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -257,8 +257,8 @@ CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, * \brief Identifies a specific source location within a translation * unit. * - * Use clang_getInstantiationLocation() to map a source location to a - * particular file, line, and column. + * Use clang_getInstantiationLocation() or clang_getSpellingLocation() + * to map a source location to a particular file, line, and column. */ typedef struct { void *ptr_data[2]; @@ -325,6 +325,9 @@ CINDEX_LINKAGE CXSourceRange clang_getRange(CXSourceLocation begin, * \brief Retrieve the file, line, column, and offset represented by * the given source location. * + * If the location refers into a macro instantiation, retrieves the + * location of the macro instantiation. + * * \param location the location within a source file that will be decomposed * into its parts. * @@ -346,6 +349,34 @@ CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, unsigned *column, unsigned *offset); +/** + * \brief Retrieve the file, line, column, and offset represented by + * the given source location. + * + * If the location refers into a macro instantiation, return where the + * location was originally spelled in the source file. + * + * \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_getSpellingLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + /** * \brief Retrieve a source location representing the first character within a * source range. -- cgit v1.2.3