1 //===--- PrintPreprocessedOutput.cpp - Implement the -E mode --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This code simply runs the preprocessor on the input file and prints out the
11 // result. This is the traditional behavior of the -E option.
13 //===----------------------------------------------------------------------===//
15 #include "clang/Frontend/Utils.h"
16 #include "clang/Basic/CharInfo.h"
17 #include "clang/Basic/Diagnostic.h"
18 #include "clang/Basic/SourceManager.h"
19 #include "clang/Frontend/PreprocessorOutputOptions.h"
20 #include "clang/Lex/MacroInfo.h"
21 #include "clang/Lex/PPCallbacks.h"
22 #include "clang/Lex/Pragma.h"
23 #include "clang/Lex/Preprocessor.h"
24 #include "clang/Lex/TokenConcatenation.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/ADT/StringRef.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/raw_ostream.h"
31 using namespace clang;
33 /// PrintMacroDefinition - Print a macro definition in a form that will be
34 /// properly accepted back as a definition.
35 static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
36 Preprocessor &PP, raw_ostream &OS) {
37 OS << "#define " << II.getName();
39 if (MI.isFunctionLike()) {
41 if (!MI.arg_empty()) {
42 MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end();
43 for (; AI+1 != E; ++AI) {
44 OS << (*AI)->getName();
49 if ((*AI)->getName() == "__VA_ARGS__")
52 OS << (*AI)->getName();
55 if (MI.isGNUVarargs())
56 OS << "..."; // #define foo(x...)
61 // GCC always emits a space, even if the macro body is empty. However, do not
62 // want to emit two spaces if the first token has a leading space.
63 if (MI.tokens_empty() || !MI.tokens_begin()->hasLeadingSpace())
66 SmallString<128> SpellingBuffer;
67 for (const auto &T : MI.tokens()) {
68 if (T.hasLeadingSpace())
71 OS << PP.getSpelling(T, SpellingBuffer);
75 //===----------------------------------------------------------------------===//
76 // Preprocessed token printer
77 //===----------------------------------------------------------------------===//
80 class PrintPPOutputPPCallbacks : public PPCallbacks {
83 TokenConcatenation ConcatInfo;
89 bool EmittedTokensOnThisLine;
90 bool EmittedDirectiveOnThisLine;
91 SrcMgr::CharacteristicKind FileType;
92 SmallString<512> CurFilename;
94 bool DisableLineMarkers;
96 bool UseLineDirectives;
97 bool IsFirstFileEntered;
99 PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
100 bool defines, bool UseLineDirectives)
101 : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
102 DisableLineMarkers(lineMarkers), DumpDefines(defines),
103 UseLineDirectives(UseLineDirectives) {
105 CurFilename += "<uninit>";
106 EmittedTokensOnThisLine = false;
107 EmittedDirectiveOnThisLine = false;
108 FileType = SrcMgr::C_User;
110 IsFirstFileEntered = false;
113 void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
114 bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; }
116 void setEmittedDirectiveOnThisLine() { EmittedDirectiveOnThisLine = true; }
117 bool hasEmittedDirectiveOnThisLine() const {
118 return EmittedDirectiveOnThisLine;
121 bool startNewLineIfNeeded(bool ShouldUpdateCurrentLine = true);
123 void FileChanged(SourceLocation Loc, FileChangeReason Reason,
124 SrcMgr::CharacteristicKind FileType,
125 FileID PrevFID) override;
126 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
127 StringRef FileName, bool IsAngled,
128 CharSourceRange FilenameRange, const FileEntry *File,
129 StringRef SearchPath, StringRef RelativePath,
130 const Module *Imported) override;
131 void Ident(SourceLocation Loc, const std::string &str) override;
132 void PragmaMessage(SourceLocation Loc, StringRef Namespace,
133 PragmaMessageKind Kind, StringRef Str) override;
134 void PragmaDebug(SourceLocation Loc, StringRef DebugType) override;
135 void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override;
136 void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override;
137 void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
138 diag::Severity Map, StringRef Str) override;
139 void PragmaWarning(SourceLocation Loc, StringRef WarningSpec,
140 ArrayRef<int> Ids) override;
141 void PragmaWarningPush(SourceLocation Loc, int Level) override;
142 void PragmaWarningPop(SourceLocation Loc) override;
144 bool HandleFirstTokOnLine(Token &Tok);
146 /// Move to the line of the provided source location. This will
147 /// return true if the output stream required adjustment or if
148 /// the requested location is on the first line.
149 bool MoveToLine(SourceLocation Loc) {
150 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
151 if (PLoc.isInvalid())
153 return MoveToLine(PLoc.getLine()) || (PLoc.getLine() == 1);
155 bool MoveToLine(unsigned LineNo);
157 bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok,
159 return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok);
161 void WriteLineInfo(unsigned LineNo, const char *Extra=nullptr,
162 unsigned ExtraLen=0);
163 bool LineMarkersAreDisabled() const { return DisableLineMarkers; }
164 void HandleNewlinesInToken(const char *TokStr, unsigned Len);
166 /// MacroDefined - This hook is called whenever a macro definition is seen.
167 void MacroDefined(const Token &MacroNameTok,
168 const MacroDirective *MD) override;
170 /// MacroUndefined - This hook is called whenever a macro #undef is seen.
171 void MacroUndefined(const Token &MacroNameTok,
172 const MacroDefinition &MD) override;
174 } // end anonymous namespace
176 void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
179 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
181 // Emit #line directives or GNU line markers depending on what mode we're in.
182 if (UseLineDirectives) {
183 OS << "#line" << ' ' << LineNo << ' ' << '"';
184 OS.write_escaped(CurFilename);
187 OS << '#' << ' ' << LineNo << ' ' << '"';
188 OS.write_escaped(CurFilename);
192 OS.write(Extra, ExtraLen);
194 if (FileType == SrcMgr::C_System)
196 else if (FileType == SrcMgr::C_ExternCSystem)
202 /// MoveToLine - Move the output to the source line specified by the location
203 /// object. We can do this by emitting some number of \n's, or be emitting a
204 /// #line directive. This returns false if already at the specified line, true
205 /// if some newlines were emitted.
206 bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) {
207 // If this line is "close enough" to the original line, just print newlines,
208 // otherwise print a #line directive.
209 if (LineNo-CurLine <= 8) {
210 if (LineNo-CurLine == 1)
212 else if (LineNo == CurLine)
213 return false; // Spelling line moved, but expansion line didn't.
215 const char *NewLines = "\n\n\n\n\n\n\n\n";
216 OS.write(NewLines, LineNo-CurLine);
218 } else if (!DisableLineMarkers) {
219 // Emit a #line or line marker.
220 WriteLineInfo(LineNo, nullptr, 0);
222 // Okay, we're in -P mode, which turns off line markers. However, we still
223 // need to emit a newline between tokens on different lines.
224 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
232 PrintPPOutputPPCallbacks::startNewLineIfNeeded(bool ShouldUpdateCurrentLine) {
233 if (EmittedTokensOnThisLine || EmittedDirectiveOnThisLine) {
235 EmittedTokensOnThisLine = false;
236 EmittedDirectiveOnThisLine = false;
237 if (ShouldUpdateCurrentLine)
245 /// FileChanged - Whenever the preprocessor enters or exits a #include file
246 /// it invokes this handler. Update our conception of the current source
248 void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
249 FileChangeReason Reason,
250 SrcMgr::CharacteristicKind NewFileType,
252 // Unless we are exiting a #include, make sure to skip ahead to the line the
253 // #include directive was at.
254 SourceManager &SourceMgr = SM;
256 PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc);
257 if (UserLoc.isInvalid())
260 unsigned NewLine = UserLoc.getLine();
262 if (Reason == PPCallbacks::EnterFile) {
263 SourceLocation IncludeLoc = UserLoc.getIncludeLoc();
264 if (IncludeLoc.isValid())
265 MoveToLine(IncludeLoc);
266 } else if (Reason == PPCallbacks::SystemHeaderPragma) {
267 // GCC emits the # directive for this directive on the line AFTER the
268 // directive and emits a bunch of spaces that aren't needed. This is because
269 // otherwise we will emit a line marker for THIS line, which requires an
270 // extra blank line after the directive to avoid making all following lines
271 // off by one. We can do better by simply incrementing NewLine here.
278 CurFilename += UserLoc.getFilename();
279 FileType = NewFileType;
281 if (DisableLineMarkers) {
282 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
287 WriteLineInfo(CurLine);
291 // Do not emit an enter marker for the main file (which we expect is the first
292 // entered file). This matches gcc, and improves compatibility with some tools
293 // which track the # line markers as a way to determine when the preprocessed
294 // output is in the context of the main file.
295 if (Reason == PPCallbacks::EnterFile && !IsFirstFileEntered) {
296 IsFirstFileEntered = true;
301 case PPCallbacks::EnterFile:
302 WriteLineInfo(CurLine, " 1", 2);
304 case PPCallbacks::ExitFile:
305 WriteLineInfo(CurLine, " 2", 2);
307 case PPCallbacks::SystemHeaderPragma:
308 case PPCallbacks::RenameFile:
309 WriteLineInfo(CurLine);
314 void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
315 const Token &IncludeTok,
318 CharSourceRange FilenameRange,
319 const FileEntry *File,
320 StringRef SearchPath,
321 StringRef RelativePath,
322 const Module *Imported) {
323 // When preprocessing, turn implicit imports into @imports.
324 // FIXME: This is a stop-gap until a more comprehensive "preprocessing with
325 // modules" solution is introduced.
327 startNewLineIfNeeded();
329 OS << "@import " << Imported->getFullModuleName() << ";"
330 << " /* clang -E: implicit import for \"" << File->getName() << "\" */";
331 // Since we want a newline after the @import, but not a #<line>, start a new
333 EmittedTokensOnThisLine = true;
334 startNewLineIfNeeded();
338 /// Ident - Handle #ident directives when read by the preprocessor.
340 void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) {
343 OS.write("#ident ", strlen("#ident "));
344 OS.write(&S[0], S.size());
345 EmittedTokensOnThisLine = true;
348 /// MacroDefined - This hook is called whenever a macro definition is seen.
349 void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
350 const MacroDirective *MD) {
351 const MacroInfo *MI = MD->getMacroInfo();
352 // Only print out macro definitions in -dD mode.
354 // Ignore __FILE__ etc.
355 MI->isBuiltinMacro()) return;
357 MoveToLine(MI->getDefinitionLoc());
358 PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
359 setEmittedDirectiveOnThisLine();
362 void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
363 const MacroDefinition &MD) {
364 // Only print out macro definitions in -dD mode.
365 if (!DumpDefines) return;
367 MoveToLine(MacroNameTok.getLocation());
368 OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName();
369 setEmittedDirectiveOnThisLine();
372 static void outputPrintable(llvm::raw_ostream& OS,
373 const std::string &Str) {
374 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
375 unsigned char Char = Str[i];
376 if (isPrintable(Char) && Char != '\\' && Char != '"')
378 else // Output anything hard as an octal escape.
380 << (char)('0'+ ((Char >> 6) & 7))
381 << (char)('0'+ ((Char >> 3) & 7))
382 << (char)('0'+ ((Char >> 0) & 7));
386 void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc,
388 PragmaMessageKind Kind,
390 startNewLineIfNeeded();
393 if (!Namespace.empty())
394 OS << Namespace << ' ';
407 outputPrintable(OS, Str);
409 if (Kind == PMK_Message)
411 setEmittedDirectiveOnThisLine();
414 void PrintPPOutputPPCallbacks::PragmaDebug(SourceLocation Loc,
415 StringRef DebugType) {
416 startNewLineIfNeeded();
419 OS << "#pragma clang __debug ";
422 setEmittedDirectiveOnThisLine();
425 void PrintPPOutputPPCallbacks::
426 PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) {
427 startNewLineIfNeeded();
429 OS << "#pragma " << Namespace << " diagnostic push";
430 setEmittedDirectiveOnThisLine();
433 void PrintPPOutputPPCallbacks::
434 PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) {
435 startNewLineIfNeeded();
437 OS << "#pragma " << Namespace << " diagnostic pop";
438 setEmittedDirectiveOnThisLine();
441 void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
445 startNewLineIfNeeded();
447 OS << "#pragma " << Namespace << " diagnostic ";
449 case diag::Severity::Remark:
452 case diag::Severity::Warning:
455 case diag::Severity::Error:
458 case diag::Severity::Ignored:
461 case diag::Severity::Fatal:
465 OS << " \"" << Str << '"';
466 setEmittedDirectiveOnThisLine();
469 void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc,
470 StringRef WarningSpec,
472 startNewLineIfNeeded();
474 OS << "#pragma warning(" << WarningSpec << ':';
475 for (ArrayRef<int>::iterator I = Ids.begin(), E = Ids.end(); I != E; ++I)
478 setEmittedDirectiveOnThisLine();
481 void PrintPPOutputPPCallbacks::PragmaWarningPush(SourceLocation Loc,
483 startNewLineIfNeeded();
485 OS << "#pragma warning(push";
489 setEmittedDirectiveOnThisLine();
492 void PrintPPOutputPPCallbacks::PragmaWarningPop(SourceLocation Loc) {
493 startNewLineIfNeeded();
495 OS << "#pragma warning(pop)";
496 setEmittedDirectiveOnThisLine();
499 /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this
500 /// is called for the first token on each new line. If this really is the start
501 /// of a new logical line, handle it and return true, otherwise return false.
502 /// This may not be the start of a logical line because the "start of line"
503 /// marker is set for spelling lines, not expansion ones.
504 bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) {
505 // Figure out what line we went to and insert the appropriate number of
506 // newline characters.
507 if (!MoveToLine(Tok.getLocation()))
510 // Print out space characters so that the first token on a line is
511 // indented for easy reading.
512 unsigned ColNo = SM.getExpansionColumnNumber(Tok.getLocation());
514 // The first token on a line can have a column number of 1, yet still expect
515 // leading white space, if a macro expansion in column 1 starts with an empty
516 // macro argument, or an empty nested macro expansion. In this case, move the
517 // token to column 2.
518 if (ColNo == 1 && Tok.hasLeadingSpace())
521 // This hack prevents stuff like:
523 // HASH define foo bar
524 // From having the # character end up at column 1, which makes it so it
525 // is not handled as a #define next time through the preprocessor if in
526 // -fpreprocessed mode.
527 if (ColNo <= 1 && Tok.is(tok::hash))
530 // Otherwise, indent the appropriate number of spaces.
531 for (; ColNo > 1; --ColNo)
537 void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr,
539 unsigned NumNewlines = 0;
540 for (; Len; --Len, ++TokStr) {
541 if (*TokStr != '\n' &&
547 // If we have \n\r or \r\n, skip both and count as one line.
549 (TokStr[1] == '\n' || TokStr[1] == '\r') &&
550 TokStr[0] != TokStr[1])
554 if (NumNewlines == 0) return;
556 CurLine += NumNewlines;
561 struct UnknownPragmaHandler : public PragmaHandler {
563 PrintPPOutputPPCallbacks *Callbacks;
565 UnknownPragmaHandler(const char *prefix, PrintPPOutputPPCallbacks *callbacks)
566 : Prefix(prefix), Callbacks(callbacks) {}
567 void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
568 Token &PragmaTok) override {
569 // Figure out what line we went to and insert the appropriate number of
570 // newline characters.
571 Callbacks->startNewLineIfNeeded();
572 Callbacks->MoveToLine(PragmaTok.getLocation());
573 Callbacks->OS.write(Prefix, strlen(Prefix));
574 // Read and print all of the pragma tokens.
575 while (PragmaTok.isNot(tok::eod)) {
576 if (PragmaTok.hasLeadingSpace())
577 Callbacks->OS << ' ';
578 std::string TokSpell = PP.getSpelling(PragmaTok);
579 Callbacks->OS.write(&TokSpell[0], TokSpell.size());
581 // Expand macros in pragmas with -fms-extensions. The assumption is that
582 // the majority of pragmas in such a file will be Microsoft pragmas.
583 if (PP.getLangOpts().MicrosoftExt)
586 PP.LexUnexpandedToken(PragmaTok);
588 Callbacks->setEmittedDirectiveOnThisLine();
591 } // end anonymous namespace
594 static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
595 PrintPPOutputPPCallbacks *Callbacks,
597 bool DropComments = PP.getLangOpts().TraditionalCPP &&
598 !PP.getCommentRetentionState();
601 Token PrevPrevTok, PrevTok;
602 PrevPrevTok.startToken();
603 PrevTok.startToken();
605 if (Callbacks->hasEmittedDirectiveOnThisLine()) {
606 Callbacks->startNewLineIfNeeded();
607 Callbacks->MoveToLine(Tok.getLocation());
610 // If this token is at the start of a line, emit newlines if needed.
611 if (Tok.isAtStartOfLine() && Callbacks->HandleFirstTokOnLine(Tok)) {
613 } else if (Tok.hasLeadingSpace() ||
614 // If we haven't emitted a token on this line yet, PrevTok isn't
615 // useful to look at and no concatenation could happen anyway.
616 (Callbacks->hasEmittedTokensOnThisLine() &&
617 // Don't print "-" next to "-", it would form "--".
618 Callbacks->AvoidConcat(PrevPrevTok, PrevTok, Tok))) {
622 if (DropComments && Tok.is(tok::comment)) {
623 // Skip comments. Normally the preprocessor does not generate
624 // tok::comment nodes at all when not keeping comments, but under
625 // -traditional-cpp the lexer keeps /all/ whitespace, including comments.
626 SourceLocation StartLoc = Tok.getLocation();
627 Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength()));
628 } else if (Tok.is(tok::annot_module_include) ||
629 Tok.is(tok::annot_module_begin) ||
630 Tok.is(tok::annot_module_end)) {
631 // PrintPPOutputPPCallbacks::InclusionDirective handles producing
632 // appropriate output here. Ignore this token entirely.
635 } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
637 } else if (Tok.isLiteral() && !Tok.needsCleaning() &&
638 Tok.getLiteralData()) {
639 OS.write(Tok.getLiteralData(), Tok.getLength());
640 } else if (Tok.getLength() < 256) {
641 const char *TokPtr = Buffer;
642 unsigned Len = PP.getSpelling(Tok, TokPtr);
643 OS.write(TokPtr, Len);
645 // Tokens that can contain embedded newlines need to adjust our current
647 if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown)
648 Callbacks->HandleNewlinesInToken(TokPtr, Len);
650 std::string S = PP.getSpelling(Tok);
651 OS.write(&S[0], S.size());
653 // Tokens that can contain embedded newlines need to adjust our current
655 if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown)
656 Callbacks->HandleNewlinesInToken(&S[0], S.size());
658 Callbacks->setEmittedTokensOnThisLine();
660 if (Tok.is(tok::eof)) break;
662 PrevPrevTok = PrevTok;
668 typedef std::pair<const IdentifierInfo *, MacroInfo *> id_macro_pair;
669 static int MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS) {
670 return LHS->first->getName().compare(RHS->first->getName());
673 static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
674 // Ignore unknown pragmas.
677 // -dM mode just scans and ignores all tokens in the files, then dumps out
678 // the macro table at the end.
679 PP.EnterMainSourceFile();
683 while (Tok.isNot(tok::eof));
685 SmallVector<id_macro_pair, 128> MacrosByID;
686 for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
688 auto *MD = I->second.getLatest();
689 if (MD && MD->isDefined())
690 MacrosByID.push_back(id_macro_pair(I->first, MD->getMacroInfo()));
692 llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);
694 for (unsigned i = 0, e = MacrosByID.size(); i != e; ++i) {
695 MacroInfo &MI = *MacrosByID[i].second;
696 // Ignore computed macros like __LINE__ and friends.
697 if (MI.isBuiltinMacro()) continue;
699 PrintMacroDefinition(*MacrosByID[i].first, MI, PP, *OS);
704 /// DoPrintPreprocessedInput - This implements -E mode.
706 void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
707 const PreprocessorOutputOptions &Opts) {
708 // Show macros with no output is handled specially.
710 assert(Opts.ShowMacros && "Not yet implemented!");
711 DoPrintMacros(PP, OS);
715 // Inform the preprocessor whether we want it to retain comments or not, due
717 PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments);
719 PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(
720 PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros, Opts.UseLineDirectives);
721 PP.AddPragmaHandler(new UnknownPragmaHandler("#pragma", Callbacks));
722 PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",Callbacks));
723 PP.AddPragmaHandler("clang",
724 new UnknownPragmaHandler("#pragma clang", Callbacks));
726 PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callbacks));
728 // After we have configured the preprocessor, enter the main file.
729 PP.EnterMainSourceFile();
731 // Consume all of the tokens that come from the predefines buffer. Those
732 // should not be emitted into the output and are guaranteed to be at the
734 const SourceManager &SourceMgr = PP.getSourceManager();
738 if (Tok.is(tok::eof) || !Tok.getLocation().isFileID())
741 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
742 if (PLoc.isInvalid())
745 if (strcmp(PLoc.getFilename(), "<built-in>"))
749 // Read all the preprocessed tokens, printing them out to the stream.
750 PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);