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

Chris Lattner sabre at nondot.org
Mon Nov 17 23:59:24 PST 2008


Author: lattner
Date: Tue Nov 18 01:59:24 2008
New Revision: 59511

URL: http://llvm.org/viewvc/llvm-project?rev=59511&view=rev
Log:
Convert the lexer and start converting the PP over to using canonical Diag methods.

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

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Tue Nov 18 01:59:24 2008
@@ -25,6 +25,7 @@
 class Diagnostic;
 class SourceManager;
 class Preprocessor;
+class DiagnosticInfo;
 
 /// Lexer - This provides a simple interface that turns a text buffer into a
 /// stream of tokens.  This provides no support for file reading or buffering,
@@ -171,8 +172,7 @@
  
   /// Diag - Forwarding function for diagnostics.  This translate a source
   /// 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;
+  DiagnosticInfo Diag(const char *Loc, unsigned DiagID) const;
 
   /// getSourceLocation - Return a source location identifier for the specified
   /// offset in the current file.

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Nov 18 01:59:24 2008
@@ -397,16 +397,14 @@
   /// Diag - Forwarding function for diagnostics.  This emits a diagnostic at
   /// the specified Token's location, translating the token's start
   /// position in the current buffer into a SourcePosition object for rendering.
-  void Diag(SourceLocation Loc, unsigned DiagID);  
+  DiagnosticInfo Diag(SourceLocation Loc, unsigned DiagID);  
+  DiagnosticInfo Diag(const Token &Tok, unsigned DiagID);
   void Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
   void Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
             const SourceRange &R1, const SourceRange &R2);
   void Diag(SourceLocation Loc, unsigned DiagID, const SourceRange &R);
   void Diag(SourceLocation Loc, unsigned DiagID, const SourceRange &R1,
             const SourceRange &R2);
-  void Diag(const Token &Tok, unsigned DiagID) {
-    Diag(Tok.getLocation(), DiagID);
-  }
   void Diag(const Token &Tok, unsigned DiagID, const std::string &Msg) {
     Diag(Tok.getLocation(), DiagID, Msg);
   }

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

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Tue Nov 18 01:59:24 2008
@@ -306,11 +306,10 @@
 
 /// Diag - Forwarding function for diagnostics.  This translate a source
 /// position in the current buffer into a SourceLocation object for rendering.
-void Lexer::Diag(const char *Loc, unsigned DiagID,
-                 const std::string &Msg) const {
+DiagnosticInfo Lexer::Diag(const char *Loc, unsigned DiagID) const {
   if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
-    return;
-  PP->Diag(getSourceLocation(Loc), DiagID, Msg);
+    return DiagnosticInfo(0, FullSourceLoc(), 0);
+  return PP->Diag(getSourceLocation(Loc), DiagID);
 }
 
 //===----------------------------------------------------------------------===//
@@ -340,14 +339,14 @@
 /// whether trigraphs are enabled or not.
 static char DecodeTrigraphChar(const char *CP, Lexer *L) {
   char Res = GetTrigraphCharForLetter(*CP);
-  if (Res && L) {
-    if (!L->getFeatures().Trigraphs) {
-      L->Diag(CP-2, diag::trigraph_ignored);
-      return 0;
-    } else {
-      L->Diag(CP-2, diag::trigraph_converted, std::string()+Res);
-    }
+  if (!Res || !L) return Res;
+  
+  if (!L->getFeatures().Trigraphs) {
+    L->Diag(CP-2, diag::trigraph_ignored);
+    return 0;
   }
+    
+  L->Diag(CP-2, diag::trigraph_converted) << std::string()+Res;
   return Res;
 }
 

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

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Nov 18 01:59:24 2008
@@ -48,8 +48,10 @@
   LexUnexpandedToken(MacroNameTok);
   
   // Missing macro name?
-  if (MacroNameTok.is(tok::eom))
-    return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
+  if (MacroNameTok.is(tok::eom)) {
+    Diag(MacroNameTok, diag::err_pp_missing_macro_name);
+    return;
+  }
   
   IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
   if (II == 0) {
@@ -489,8 +491,10 @@
   
   // If the token kind isn't a string, it's a malformed directive.
   if (StrTok.isNot(tok::string_literal) &&
-      StrTok.isNot(tok::wide_string_literal))
-    return Diag(StrTok, diag::err_pp_malformed_ident);
+      StrTok.isNot(tok::wide_string_literal)) {
+    Diag(StrTok, diag::err_pp_malformed_ident);
+    return;
+  }
   
   // Verify that there is nothing after the string, other than EOM.
   CheckEndOfDirective("#ident");
@@ -658,16 +662,20 @@
   CheckEndOfDirective("#include");
 
   // Check that we don't have infinite #include recursion.
-  if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1)
-    return Diag(FilenameTok, diag::err_pp_include_too_deep);
+  if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
+    Diag(FilenameTok, diag::err_pp_include_too_deep);
+    return;
+  }
   
   // Search include directories.
   const DirectoryLookup *CurDir;
   const FileEntry *File = LookupFile(FilenameStart, FilenameEnd,
                                      isAngled, LookupFrom, CurDir);
