* \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 {
* \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.
* \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,
}
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()) {
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) {
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,
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);
= 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),