]> granicus.if.org Git - clang/commitdiff
Switch PTHManager to using diagnostics for most errors.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 12 Nov 2009 02:53:48 +0000 (02:53 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 12 Nov 2009 02:53:48 +0000 (02:53 +0000)
Also, always give errors on a token-cache PTH failure.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86939 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
include/clang/Lex/PTHManager.h
lib/Lex/PTHLexer.cpp
tools/clang-cc/clang-cc.cpp

index bbc551373d967473361d9cfe003dd694b965f22e..7f3f4ea1fca0607d5dcf17678754c2e19df7acbd 100644 (file)
@@ -89,6 +89,14 @@ def err_pascal_string_too_long : Error<"Pascal string is too long">;
 def warn_octal_escape_too_large : ExtWarn<"octal escape sequence out of range">;
 def warn_hex_escape_too_large : ExtWarn<"hex escape sequence out of range">;
 
+//===----------------------------------------------------------------------===//
+// PTH Diagnostics
+//===----------------------------------------------------------------------===//
+def err_pth_cannot_read : Error<
+    "PTH file '%0' could not be read">;
+def err_invalid_pth_file : Error<
+    "invalid or corrupt PTH file '%0'">;
+
 //===----------------------------------------------------------------------===//
 // Preprocessor Diagnostics
 //===----------------------------------------------------------------------===//
index ff1a17259e8a6aa6dbd48a1419684f6c726b26ad..ac5594e55d7d5dd255d4e3bbda0db025311e97d4 100644 (file)
@@ -119,8 +119,7 @@ public:
 
   /// Create - This method creates PTHManager objects.  The 'file' argument
   ///  is the name of the PTH file.  This method returns NULL upon failure.
-  static PTHManager *Create(const std::string& file, Diagnostic* Diags = 0,
-                            Diagnostic::Level failureLevel=Diagnostic::Warning);
+  static PTHManager *Create(const std::string& file, Diagnostic &Diags);
 
   void setPreprocessor(Preprocessor *pp) { PP = pp; }
 
index 60deeb325c0ae76aabb6b85c92120c71fa9ede2c..d6a73cc74f6affe05439242f6dec165873e82e79 100644 (file)
@@ -15,6 +15,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/OnDiskHashTable.h"
+#include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/PTHLexer.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PTHManager.h"
@@ -407,26 +408,17 @@ PTHManager::~PTHManager() {
   free(PerIDCache);
 }
 
-static void InvalidPTH(Diagnostic *Diags, Diagnostic::Level level,
-                       const char* Msg = 0) {
-  if (!Diags) return;
-  if (!Msg) Msg = "Invalid or corrupted PTH file";
-  Diags->Report(Diags->getCustomDiagID(level, Msg));
+static void InvalidPTH(Diagnostic &Diags, const char *Msg) {
+  Diags.Report(Diags.getCustomDiagID(Diagnostic::Error, Msg));
 }
 
-PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
-                               Diagnostic::Level level) {
+PTHManager* PTHManager::Create(const std::string& file, Diagnostic &Diags) {
   // Memory map the PTH file.
   llvm::OwningPtr<llvm::MemoryBuffer>
   File(llvm::MemoryBuffer::getFile(file.c_str()));
 
   if (!File) {
-    if (Diags) {
-      unsigned DiagID =Diags->getCustomDiagID(level,
-                                              "PTH file %0 could not be read");
-      Diags->Report(DiagID) << file;
-    }
-
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
@@ -438,7 +430,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   // Check the prologue of the file.
   if ((BufEnd - BufBeg) < (signed) (sizeof("cfe-pth") + 3 + 4) ||
       memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0) {
-    InvalidPTH(Diags, level);
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
@@ -446,8 +438,8 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
   unsigned Version = ReadLE32(p);
 
-  if (Version != PTHManager::Version) {
-    InvalidPTH(Diags, level,
+  if (Version < PTHManager::Version) {
+    InvalidPTH(Diags,
         Version < PTHManager::Version
         ? "PTH file uses an older PTH format that is no longer supported"
         : "PTH file uses a newer PTH format that cannot be read");
@@ -458,7 +450,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   const unsigned char *PrologueOffset = p;
 
   if (PrologueOffset >= BufEnd) {
-    InvalidPTH(Diags, level);
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
@@ -468,7 +460,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset);
 
   if (!(FileTable > BufBeg && FileTable < BufEnd)) {
-    InvalidPTH(Diags, level);
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0; // FIXME: Proper error diagnostic?
   }
 
@@ -477,7 +469,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   // Warn if the PTH file is empty.  We still want to create a PTHManager
   // as the PTH could be used with -include-pth.
   if (FL->isEmpty())
-    InvalidPTH(Diags, level, "PTH file contains no cached source data");
+    InvalidPTH(Diags, "PTH file contains no cached source data");
 
   // Get the location of the table mapping from persistent ids to the
   // data needed to reconstruct identifiers.
@@ -485,7 +477,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset);
 
   if (!(IData >= BufBeg && IData < BufEnd)) {
-    InvalidPTH(Diags, level);
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
@@ -494,7 +486,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1;
   const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset);
   if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) {
-    InvalidPTH(Diags, level);
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
@@ -505,7 +497,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3;
   const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset);
   if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) {
-    InvalidPTH(Diags, level);
+    Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
@@ -520,8 +512,7 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags,
   if (NumIds) {
     PerIDCache = (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));
     if (!PerIDCache) {
-      InvalidPTH(Diags, level,
-                 "Could not allocate memory for processing PTH file");
+      InvalidPTH(Diags, "Could not allocate memory for processing PTH file");
       return 0;
     }
   }
index 403eddb1959b5d46de817727195834a84a8701d6..5803b1291077dc3f7ecb7490ea446f2b03c04a09 100644 (file)
@@ -392,9 +392,7 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo,
   if (!TokenCache.empty() || !PPOpts.getImplicitPTHInclude().empty()) {
     const std::string& x = TokenCache.empty() ?
       PPOpts.getImplicitPTHInclude() : TokenCache;
-    PTHMgr = PTHManager::Create(x, &Diags,
-                                TokenCache.empty() ? Diagnostic::Error
-                                : Diagnostic::Warning);
+    PTHMgr = PTHManager::Create(x, Diags);
   }
 
   if (Diags.hasErrorOccurred())