Move some diagnostic handling to PreprocessorLexer.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59191 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index b71452b..4e93600 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -63,7 +63,7 @@
 /// outlive it, so it doesn't take ownership of either of them.
 Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp,
              const char *BufStart, const char *BufEnd)
-  : FileLoc(fileloc), PP(&pp), Features(pp.getLangOptions()) {
+  : PreprocessorLexer(&pp), FileLoc(fileloc), Features(pp.getLangOptions()) {
       
   SourceManager &SourceMgr = PP->getSourceManager();
   unsigned InputFileID = SourceMgr.getPhysicalLoc(FileLoc).getFileID();
@@ -110,7 +110,7 @@
 Lexer::Lexer(SourceLocation fileloc, const LangOptions &features,
              const char *BufStart, const char *BufEnd,
              const llvm::MemoryBuffer *FromFile)
-  : FileLoc(fileloc), PP(0), Features(features) {
+  : PreprocessorLexer(0), FileLoc(fileloc), Features(features) {
   Is_PragmaLexer = false;
   InitCharacterInfo();
   
@@ -312,13 +312,6 @@
     return;
   PP->Diag(getSourceLocation(Loc), DiagID, Msg);
 }
-void Lexer::Diag(SourceLocation Loc, unsigned DiagID,
-                 const std::string &Msg) const {
-  if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
-    return;
-  PP->Diag(Loc, DiagID, Msg);
-}
-
 
 //===----------------------------------------------------------------------===//
 // Trigraph and Escaped Newline Handling Code.
@@ -1138,7 +1131,9 @@
 
   // If we are in a #if directive, emit an error.
   while (!ConditionalStack.empty()) {
-    Diag(ConditionalStack.back().IfLoc, diag::err_pp_unterminated_conditional);
+    PreprocessorLexer::Diag(ConditionalStack.back().IfLoc,
+                            diag::err_pp_unterminated_conditional);
+    
     ConditionalStack.pop_back();
   }
   
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index e1b3920..b0ecb27 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -20,7 +20,8 @@
 
 PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
                    const Token *TokArray, unsigned NumToks)
-  : PP(pp), FileLoc(fileloc), Tokens(TokArray), NumTokens(NumToks), CurToken(0){
+  : PreprocessorLexer(&pp), FileLoc(fileloc), Tokens(TokArray),
+    NumTokens(NumToks), CurToken(0) {
 
   assert (Tokens[NumTokens-1].is(tok::eof));
   --NumTokens;
@@ -46,7 +47,7 @@
       // FIXME: eom handling?
     }
     else
-      PP.HandleEndOfFile(Tok, false);
+      PP->HandleEndOfFile(Tok, false);
     
     return;
   }
@@ -65,8 +66,8 @@
     ++CurToken;
 
   if (Tok.isAtStartOfLine() && Tok.is(tok::hash) && !LexingRawMode) {
-    PP.HandleDirective(Tok);
-    PP.Lex(Tok);
+    PP->HandleDirective(Tok);
+    PP->Lex(Tok);
     return;
   }
     
diff --git a/lib/Lex/PreprocessorLexer.cpp b/lib/Lex/PreprocessorLexer.cpp
index f3d91af..3c5d81b 100644
--- a/lib/Lex/PreprocessorLexer.cpp
+++ b/lib/Lex/PreprocessorLexer.cpp
@@ -20,6 +20,13 @@
 
 PreprocessorLexer::~PreprocessorLexer() {}
 
+void PreprocessorLexer::Diag(SourceLocation Loc, unsigned DiagID,
+                             const std::string &Msg) const {
+  if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
+    return;
+  PP->Diag(Loc, DiagID, Msg);
+}
+
 /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
 /// (potentially) macro expand the filename.
 void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {