[cfe-commits] PATCH: Change PPCallbacks to use Token more often
Chris Lattner
clattner at apple.com
Thu Nov 18 21:22:19 PST 2010
On Nov 18, 2010, at 4:27 PM, Craig Silverstein wrote:
> Several PPCallbacks take an SourceLocation + IdentifierInfo, rather
> than a Token that holds the same information all in one easy-to-use
> package. There's no technical reason to prefer the former -- the
> information comes from a Token originally -- and it's clumsier to use,
> so I've changed the code to use tokens everywhere.
>
> Look ok to commit?
Makes sense to me, please commit!
-Chris
>
> craig
> Index: include/clang/Lex/PPCallbacks.h
> ===================================================================
> --- include/clang/Lex/PPCallbacks.h (revision 119697)
> +++ include/clang/Lex/PPCallbacks.h (working copy)
> @@ -113,17 +113,16 @@
> /// MacroExpands - This is called by
> /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is
> /// found.
> - virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
> + virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI) {
> }
>
> /// MacroDefined - This hook is called whenever a macro definition is seen.
> - virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
> + virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
> }
>
> /// MacroUndefined - This hook is called whenever a macro #undef is seen.
> /// MI is released immediately following this callback.
> - virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
> - const MacroInfo *MI) {
> + virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
> }
>
> /// If -- This hook is called whenever an #if is seen.
> @@ -141,13 +140,13 @@
> /// Ifdef -- This hook is called whenever an #ifdef is seen.
> /// \param Loc The location of the token being tested.
> /// \param II Information on the token being tested.
> - virtual void Ifdef(SourceLocation Loc, const IdentifierInfo* II) {
> + virtual void Ifdef(const Token &MacroNameTok) {
> }
>
> /// Ifndef -- This hook is called whenever an #ifndef is seen.
> /// \param Loc The location of the token being tested.
> /// \param II Information on the token being tested.
> - virtual void Ifndef(SourceLocation Loc, const IdentifierInfo* II) {
> + virtual void Ifndef(const Token &MacroNameTok) {
> }
>
> /// Else -- This hook is called whenever an #else is seen.
> @@ -205,20 +204,19 @@
> Second->PragmaMessage(Loc, Str);
> }
>
> - virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
> - First->MacroExpands(Id, MI);
> - Second->MacroExpands(Id, MI);
> + virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI) {
> + First->MacroExpands(MacroNameTok, MI);
> + Second->MacroExpands(MacroNameTok, MI);
> }
>
> - virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
> - First->MacroDefined(II, MI);
> - Second->MacroDefined(II, MI);
> + virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) {
> + First->MacroDefined(MacroNameTok, MI);
> + Second->MacroDefined(MacroNameTok, MI);
> }
>
> - virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
> - const MacroInfo *MI) {
> - First->MacroUndefined(Loc, II, MI);
> - Second->MacroUndefined(Loc, II, MI);
> + virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) {
> + First->MacroUndefined(MacroNameTok, MI);
> + Second->MacroUndefined(MacroNameTok, MI);
> }
>
> /// If -- This hook is called whenever an #if is seen.
> @@ -234,15 +232,15 @@
> }
>
> /// Ifdef -- This hook is called whenever an #ifdef is seen.
> - virtual void Ifdef(SourceLocation Loc, const IdentifierInfo* II) {
> - First->Ifdef(Loc, II);
> - Second->Ifdef(Loc, II);
> + virtual void Ifdef(const Token &MacroNameTok) {
> + First->Ifdef(MacroNameTok);
> + Second->Ifdef(MacroNameTok);
> }
>
> /// Ifndef -- This hook is called whenever an #ifndef is seen.
> - virtual void Ifndef(SourceLocation Loc, const IdentifierInfo* II) {
> - First->Ifndef(Loc, II);
> - Second->Ifndef(Loc, II);
> + virtual void Ifndef(cosnt Token &MacroNameTok) {
> + First->Ifndef(MacroNameTok);
> + Second->Ifndef(MacroNameTok);
> }
>
> /// Else -- This hook is called whenever an #else is seen.
> Index: include/clang/Lex/PreprocessingRecord.h
> ===================================================================
> --- include/clang/Lex/PreprocessingRecord.h (revision 119697)
> +++ include/clang/Lex/PreprocessingRecord.h (working copy)
> @@ -325,9 +325,8 @@
> MacroDefinition *findMacroDefinition(const MacroInfo *MI);
>
> virtual void MacroExpands(const Token &Id, const MacroInfo* MI);
> - virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI);
> - virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
> - const MacroInfo *MI);
> + virtual void MacroDefined(const Token &Id, const MacroInfo *MI);
> + virtual void MacroUndefined(const Token &Id, const MacroInfo *MI);
> virtual void InclusionDirective(SourceLocation HashLoc,
> const Token &IncludeTok,
> llvm::StringRef FileName,
> Index: lib/Frontend/PrintPreprocessedOutput.cpp
> ===================================================================
> --- lib/Frontend/PrintPreprocessedOutput.cpp (revision 119697)
> +++ lib/Frontend/PrintPreprocessedOutput.cpp (working copy)
> @@ -147,11 +147,10 @@
> void HandleNewlinesInToken(const char *TokStr, unsigned Len);
>
> /// MacroDefined - This hook is called whenever a macro definition is seen.
> - void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI);
> + void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI);
>
> /// MacroUndefined - This hook is called whenever a macro #undef is seen.
> - void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II,
> - const MacroInfo *MI);
> + void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI);
> };
> } // end anonymous namespace
>
> @@ -323,7 +322,7 @@
> }
>
> /// MacroDefined - This hook is called whenever a macro definition is seen.
> -void PrintPPOutputPPCallbacks::MacroDefined(const IdentifierInfo *II,
> +void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
> const MacroInfo *MI) {
> // Only print out macro definitions in -dD mode.
> if (!DumpDefines ||
> @@ -331,18 +330,17 @@
> MI->isBuiltinMacro()) return;
>
> MoveToLine(MI->getDefinitionLoc());
> - PrintMacroDefinition(*II, *MI, PP, OS);
> + PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
> EmittedMacroOnThisLine = true;
> }
>
> -void PrintPPOutputPPCallbacks::MacroUndefined(SourceLocation Loc,
> - const IdentifierInfo *II,
> +void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
> const MacroInfo *MI) {
> // Only print out macro definitions in -dD mode.
> if (!DumpDefines) return;
>
> - MoveToLine(Loc);
> - OS << "#undef " << II->getName();
> + MoveToLine(MacroNameTok.getLocation());
> + OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName();
> EmittedMacroOnThisLine = true;
> }
>
> @@ -616,4 +614,3 @@
> PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);
> *OS << '\n';
> }
> -
> Index: lib/Lex/PPDirectives.cpp
> ===================================================================
> --- lib/Lex/PPDirectives.cpp (revision 119697)
> +++ lib/Lex/PPDirectives.cpp (working copy)
> @@ -1532,7 +1532,7 @@
>
> // If the callbacks want to know, tell them about the macro definition.
> if (Callbacks)
> - Callbacks->MacroDefined(MacroNameTok.getIdentifierInfo(), MI);
> + Callbacks->MacroDefined(MacroNameTok, MI);
> }
>
> /// HandleUndefDirective - Implements #undef.
> @@ -1561,8 +1561,7 @@
>
> // If the callbacks want to know, tell them about the macro #undef.
> if (Callbacks)
> - Callbacks->MacroUndefined(MacroNameTok.getLocation(),
> - MacroNameTok.getIdentifierInfo(), MI);
> + Callbacks->MacroUndefined(MacroNameTok, MI);
>
> // Free macro definition.
> ReleaseMacroInfo(MI);
> @@ -1633,9 +1632,9 @@
>
> if (Callbacks) {
> if (isIfndef)
> - Callbacks->Ifndef(MacroNameTok.getLocation(), MII);
> + Callbacks->Ifndef(MacroNameTok);
> else
> - Callbacks->Ifdef(MacroNameTok.getLocation(), MII);
> + Callbacks->Ifdef(MacroNameTok);
> }
> }
>
> Index: lib/Lex/PreprocessingRecord.cpp
> ===================================================================
> --- lib/Lex/PreprocessingRecord.cpp (revision 119697)
> +++ lib/Lex/PreprocessingRecord.cpp (working copy)
> @@ -127,17 +127,18 @@
> Def));
> }
>
> -void PreprocessingRecord::MacroDefined(const IdentifierInfo *II,
> +void PreprocessingRecord::MacroDefined(const Token &Id,
> const MacroInfo *MI) {
> SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc());
> MacroDefinition *Def
> - = new (*this) MacroDefinition(II, MI->getDefinitionLoc(), R);
> + = new (*this) MacroDefinition(Id.getIdentifierInfo(),
> + MI->getDefinitionLoc(),
> + R);
> MacroDefinitions[MI] = Def;
> PreprocessedEntities.push_back(Def);
> }
>
> -void PreprocessingRecord::MacroUndefined(SourceLocation Loc,
> - const IdentifierInfo *II,
> +void PreprocessingRecord::MacroUndefined(const Token &Id,
> const MacroInfo *MI) {
> llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos
> = MacroDefinitions.find(MI);
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list