summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang/CXCursor.h
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-07 19:16:25 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-01-07 19:16:25 +0000
commit579825a50aad9759912f349fd9f52c8961056dd3 (patch)
tree4d422a1bf72d7cd1103b8e9bce377f8ffd4d0fb6 /clang/tools/libclang/CXCursor.h
parent7572be2e447b8b1762479a58b4dc3617db0ce120 (diff)
downloadbcm5719-llvm-579825a50aad9759912f349fd9f52c8961056dd3.tar.gz
bcm5719-llvm-579825a50aad9759912f349fd9f52c8961056dd3.zip
[libclang] When getting the cursor for an identifier inside a macro definition, check if
this was ever a macro name and return a specific CXCursor_MacroExpansion cursor in such a case, instead of the generic CXCursor_MacroDefinition. Checking for macro name makes sure the identifier is not part of the identifier list in a function macro. While, in general, resolving identifiers in macro definitions to other macros may not be completely accurate, it greatly improves functionality such as give-me-the-definition-of-this, which was not working at all inside macro definitions. llvm-svn: 171773
Diffstat (limited to 'clang/tools/libclang/CXCursor.h')
-rw-r--r--clang/tools/libclang/CXCursor.h49
1 files changed, 46 insertions, 3 deletions
diff --git a/clang/tools/libclang/CXCursor.h b/clang/tools/libclang/CXCursor.h
index 120b881069d..86fb9752439 100644
--- a/clang/tools/libclang/CXCursor.h
+++ b/clang/tools/libclang/CXCursor.h
@@ -42,6 +42,7 @@ class TemplateDecl;
class TemplateName;
class TypeDecl;
class VarDecl;
+class IdentifierInfo;
namespace cxcursor {
@@ -153,9 +154,51 @@ MacroDefinition *getCursorMacroDefinition(CXCursor C);
CXCursor MakeMacroExpansionCursor(MacroExpansion *,
CXTranslationUnit TU);
-/// \brief Unpack a given macro expansion cursor to retrieve its
-/// source range.
-MacroExpansion *getCursorMacroExpansion(CXCursor C);
+/// \brief Create a "pseudo" macro expansion cursor, using a macro definition
+/// and a source location.
+CXCursor MakeMacroExpansionCursor(MacroDefinition *, SourceLocation Loc,
+ CXTranslationUnit TU);
+
+/// \brief Wraps a macro expansion cursor and provides a common interface
+/// for a normal macro expansion cursor or a "pseudo" one.
+///
+/// "Pseudo" macro expansion cursors (essentially a macro definition along with
+/// a source location) are created in special cases, for example they can be
+/// created for identifiers inside macro definitions, if these identifiers are
+/// macro names.
+class MacroExpansionCursor {
+ CXCursor C;
+
+ bool isPseudo() const {
+ return C.data[1] != 0;
+ }
+ MacroDefinition *getAsMacroDefinition() const {
+ assert(isPseudo());
+ return static_cast<MacroDefinition *>(C.data[0]);
+ }
+ MacroExpansion *getAsMacroExpansion() const {
+ assert(!isPseudo());
+ return static_cast<MacroExpansion *>(C.data[0]);
+ }
+ SourceLocation getPseudoLoc() const {
+ assert(isPseudo());
+ return SourceLocation::getFromPtrEncoding(C.data[1]);
+ }
+
+public:
+ MacroExpansionCursor(CXCursor C) : C(C) {
+ assert(C.kind == CXCursor_MacroExpansion);
+ }
+
+ const IdentifierInfo *getName() const;
+ MacroDefinition *getDefinition() const;
+ SourceRange getSourceRange() const;
+};
+
+/// \brief Unpack a given macro expansion cursor to retrieve its info.
+static inline MacroExpansionCursor getCursorMacroExpansion(CXCursor C) {
+ return C;
+}
/// \brief Create an inclusion directive cursor.
CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
OpenPOWER on IntegriCloud