diff options
Diffstat (limited to 'lib/Frontend/PrintPreprocessedOutput.cpp')
| -rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 38 | 
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index 7c1d9a568831..037a6a525e2f 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -64,12 +64,11 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,      OS << ' ';    SmallString<128> SpellingBuffer; -  for (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end(); -       I != E; ++I) { -    if (I->hasLeadingSpace()) +  for (const auto &T : MI.tokens()) { +    if (T.hasLeadingSpace())        OS << ' '; -    OS << PP.getSpelling(*I, SpellingBuffer); +    OS << PP.getSpelling(T, SpellingBuffer);    }  } @@ -94,14 +93,14 @@ private:    bool Initialized;    bool DisableLineMarkers;    bool DumpDefines; -  bool UseLineDirective; +  bool UseLineDirectives;    bool IsFirstFileEntered;  public: -  PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, -                           bool lineMarkers, bool defines) -     : PP(pp), SM(PP.getSourceManager()), -       ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers), -       DumpDefines(defines) { +  PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers, +                           bool defines, bool UseLineDirectives) +      : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os), +        DisableLineMarkers(lineMarkers), DumpDefines(defines), +        UseLineDirectives(UseLineDirectives) {      CurLine = 0;      CurFilename += "<uninit>";      EmittedTokensOnThisLine = false; @@ -109,9 +108,6 @@ public:      FileType = SrcMgr::C_User;      Initialized = false;      IsFirstFileEntered = false; - -    // If we're in microsoft mode, use normal #line instead of line markers. -    UseLineDirective = PP.getLangOpts().MicrosoftExt;    }    void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; } @@ -173,7 +169,7 @@ public:    /// MacroUndefined - This hook is called whenever a macro #undef is seen.    void MacroUndefined(const Token &MacroNameTok, -                      const MacroDirective *MD) override; +                      const MacroDefinition &MD) override;  };  }  // end anonymous namespace @@ -183,7 +179,7 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,    startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);    // Emit #line directives or GNU line markers depending on what mode we're in. -  if (UseLineDirective) { +  if (UseLineDirectives) {      OS << "#line" << ' ' << LineNo << ' ' << '"';      OS.write_escaped(CurFilename);      OS << '"'; @@ -364,7 +360,7 @@ void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,  }  void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok, -                                              const MacroDirective *MD) { +                                              const MacroDefinition &MD) {    // Only print out macro definitions in -dD mode.    if (!DumpDefines) return; @@ -689,8 +685,9 @@ static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {    SmallVector<id_macro_pair, 128> MacrosByID;    for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();         I != E; ++I) { -    if (I->first->hasMacroDefinition()) -      MacrosByID.push_back(id_macro_pair(I->first, I->second->getMacroInfo())); +    auto *MD = I->second.getLatest(); +    if (MD && MD->isDefined()) +      MacrosByID.push_back(id_macro_pair(I->first, MD->getMacroInfo()));    }    llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare); @@ -719,9 +716,8 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,    // to -C or -CC.    PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments); -  PrintPPOutputPPCallbacks *Callbacks = -      new PrintPPOutputPPCallbacks(PP, *OS, !Opts.ShowLineMarkers, -                                   Opts.ShowMacros); +  PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks( +      PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros, Opts.UseLineDirectives);    PP.AddPragmaHandler(new UnknownPragmaHandler("#pragma", Callbacks));    PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",Callbacks));    PP.AddPragmaHandler("clang",  | 
