[cfe-commits] r59191 - in /cfe/trunk: include/clang/Lex/Lexer.h include/clang/Lex/PTHLexer.h include/clang/Lex/PreprocessorLexer.h lib/Lex/Lexer.cpp lib/Lex/PTHLexer.cpp lib/Lex/PreprocessorLexer.cpp

Ted Kremenek kremenek at apple.com
Wed Nov 12 15:14:59 PST 2008


Author: kremenek
Date: Wed Nov 12 17:13:54 2008
New Revision: 59191

URL: http://llvm.org/viewvc/llvm-project?rev=59191&view=rev
Log:
Move some diagnostic handling to PreprocessorLexer.

Modified:
    cfe/trunk/include/clang/Lex/Lexer.h
    cfe/trunk/include/clang/Lex/PTHLexer.h
    cfe/trunk/include/clang/Lex/PreprocessorLexer.h
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Lex/PTHLexer.cpp
    cfe/trunk/lib/Lex/PreprocessorLexer.cpp

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=59191&r1=59190&r2=59191&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Wed Nov 12 17:13:54 2008
@@ -36,7 +36,6 @@
   const char *BufferStart;       // Start of the buffer.
   const char *BufferEnd;         // End of the buffer.
   SourceLocation FileLoc;        // Location for start of file.
-  Preprocessor *PP;              // Preprocessor object controlling lexing.
   LangOptions Features;          // Features enabled by this language (cache).
   bool Is_PragmaLexer;           // True if lexer for _Pragma handling.
   
@@ -171,8 +170,6 @@
   /// position in the current buffer into a SourceLocation object for rendering.
   void Diag(const char *Loc, unsigned DiagID,
             const std::string &Msg = std::string()) const;
-  void Diag(SourceLocation Loc, unsigned DiagID,
-            const std::string &Msg = std::string()) const;
 
   /// getSourceLocation - Return a source location identifier for the specified
   /// offset in the current file.

Modified: cfe/trunk/include/clang/Lex/PTHLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHLexer.h?rev=59191&r1=59190&r2=59191&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Wed Nov 12 17:13:54 2008
@@ -19,10 +19,6 @@
 namespace clang {
   
 class PTHLexer : public PreprocessorLexer {
-
-  /// PP - Preprocessor.
-  Preprocessor& PP;
-  
   /// FileLoc - Location for the start of the file.
   ///
   SourceLocation FileLoc;

Modified: cfe/trunk/include/clang/Lex/PreprocessorLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorLexer.h?rev=59191&r1=59190&r2=59191&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessorLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorLexer.h Wed Nov 12 17:13:54 2008
@@ -17,14 +17,19 @@
 #include "clang/Lex/MultipleIncludeOpt.h"
 #include "clang/Lex/Token.h"
 #include <vector>
-
+#include <string>
+	
 namespace clang {
 
 class Preprocessor;
 
 class PreprocessorLexer {
-protected:  
+protected:
+  Preprocessor *PP;              // Preprocessor object controlling lexing.
+  
+  //===--------------------------------------------------------------------===//
   // Context-specific lexing flags set by the preprocessor.
+  //===--------------------------------------------------------------------===//
   
   /// ParsingPreprocessorDirective - This is true when parsing #XXX.  This turns
   /// '\n' into a tok::eom token.
@@ -59,12 +64,15 @@
   void operator=(const PreprocessorLexer&); // DO NOT IMPLEMENT
   friend class Preprocessor;
   
-  PreprocessorLexer() {}
+  PreprocessorLexer(Preprocessor* pp) : PP(pp) {}
   virtual ~PreprocessorLexer();
   
   virtual void IndirectLex(Token& Result) = 0;
   
-protected:
+  /// Diag - Forwarding function for diagnostics.  This translate a source
+  /// position in the current buffer into a SourceLocation object for rendering.
+  void Diag(SourceLocation Loc, unsigned DiagID,
+            const std::string &Msg = std::string()) const;
   
   //===--------------------------------------------------------------------===//
   // #if directive handling.

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=59191&r1=59190&r2=59191&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Wed Nov 12 17:13:54 2008
@@ -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();
   }
   

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=59191&r1=59190&r2=59191&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Wed Nov 12 17:13:54 2008
@@ -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;
   }
     

Modified: cfe/trunk/lib/Lex/PreprocessorLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessorLexer.cpp?rev=59191&r1=59190&r2=59191&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PreprocessorLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessorLexer.cpp Wed Nov 12 17:13:54 2008
@@ -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) {





More information about the cfe-commits mailing list