]> granicus.if.org Git - clang/commitdiff
add a virtual method to DiagnosticClient to get rid of some fragile
authorChris Lattner <sabre@nondot.org>
Fri, 17 Apr 2009 20:16:08 +0000 (20:16 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 17 Apr 2009 20:16:08 +0000 (20:16 +0000)
casting in clang-cc.

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

include/clang/Basic/Diagnostic.h
include/clang/Frontend/TextDiagnosticPrinter.h
tools/clang-cc/clang-cc.cpp

index 87489257cc59b4132c4f24a9d695620e7db8e5a1..9c0a02ca878ca79476a72d15dfd17edd230e22cd 100644 (file)
@@ -27,6 +27,7 @@ namespace clang {
   class SourceRange;
   class DiagnosticBuilder;
   class IdentifierInfo;
+  class LangOptions;
   
   // Import the diagnostic enums themselves.
   namespace diag {
@@ -667,6 +668,13 @@ class DiagnosticClient {
 public:
   virtual ~DiagnosticClient();
   
+  /// setLangOptions - This is set by clients of diagnostics when they know the
+  /// language parameters of the diagnostics that may be sent through.  Note
+  /// that this can change over time if a DiagClient has multiple languages sent
+  /// through it.  It may also be set to null (e.g. when processing command line
+  /// options).
+  virtual void setLangOptions(const LangOptions *LO) {}
+  
   /// IncludeInDiagnosticCounts - This method (whose default implementation
   ///  returns true) indicates whether the diagnostics handled by this
   ///  DiagnosticClient should be included in the number of diagnostics
index 9341b89f56ab9d164974926979a777cfca780f36..afdafb2b34a95570a41114476f3d576e2b5035ee 100644 (file)
@@ -50,8 +50,8 @@ public:
       PrintRangeInfo(printRangeInfo),
       PrintDiagnosticOption(printDiagnosticOption) {}
 
-  void SetLangOpts(const LangOptions &LO) {
-    LangOpts = &LO;
+  void setLangOptions(const LangOptions *LO) {
+    LangOpts = LO;
   }
   
   void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM);
index e9e5c3744a9c74a411396cbd89af2d9a7d0e6ab1..81d1e397904b4ec5a3b0e58b8f212f8aeb37b271 100644 (file)
@@ -2301,11 +2301,7 @@ int main(int argc, char **argv) {
     
     // Initialize language options, inferring file types from input filenames.
     LangOptions LangInfo;
-    
-    if (!VerifyDiagnostics)
-      static_cast<TextDiagnosticPrinter*>(TextDiagClient)
-        ->SetLangOpts(LangInfo);
-
+    TextDiagClient->setLangOptions(&LangInfo);
     
     InitializeBaseLanguage();
     LangKind LK = GetLanguage(InFile);
@@ -2346,7 +2342,8 @@ int main(int argc, char **argv) {
     // Process the source file.
     ProcessInputFile(*PP, PPFactory, InFile, ProgAction);
     
-    HeaderInfo.ClearFileInfo();      
+    HeaderInfo.ClearFileInfo();
+    TextDiagClient->setLangOptions(0);
   }
 
   if (Verbose)