Expose macro definitions as CIndex cursors. These can still only be
generated by clang_annotateTokens().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98837 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index deab846..ce21885 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -1443,6 +1443,10 @@
return createCXString(getCursorMacroInstantiation(C)->getName()
->getNameStart());
+ if (C.kind == CXCursor_MacroDefinition)
+ return createCXString(getCursorMacroDefinition(C)->getName()
+ ->getNameStart());
+
if (clang_isDeclaration(C.kind))
return getDeclSpelling(getCursorDecl(C));
@@ -1527,6 +1531,8 @@
return createCXString("attribute(iboutlet)");
case CXCursor_PreprocessingDirective:
return createCXString("preprocessing directive");
+ case CXCursor_MacroDefinition:
+ return createCXString("macro definition");
case CXCursor_MacroInstantiation:
return createCXString("macro instantiation");
}
@@ -1665,6 +1671,11 @@
= cxcursor::getCursorMacroInstantiation(C)->getSourceRange().getBegin();
return cxloc::translateSourceLocation(getCursorContext(C), L);
}
+
+ if (C.kind == CXCursor_MacroDefinition) {
+ SourceLocation L = cxcursor::getCursorMacroDefinition(C)->getLocation();
+ return cxloc::translateSourceLocation(getCursorContext(C), L);
+ }
if (!getCursorDecl(C))
return clang_getNullLocation();
@@ -1726,6 +1737,11 @@
SourceRange R = cxcursor::getCursorMacroInstantiation(C)->getSourceRange();
return cxloc::translateSourceRange(getCursorContext(C), R);
}
+
+ if (C.kind == CXCursor_MacroDefinition) {
+ SourceRange R = cxcursor::getCursorMacroDefinition(C)->getSourceRange();
+ return cxloc::translateSourceRange(getCursorContext(C), R);
+ }
if (!getCursorDecl(C))
return clang_getNullRange();
@@ -2387,7 +2403,15 @@
continue;
}
- // FIXME: expose other preprocessed entities.
+ if (MacroDefinition *MD = dyn_cast<MacroDefinition>(Entity)) {
+ SourceLocation Loc = MD->getLocation();
+ if (Loc.isFileID()) {
+ Annotated[Loc.getRawEncoding()]
+ = MakeMacroDefinitionCursor(MD, CXXUnit);
+ }
+
+ continue;
+ }
}
}
diff --git a/tools/CIndex/CXCursor.cpp b/tools/CIndex/CXCursor.cpp
index 1e5265e..407f44c 100644
--- a/tools/CIndex/CXCursor.cpp
+++ b/tools/CIndex/CXCursor.cpp
@@ -314,6 +314,16 @@
reinterpret_cast<uintptr_t> (C.data[1])));
}
+CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, ASTUnit *TU) {
+ CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } };
+ return C;
+}
+
+MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
+ assert(C.kind == CXCursor_MacroDefinition);
+ return static_cast<MacroDefinition *>(C.data[0]);
+}
+
CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI,
ASTUnit *TU) {
CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } };
diff --git a/tools/CIndex/CXCursor.h b/tools/CIndex/CXCursor.h
index 24ac1e4..1664f5a 100644
--- a/tools/CIndex/CXCursor.h
+++ b/tools/CIndex/CXCursor.h
@@ -25,6 +25,7 @@
class Attr;
class Decl;
class Expr;
+class MacroDefinition;
class MacroInstantiation;
class NamedDecl;
class ObjCInterfaceDecl;
@@ -80,6 +81,13 @@
/// \brief Unpack a given preprocessing directive to retrieve its source range.
SourceRange getCursorPreprocessingDirective(CXCursor C);
+/// \brief Create a macro definition cursor.
+CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
+
+/// \brief Unpack a given macro definition cursor to retrieve its
+/// source range.
+MacroDefinition *getCursorMacroDefinition(CXCursor C);
+
/// \brief Create a macro instantiation cursor.
CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);