[cfe-commits] r44878 - in /cfe/trunk: Analysis/ Basic/ CodeGen/ Driver/ Lex/ Parse/ Sema/ include/clang/AST/ include/clang/Basic/ include/clang/Parse/

Ted Kremenek kremenek at apple.com
Tue Dec 11 13:27:58 PST 2007


Author: kremenek
Date: Tue Dec 11 15:27:55 2007
New Revision: 44878

URL: http://llvm.org/viewvc/llvm-project?rev=44878&view=rev
Log:
Mega-patch: ripped SourceManager out of Diagnostic/DiagnosticClient.  Now
SourceManager is passed by reference, allowing the SourceManager to be
associated with a specific translation unit, and not the entire execution
of the driver.

Modified all users of Diagnostics to comply with this new interface.

Integrated SourceManager as a member variable of TargetInfo. TargetInfo will
eventually be associated with a single translation unit (just like
SourceManager).

Made the SourceManager reference in ASTContext private. Provided accessor
getSourceManager() for clients to use instead. Modified clients to comply with
new interface.

Modified:
    cfe/trunk/Analysis/DeadStores.cpp
    cfe/trunk/Analysis/UninitializedValues.cpp
    cfe/trunk/Basic/Diagnostic.cpp
    cfe/trunk/Basic/TargetInfo.cpp
    cfe/trunk/CodeGen/CGExprComplex.cpp
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/CodeGen/CodeGenModule.cpp
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/Driver/Targets.cpp
    cfe/trunk/Driver/TextDiagnosticBuffer.cpp
    cfe/trunk/Driver/TextDiagnosticBuffer.h
    cfe/trunk/Driver/TextDiagnosticPrinter.cpp
    cfe/trunk/Driver/TextDiagnosticPrinter.h
    cfe/trunk/Driver/TextDiagnostics.cpp
    cfe/trunk/Driver/TextDiagnostics.h
    cfe/trunk/Driver/TranslationUnit.cpp
    cfe/trunk/Driver/clang.cpp
    cfe/trunk/Driver/clang.h
    cfe/trunk/Lex/Preprocessor.cpp
    cfe/trunk/Parse/DeclSpec.cpp
    cfe/trunk/Parse/ParseDecl.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/Sema/Sema.cpp
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/include/clang/Parse/DeclSpec.h

Modified: cfe/trunk/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/DeadStores.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/Analysis/DeadStores.cpp Tue Dec 11 15:27:55 2007
@@ -41,7 +41,7 @@
           if (VD->hasLocalStorage() && !Live(VD,AD)) {
             SourceRange R = B->getRHS()->getSourceRange();
             Diags.Report(DR->getSourceRange().getBegin(), diag::warn_dead_store,
-                         0, 0, &R, 1);                                                                        
+                         Ctx.getSourceManager(), 0, 0, &R, 1);                                                                        
         }
     }
     else if(DeclStmt* DS = dyn_cast<DeclStmt>(S))
@@ -62,8 +62,8 @@
               if (!E->isConstantExpr(Ctx,NULL)) {
                 // Flag a warning.
                 SourceRange R = E->getSourceRange();
-                Diags.Report(V->getLocation(), diag::warn_dead_store, 0, 0,
-                             &R,1);
+                Diags.Report(V->getLocation(), diag::warn_dead_store,
+                             Ctx.getSourceManager(), 0, 0, &R, 1);
               }
             }
           }

Modified: cfe/trunk/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UninitializedValues.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/Analysis/UninitializedValues.cpp Tue Dec 11 15:27:55 2007
@@ -222,7 +222,8 @@
     
     if (V(VD,AD) == Uninitialized)
       if (AlreadyWarned.insert(VD))
-        Diags.Report(DR->getSourceRange().getBegin(), diag::warn_uninit_val);
+        Diags.Report(DR->getSourceRange().getBegin(), diag::warn_uninit_val,
+                     Ctx.getSourceManager());
   }
 };
 } // end anonymous namespace

Modified: cfe/trunk/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/Diagnostic.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/Basic/Diagnostic.cpp Tue Dec 11 15:27:55 2007
@@ -198,6 +198,7 @@
 /// compilation, return true, otherwise return false.  DiagID is a member of
 /// the diag::kind enum.  
 void Diagnostic::Report(SourceLocation Pos, unsigned DiagID,
+                        SourceManager& SrcMgr,
                         const std::string *Strs, unsigned NumStrs,
                         const SourceRange *Ranges, unsigned NumRanges) {
   // Figure out the diagnostic level of this message.
@@ -213,11 +214,11 @@
   }
 
   // Are we going to ignore this diagnosic?
-  if (Client.IgnoreDiagnostic(DiagLevel, Pos))
+  if (Client.IgnoreDiagnostic(DiagLevel, Pos, SrcMgr))
     return;
 
   // Finally, report it.
-  Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID,
+  Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID, SrcMgr,
                           Strs, NumStrs, Ranges, NumRanges);
   ++NumDiagnostics;
 }

Modified: cfe/trunk/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/TargetInfo.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/Basic/TargetInfo.cpp Tue Dec 11 15:27:55 2007
@@ -65,7 +65,7 @@
 /// non-portable.
 void TargetInfo::DiagnoseNonPortability(SourceLocation Loc, unsigned DiagKind) {
   NonPortable = true;
-  if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind);
+  if (Diag && Loc.isValid()) Diag->Report(Loc, DiagKind, SrcMgr);
 }
 
 /// GetTargetDefineMap - Get the set of target #defines in an associative

Modified: cfe/trunk/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprComplex.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/CodeGen/CGExprComplex.cpp Tue Dec 11 15:27:55 2007
@@ -67,7 +67,7 @@
   //===--------------------------------------------------------------------===//
 
   ComplexPairTy VisitStmt(Stmt *S) {
-    S->dump(CGF.getContext().SourceMgr);
+    S->dump(CGF.getContext().getSourceManager());
     assert(0 && "Stmt can't have complex result type!");
     return ComplexPairTy();
   }

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Tue Dec 11 15:27:55 2007
@@ -85,7 +85,7 @@
   //===--------------------------------------------------------------------===//
 
   Value *VisitStmt(Stmt *S) {
-    S->dump(CGF.getContext().SourceMgr);
+    S->dump(CGF.getContext().getSourceManager());
     assert(0 && "Stmt can't have complex result type!");
     return 0;
   }

Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Tue Dec 11 15:27:55 2007
@@ -40,7 +40,8 @@
                                                "cannot codegen this %0 yet");
   SourceRange Range = S->getSourceRange();
   std::string Msg = Type;
