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...

llvm-svn: 138860
This commit is contained in:
Chandler Carruth 2011-08-31 16:53:37 +00:00
parent 5247ca0ae5
commit 4aa01ef19c
2 changed files with 41 additions and 19 deletions

View File

@ -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,

View File

@ -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<const SourceManager*>(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),