[cfe-commits] r38746 - in /cfe/cfe/trunk: Lex/Lexer.cpp Lex/Pragma.cpp Lex/Preprocessor.cpp include/clang/Lex/Lexer.h include/clang/Lex/Preprocessor.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:17 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:17 2007
New Revision: 38746

URL: http://llvm.org/viewvc/llvm-project?rev=38746&view=rev
Log:
Simplify "raw lexing mode" even further.  Now the preprocessor is only called
into when a hard error is found.  This simplifies logic and eliminates the need
for the preprocessor to know about raw mode.

Modified:
    cfe/cfe/trunk/Lex/Lexer.cpp
    cfe/cfe/trunk/Lex/Pragma.cpp
    cfe/cfe/trunk/Lex/Preprocessor.cpp
    cfe/cfe/trunk/include/clang/Lex/Lexer.h
    cfe/cfe/trunk/include/clang/Lex/Preprocessor.h

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

==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:24:17 2007
@@ -158,8 +158,17 @@
 /// position in the current buffer into a SourceLocation object for rendering.
 void Lexer::Diag(const char *Loc, unsigned DiagID,
                  const std::string &Msg) const {
+  if (LexingRawMode && Diagnostic::isNoteWarningOrExtension(DiagID))
+    return;
   PP.Diag(getSourceLocation(Loc), DiagID, Msg);
 }
+void Lexer::Diag(SourceLocation Loc, unsigned DiagID,
+                 const std::string &Msg) const {
+  if (LexingRawMode && Diagnostic::isNoteWarningOrExtension(DiagID))
+    return;
+  PP.Diag(Loc, DiagID, Msg);
+}
+
 
 //===----------------------------------------------------------------------===//
 // Trigraph and Escaped Newline Handling Code.
@@ -814,7 +823,7 @@
 
   // No filename?
   if (FilenameTok.getKind() == tok::eom) {
-    PP.Diag(FilenameTok, diag::err_pp_expects_filename);
+    Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
     return "";
   }
   
@@ -825,25 +834,25 @@
   // Make sure the filename is <x> or "x".
   if (Filename[0] == '<') {
     if (Filename[Filename.size()-1] != '>') {
-      PP.Diag(FilenameTok, diag::err_pp_expects_filename);
+      Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
       FilenameTok.SetKind(tok::eom);
       return "";
     }
   } else if (Filename[0] == '"') {
     if (Filename[Filename.size()-1] != '"') {
-      PP.Diag(FilenameTok, diag::err_pp_expects_filename);
+      Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
       FilenameTok.SetKind(tok::eom);
       return "";
     }
   } else {
-    PP.Diag(FilenameTok, diag::err_pp_expects_filename);
+    Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
     FilenameTok.SetKind(tok::eom);
     return "";
   }
   
   // Diagnose #include "" as invalid.
   if (Filename.size() == 2) {
-    PP.Diag(FilenameTok, diag::err_pp_empty_filename);
+    Diag(FilenameTok.getLocation(), diag::err_pp_empty_filename);
     FilenameTok.SetKind(tok::eom);
     return "";
   }
@@ -922,8 +931,7 @@
 
   // If we are in a #if directive, emit an error.
   while (!ConditionalStack.empty()) {
-    PP.Diag(ConditionalStack.back().IfLoc,
-            diag::err_pp_unterminated_conditional);
+    Diag(ConditionalStack.back().IfLoc, diag::err_pp_unterminated_conditional);
     ConditionalStack.pop_back();
   }
   

Modified: cfe/cfe/trunk/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Pragma.cpp?rev=38746&r1=38745&r2=38746&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Pragma.cpp (original)
+++ cfe/cfe/trunk/Lex/Pragma.cpp Wed Jul 11 11:24:17 2007
@@ -182,7 +182,7 @@
 ///
 void Preprocessor::HandlePragmaPoison(LexerToken &PoisonTok) {
   LexerToken Tok;
-  assert(!isSkipping() && "Why are we handling pragmas while skipping?");
+
   while (1) {
     // Read the next token to poison.  While doing this, pretend that we are
     // skipping while reading the identifier to poison.

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38746&r1=38745&r2=38746&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:24:17 2007
@@ -133,11 +133,6 @@
 /// position in the current buffer into a SourcePosition object for rendering.
 void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID, 
                         const std::string &Msg) {
-  // If we are in a '#if 0' block, don't emit any diagnostics for notes,
-  // warnings or extensions.
-  if (isSkipping() && Diagnostic::isNoteWarningOrExtension(DiagID))
-    return;
-  
   Diags.Report(Loc, DiagID, Msg);
 }
 
@@ -1903,7 +1898,7 @@
   if (CurLexer->getConditionalStackDepth() == 0)
     CurLexer->MIOpt.ExitTopLevelConditional();
   
-  assert(!CondInfo.WasSkipping && !isSkipping() &&
+  assert(!CondInfo.WasSkipping && !CurLexer->LexingRawMode &&
          "This code should only be reachable in the non-skipping case!");
 }
 

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Lexer.h Wed Jul 11 11:24:17 2007
@@ -83,6 +83,7 @@
   ///  3. "#" tokens at the start of a line are treated as normal tokens, not
   ///     implicitly transformed by the lexer.
   ///  4. All notes, warnings, and extension messages are disabled.
+  ///  5. The only callback made into the preprocessor is to report hard errors.
   ///
   bool LexingRawMode;
   
@@ -175,6 +176,8 @@
   /// position in the current buffer into a SourceLocation object for rendering.
   void Diag(const char *Loc, unsigned DiagID,
             const std::string &Msg = "") const;
+  void Diag(SourceLocation Loc, unsigned DiagID,
+            const std::string &Msg = "") const;
 
   /// getSourceLocation - Return a source location identifier for the specified
   /// offset in the current file.

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:24:17 2007
@@ -214,10 +214,6 @@
 
   IdentifierTable &getIdentifierTable() { return Identifiers; }
 
-  /// isSkipping - Return true if we're lexing a '#if 0' block.  This causes
-  /// lexer errors/warnings to get ignored.
-  bool isSkipping() const { return CurLexer && CurLexer->LexingRawMode; }
-  
   /// isCurrentLexer - Return true if we are lexing directly from the specified
   /// lexer.
   bool isCurrentLexer(const Lexer *L) const {





More information about the cfe-commits mailing list