blob: afad0a9f5ff39dc810540f1ef23e9c0a52283bce [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- PrintPreprocessedOutput.cpp - Implement the -E mode --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
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.
12//
13//===----------------------------------------------------------------------===//
14
Eli Friedmanb09f6e12009-05-19 04:14:29 +000015#include "clang/Frontend/Utils.h"
Daniel Dunbar775bee72009-11-11 10:07:22 +000016#include "clang/Basic/Diagnostic.h"
17#include "clang/Basic/SourceManager.h"
18#include "clang/Frontend/PreprocessorOutputOptions.h"
Chris Lattnerf73903a2009-02-06 06:45:26 +000019#include "clang/Lex/MacroInfo.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "clang/Lex/PPCallbacks.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000021#include "clang/Lex/Pragma.h"
Daniel Dunbar775bee72009-11-11 10:07:22 +000022#include "clang/Lex/Preprocessor.h"
Chris Lattnerd7038e12009-02-13 00:46:04 +000023#include "clang/Lex/TokenConcatenation.h"
Benjamin Kramer3ff2a4b2010-01-19 17:42:20 +000024#include "llvm/ADT/STLExtras.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000025#include "llvm/ADT/SmallString.h"
Chris Lattnerabfe0942010-06-26 17:11:39 +000026#include "llvm/ADT/StringRef.h"
Douglas Gregorc09ce122011-06-22 19:41:48 +000027#include "llvm/Support/ErrorHandling.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "llvm/Support/raw_ostream.h"
Joerg Sonnenberger7094dee2012-08-10 10:58:18 +000029#include <cctype>
Reid Spencer5f016e22007-07-11 17:01:13 +000030#include <cstdio>
31using namespace clang;
32
Chris Lattnerd82df3a2009-04-12 01:56:53 +000033/// PrintMacroDefinition - Print a macro definition in a form that will be
34/// properly accepted back as a definition.
35static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
Chris Lattner5f9e2722011-07-23 10:55:15 +000036 Preprocessor &PP, raw_ostream &OS) {
Chris Lattnerd82df3a2009-04-12 01:56:53 +000037 OS << "#define " << II.getName();
Mike Stump1eb44332009-09-09 15:08:12 +000038
Chris Lattnerd82df3a2009-04-12 01:56:53 +000039 if (MI.isFunctionLike()) {
40 OS << '(';
Chris Lattner13d55582009-12-09 02:08:14 +000041 if (!MI.arg_empty()) {
Chris Lattnerd82df3a2009-04-12 01:56:53 +000042 MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end();
Chris Lattner13d55582009-12-09 02:08:14 +000043 for (; AI+1 != E; ++AI) {
44 OS << (*AI)->getName();
Chris Lattner807b93e2009-12-07 01:58:34 +000045 OS << ',';
Chris Lattner807b93e2009-12-07 01:58:34 +000046 }
Chris Lattner13d55582009-12-09 02:08:14 +000047
48 // Last argument.
49 if ((*AI)->getName() == "__VA_ARGS__")
50 OS << "...";
51 else
52 OS << (*AI)->getName();
Chris Lattnerd82df3a2009-04-12 01:56:53 +000053 }
Mike Stump1eb44332009-09-09 15:08:12 +000054
Chris Lattner807b93e2009-12-07 01:58:34 +000055 if (MI.isGNUVarargs())
56 OS << "..."; // #define foo(x...)
Kovarththanan Rajaratnama5d10c42010-03-07 07:30:06 +000057
Chris Lattnerd82df3a2009-04-12 01:56:53 +000058 OS << ')';
59 }
Mike Stump1eb44332009-09-09 15:08:12 +000060
Chris Lattnerd82df3a2009-04-12 01:56:53 +000061 // 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())
64 OS << ' ';
Mike Stump1eb44332009-09-09 15:08:12 +000065
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +000066 SmallString<128> SpellingBuffer;
Chris Lattnerd82df3a2009-04-12 01:56:53 +000067 for (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end();
68 I != E; ++I) {
69 if (I->hasLeadingSpace())
70 OS << ' ';
Mike Stump1eb44332009-09-09 15:08:12 +000071
Benjamin Kramerddeea562010-02-27 13:44:12 +000072 OS << PP.getSpelling(*I, SpellingBuffer);
Chris Lattnerd82df3a2009-04-12 01:56:53 +000073 }
74}
75
Reid Spencer5f016e22007-07-11 17:01:13 +000076//===----------------------------------------------------------------------===//
77// Preprocessed token printer
78//===----------------------------------------------------------------------===//
79
Reid Spencer5f016e22007-07-11 17:01:13 +000080namespace {
81class PrintPPOutputPPCallbacks : public PPCallbacks {
82 Preprocessor &PP;
Chris Lattnerdf721402010-04-13 00:06:42 +000083 SourceManager &SM;
Chris Lattnerd7038e12009-02-13 00:46:04 +000084 TokenConcatenation ConcatInfo;
Chris Lattnere96de3e2008-08-17 03:12:02 +000085public:
Chris Lattner5f9e2722011-07-23 10:55:15 +000086 raw_ostream &OS;
Chris Lattnere96de3e2008-08-17 03:12:02 +000087private:
Reid Spencer5f016e22007-07-11 17:01:13 +000088 unsigned CurLine;
Daniel Dunbarf7c16d92010-08-24 22:44:13 +000089
Reid Spencer5f016e22007-07-11 17:01:13 +000090 bool EmittedTokensOnThisLine;
Jordan Rose0cdd1fe2012-06-15 23:33:51 +000091 bool EmittedDirectiveOnThisLine;
Chris Lattner9d728512008-10-27 01:19:25 +000092 SrcMgr::CharacteristicKind FileType;
Dylan Noblesmithf7ccbad2012-02-05 02:13:05 +000093 SmallString<512> CurFilename;
Daniel Dunbar737bdb42008-09-05 03:22:57 +000094 bool Initialized;
Eli Friedman12d3b1d2009-05-19 03:06:47 +000095 bool DisableLineMarkers;
96 bool DumpDefines;
Chris Lattnerf7449342009-12-07 01:42:56 +000097 bool UseLineDirective;
Daniel Dunbar2a9be3e2012-11-16 01:51:11 +000098 bool IsFirstFileEntered;
Reid Spencer5f016e22007-07-11 17:01:13 +000099public:
Chris Lattner5f9e2722011-07-23 10:55:15 +0000100 PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os,
Daniel Dunbareef63e02011-02-02 15:41:17 +0000101 bool lineMarkers, bool defines)
Chris Lattnerdf721402010-04-13 00:06:42 +0000102 : PP(pp), SM(PP.getSourceManager()),
103 ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers),
Daniel Dunbareef63e02011-02-02 15:41:17 +0000104 DumpDefines(defines) {
105 CurLine = 0;
Chris Lattnerd8e30832007-07-24 06:57:14 +0000106 CurFilename += "<uninit>";
Reid Spencer5f016e22007-07-11 17:01:13 +0000107 EmittedTokensOnThisLine = false;
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000108 EmittedDirectiveOnThisLine = false;
Chris Lattner0b9e7362008-09-26 21:18:42 +0000109 FileType = SrcMgr::C_User;
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000110 Initialized = false;
Daniel Dunbar2a9be3e2012-11-16 01:51:11 +0000111 IsFirstFileEntered = false;
Kovarththanan Rajaratnama5d10c42010-03-07 07:30:06 +0000112
Chris Lattnerf7449342009-12-07 01:42:56 +0000113 // If we're in microsoft mode, use normal #line instead of line markers.
David Blaikie4e4d0842012-03-11 07:00:24 +0000114 UseLineDirective = PP.getLangOpts().MicrosoftExt;
Reid Spencer5f016e22007-07-11 17:01:13 +0000115 }
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000117 void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
Chris Lattnerf0f2b292007-07-23 06:09:34 +0000118 bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; }
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000120 void setEmittedDirectiveOnThisLine() { EmittedDirectiveOnThisLine = true; }
121 bool hasEmittedDirectiveOnThisLine() const {
122 return EmittedDirectiveOnThisLine;
123 }
124
125 bool startNewLineIfNeeded(bool ShouldUpdateCurrentLine = true);
Douglas Gregor80c60f72010-09-09 22:45:38 +0000126
Reid Spencer5f016e22007-07-11 17:01:13 +0000127 virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
Argyrios Kyrtzidisc892c5f2011-10-11 17:29:44 +0000128 SrcMgr::CharacteristicKind FileType,
129 FileID PrevFID);
Reid Spencer5f016e22007-07-11 17:01:13 +0000130 virtual void Ident(SourceLocation Loc, const std::string &str);
Mike Stump1eb44332009-09-09 15:08:12 +0000131 virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000132 const std::string &Str);
Chris Lattner5f9e2722011-07-23 10:55:15 +0000133 virtual void PragmaMessage(SourceLocation Loc, StringRef Str);
Douglas Gregorc09ce122011-06-22 19:41:48 +0000134 virtual void PragmaDiagnosticPush(SourceLocation Loc,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000135 StringRef Namespace);
Douglas Gregorc09ce122011-06-22 19:41:48 +0000136 virtual void PragmaDiagnosticPop(SourceLocation Loc,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000137 StringRef Namespace);
138 virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
Benjamin Kramerd7a3e2c2012-02-07 22:29:24 +0000139 diag::Mapping Map, StringRef Str);
Reid Spencer5f016e22007-07-11 17:01:13 +0000140
Chris Lattner5f180322007-12-09 21:11:08 +0000141 bool HandleFirstTokOnLine(Token &Tok);
Chris Lattner88aae912010-04-13 00:01:41 +0000142 bool MoveToLine(SourceLocation Loc) {
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000143 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
144 if (PLoc.isInvalid())
145 return false;
146 return MoveToLine(PLoc.getLine());
Chris Lattner88aae912010-04-13 00:01:41 +0000147 }
148 bool MoveToLine(unsigned LineNo);
149
Chris Lattner88773212010-04-14 03:57:19 +0000150 bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok,
151 const Token &Tok) {
152 return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok);
Chris Lattnerd7038e12009-02-13 00:46:04 +0000153 }
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000154 void WriteLineInfo(unsigned LineNo, const char *Extra=0, unsigned ExtraLen=0);
Douglas Gregor80c60f72010-09-09 22:45:38 +0000155 bool LineMarkersAreDisabled() const { return DisableLineMarkers; }
Chris Lattner3ee211f2009-06-15 01:25:23 +0000156 void HandleNewlinesInToken(const char *TokStr, unsigned Len);
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Chris Lattnerd82df3a2009-04-12 01:56:53 +0000158 /// MacroDefined - This hook is called whenever a macro definition is seen.
Craig Silverstein2aa92672010-11-19 21:33:15 +0000159 void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI);
Mike Stump1eb44332009-09-09 15:08:12 +0000160
Benjamin Kramer2f054492010-08-07 22:27:00 +0000161 /// MacroUndefined - This hook is called whenever a macro #undef is seen.
Craig Silverstein2aa92672010-11-19 21:33:15 +0000162 void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI);
Reid Spencer5f016e22007-07-11 17:01:13 +0000163};
Chris Lattner5db17c92008-04-08 04:16:20 +0000164} // end anonymous namespace
Reid Spencer5f016e22007-07-11 17:01:13 +0000165
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000166void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
167 const char *Extra,
168 unsigned ExtraLen) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000169 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000170
Chris Lattnerf7449342009-12-07 01:42:56 +0000171 // Emit #line directives or GNU line markers depending on what mode we're in.
172 if (UseLineDirective) {
173 OS << "#line" << ' ' << LineNo << ' ' << '"';
Ted Kremenek23465132010-09-17 00:41:18 +0000174 OS.write(CurFilename.data(), CurFilename.size());
Chris Lattnerf7449342009-12-07 01:42:56 +0000175 OS << '"';
176 } else {
177 OS << '#' << ' ' << LineNo << ' ' << '"';
Ted Kremenek23465132010-09-17 00:41:18 +0000178 OS.write(CurFilename.data(), CurFilename.size());
Chris Lattnerf7449342009-12-07 01:42:56 +0000179 OS << '"';
Kovarththanan Rajaratnama5d10c42010-03-07 07:30:06 +0000180
Steve Naroffd76fbda2009-12-06 01:02:14 +0000181 if (ExtraLen)
182 OS.write(Extra, ExtraLen);
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000183
Steve Naroffd76fbda2009-12-06 01:02:14 +0000184 if (FileType == SrcMgr::C_System)
185 OS.write(" 3", 2);
186 else if (FileType == SrcMgr::C_ExternCSystem)
187 OS.write(" 3 4", 4);
188 }
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000189 OS << '\n';
190}
191
Reid Spencer5f016e22007-07-11 17:01:13 +0000192/// MoveToLine - Move the output to the source line specified by the location
193/// object. We can do this by emitting some number of \n's, or be emitting a
Chris Lattner5f180322007-12-09 21:11:08 +0000194/// #line directive. This returns false if already at the specified line, true
195/// if some newlines were emitted.
Chris Lattner88aae912010-04-13 00:01:41 +0000196bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000197 // If this line is "close enough" to the original line, just print newlines,
198 // otherwise print a #line directive.
Daniel Dunbarfd966842008-09-26 01:13:35 +0000199 if (LineNo-CurLine <= 8) {
Chris Lattner822f9402007-07-23 05:14:05 +0000200 if (LineNo-CurLine == 1)
Chris Lattnere96de3e2008-08-17 03:12:02 +0000201 OS << '\n';
Chris Lattner5f180322007-12-09 21:11:08 +0000202 else if (LineNo == CurLine)
Chandler Carruth9f79a1f2011-07-14 16:14:52 +0000203 return false; // Spelling line moved, but expansion line didn't.
Chris Lattner822f9402007-07-23 05:14:05 +0000204 else {
205 const char *NewLines = "\n\n\n\n\n\n\n\n";
Chris Lattnere96de3e2008-08-17 03:12:02 +0000206 OS.write(NewLines, LineNo-CurLine);
Chris Lattner822f9402007-07-23 05:14:05 +0000207 }
Chris Lattner6133aeb2010-06-12 16:20:56 +0000208 } else if (!DisableLineMarkers) {
209 // Emit a #line or line marker.
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000210 WriteLineInfo(LineNo, 0, 0);
Chris Lattner6133aeb2010-06-12 16:20:56 +0000211 } else {
212 // Okay, we're in -P mode, which turns off line markers. However, we still
213 // need to emit a newline between tokens on different lines.
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000214 startNewLineIfNeeded(/*ShouldUpdateCurrentLine=*/false);
Mike Stump1eb44332009-09-09 15:08:12 +0000215 }
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000216
Mike Stump1eb44332009-09-09 15:08:12 +0000217 CurLine = LineNo;
Chris Lattner5f180322007-12-09 21:11:08 +0000218 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000219}
220
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000221bool
222PrintPPOutputPPCallbacks::startNewLineIfNeeded(bool ShouldUpdateCurrentLine) {
223 if (EmittedTokensOnThisLine || EmittedDirectiveOnThisLine) {
Douglas Gregor80c60f72010-09-09 22:45:38 +0000224 OS << '\n';
225 EmittedTokensOnThisLine = false;
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000226 EmittedDirectiveOnThisLine = false;
227 if (ShouldUpdateCurrentLine)
228 ++CurLine;
Douglas Gregor80c60f72010-09-09 22:45:38 +0000229 return true;
230 }
231
232 return false;
233}
Reid Spencer5f016e22007-07-11 17:01:13 +0000234
235/// FileChanged - Whenever the preprocessor enters or exits a #include file
236/// it invokes this handler. Update our conception of the current source
237/// position.
238void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
239 FileChangeReason Reason,
Argyrios Kyrtzidisc892c5f2011-10-11 17:29:44 +0000240 SrcMgr::CharacteristicKind NewFileType,
241 FileID PrevFID) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000242 // Unless we are exiting a #include, make sure to skip ahead to the line the
243 // #include directive was at.
Chris Lattnerdf721402010-04-13 00:06:42 +0000244 SourceManager &SourceMgr = SM;
Chris Lattner88aae912010-04-13 00:01:41 +0000245
246 PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc);
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000247 if (UserLoc.isInvalid())
248 return;
249
Chris Lattner86d0ef72010-04-14 04:28:50 +0000250 unsigned NewLine = UserLoc.getLine();
Daniel Dunbarf7c16d92010-08-24 22:44:13 +0000251
Reid Spencer5f016e22007-07-11 17:01:13 +0000252 if (Reason == PPCallbacks::EnterFile) {
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000253 SourceLocation IncludeLoc = UserLoc.getIncludeLoc();
Chris Lattner71d8bfb2009-01-30 18:44:17 +0000254 if (IncludeLoc.isValid())
255 MoveToLine(IncludeLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000256 } else if (Reason == PPCallbacks::SystemHeaderPragma) {
Chris Lattner88aae912010-04-13 00:01:41 +0000257 MoveToLine(NewLine);
Mike Stump1eb44332009-09-09 15:08:12 +0000258
Reid Spencer5f016e22007-07-11 17:01:13 +0000259 // TODO GCC emits the # directive for this directive on the line AFTER the
260 // directive and emits a bunch of spaces that aren't needed. Emulate this
261 // strange behavior.
262 }
Chris Lattner88aae912010-04-13 00:01:41 +0000263
264 CurLine = NewLine;
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000265
Chris Lattnerd8e30832007-07-24 06:57:14 +0000266 CurFilename.clear();
Chris Lattner88aae912010-04-13 00:01:41 +0000267 CurFilename += UserLoc.getFilename();
Chris Lattnerd8e30832007-07-24 06:57:14 +0000268 Lexer::Stringify(CurFilename);
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000269 FileType = NewFileType;
270
Daniel Dunbarf7c16d92010-08-24 22:44:13 +0000271 if (DisableLineMarkers) return;
272
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000273 if (!Initialized) {
274 WriteLineInfo(CurLine);
275 Initialized = true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000276 }
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000277
Daniel Dunbar2a9be3e2012-11-16 01:51:11 +0000278 // Do not emit an enter marker for the main file (which we expect is the first
279 // entered file). This matches gcc, and improves compatibility with some tools
280 // which track the # line markers as a way to determine when the preprocessed
281 // output is in the context of the main file.
282 if (Reason == PPCallbacks::EnterFile && !IsFirstFileEntered) {
283 IsFirstFileEntered = true;
284 return;
285 }
286
Reid Spencer5f016e22007-07-11 17:01:13 +0000287 switch (Reason) {
288 case PPCallbacks::EnterFile:
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000289 WriteLineInfo(CurLine, " 1", 2);
Reid Spencer5f016e22007-07-11 17:01:13 +0000290 break;
291 case PPCallbacks::ExitFile:
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000292 WriteLineInfo(CurLine, " 2", 2);
Reid Spencer5f016e22007-07-11 17:01:13 +0000293 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000294 case PPCallbacks::SystemHeaderPragma:
295 case PPCallbacks::RenameFile:
Daniel Dunbar737bdb42008-09-05 03:22:57 +0000296 WriteLineInfo(CurLine);
297 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000298 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000299}
300
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000301/// Ident - Handle #ident directives when read by the preprocessor.
Reid Spencer5f016e22007-07-11 17:01:13 +0000302///
303void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) {
304 MoveToLine(Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Chris Lattnere96de3e2008-08-17 03:12:02 +0000306 OS.write("#ident ", strlen("#ident "));
307 OS.write(&S[0], S.size());
Reid Spencer5f016e22007-07-11 17:01:13 +0000308 EmittedTokensOnThisLine = true;
309}
310
Chris Lattnerd82df3a2009-04-12 01:56:53 +0000311/// MacroDefined - This hook is called whenever a macro definition is seen.
Craig Silverstein2aa92672010-11-19 21:33:15 +0000312void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
Chris Lattnerd82df3a2009-04-12 01:56:53 +0000313 const MacroInfo *MI) {
314 // Only print out macro definitions in -dD mode.
315 if (!DumpDefines ||
316 // Ignore __FILE__ etc.
317 MI->isBuiltinMacro()) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000318
Chris Lattnerd82df3a2009-04-12 01:56:53 +0000319 MoveToLine(MI->getDefinitionLoc());
Craig Silverstein2aa92672010-11-19 21:33:15 +0000320 PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000321 setEmittedDirectiveOnThisLine();
Chris Lattnerd82df3a2009-04-12 01:56:53 +0000322}
323
Craig Silverstein2aa92672010-11-19 21:33:15 +0000324void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
Benjamin Kramer2f054492010-08-07 22:27:00 +0000325 const MacroInfo *MI) {
326 // Only print out macro definitions in -dD mode.
327 if (!DumpDefines) return;
328
Craig Silverstein2aa92672010-11-19 21:33:15 +0000329 MoveToLine(MacroNameTok.getLocation());
330 OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName();
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000331 setEmittedDirectiveOnThisLine();
Benjamin Kramer2f054492010-08-07 22:27:00 +0000332}
Chris Lattnerd82df3a2009-04-12 01:56:53 +0000333
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000334void PrintPPOutputPPCallbacks::PragmaComment(SourceLocation Loc,
Mike Stump1eb44332009-09-09 15:08:12 +0000335 const IdentifierInfo *Kind,
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000336 const std::string &Str) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000337 startNewLineIfNeeded();
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000338 MoveToLine(Loc);
339 OS << "#pragma comment(" << Kind->getName();
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000341 if (!Str.empty()) {
342 OS << ", \"";
Mike Stump1eb44332009-09-09 15:08:12 +0000343
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000344 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
345 unsigned char Char = Str[i];
Chris Lattner52a3e9e2009-01-16 22:13:37 +0000346 if (isprint(Char) && Char != '\\' && Char != '"')
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000347 OS << (char)Char;
348 else // Output anything hard as an octal escape.
349 OS << '\\'
350 << (char)('0'+ ((Char >> 6) & 7))
351 << (char)('0'+ ((Char >> 3) & 7))
352 << (char)('0'+ ((Char >> 0) & 7));
353 }
354 OS << '"';
355 }
Mike Stump1eb44332009-09-09 15:08:12 +0000356
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000357 OS << ')';
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000358 setEmittedDirectiveOnThisLine();
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000359}
360
Chris Lattnerabfe0942010-06-26 17:11:39 +0000361void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000362 StringRef Str) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000363 startNewLineIfNeeded();
Chris Lattnerabfe0942010-06-26 17:11:39 +0000364 MoveToLine(Loc);
365 OS << "#pragma message(";
366
367 OS << '"';
368
369 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
370 unsigned char Char = Str[i];
371 if (isprint(Char) && Char != '\\' && Char != '"')
372 OS << (char)Char;
373 else // Output anything hard as an octal escape.
374 OS << '\\'
375 << (char)('0'+ ((Char >> 6) & 7))
376 << (char)('0'+ ((Char >> 3) & 7))
377 << (char)('0'+ ((Char >> 0) & 7));
378 }
379 OS << '"';
380
381 OS << ')';
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000382 setEmittedDirectiveOnThisLine();
Chris Lattnerabfe0942010-06-26 17:11:39 +0000383}
384
Douglas Gregorc09ce122011-06-22 19:41:48 +0000385void PrintPPOutputPPCallbacks::
Chris Lattner5f9e2722011-07-23 10:55:15 +0000386PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000387 startNewLineIfNeeded();
Douglas Gregorc09ce122011-06-22 19:41:48 +0000388 MoveToLine(Loc);
389 OS << "#pragma " << Namespace << " diagnostic push";
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000390 setEmittedDirectiveOnThisLine();
Douglas Gregorc09ce122011-06-22 19:41:48 +0000391}
392
393void PrintPPOutputPPCallbacks::
Chris Lattner5f9e2722011-07-23 10:55:15 +0000394PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000395 startNewLineIfNeeded();
Douglas Gregorc09ce122011-06-22 19:41:48 +0000396 MoveToLine(Loc);
397 OS << "#pragma " << Namespace << " diagnostic pop";
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000398 setEmittedDirectiveOnThisLine();
Douglas Gregorc09ce122011-06-22 19:41:48 +0000399}
400
401void PrintPPOutputPPCallbacks::
Chris Lattner5f9e2722011-07-23 10:55:15 +0000402PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
Benjamin Kramerd7a3e2c2012-02-07 22:29:24 +0000403 diag::Mapping Map, StringRef Str) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000404 startNewLineIfNeeded();
Douglas Gregorc09ce122011-06-22 19:41:48 +0000405 MoveToLine(Loc);
406 OS << "#pragma " << Namespace << " diagnostic ";
Benjamin Kramerd7a3e2c2012-02-07 22:29:24 +0000407 switch (Map) {
Douglas Gregorc09ce122011-06-22 19:41:48 +0000408 case diag::MAP_WARNING:
409 OS << "warning";
410 break;
411 case diag::MAP_ERROR:
412 OS << "error";
413 break;
414 case diag::MAP_IGNORE:
415 OS << "ignored";
416 break;
417 case diag::MAP_FATAL:
418 OS << "fatal";
419 break;
420 }
421 OS << " \"" << Str << '"';
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000422 setEmittedDirectiveOnThisLine();
Douglas Gregorc09ce122011-06-22 19:41:48 +0000423}
Chris Lattnerc7d945d2009-01-16 19:25:54 +0000424
Reid Spencer5f016e22007-07-11 17:01:13 +0000425/// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this
Chris Lattner5f180322007-12-09 21:11:08 +0000426/// is called for the first token on each new line. If this really is the start
427/// of a new logical line, handle it and return true, otherwise return false.
428/// This may not be the start of a logical line because the "start of line"
Chandler Carruth9f79a1f2011-07-14 16:14:52 +0000429/// marker is set for spelling lines, not expansion ones.
Chris Lattner5f180322007-12-09 21:11:08 +0000430bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000431 // Figure out what line we went to and insert the appropriate number of
432 // newline characters.
Chris Lattner5f180322007-12-09 21:11:08 +0000433 if (!MoveToLine(Tok.getLocation()))
434 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000435
Reid Spencer5f016e22007-07-11 17:01:13 +0000436 // Print out space characters so that the first token on a line is
437 // indented for easy reading.
Chandler Carrutha77c0312011-07-25 20:57:57 +0000438 unsigned ColNo = SM.getExpansionColumnNumber(Tok.getLocation());
Mike Stump1eb44332009-09-09 15:08:12 +0000439
Reid Spencer5f016e22007-07-11 17:01:13 +0000440 // This hack prevents stuff like:
441 // #define HASH #
442 // HASH define foo bar
443 // From having the # character end up at column 1, which makes it so it
444 // is not handled as a #define next time through the preprocessor if in
445 // -fpreprocessed mode.
Chris Lattner057aaf62007-10-09 18:03:42 +0000446 if (ColNo <= 1 && Tok.is(tok::hash))
Chris Lattnere96de3e2008-08-17 03:12:02 +0000447 OS << ' ';
Mike Stump1eb44332009-09-09 15:08:12 +0000448
Reid Spencer5f016e22007-07-11 17:01:13 +0000449 // Otherwise, indent the appropriate number of spaces.
450 for (; ColNo > 1; --ColNo)
Chris Lattnere96de3e2008-08-17 03:12:02 +0000451 OS << ' ';
Mike Stump1eb44332009-09-09 15:08:12 +0000452
Chris Lattner5f180322007-12-09 21:11:08 +0000453 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000454}
455
Chris Lattner3ee211f2009-06-15 01:25:23 +0000456void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr,
457 unsigned Len) {
458 unsigned NumNewlines = 0;
459 for (; Len; --Len, ++TokStr) {
460 if (*TokStr != '\n' &&
461 *TokStr != '\r')
462 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000463
Chris Lattner3ee211f2009-06-15 01:25:23 +0000464 ++NumNewlines;
Mike Stump1eb44332009-09-09 15:08:12 +0000465
Chris Lattner3ee211f2009-06-15 01:25:23 +0000466 // If we have \n\r or \r\n, skip both and count as one line.
467 if (Len != 1 &&
468 (TokStr[1] == '\n' || TokStr[1] == '\r') &&
469 TokStr[0] != TokStr[1])
470 ++TokStr, --Len;
471 }
Mike Stump1eb44332009-09-09 15:08:12 +0000472
Chris Lattner3ee211f2009-06-15 01:25:23 +0000473 if (NumNewlines == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000474
Chris Lattnered2d7c42009-06-15 04:08:28 +0000475 CurLine += NumNewlines;
Chris Lattner3ee211f2009-06-15 01:25:23 +0000476}
477
478
Reid Spencer5f016e22007-07-11 17:01:13 +0000479namespace {
480struct UnknownPragmaHandler : public PragmaHandler {
481 const char *Prefix;
482 PrintPPOutputPPCallbacks *Callbacks;
Mike Stump1eb44332009-09-09 15:08:12 +0000483
Reid Spencer5f016e22007-07-11 17:01:13 +0000484 UnknownPragmaHandler(const char *prefix, PrintPPOutputPPCallbacks *callbacks)
Argyrios Kyrtzidis9b36c3f2010-07-13 09:07:17 +0000485 : Prefix(prefix), Callbacks(callbacks) {}
Douglas Gregor80c60f72010-09-09 22:45:38 +0000486 virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
487 Token &PragmaTok) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000488 // Figure out what line we went to and insert the appropriate number of
489 // newline characters.
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000490 Callbacks->startNewLineIfNeeded();
Reid Spencer5f016e22007-07-11 17:01:13 +0000491 Callbacks->MoveToLine(PragmaTok.getLocation());
Chris Lattnere96de3e2008-08-17 03:12:02 +0000492 Callbacks->OS.write(Prefix, strlen(Prefix));
Reid Spencer5f016e22007-07-11 17:01:13 +0000493 // Read and print all of the pragma tokens.
Peter Collingbourne84021552011-02-28 02:37:51 +0000494 while (PragmaTok.isNot(tok::eod)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000495 if (PragmaTok.hasLeadingSpace())
Chris Lattnere96de3e2008-08-17 03:12:02 +0000496 Callbacks->OS << ' ';
Reid Spencer5f016e22007-07-11 17:01:13 +0000497 std::string TokSpell = PP.getSpelling(PragmaTok);
Chris Lattnere96de3e2008-08-17 03:12:02 +0000498 Callbacks->OS.write(&TokSpell[0], TokSpell.size());
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 PP.LexUnexpandedToken(PragmaTok);
500 }
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000501 Callbacks->setEmittedDirectiveOnThisLine();
Reid Spencer5f016e22007-07-11 17:01:13 +0000502 }
503};
504} // end anonymous namespace
505
Chris Lattnerf0f2b292007-07-23 06:09:34 +0000506
Chris Lattner59076ab2009-02-06 05:56:11 +0000507static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
508 PrintPPOutputPPCallbacks *Callbacks,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000509 raw_ostream &OS) {
Benjamin Kramere3960072010-02-27 18:02:51 +0000510 char Buffer[256];
Chris Lattnerc54539c2010-06-15 21:06:38 +0000511 Token PrevPrevTok, PrevTok;
512 PrevPrevTok.startToken();
513 PrevTok.startToken();
Chris Lattner6f688e12007-10-10 20:45:16 +0000514 while (1) {
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000515 if (Callbacks->hasEmittedDirectiveOnThisLine()) {
516 Callbacks->startNewLineIfNeeded();
517 Callbacks->MoveToLine(Tok.getLocation());
518 }
Mike Stump1eb44332009-09-09 15:08:12 +0000519
Reid Spencer5f016e22007-07-11 17:01:13 +0000520 // If this token is at the start of a line, emit newlines if needed.
Chris Lattner5f180322007-12-09 21:11:08 +0000521 if (Tok.isAtStartOfLine() && Callbacks->HandleFirstTokOnLine(Tok)) {
522 // done.
Mike Stump1eb44332009-09-09 15:08:12 +0000523 } else if (Tok.hasLeadingSpace() ||
Chris Lattnerf0f2b292007-07-23 06:09:34 +0000524 // If we haven't emitted a token on this line yet, PrevTok isn't
525 // useful to look at and no concatenation could happen anyway.
Chris Lattnerb638a302007-07-23 23:21:34 +0000526 (Callbacks->hasEmittedTokensOnThisLine() &&
Chris Lattnerf0f2b292007-07-23 06:09:34 +0000527 // Don't print "-" next to "-", it would form "--".
Chris Lattner88773212010-04-14 03:57:19 +0000528 Callbacks->AvoidConcat(PrevPrevTok, PrevTok, Tok))) {
Chris Lattnere96de3e2008-08-17 03:12:02 +0000529 OS << ' ';
Reid Spencer5f016e22007-07-11 17:01:13 +0000530 }
Mike Stump1eb44332009-09-09 15:08:12 +0000531
Benjamin Kramere3960072010-02-27 18:02:51 +0000532 if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
533 OS << II->getName();
534 } else if (Tok.isLiteral() && !Tok.needsCleaning() &&
535 Tok.getLiteralData()) {
536 OS.write(Tok.getLiteralData(), Tok.getLength());
537 } else if (Tok.getLength() < 256) {
538 const char *TokPtr = Buffer;
539 unsigned Len = PP.getSpelling(Tok, TokPtr);
540 OS.write(TokPtr, Len);
Mike Stump1eb44332009-09-09 15:08:12 +0000541
Benjamin Kramere3960072010-02-27 18:02:51 +0000542 // Tokens that can contain embedded newlines need to adjust our current
543 // line number.
544 if (Tok.getKind() == tok::comment)
545 Callbacks->HandleNewlinesInToken(TokPtr, Len);
546 } else {
547 std::string S = PP.getSpelling(Tok);
548 OS.write(&S[0], S.size());
549
550 // Tokens that can contain embedded newlines need to adjust our current
551 // line number.
552 if (Tok.getKind() == tok::comment)
553 Callbacks->HandleNewlinesInToken(&S[0], S.size());
554 }
Jordan Rose0cdd1fe2012-06-15 23:33:51 +0000555 Callbacks->setEmittedTokensOnThisLine();
Mike Stump1eb44332009-09-09 15:08:12 +0000556
Chris Lattner6f688e12007-10-10 20:45:16 +0000557 if (Tok.is(tok::eof)) break;
Mike Stump1eb44332009-09-09 15:08:12 +0000558
Chris Lattner88773212010-04-14 03:57:19 +0000559 PrevPrevTok = PrevTok;
Chris Lattner6f688e12007-10-10 20:45:16 +0000560 PrevTok = Tok;
561 PP.Lex(Tok);
562 }
Chris Lattner59076ab2009-02-06 05:56:11 +0000563}
564
Benjamin Kramer3ff2a4b2010-01-19 17:42:20 +0000565typedef std::pair<IdentifierInfo*, MacroInfo*> id_macro_pair;
566static int MacroIDCompare(const void* a, const void* b) {
567 const id_macro_pair *LHS = static_cast<const id_macro_pair*>(a);
568 const id_macro_pair *RHS = static_cast<const id_macro_pair*>(b);
569 return LHS->first->getName().compare(RHS->first->getName());
Chris Lattner2a2bb182009-02-10 22:28:19 +0000570}
Chris Lattner59076ab2009-02-06 05:56:11 +0000571
Chris Lattner5f9e2722011-07-23 10:55:15 +0000572static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
Daniel Dunbarc72cc502010-06-11 20:10:12 +0000573 // Ignore unknown pragmas.
Argyrios Kyrtzidis9b36c3f2010-07-13 09:07:17 +0000574 PP.AddPragmaHandler(new EmptyPragmaHandler());
Daniel Dunbarc72cc502010-06-11 20:10:12 +0000575
Eli Friedmanf1db5852009-05-19 01:32:34 +0000576 // -dM mode just scans and ignores all tokens in the files, then dumps out
577 // the macro table at the end.
Chris Lattnere127a0d2010-04-20 20:35:58 +0000578 PP.EnterMainSourceFile();
Eli Friedmanf1db5852009-05-19 01:32:34 +0000579
580 Token Tok;
581 do PP.Lex(Tok);
582 while (Tok.isNot(tok::eof));
583
Alexander Kornienko8a64bb52012-08-29 00:20:03 +0000584 SmallVector<id_macro_pair, 128> MacrosByID;
585 for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
586 I != E; ++I) {
587 if (I->first->hasMacroDefinition())
588 MacrosByID.push_back(id_macro_pair(I->first, I->second));
589 }
Benjamin Kramer3ff2a4b2010-01-19 17:42:20 +0000590 llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);
Eli Friedmanf1db5852009-05-19 01:32:34 +0000591
592 for (unsigned i = 0, e = MacrosByID.size(); i != e; ++i) {
593 MacroInfo &MI = *MacrosByID[i].second;
Mike Stump1eb44332009-09-09 15:08:12 +0000594 // Ignore computed macros like __LINE__ and friends.
Eli Friedmanf1db5852009-05-19 01:32:34 +0000595 if (MI.isBuiltinMacro()) continue;
596
597 PrintMacroDefinition(*MacrosByID[i].first, MI, PP, *OS);
Benjamin Kramer3ff2a4b2010-01-19 17:42:20 +0000598 *OS << '\n';
Eli Friedmanf1db5852009-05-19 01:32:34 +0000599 }
600}
601
Chris Lattner59076ab2009-02-06 05:56:11 +0000602/// DoPrintPreprocessedInput - This implements -E mode.
603///
Chris Lattner5f9e2722011-07-23 10:55:15 +0000604void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000605 const PreprocessorOutputOptions &Opts) {
Daniel Dunbar775bee72009-11-11 10:07:22 +0000606 // Show macros with no output is handled specially.
607 if (!Opts.ShowCPP) {
608 assert(Opts.ShowMacros && "Not yet implemented!");
609 DoPrintMacros(PP, OS);
610 return;
611 }
612
Chris Lattner59076ab2009-02-06 05:56:11 +0000613 // Inform the preprocessor whether we want it to retain comments or not, due
614 // to -C or -CC.
Daniel Dunbar775bee72009-11-11 10:07:22 +0000615 PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments);
Eli Friedmanf54fce82009-05-19 01:02:07 +0000616
Eli Friedman12d3b1d2009-05-19 03:06:47 +0000617 PrintPPOutputPPCallbacks *Callbacks =
Daniel Dunbar775bee72009-11-11 10:07:22 +0000618 new PrintPPOutputPPCallbacks(PP, *OS, !Opts.ShowLineMarkers,
Daniel Dunbareef63e02011-02-02 15:41:17 +0000619 Opts.ShowMacros);
Argyrios Kyrtzidis9b36c3f2010-07-13 09:07:17 +0000620 PP.AddPragmaHandler(new UnknownPragmaHandler("#pragma", Callbacks));
Chris Lattner13973992010-11-10 01:00:49 +0000621 PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",Callbacks));
622 PP.AddPragmaHandler("clang",
623 new UnknownPragmaHandler("#pragma clang", Callbacks));
Chris Lattner59076ab2009-02-06 05:56:11 +0000624
Kovarththanan Rajaratnama5d10c42010-03-07 07:30:06 +0000625 PP.addPPCallbacks(Callbacks);
Chris Lattner59076ab2009-02-06 05:56:11 +0000626
Eli Friedmanf1db5852009-05-19 01:32:34 +0000627 // After we have configured the preprocessor, enter the main file.
Chris Lattnere127a0d2010-04-20 20:35:58 +0000628 PP.EnterMainSourceFile();
Chris Lattner59076ab2009-02-06 05:56:11 +0000629
Eli Friedmanf1db5852009-05-19 01:32:34 +0000630 // Consume all of the tokens that come from the predefines buffer. Those
631 // should not be emitted into the output and are guaranteed to be at the
632 // start.
633 const SourceManager &SourceMgr = PP.getSourceManager();
634 Token Tok;
Douglas Gregorcb7b1e12010-11-12 07:15:47 +0000635 do {
636 PP.Lex(Tok);
637 if (Tok.is(tok::eof) || !Tok.getLocation().isFileID())
638 break;
639
640 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
641 if (PLoc.isInvalid())
642 break;
643
644 if (strcmp(PLoc.getFilename(), "<built-in>"))
645 break;
646 } while (true);
Chris Lattner59076ab2009-02-06 05:56:11 +0000647
Eli Friedmanf1db5852009-05-19 01:32:34 +0000648 // Read all the preprocessed tokens, printing them out to the stream.
649 PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);
650 *OS << '\n';
Reid Spencer5f016e22007-07-11 17:01:13 +0000651}