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 (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end();
69 if (I->hasLeadingSpace())
72 OS << PP.getSpelling(*I, SpellingBuffer);
76 //===----------------------------------------------------------------------===//
77 // Preprocessed token printer
78 //===----------------------------------------------------------------------===//
81 class PrintPPOutputPPCallbacks : public PPCallbacks {
84 TokenConcatenation ConcatInfo;
90 bool EmittedTokensOnThisLine;
91 bool EmittedDirectiveOnThisLine;
92 SrcMgr::CharacteristicKind FileType;
93 SmallString<512> CurFilename;
95 bool DisableLineMarkers;
97 bool UseLineDirective;
98 bool IsFirstFileEntered;
100 PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os,
101 bool lineMarkers, bool defines)
102 : PP(pp), SM(PP.getSourceManager()),
103 ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers),
104 DumpDefines(defines) {
106 CurFilename += "<uninit>";
107 EmittedTokensOnThisLine = false;
108 EmittedDirectiveOnThisLine = false;
109 FileType = SrcMgr::C_User;
111 IsFirstFileEntered = false;
113 // If we're in microsoft mode, use normal #line instead of line markers.
114 UseLineDirective = PP.getLangOpts().MicrosoftExt;
117 void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
118 bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; }
120 void setEmittedDirectiveOnThisLine() { EmittedDirectiveOnThisLine = true; }
121 bool hasEmittedDirectiveOnThisLine() const {
122 return EmittedDirectiveOnThisLine;
125 bool startNewLineIfNeeded(bool ShouldUpdateCurrentLine = true);
127 void FileChanged(SourceLocation Loc, FileChangeReason Reason,
128 SrcMgr::CharacteristicKind FileType,
129 FileID PrevFID) override;
130 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
131 StringRef FileName, bool IsAngled,
132 CharSourceRange FilenameRange, const FileEntry *File,
133 StringRef SearchPath, StringRef RelativePath,
134 const Module *Imported) override;
135 void Ident(SourceLocation Loc, const std::string &str) override;
136 void PragmaMessage(SourceLocation Loc, StringRef Namespace,
137 PragmaMessageKind Kind, StringRef Str) override;
138 void PragmaDebug(SourceLocation Loc, StringRef DebugType) override;
139 void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override;
140 void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override;
141 void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
142 diag::Severity Map, StringRef Str) override;
143 void PragmaWarning(SourceLocation Loc, StringRef WarningSpec,
144 ArrayRef<int> Ids) override;
145 void PragmaWarningPush(SourceLocation Loc, int Level) override;
146 void PragmaWarningPop(SourceLocation Loc) override;
148 bool HandleFirstTokOnLine(Token &Tok);
150 /// Move to the line of the provided source location. This will
151 /// return true if the output stream required adjustment or if
152 /// the requested location is on the first line.
153 bool MoveToLine(SourceLocation Loc) {
154 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
155 if (PLoc.isInvalid())
157 return MoveToLine(PLoc.getLine()) || (PLoc.getLine() == 1);
159 bool MoveToLine(unsigned LineNo);
161 bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok,
163 return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok);
165 void WriteLineInfo(unsigned LineNo, const char *Extra=nullptr,
166 unsigned ExtraLen=0);
167 bool LineMarkersAreDisabled() const { return DisableLineMarkers; }
168 void HandleNewlinesInToken(const char *TokStr, unsigned Len);
170 /// MacroDefined - This hook is called whenever a macro definition is seen.
171 void MacroDefined(const Token &MacroNameTok,
172 const MacroDirective *MD) override;
174 /// MacroUndefined - This hook is called whenever a macro #undef is seen.
175 void MacroUndefined(const Token &MacroNameTok,
176 const MacroDirective *MD) override;
178 } // end anonymous namespace
180 void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
183 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
185 // Emit #line directives or GNU line markers depending on what mode we're in.
186 if (UseLineDirective) {
187 OS << "#line" << ' ' << LineNo << ' ' << '"';
188 OS.write_escaped(CurFilename);
191 OS << '#' << ' ' << LineNo << ' ' << '"';
192 OS.write_escaped(CurFilename);
196 OS.write(Extra, ExtraLen);
198 if (FileType == SrcMgr::C_System)
200 else if (FileType == SrcMgr::C_ExternCSystem)
206 /// MoveToLine - Move the output to the source line specified by the location
207 /// object. We can do this by emitting some number of \n's, or be emitting a
208 /// #line directive. This returns false if already at the specified line, true
209 /// if some newlines were emitted.
210 bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) {
211 // If this line is "close enough" to the original line, just print newlines,
212 // otherwise print a #line directive.
213 if (LineNo-CurLine <= 8) {
214 if (LineNo-CurLine == 1)
216 else if (LineNo == CurLine)
217 return false; // Spelling line moved, but expansion line didn't.
219 const char *NewLines = "\n\n\n\n\n\n\n\n";
220 OS.write(NewLines, LineNo-CurLine);
222 } else if (!DisableLineMarkers) {
223 // Emit a #line or line marker.
224 WriteLineInfo(LineNo, nullptr, 0);
226 // Okay, we're in -P mode, which turns off line markers. However, we still
227 // need to emit a newline between tokens on different lines.
228 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
236 PrintPPOutputPPCallbacks::startNewLineIfNeeded(bool ShouldUpdateCurrentLine) {
237 if (EmittedTokensOnThisLine || EmittedDirectiveOnThisLine) {
239 EmittedTokensOnThisLine = false;
240 EmittedDirectiveOnThisLine = false;
241 if (ShouldUpdateCurrentLine)
249 /// FileChanged - Whenever the preprocessor enters or exits a #include file
250 /// it invokes this handler. Update our conception of the current source
252 void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
253 FileChangeReason Reason,
254 SrcMgr::CharacteristicKind NewFileType,
256 // Unless we are exiting a #include, make sure to skip ahead to the line the
257 // #include directive was at.
258 SourceManager &SourceMgr = SM;
260 PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc);
261 if (UserLoc.isInvalid())
264 unsigned NewLine = UserLoc.getLine();
266 if (Reason == PPCallbacks::EnterFile) {
267 SourceLocation IncludeLoc = UserLoc.getIncludeLoc();
268 if (IncludeLoc.isValid())
269 MoveToLine(IncludeLoc);
270 } else if (Reason == PPCallbacks::SystemHeaderPragma) {
271 // GCC emits the # directive for this directive on the line AFTER the
272 // directive and emits a bunch of spaces that aren't needed. This is because
273 // otherwise we will emit a line marker for THIS line, which requires an
274 // extra blank line after the directive to avoid making all following lines
275 // off by one. We can do better by simply incrementing NewLine here.
282 CurFilename += UserLoc.getFilename();
283 FileType = NewFileType;
285 if (DisableLineMarkers) {
286 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
291 WriteLineInfo(CurLine);
295 // Do not emit an enter marker for the main file (which we expect is the first
296 // entered file). This matches gcc, and improves compatibility with some tools
297 // which track the # line markers as a way to determine when the preprocessed
298 // output is in the context of the main file.
299 if (Reason == PPCallbacks::EnterFile && !IsFirstFileEntered) {
300 IsFirstFileEntered = true;
305 case PPCallbacks::EnterFile:
306 WriteLineInfo(CurLine, " 1", 2);
308 case PPCallbacks::ExitFile:
309 WriteLineInfo(CurLine, " 2", 2);
311 case PPCallbacks::SystemHeaderPragma:
312 case PPCallbacks::RenameFile:
313 WriteLineInfo(CurLine);
318 void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
319 const Token &IncludeTok,
322 CharSourceRange FilenameRange,
323 const FileEntry *File,
324 StringRef SearchPath,
325 StringRef RelativePath,
326 const Module *Imported) {
327 // When preprocessing, turn implicit imports into @imports.
328 // FIXME: This is a stop-gap until a more comprehensive "preprocessing with
329 // modules" solution is introduced.
331 startNewLineIfNeeded();
333 OS << "@import " << Imported->getFullModuleName() << ";"
334 << " /* clang -E: implicit import for \"" << File->getName() << "\" */";
335 EmittedTokensOnThisLine = true;
339 /// Ident - Handle #ident directives when read by the preprocessor.
341 void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) {
344 OS.write("#ident ", strlen("#ident "));
345 OS.write(&S[0], S.size());
346 EmittedTokensOnThisLine = true;
349 /// MacroDefined - This hook is called whenever a macro definition is seen.
350 void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
351 const MacroDirective *MD) {
352 const MacroInfo *MI = MD->getMacroInfo();
353 // Only print out macro definitions in -dD mode.
355 // Ignore __FILE__ etc.
356 MI->isBuiltinMacro()) return;
358 MoveToLine(MI->getDefinitionLoc());
359 PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
360 setEmittedDirectiveOnThisLine();
363 void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
364 const MacroDirective *MD) {
365 // Only print out macro definitions in -dD mode.
366 if (!DumpDefines) return;
368 MoveToLine(MacroNameTok.getLocation());
369 OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName();
370 setEmittedDirectiveOnThisLine();
373 static void outputPrintable(llvm::raw_ostream& OS,
374 const std::string &Str) {
375 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
376 unsigned char Char = Str[i];
377 if (isPrintable(Char) && Char != '\\' && Char != '"')
379 else // Output anything hard as an octal escape.
381 << (char)('0'+ ((Char >> 6) & 7))
382 << (char)('0'+ ((Char >> 3) & 7))
383 << (char)('0'+ ((Char >> 0) & 7));
387 void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc,
389 PragmaMessageKind Kind,
391 startNewLineIfNeeded();
394 if (!Namespace.empty())
395 OS << Namespace << ' ';
408 outputPrintable(OS, Str);
410 if (Kind == PMK_Message)
412 setEmittedDirectiveOnThisLine();
415 void PrintPPOutputPPCallbacks::PragmaDebug(SourceLocation Loc,
416 StringRef DebugType) {
417 startNewLineIfNeeded();
420 OS << "#pragma clang __debug ";
423 setEmittedDirectiveOnThisLine();
426 void PrintPPOutputPPCallbacks::
427 PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) {
428 startNewLineIfNeeded();
430 OS << "#pragma " << Namespace << " diagnostic push";
431 setEmittedDirectiveOnThisLine();
434 void PrintPPOutputPPCallbacks::
435 PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) {
436 startNewLineIfNeeded();
438 OS << "#pragma " << Namespace << " diagnostic pop";
439 setEmittedDirectiveOnThisLine();
442 void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
446 startNewLineIfNeeded();
448 OS << "#pragma " << Namespace << " diagnostic ";
450 case diag::Severity::Remark:
453 case diag::Severity::Warning:
456 case diag::Severity::Error:
459 case diag::Severity::Ignored:
462 case diag::Severity::Fatal:
466 OS << " \"" << Str << '"';
467 setEmittedDirectiveOnThisLine();
470 void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc,
471 StringRef WarningSpec,
473 startNewLineIfNeeded();
475 OS << "#pragma warning(" << WarningSpec << ':';
476 for (ArrayRef<int>::iterator I = Ids.begin(), E = Ids.end(); I != E; ++I)
479 setEmittedDirectiveOnThisLine();
482 void PrintPPOutputPPCallbacks::PragmaWarningPush(SourceLocation Loc,
484 startNewLineIfNeeded();
486 OS << "#pragma warning(push";
490 setEmittedDirectiveOnThisLine();
493 void PrintPPOutputPPCallbacks::PragmaWarningPop(SourceLocation Loc) {
494 startNewLineIfNeeded();
496 OS << "#pragma warning(pop)";
497 setEmittedDirectiveOnThisLine();
500 /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this
501 /// is called for the first token on each new line. If this really is the start
502 /// of a new logical line, handle it and return true, otherwise return false.
503 /// This may not be the start of a logical line because the "start of line"
504 /// marker is set for spelling lines, not expansion ones.
505 bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) {
506 // Figure out what line we went to and insert the appropriate number of
507 // newline characters.
508 if (!MoveToLine(Tok.getLocation()))
511 // Print out space characters so that the first token on a line is
512 // indented for easy reading.
513 unsigned ColNo = SM.getExpansionColumnNumber(Tok.getLocation());
515 // The first token on a line can have a column number of 1, yet still expect
516 // leading white space, if a macro expansion in column 1 starts with an empty
517 // macro argument, or an empty nested macro expansion. In this case, move the
518 // token to column 2.
519 if (ColNo == 1 && Tok.hasLeadingSpace())
522 // This hack prevents stuff like:
524 // HASH define foo bar
525 // From having the # character end up at column 1, which makes it so it
526 // is not handled as a #define next time through the preprocessor if in
527 // -fpreprocessed mode.
528 if (ColNo <= 1 && Tok.is(tok::hash))
531 // Otherwise, indent the appropriate number of spaces.
532 for (; ColNo > 1; --ColNo)
538 void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr,
540 unsigned NumNewlines = 0;
541 for (; Len; --Len, ++TokStr) {
542 if (*TokStr != '\n' &&
548 // If we have \n\r or \r\n, skip both and count as one line.
550 (TokStr[1] == '\n' || TokStr[1] == '\r') &&
551 TokStr[0] != TokStr[1])
555 if (NumNewlines == 0) return;
557 CurLine += NumNewlines;
562 struct UnknownPragmaHandler : public PragmaHandler {
564 PrintPPOutputPPCallbacks *Callbacks;
566 UnknownPragmaHandler(const char *prefix, PrintPPOutputPPCallbacks *callbacks)
567 : Prefix(prefix), Callbacks(callbacks) {}
568 void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
569 Token &PragmaTok) override {
570 // Figure out what line we went to and insert the appropriate number of
571 // newline characters.
572 Callbacks->startNewLineIfNeeded();
573 Callbacks->MoveToLine(PragmaTok.getLocation());
574 Callbacks->OS.write(Prefix, strlen(Prefix));
575 // Read and print all of the pragma tokens.
576 while (PragmaTok.isNot(tok::eod)) {
577 if (PragmaTok.hasLeadingSpace())
578 Callbacks->OS << ' ';
579 std::string TokSpell = PP.getSpelling(PragmaTok);
580 Callbacks->OS.write(&TokSpell[0], TokSpell.size());
582 // Expand macros in pragmas with -fms-extensions. The assumption is that
583 // the majority of pragmas in such a file will be Microsoft pragmas.
584 if (PP.getLangOpts().MicrosoftExt)
587 PP.LexUnexpandedToken(PragmaTok);
589 Callbacks->setEmittedDirectiveOnThisLine();
592 } // end anonymous namespace
595 static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
596 PrintPPOutputPPCallbacks *Callbacks,
598 bool DropComments = PP.getLangOpts().TraditionalCPP &&
599 !PP.getCommentRetentionState();
602 Token PrevPrevTok, PrevTok;
603 PrevPrevTok.startToken();
604 PrevTok.startToken();
606 if (Callbacks->hasEmittedDirectiveOnThisLine()) {
607 Callbacks->startNewLineIfNeeded();
608 Callbacks->MoveToLine(Tok.getLocation());
611 // If this token is at the start of a line, emit newlines if needed.
612 if (Tok.isAtStartOfLine() && Callbacks->HandleFirstTokOnLine(Tok)) {
614 } else if (Tok.hasLeadingSpace() ||
615 // If we haven't emitted a token on this line yet, PrevTok isn't
616 // useful to look at and no concatenation could happen anyway.
617 (Callbacks->hasEmittedTokensOnThisLine() &&
618 // Don't print "-" next to "-", it would form "--".
619 Callbacks->AvoidConcat(PrevPrevTok, PrevTok, Tok))) {
623 if (DropComments && Tok.is(tok::comment)) {
624 // Skip comments. Normally the preprocessor does not generate
625 // tok::comment nodes at all when not keeping comments, but under
626 // -traditional-cpp the lexer keeps /all/ whitespace, including comments.
627 SourceLocation StartLoc = Tok.getLocation();
628 Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength()));
629 } else if (Tok.is(tok::annot_module_include) ||
630 Tok.is(tok::annot_module_begin) ||
631 Tok.is(tok::annot_module_end)) {
632 // PrintPPOutputPPCallbacks::InclusionDirective handles producing
633 // appropriate output here. Ignore this token entirely.
636 } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
638 } else if (Tok.isLiteral() && !Tok.needsCleaning() &&
639 Tok.getLiteralData()) {
640 OS.write(Tok.getLiteralData(), Tok.getLength());
641 } else if (Tok.getLength() < 256) {
642 const char *TokPtr = Buffer;
643 unsigned Len = PP.getSpelling(Tok, TokPtr);
644 OS.write(TokPtr, Len);
646 // Tokens that can contain embedded newlines need to adjust our current
648 if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown)
649 Callbacks->HandleNewlinesInToken(TokPtr, Len);
651 std::string S = PP.getSpelling(Tok);
652 OS.write(&S[0], S.size());
654 // Tokens that can contain embedded newlines need to adjust our current
656 if (Tok.getKind() == tok::comment || Tok.getKind() == tok::unknown)
657 Callbacks->HandleNewlinesInToken(&S[0], S.size());
659 Callbacks->setEmittedTokensOnThisLine();
661 if (Tok.is(tok::eof)) break;
663 PrevPrevTok = PrevTok;
669 typedef std::pair<const IdentifierInfo *, MacroInfo *> id_macro_pair;
670 static int MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS) {
671 return LHS->first->getName().compare(RHS->first->getName());
674 static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
675 // Ignore unknown pragmas.
678 // -dM mode just scans and ignores all tokens in the files, then dumps out
679 // the macro table at the end.
680 PP.EnterMainSourceFile();
684 while (Tok.isNot(tok::eof));
686 SmallVector<id_macro_pair, 128> MacrosByID;
687 for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
689 if (I->first->hasMacroDefinition())
690 MacrosByID.push_back(id_macro_pair(I->first, I->second->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 =
720 new PrintPPOutputPPCallbacks(PP, *OS, !Opts.ShowLineMarkers,
722 PP.AddPragmaHandler(new UnknownPragmaHandler("#pragma", Callbacks));
723 PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",Callbacks));
724 PP.AddPragmaHandler("clang",
725 new UnknownPragmaHandler("#pragma clang", Callbacks));
727 PP.addPPCallbacks(Callbacks);
729 // After we have configured the preprocessor, enter the main file.
730 PP.EnterMainSourceFile();
732 // Consume all of the tokens that come from the predefines buffer. Those
733 // should not be emitted into the output and are guaranteed to be at the
735 const SourceManager &SourceMgr = PP.getSourceManager();
739 if (Tok.is(tok::eof) || !Tok.getLocation().isFileID())
742 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
743 if (PLoc.isInvalid())
746 if (strcmp(PLoc.getFilename(), "<built-in>"))
750 // Read all the preprocessed tokens, printing them out to the stream.
751 PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);