From: Chandler Carruth Date: Wed, 31 Aug 2011 16:53:37 +0000 (+0000) Subject: Update libclang to have APIs corresponding to the new 'expansion' naming X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20174221af145554b76a0b0f5e4eb3ac70d05945;p=clang Update libclang to have APIs corresponding to the new 'expansion' naming system for macro-backed source locations. The old APIs are preserved for legacy users. This was intended to land with the main work of instantiation -> expansion, but despite running it by Doug over a month ago, I forgot to commit it. Very sorry for that... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138860 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 7c32250438..644518ac0f 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -263,7 +263,7 @@ CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu, * \brief Identifies a specific source location within a translation * unit. * - * Use clang_getInstantiationLocation() or clang_getSpellingLocation() + * Use clang_getExpansionLocation() or clang_getSpellingLocation() * to map a source location to a particular file, line, and column. */ typedef struct { @@ -339,8 +339,8 @@ CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1, * \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. + * If the location refers into a macro expansion, retrieves the + * location of the macro expansion. * * \param location the location within a source file that will be decomposed * into its parts. @@ -357,6 +357,20 @@ CINDEX_LINKAGE unsigned clang_equalRanges(CXSourceRange range1, * \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_getExpansionLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset); + +/** + * \brief Legacy API to retrieve the file, line, column, and offset represented + * by the given source location. + * + * This interface has been replaced by the newer interface + * \see clang_getExpansionLocation(). See that interface's documentation for + * details. + */ CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location, CXFile *file, unsigned *line, diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 274a6c4aac..7f06a57feb 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -2826,11 +2826,11 @@ static void createNullLocation(CXFile *file, unsigned *line, } extern "C" { -void clang_getInstantiationLocation(CXSourceLocation location, - CXFile *file, - unsigned *line, - unsigned *column, - unsigned *offset) { +void clang_getExpansionLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset) { SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data); if (!location.ptr_data[0] || Loc.isInvalid()) { @@ -2840,11 +2840,11 @@ void clang_getInstantiationLocation(CXSourceLocation location, const SourceManager &SM = *static_cast(location.ptr_data[0]); - SourceLocation InstLoc = SM.getExpansionLoc(Loc); + SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc); // Check that the FileID is invalid on the expansion location. // This can manifest in invalid code. - FileID fileID = SM.getFileID(InstLoc); + FileID fileID = SM.getFileID(ExpansionLoc); bool Invalid = false; const SrcMgr::SLocEntry &sloc = SM.getSLocEntry(fileID, &Invalid); if (!sloc.isFile() || Invalid) { @@ -2855,11 +2855,20 @@ void clang_getInstantiationLocation(CXSourceLocation location, if (file) *file = (void *)SM.getFileEntryForSLocEntry(sloc); if (line) - *line = SM.getExpansionLineNumber(InstLoc); + *line = SM.getExpansionLineNumber(ExpansionLoc); if (column) - *column = SM.getExpansionColumnNumber(InstLoc); + *column = SM.getExpansionColumnNumber(ExpansionLoc); if (offset) - *offset = SM.getDecomposedLoc(InstLoc).second; + *offset = SM.getDecomposedLoc(ExpansionLoc).second; +} + +void clang_getInstantiationLocation(CXSourceLocation location, + CXFile *file, + unsigned *line, + unsigned *column, + unsigned *offset) { + // Redirect to new API. + clang_getExpansionLocation(location, file, line, column, offset); } void clang_getSpellingLocation(CXSourceLocation location, @@ -3531,10 +3540,9 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) { const char *IsDef = clang_isCursorDefinition(Result)? " (Definition)" : ""; CXSourceLocation ResultLoc = clang_getCursorLocation(Result); - clang_getInstantiationLocation(Loc, &SearchFile, &SearchLine, &SearchColumn, - 0); - clang_getInstantiationLocation(ResultLoc, &ResultFile, &ResultLine, - &ResultColumn, 0); + clang_getExpansionLocation(Loc, &SearchFile, &SearchLine, &SearchColumn, 0); + clang_getExpansionLocation(ResultLoc, &ResultFile, &ResultLine, + &ResultColumn, 0); SearchFileName = clang_getFileName(SearchFile); ResultFileName = clang_getFileName(ResultFile); KindSpelling = clang_getCursorKindSpelling(Result.kind); @@ -3556,8 +3564,8 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) { = clang_getCursorKindSpelling(Definition.kind); CXFile DefinitionFile; unsigned DefinitionLine, DefinitionColumn; - clang_getInstantiationLocation(DefinitionLoc, &DefinitionFile, - &DefinitionLine, &DefinitionColumn, 0); + clang_getExpansionLocation(DefinitionLoc, &DefinitionFile, + &DefinitionLine, &DefinitionColumn, 0); CXString DefinitionFileName = clang_getFileName(DefinitionFile); fprintf(stderr, " -> %s(%s:%d:%d)\n", clang_getCString(DefinitionKindSpelling),