-  getDiags().Report(S->getLocStart(), DiagID, &Msg, 1, &Range, 1);
+  getDiags().Report(S->getLocStart(), DiagID, Context.getSourceManager(),
+                    &Msg, 1, &Range, 1);
 }
 
 /// ReplaceMapValuesWith - This is a really slow and bad function that

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Tue Dec 11 15:27:55 2007
@@ -356,7 +356,7 @@
     ASTDumper() : DeclPrinter() {}
     
     void Initialize(ASTContext &Context, unsigned MainFileID) {
-      SM = &Context.SourceMgr;
+      SM = &Context.getSourceManager();
     }
     
     virtual void HandleTopLevelDecl(Decl *D) {
@@ -400,7 +400,7 @@
     SourceManager *SM;
   public:
     void Initialize(ASTContext &Context, unsigned MainFileID) {
-      SM = &Context.SourceMgr;
+      SM = &Context.getSourceManager();
     }
     
     virtual void HandleTopLevelDecl(Decl *D) {
@@ -482,7 +482,7 @@
     SourceManager *SM;
   public:
     virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
-      SM = &Context.SourceMgr;
+      SM = &Context.getSourceManager();
     }
 
     virtual void VisitCFG(CFG& C) {

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Dec 11 15:27:55 2007
@@ -64,7 +64,7 @@
   public:
     void Initialize(ASTContext &context, unsigned mainFileID) {
       Context = &context;
-      SM = &Context->SourceMgr;
+      SM = &Context->getSourceManager();
       MsgSendFunctionDecl = 0;
       MsgSendSuperFunctionDecl = 0;
       MsgSendStretFunctionDecl = 0;
@@ -87,7 +87,7 @@
       MainFileEnd = MainBuf->getBufferEnd();
       
       
-      Rewrite.setSourceMgr(Context->SourceMgr);
+      Rewrite.setSourceMgr(Context->getSourceManager());
       // declaring objc_selector outside the parameter list removes a silly
       // scope related warning...
       const char *s = "struct objc_selector; struct objc_class;\n"
@@ -917,7 +917,8 @@
     unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error, 
                      "rewriter could not replace sub-expression due to macros");
     SourceRange Range = Exp->getSourceRange();
-    Diags.Report(Exp->getAtLoc(), DiagID, 0, 0, &Range, 1);
+    Diags.Report(Exp->getAtLoc(), DiagID, Context->getSourceManager(),
+                 0, 0, &Range, 1);
     delete Replacement;
     return Exp;
   }

Modified: cfe/trunk/Driver/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/Targets.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/Targets.cpp (original)
+++ cfe/trunk/Driver/Targets.cpp Tue Dec 11 15:27:55 2007
@@ -702,7 +702,8 @@
 
 /// CreateTargetInfo - Return the set of target info objects as specified by
 /// the -arch command line option.
-TargetInfo *clang::CreateTargetInfo(const std::vector<std::string>& triples, 
+TargetInfo *clang::CreateTargetInfo(SourceManager& SrcMgr,
+                                    const std::vector<std::string>& triples, 
                                     Diagnostic *Diags) {
 
   assert (!triples.empty() && "No target triple.");
@@ -713,7 +714,7 @@
   if (!PrimaryTarget)
     return NULL;
   
-  TargetInfo *TI = new TargetInfo(PrimaryTarget, Diags);
+  TargetInfo *TI = new TargetInfo(SrcMgr, PrimaryTarget, Diags);
   
   // Add all secondary targets.
   for (unsigned i = 1, e = triples.size(); i != e; ++i) {

Modified: cfe/trunk/Driver/TextDiagnosticBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticBuffer.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticBuffer.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticBuffer.cpp Tue Dec 11 15:27:55 2007
@@ -21,6 +21,7 @@
                                             Diagnostic::Level Level,
                                             SourceLocation Pos,
                                             diag::kind ID,
+                                            SourceManager& SrcMgr,
                                             const std::string *Strs,
                                             unsigned NumStrs,
                                             const SourceRange *,

Modified: cfe/trunk/Driver/TextDiagnosticBuffer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticBuffer.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticBuffer.h (original)
+++ cfe/trunk/Driver/TextDiagnosticBuffer.h Tue Dec 11 15:27:55 2007
@@ -30,7 +30,7 @@
 private:
   DiagList Errors, Warnings;
 public:
-  TextDiagnosticBuffer(SourceManager &SM) : TextDiagnostics(SM) {}
+  TextDiagnosticBuffer() {}
 
   const_iterator err_begin() const  { return Errors.begin(); }
   const_iterator err_end() const    { return Errors.end(); }
@@ -40,7 +40,9 @@
 
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
-                                diag::kind ID, const std::string *Strs,
+                                diag::kind ID,
+                                SourceManager& SrcMgr,
+                                const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges);

Modified: cfe/trunk/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Tue Dec 11 15:27:55 2007
@@ -31,13 +31,13 @@
                                   " diagnostics"));
 
 void TextDiagnosticPrinter::
-PrintIncludeStack(SourceLocation Pos) {
+PrintIncludeStack(SourceLocation Pos, SourceManager& SourceMgr) {
   if (Pos.isInvalid()) return;
 
   Pos = SourceMgr.getLogicalLoc(Pos);
 
   // Print out the other include frames first.
-  PrintIncludeStack(SourceMgr.getIncludeLoc(Pos));
+  PrintIncludeStack(SourceMgr.getIncludeLoc(Pos),SourceMgr);
   unsigned LineNo = SourceMgr.getLineNumber(Pos);
   
   std::cerr << "In file included from " << SourceMgr.getSourceName(Pos)
@@ -46,7 +46,8 @@
 
 /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
 /// any characters in LineNo that intersect the SourceRange.
-void TextDiagnosticPrinter::HighlightRange(const SourceRange &R, 
+void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
+                                           SourceManager& SourceMgr,
                                            unsigned LineNo,
                                            std::string &CaratLine,
                                            const std::string &SourceLine) {
@@ -101,6 +102,7 @@
                                              Diagnostic::Level Level, 
                                              SourceLocation Pos,
                                              diag::kind ID,
+                                             SourceManager& SourceMgr,
                                              const std::string *Strs,
                                              unsigned NumStrs,
                                              const SourceRange *Ranges,
@@ -116,7 +118,7 @@
     // "included from" lines.
     if (LastWarningLoc != SourceMgr.getIncludeLoc(LPos)) {
       LastWarningLoc = SourceMgr.getIncludeLoc(LPos);
-      PrintIncludeStack(LastWarningLoc);
+      PrintIncludeStack(LastWarningLoc,SourceMgr);
     }
   
     // Compute the column number.  Rewind from the current position to the start
@@ -162,7 +164,7 @@
     
     // Highlight all of the characters covered by Ranges with ~ characters.
     for (unsigned i = 0; i != NumRanges; ++i)
-      HighlightRange(Ranges[i], LineNo, CaratLine, SourceLine);
+      HighlightRange(Ranges[i], SourceMgr, LineNo, CaratLine, SourceLine);
     
     // Next, insert the carat itself.
     if (ColNo-1 < CaratLine.size())

Modified: cfe/trunk/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.h Tue Dec 11 15:27:55 2007
@@ -24,17 +24,20 @@
 class TextDiagnosticPrinter : public TextDiagnostics {
   SourceLocation LastWarningLoc;
 public:
-  TextDiagnosticPrinter(SourceManager &sourceMgr)
-    : TextDiagnostics(sourceMgr) {}
+  TextDiagnosticPrinter() {}
 
-  void PrintIncludeStack(SourceLocation Pos);
-  void HighlightRange(const SourceRange &R, unsigned LineNo,
+  void PrintIncludeStack(SourceLocation Pos, SourceManager& SrcMgr);
+  void HighlightRange(const SourceRange &R,
+                      SourceManager& SrcMgr,
+                      unsigned LineNo,
                       std::string &CaratLine,
                       const std::string &SourceLine);
 
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
-                                diag::kind ID, const std::string *Strs,
+                                diag::kind ID,
+                                SourceManager& SrcMgr,
+                                const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges);

Modified: cfe/trunk/Driver/TextDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.cpp (original)
+++ cfe/trunk/Driver/TextDiagnostics.cpp Tue Dec 11 15:27:55 2007
@@ -40,7 +40,8 @@
 }
 
 bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
-                                       SourceLocation Pos) {
+                                       SourceLocation Pos,
+                                       SourceManager& SourceMgr) {
   if (Pos.isValid()) {
     // If this is a warning or note, and if it a system header, suppress the
     // diagnostic.

Modified: cfe/trunk/Driver/TextDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.h (original)
+++ cfe/trunk/Driver/TextDiagnostics.h Tue Dec 11 15:27:55 2007
@@ -24,23 +24,25 @@
 class TextDiagnostics : public DiagnosticClient {
   HeaderSearch *TheHeaderSearch;
 protected:
-  SourceManager &SourceMgr;
-
   std::string FormatDiagnostic(Diagnostic &Diags, Diagnostic::Level Level,
                                diag::kind ID,
                                const std::string *Strs,
                                unsigned NumStrs);
 public:
-  TextDiagnostics(SourceManager &sourceMgr) : SourceMgr(sourceMgr) {}
+  TextDiagnostics() {}
   virtual ~TextDiagnostics();
 
   void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
 
   virtual bool IgnoreDiagnostic(Diagnostic::Level Level, 
-                                SourceLocation Pos);
+                                SourceLocation Pos,
+                                SourceManager& SrcMgr);
+
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 SourceLocation Pos,
-                                diag::kind ID, const std::string *Strs,
+                                diag::kind ID,
+                                SourceManager& SrcMgr,
+                                const std::string *Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges) = 0;

Modified: cfe/trunk/Driver/TranslationUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TranslationUnit.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/TranslationUnit.cpp (original)
+++ cfe/trunk/Driver/TranslationUnit.cpp Tue Dec 11 15:27:55 2007
@@ -102,7 +102,7 @@
   Sezr.EnterBlock();
   
   // Emit the SourceManager.
-  Sezr.Emit(Context->SourceMgr);
+  Sezr.Emit(Context->getSourceManager());
   
   // Emit the LangOptions.
   Sezr.Emit(LangOpts);
@@ -184,7 +184,7 @@
   assert (FoundBlock);
 
   // Read the SourceManager.
-  SourceManager::CreateAndRegister(Dezr,FMgr);
+  SourceManager& SrcMgr = *SourceManager::CreateAndRegister(Dezr,FMgr);
   
   // Read the LangOptions.
   TU->LangOpts.Read(Dezr);
@@ -196,7 +196,7 @@
     std::vector<std::string> triples;
     triples.push_back(triple);
     delete [] triple;
-    Dezr.RegisterPtr(PtrID,CreateTargetInfo(triples,NULL));
+    Dezr.RegisterPtr(PtrID,CreateTargetInfo(SrcMgr,triples,NULL));
   }
   
   // For Selectors, we must read the identifier table first because the

Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Tue Dec 11 15:27:55 2007
@@ -989,10 +989,10 @@
   std::auto_ptr<TextDiagnostics> DiagClient;
   if (!VerifyDiagnostics) {
     // Print diagnostics to stderr by default.
-    DiagClient.reset(new TextDiagnosticPrinter(SourceMgr));
+    DiagClient.reset(new TextDiagnosticPrinter());
   } else {
     // When checking diagnostics, just buffer them up.
-    DiagClient.reset(new TextDiagnosticBuffer(SourceMgr));
+    DiagClient.reset(new TextDiagnosticBuffer());
    
     if (InputFilenames.size() != 1) {
       fprintf(stderr,
@@ -1013,7 +1013,7 @@
   { // Create triples, and create the TargetInfo.
     std::vector<std::string> triples;
     CreateTargetTriples(triples);
-    Target = CreateTargetInfo(triples,&Diags);
+    Target = CreateTargetInfo(SourceMgr,triples,&Diags);
   
     if (Target == 0) {
       fprintf(stderr, "Sorry, I don't know what target this is: %s\n",
@@ -1026,7 +1026,9 @@
   // -I- is a deprecated GCC feature, scan for it and reject it.
   for (unsigned i = 0, e = I_dirs.size(); i != e; ++i) {
     if (I_dirs[i] == "-") {
-      Diags.Report(SourceLocation(), diag::err_pp_I_dash_not_supported);
+      Diags.Report(SourceLocation(), diag::err_pp_I_dash_not_supported,
+                   SourceMgr);
+      
       I_dirs.erase(I_dirs.begin()+i);
       --i;
     }

Modified: cfe/trunk/Driver/clang.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Driver/clang.h (original)
+++ cfe/trunk/Driver/clang.h Tue Dec 11 15:27:55 2007
@@ -25,6 +25,7 @@
 class Diagnostic;
 class ASTConsumer;
 class IdentifierTable;
+class SourceManager;
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP,
@@ -36,7 +37,8 @@
 
 /// CreateTargetInfo - Return the set of target info objects as specified by
 /// the -arch command line option.
-TargetInfo *CreateTargetInfo(const std::vector<std::string>& triples,
+TargetInfo *CreateTargetInfo(SourceManager& SrcMgr,
+                             const std::vector<std::string>& triples,
                              Diagnostic *Diags);
 
 /// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C.

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

==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Tue Dec 11 15:27:55 2007
@@ -120,12 +120,12 @@
 /// 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(Loc, DiagID);
+  Diags.Report(Loc, DiagID, SourceMgr);
 }
 
 void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID, 
                         const std::string &Msg) {
-  Diags.Report(Loc, DiagID, &Msg, 1);
+  Diags.Report(Loc, DiagID, SourceMgr, &Msg, 1);
 }
 
 void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const {

Modified: cfe/trunk/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/DeclSpec.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Parse/DeclSpec.cpp (original)
+++ cfe/trunk/Parse/DeclSpec.cpp Tue Dec 11 15:27:55 2007
@@ -209,7 +209,8 @@
 /// "_Imaginary" (lacking an FP type).  This returns a diagnostic to issue or
 /// diag::NUM_DIAGNOSTICS if there is no error.  After calling this method,
 /// DeclSpec is guaranteed self-consistent, even if an error occurred.
-void DeclSpec::Finish(Diagnostic &D, const LangOptions &Lang) {
+void DeclSpec::Finish(Diagnostic &D, SourceManager& SrcMgr, 
+                      const LangOptions &Lang) {
   // Check the type specifier components first.
 
   // signed/unsigned are only valid with int/char.
@@ -217,7 +218,7 @@
     if (TypeSpecType == TST_unspecified)
       TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int.
     else if (TypeSpecType != TST_int && TypeSpecType != TST_char) {
-      Diag(D, TSSLoc, diag::err_invalid_sign_spec,
+      Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec,
            getSpecifierName( (TST)TypeSpecType));
       // signed double -> double.
       TypeSpecSign = TSS_unspecified;
@@ -232,7 +233,7 @@
     if (TypeSpecType == TST_unspecified)
       TypeSpecType = TST_int; // short -> short int, long long -> long long int.
     else if (TypeSpecType != TST_int) {
-      Diag(D, TSWLoc,
+      Diag(D, TSWLoc, SrcMgr,
            TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec
                                       : diag::err_invalid_longlong_spec,
            getSpecifierName( (TST)TypeSpecType));
@@ -243,7 +244,7 @@
     if (TypeSpecType == TST_unspecified)
       TypeSpecType = TST_int;  // long -> long int.
     else if (TypeSpecType != TST_int && TypeSpecType != TST_double) {
-      Diag(D, TSWLoc, diag::err_invalid_long_spec,
+      Diag(D, TSWLoc, SrcMgr, diag::err_invalid_long_spec,
            getSpecifierName( (TST)TypeSpecType));
       TypeSpecType = TST_int;
     }
@@ -254,13 +255,13 @@
   // disallow their use.  Need information about the backend.
   if (TypeSpecComplex != TSC_unspecified) {
     if (TypeSpecType == TST_unspecified) {
-      Diag(D, TSCLoc, diag::ext_plain_complex);
+      Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex);
       TypeSpecType = TST_double;   // _Complex -> _Complex double.
     } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
       // Note that this intentionally doesn't include _Complex _Bool.
-      Diag(D, TSTLoc, diag::ext_integer_complex);
+      Diag(D, TSTLoc, SrcMgr, diag::ext_integer_complex);
     } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) {
-      Diag(D, TSCLoc, diag::err_invalid_complex_spec, 
+      Diag(D, TSCLoc, SrcMgr, diag::err_invalid_complex_spec, 
            getSpecifierName( (TST)TypeSpecType));
       TypeSpecComplex = TSC_unspecified;
     }
@@ -272,7 +273,7 @@
       StorageClassSpec = SCS_extern; // '__thread int' -> 'extern __thread int'
     } else if (StorageClassSpec != SCS_extern &&
                StorageClassSpec != SCS_static) {
-      Diag(D, getStorageClassSpecLoc(), diag::err_invalid_thread_spec,
+      Diag(D, getStorageClassSpecLoc(), SrcMgr, diag::err_invalid_thread_spec,
            getSpecifierName( (SCS)StorageClassSpec));
       SCS_thread_specified = false;
     }

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Tue Dec 11 15:27:55 2007
@@ -424,7 +424,7 @@
     default:
       // If this is not a declaration specifier token, we're done reading decl
       // specifiers.  First verify that DeclSpec's are consistent.
-      DS.Finish(Diags, getLang());
+      DS.Finish(Diags, PP.getSourceManager(), getLang());
       return;
     
     // GNU attributes support.
@@ -1037,7 +1037,7 @@
     default:
       // If this is not a type-qualifier token, we're done reading type
       // qualifiers.  First verify that DeclSpec's are consistent.
-      DS.Finish(Diags, getLang());
+      DS.Finish(Diags, PP.getSourceManager(), getLang());
       return;
     case tok::kw_const:
       isInvalid = DS.SetTypeQual(DeclSpec::TQ_const   , Loc, PrevSpec,

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Tue Dec 11 15:27:55 2007
@@ -31,7 +31,7 @@
 
 void Parser::Diag(SourceLocation Loc, unsigned DiagID,
                   const std::string &Msg) {
-  Diags.Report(Loc, DiagID, &Msg, 1);
+  Diags.Report(Loc, DiagID, PP.getSourceManager(), &Msg, 1);
 }
 
 /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'),

Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Tue Dec 11 15:27:55 2007
@@ -118,51 +118,54 @@
 //===----------------------------------------------------------------------===//
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
-  PP.getDiagnostics().Report(Loc, DiagID);
+  PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager());
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
-  PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1);
+  PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), &Msg, 1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
                 const std::string &Msg2) {
   std::string MsgArr[] = { Msg1, Msg2 };
-  PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2);
+  PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), MsgArr, 2);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, SourceRange Range) {
-  PP.getDiagnostics().Report(Loc, DiagID, 0, 0, &Range, 1);
+  PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), 0,0, &Range,1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
                 SourceRange Range) {
-  PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, &Range, 1);
+  PP.getDiagnostics().Report(Loc,DiagID,PP.getSourceManager(),&Msg,1,&Range,1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
                 const std::string &Msg2, SourceRange Range) {
   std::string MsgArr[] = { Msg1, Msg2 };
-  PP.getDiagnostics().Report(Loc, DiagID, MsgArr, 2, &Range, 1);
+  PP.getDiagnostics().Report(Loc,DiagID,PP.getSourceManager(),
+                             MsgArr,2,&Range,1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
                 SourceRange R1, SourceRange R2) {
   SourceRange RangeArr[] = { R1, R2 };
-  PP.getDiagnostics().Report(Loc, DiagID, 0, 0, RangeArr, 2);
+  PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(),
+                             0, 0, RangeArr, 2);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
                 SourceRange R1, SourceRange R2) {
   SourceRange RangeArr[] = { R1, R2 };
-  PP.getDiagnostics().Report(Loc, DiagID, &Msg, 1, RangeArr, 2);
+  PP.getDiagnostics().Report(Loc, DiagID, PP.getSourceManager(), &Msg,
+                             1, RangeArr, 2);
   return true;
 }
 
@@ -170,7 +173,8 @@
                 const std::string &Msg2, SourceRange R1, SourceRange R2) {
   std::string MsgArr[] = { Msg1, Msg2 };
   SourceRange RangeArr[] = { R1, R2 };
-  PP.getDiagnostics().Report(Range, DiagID, MsgArr, 2, RangeArr, 2);
+  PP.getDiagnostics().Report(Range, DiagID, PP.getSourceManager(), MsgArr, 2,
+                             RangeArr, 2);
   return true;
 }
 

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Dec 11 15:27:55 2007
@@ -69,13 +69,15 @@
   
   QualType ObjcConstantStringType;
   RecordDecl *CFConstantStringTypeDecl;
-public:
-  
+
   SourceManager &SourceMgr;
+public:
   TargetInfo &Target;
   IdentifierTable &Idents;
   SelectorTable &Selectors;
   
+  SourceManager& getSourceManager() { return SourceMgr; }
+  
   /// This is intentionally not serialized.  It is populated by the
   /// ASTContext ctor, and there are no external pointers/references to
   /// internal variables of BuiltinInfo.

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Tue Dec 11 15:27:55 2007
@@ -21,6 +21,7 @@
   class DiagnosticClient;
   class SourceLocation;
   class SourceRange;
+  class SourceManager;
   
   // Import the diagnostic enums themselves.
   namespace diag {
@@ -146,7 +147,7 @@
   
   /// Report - Issue the message to the client.  DiagID is a member of the
   /// diag::kind enum.  
-  void Report(SourceLocation Pos, unsigned DiagID,
+  void Report(SourceLocation Pos, unsigned DiagID, SourceManager& SrcMgr,
               const std::string *Strs = 0, unsigned NumStrs = 0,
               const SourceRange *Ranges = 0, unsigned NumRanges = 0);
 };
@@ -160,13 +161,15 @@
   /// IgnoreDiagnostic - If the client wants to ignore this diagnostic, then
   /// return true.
   virtual bool IgnoreDiagnostic(Diagnostic::Level DiagLevel,
-                                SourceLocation Pos) = 0;
+                                SourceLocation Pos,
+                                SourceManager& SrcMgr) = 0;
 
   /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
   /// capturing it to a log as needed.
   virtual void HandleDiagnostic(Diagnostic &Diags, 
                                 Diagnostic::Level DiagLevel, SourceLocation Pos,
-                                diag::kind ID, const std::string *Strs,
+                                diag::kind ID, SourceManager& SrcMgr,
+                                const std::string *Strs,
                                 unsigned NumStrs, const SourceRange *Ranges, 
                                 unsigned NumRanges) = 0;
 };

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Dec 11 15:27:55 2007
@@ -25,6 +25,8 @@
 
 class TargetInfoImpl;
 class Diagnostic;
+class SourceManager;
+  
 namespace Builtin { struct Info; }
   
 /// TargetInfo - This class exposes information about the current target set.
@@ -40,6 +42,9 @@
 /// diagnostic info, but does expect them to be alive for as long as it is.
 ///
 class TargetInfo {
+  /// SrcMgr - The SourceManager associated with this TargetInfo.
+  SourceManager& SrcMgr;
+  
   /// Primary - This tracks the primary target in the target set.
   ///
   const TargetInfoImpl *PrimaryTarget;
@@ -61,7 +66,8 @@
   unsigned WCharWidth, WCharAlign;
   
 public:
-  TargetInfo(const TargetInfoImpl *Primary, Diagnostic *D = 0) {
+  TargetInfo(SourceManager& SMgr, const TargetInfoImpl *Primary,
+             Diagnostic *D = 0) : SrcMgr(SMgr) {
     PrimaryTarget = Primary;
     Diag = D;
     NonPortable = false;

Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=44878&r1=44877&r2=44878&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Tue Dec 11 15:27:55 2007
@@ -24,8 +24,8 @@
   class IdentifierInfo;
   
 /// DeclSpec - This class captures information about "declaration specifiers",
-/// which encompasses storage-class-specifiers, type-specifiers, type-qualifiers,
-/// and function-specifiers.
+/// which encompasses storage-class-specifiers, type-specifiers,
+/// type-qualifiers, and function-specifiers.
 class DeclSpec {
 public:
   SourceRange Range;
@@ -266,15 +266,17 @@
   /// Finish - This does final analysis of the declspec, issuing diagnostics for
   /// things like "_Imaginary" (lacking an FP type).  After calling this method,
   /// DeclSpec is guaranteed self-consistent, even if an error occurred.
-  void Finish(Diagnostic &D, const LangOptions &Lang);
+  void Finish(Diagnostic &D, SourceManager& SrcMgr, const LangOptions &Lang);
   
 private:
-  void Diag(Diagnostic &D, SourceLocation Loc, unsigned DiagID) {
-    D.Report(Loc, DiagID);
+  void Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr, 
+            unsigned DiagID) {
+    D.Report(Loc, DiagID, SrcMgr);
   }
-  void Diag(Diagnostic &D, SourceLocation Loc, unsigned DiagID,
-            const std::string &info) {
-    D.Report(Loc, DiagID, &info, 1);
+  
+  void Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr,
+            unsigned DiagID, const std::string &info) {
+    D.Report(Loc, DiagID, SrcMgr, &info, 1);
   }
 };
 





More information about the cfe-commits mailing list