-  if (File == 0)
-    return Diag(FilenameTok, diag::err_pp_file_not_found,
-                std::string(FilenameStart, FilenameEnd));
+  if (File == 0) {
+    Diag(FilenameTok, diag::err_pp_file_not_found)
+       << std::string(FilenameStart, FilenameEnd);
+    return;
+  }
   
   // Ask HeaderInfo if we should enter this #include file.  If not, #including
   // this file will have no effect.
@@ -1101,7 +1109,8 @@
   PPConditionalInfo CondInfo;
   if (CurPPLexer->popConditionalLevel(CondInfo)) {
     // No conditionals on the stack: this is an #endif without an #if.
-    return Diag(EndifToken, diag::err_pp_endif_without_if);
+    Diag(EndifToken, diag::err_pp_endif_without_if);
+    return;
   }
   
   // If this the end of a top-level #endif, inform MIOpt.
@@ -1120,8 +1129,10 @@
   CheckEndOfDirective("#else");
   
   PPConditionalInfo CI;
-  if (CurPPLexer->popConditionalLevel(CI))
-    return Diag(Result, diag::pp_err_else_without_if);
+  if (CurPPLexer->popConditionalLevel(CI)) {
+    Diag(Result, diag::pp_err_else_without_if);
+    return;
+  }
   
   // If this is a top-level #else, inform the MIOpt.
   if (CurPPLexer->getConditionalStackDepth() == 0)
@@ -1145,8 +1156,10 @@
   DiscardUntilEndOfDirective();
 
   PPConditionalInfo CI;
-  if (CurPPLexer->popConditionalLevel(CI))
-    return Diag(ElifToken, diag::pp_err_elif_without_if);
+  if (CurPPLexer->popConditionalLevel(CI)) {
+    Diag(ElifToken, diag::pp_err_elif_without_if);
+    return;
+  }
   
   // If this is a top-level #elif, inform the MIOpt.
   if (CurPPLexer->getConditionalStackDepth() == 0)

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

==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Tue Nov 18 01:59:24 2008
@@ -102,13 +102,17 @@
   
   // Read the '('.
   Lex(Tok);
-  if (Tok.isNot(tok::l_paren))
-    return Diag(PragmaLoc, diag::err__Pragma_malformed);
+  if (Tok.isNot(tok::l_paren)) {
+    Diag(PragmaLoc, diag::err__Pragma_malformed);
+    return;
+  }
 
   // Read the '"..."'.
   Lex(Tok);
-  if (Tok.isNot(tok::string_literal) && Tok.isNot(tok::wide_string_literal))
-    return Diag(PragmaLoc, diag::err__Pragma_malformed);
+  if (Tok.isNot(tok::string_literal) && Tok.isNot(tok::wide_string_literal)) {
+    Diag(PragmaLoc, diag::err__Pragma_malformed);
+    return;
+  }
   
   // Remember the string.
   std::string StrVal = getSpelling(Tok);
@@ -116,8 +120,10 @@
 
   // Read the ')'.
   Lex(Tok);
-  if (Tok.isNot(tok::r_paren))
-    return Diag(PragmaLoc, diag::err__Pragma_malformed);
+  if (Tok.isNot(tok::r_paren)) {
+    Diag(PragmaLoc, diag::err__Pragma_malformed);
+    return;
+  }
   
   // The _Pragma is lexically sound.  Destringize according to C99 6.10.9.1.
   if (StrVal[0] == 'L')  // Remove L prefix.

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

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Nov 18 01:59:24 2008
@@ -118,10 +118,15 @@
 /// Diag - Forwarding function for diagnostics.  This emits a diagnostic at
 /// the specified Token's location, translating the token's start
 /// position in the current buffer into a SourcePosition object for rendering.
-void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
-  Diags.Report(getFullLoc(Loc), DiagID);
+DiagnosticInfo Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
+  return Diags.Report(getFullLoc(Loc), DiagID);
 }
 
+DiagnosticInfo Preprocessor::Diag(const Token &Tok, unsigned DiagID) {
+  return Diags.Report(getFullLoc(Tok.getLocation()), DiagID);
+}
+
+
 void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID, 
                         const std::string &Msg) {
   Diags.Report(getFullLoc(Loc), DiagID) << Msg;





More information about the cfe-commits mailing list