diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-02-24 00:05:14 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-02-24 00:05:14 +0000 |
commit | c515978bd3a703aa733f846a0094ffa84d149074 (patch) | |
tree | 575f1660e68d74b4268c6a1460f2fbb4245da518 /include/clang/Lex | |
parent | 82a29af8cbc4b117af83c5c5dfa875b5699c97c4 (diff) |
[preprocessor] Use MacroDirective in the preprocessor callbacks to make available the
full information about the macro (e.g if it was imported and where).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175978 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex')
-rw-r--r-- | include/clang/Lex/PPCallbacks.h | 61 | ||||
-rw-r--r-- | include/clang/Lex/PPConditionalDirectiveRecord.h | 4 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 13 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 16 |
4 files changed, 49 insertions, 45 deletions
diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index a32e163049..96359a2aa3 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -26,7 +26,7 @@ namespace clang { class SourceLocation; class Token; class IdentifierInfo; - class MacroInfo; + class MacroDirective; /// \brief This interface provides a way to observe the actions of the /// preprocessor as it does its thing. @@ -184,23 +184,25 @@ public: /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a /// macro invocation is found. - virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI, + virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, SourceRange Range) { } /// \brief Hook called whenever a macro definition is seen. - virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) { + virtual void MacroDefined(const Token &MacroNameTok, + const MacroDirective *MD) { } /// \brief Hook called whenever a macro \#undef is seen. /// - /// MI is released immediately following this callback. - virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) { + /// MD is released immediately following this callback. + virtual void MacroUndefined(const Token &MacroNameTok, + const MacroDirective *MD) { } /// \brief Hook called whenever the 'defined' operator is seen. - /// \param MI The MacroInfo if the name was a macro, null otherwise. - virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI) { + /// \param MD The MacroDirective if the name was a macro, null otherwise. + virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) { } /// \brief Hook called when a source range is skipped. @@ -229,17 +231,17 @@ public: /// \brief Hook called whenever an \#ifdef is seen. /// \param Loc the source location of the directive. /// \param MacroNameTok Information on the token being tested. - /// \param MI The MacroInfo if the name was a macro, null otherwise. + /// \param MD The MacroDirective if the name was a macro, null otherwise. virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI) { + const MacroDirective *MD) { } /// \brief Hook called whenever an \#ifndef is seen. /// \param Loc the source location of the directive. /// \param MacroNameTok Information on the token being tested. - /// \param MI The MacroInfo if the name was a macro, null otherwise. + /// \param MD The MacroDirective if the name was a macro, null otherwise. virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI) { + const MacroDirective *MD) { } /// \brief Hook called whenever an \#else is seen. @@ -351,25 +353,26 @@ public: Second->PragmaDiagnostic(Loc, Namespace, mapping, Str); } - virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI, + virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, SourceRange Range) { - First->MacroExpands(MacroNameTok, MI, Range); - Second->MacroExpands(MacroNameTok, MI, Range); + First->MacroExpands(MacroNameTok, MD, Range); + Second->MacroExpands(MacroNameTok, MD, Range); } - virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) { - First->MacroDefined(MacroNameTok, MI); - Second->MacroDefined(MacroNameTok, MI); + virtual void MacroDefined(const Token &MacroNameTok, const MacroDirective *MD) { + First->MacroDefined(MacroNameTok, MD); + Second->MacroDefined(MacroNameTok, MD); } - virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) { - First->MacroUndefined(MacroNameTok, MI); - Second->MacroUndefined(MacroNameTok, MI); + virtual void MacroUndefined(const Token &MacroNameTok, + const MacroDirective *MD) { + First->MacroUndefined(MacroNameTok, MD); + Second->MacroUndefined(MacroNameTok, MD); } - virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI) { - First->Defined(MacroNameTok, MI); - Second->Defined(MacroNameTok, MI); + virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD) { + First->Defined(MacroNameTok, MD); + Second->Defined(MacroNameTok, MD); } virtual void SourceRangeSkipped(SourceRange Range) { @@ -392,16 +395,16 @@ public: /// \brief Hook called whenever an \#ifdef is seen. virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI) { - First->Ifdef(Loc, MacroNameTok, MI); - Second->Ifdef(Loc, MacroNameTok, MI); + const MacroDirective *MD) { + First->Ifdef(Loc, MacroNameTok, MD); + Second->Ifdef(Loc, MacroNameTok, MD); } /// \brief Hook called whenever an \#ifndef is seen. virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI) { - First->Ifndef(Loc, MacroNameTok, MI); - Second->Ifndef(Loc, MacroNameTok, MI); + const MacroDirective *MD) { + First->Ifndef(Loc, MacroNameTok, MD); + Second->Ifndef(Loc, MacroNameTok, MD); } /// \brief Hook called whenever an \#else is seen. diff --git a/include/clang/Lex/PPConditionalDirectiveRecord.h b/include/clang/Lex/PPConditionalDirectiveRecord.h index 29d9289274..b9a22529e2 100644 --- a/include/clang/Lex/PPConditionalDirectiveRecord.h +++ b/include/clang/Lex/PPConditionalDirectiveRecord.h @@ -90,9 +90,9 @@ private: virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc); virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI); + const MacroDirective *MD); virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI); + const MacroDirective *MD); virtual void Else(SourceLocation Loc, SourceLocation IfLoc); virtual void Endif(SourceLocation Loc, SourceLocation IfLoc); }; diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index 665d250919..b13b2be7f3 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -26,6 +26,7 @@ namespace clang { class IdentifierInfo; + class MacroInfo; class PreprocessingRecord; } @@ -557,10 +558,10 @@ namespace clang { MacroDefinition *findMacroDefinition(const MacroInfo *MI); private: - virtual void MacroExpands(const Token &Id, const MacroInfo* MI, + virtual void MacroExpands(const Token &Id, const MacroDirective *MD, SourceRange Range); - virtual void MacroDefined(const Token &Id, const MacroInfo *MI); - virtual void MacroUndefined(const Token &Id, const MacroInfo *MI); + virtual void MacroDefined(const Token &Id, const MacroDirective *MD); + virtual void MacroUndefined(const Token &Id, const MacroDirective *MD); virtual void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, @@ -571,11 +572,11 @@ namespace clang { StringRef RelativePath, const Module *Imported); virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI); + const MacroDirective *MD); virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, - const MacroInfo *MI); + const MacroDirective *MD); /// \brief Hook called whenever the 'defined' operator is seen. - virtual void Defined(const Token &MacroNameTok, const MacroInfo *MI); + virtual void Defined(const Token &MacroNameTok, const MacroDirective *MD); void addMacroExpansion(const Token &Id, const MacroInfo *MI, SourceRange Range); diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index c1c55db41a..eccd449869 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -303,10 +303,10 @@ class Preprocessor : public RefCountedBase<Preprocessor> { struct MacroExpandsInfo { Token Tok; - MacroInfo *MI; + MacroDirective *MD; SourceRange Range; - MacroExpandsInfo(Token Tok, MacroInfo *MI, SourceRange Range) - : Tok(Tok), MI(MI), Range(Range) { } + MacroExpandsInfo(Token Tok, MacroDirective *MD, SourceRange Range) + : Tok(Tok), MD(MD), Range(Range) { } }; SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks; @@ -560,10 +560,10 @@ public: MacroDirective *getMacroDirectiveHistory(const IdentifierInfo *II) const; /// \brief Specify a macro for this identifier. - void setMacroDirective(IdentifierInfo *II, MacroInfo *MI, - SourceLocation Loc, bool isImported); - void setMacroDirective(IdentifierInfo *II, MacroInfo *MI) { - setMacroDirective(II, MI, MI->getDefinitionLoc(), false); + MacroDirective *setMacroDirective(IdentifierInfo *II, MacroInfo *MI, + SourceLocation Loc, bool isImported); + MacroDirective *setMacroDirective(IdentifierInfo *II, MacroInfo *MI) { + return setMacroDirective(II, MI, MI->getDefinitionLoc(), false); } /// \brief Add a MacroInfo that was loaded from an AST file. void addLoadedMacroInfo(IdentifierInfo *II, MacroDirective *MD, @@ -1333,7 +1333,7 @@ private: /// HandleMacroExpandedIdentifier - If an identifier token is read that is to /// be expanded as a macro, handle it and return the next token as 'Tok'. If /// the macro should not be expanded return true, otherwise return false. - bool HandleMacroExpandedIdentifier(Token &Tok, MacroInfo *MI); + bool HandleMacroExpandedIdentifier(Token &Tok, MacroDirective *MD); /// \brief Cache macro expanded tokens for TokenLexers. // |