]> granicus.if.org Git - clang/commitdiff
Change the diagnostics interface to take an array of pointers to
authorChris Lattner <sabre@nondot.org>
Tue, 18 Nov 2008 04:56:44 +0000 (04:56 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 18 Nov 2008 04:56:44 +0000 (04:56 +0000)
strings instead of array of strings.  This reduces string copying
in some not-very-important cases, but paves the way for future
improvements.

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

14 files changed:
include/clang/Analysis/PathDiagnostic.h
include/clang/Analysis/PathSensitive/BugReporter.h
include/clang/Basic/Diagnostic.h
include/clang/Driver/TextDiagnosticBuffer.h
include/clang/Driver/TextDiagnosticPrinter.h
lib/Analysis/PathDiagnostic.cpp
lib/Basic/Diagnostic.cpp
lib/CodeGen/CodeGenModule.cpp
lib/Driver/TextDiagnosticBuffer.cpp
lib/Driver/TextDiagnosticPrinter.cpp
lib/Lex/Preprocessor.cpp
lib/Parse/DeclSpec.cpp
lib/Parse/Parser.cpp
lib/Sema/Sema.cpp

index e266ee8518ff0112f18c72b92c53d6cd079370d8..6183a7c3a68af1225b2e20a01054dd7b0a52831d 100644 (file)
@@ -201,7 +201,7 @@ public:
                                 Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
                                 diag::kind ID,
-                                const std::string *Strs,
+                                const std::string **Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges);
index 9d39c9cb9f76b792ae7d5220cd63535d53815c3c..6ab2a4e713d25600ccae3391a02df5ef7b67f2c4 100644 (file)
@@ -307,7 +307,7 @@ public:
                                 Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
                                 diag::kind ID,
-                                const std::string *Strs,
+                                const std::string **Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges) {
@@ -322,7 +322,7 @@ public:
       R.addRange(*Ranges);
     
     for ( ; NumStrs ; --NumStrs, ++Strs)
-      R.addString(*Strs);    
+      R.addString(**Strs);    
   }
   
   // Iterators.
index 8b0637f59ee2d9afd73bcd01eee7b191f2b83df4..41a87434b0c5ca2cac7938fc7211eac0912487ea 100644 (file)
@@ -165,7 +165,7 @@ public:
   /// Report - Issue the message to the client.  DiagID is a member of the
   /// diag::kind enum.  
   void Report(FullSourceLoc Pos, unsigned DiagID,
-              const std::string *Strs = 0, unsigned NumStrs = 0,
+              const std::string **Strs = 0, unsigned NumStrs = 0,
               const SourceRange *Ranges = 0, unsigned NumRanges = 0) {
     Report(NULL, Pos, DiagID, Strs, NumStrs, Ranges, NumRanges);
   }                                                                      
@@ -173,7 +173,7 @@ public:
   /// Report - Issue the message to the client.  DiagID is a member of the
   /// diag::kind enum.  
   void Report(unsigned DiagID,
-              const std::string *Strs = 0, unsigned NumStrs = 0,
+              const std::string **Strs = 0, unsigned NumStrs = 0,
               const SourceRange *Ranges = 0, unsigned NumRanges = 0) {
     Report(FullSourceLoc(), DiagID, Strs, NumStrs, Ranges, NumRanges);
   }
@@ -181,7 +181,7 @@ public:
   /// Report - Issue the message to the specified client. 
   ///  DiagID is a member of the diag::kind enum.
   void Report(DiagnosticClient* C, FullSourceLoc Pos, unsigned DiagID,
-              const std::string *Strs = 0, unsigned NumStrs = 0,
+              const std::string **Strs = 0, unsigned NumStrs = 0,
               const SourceRange *Ranges = 0, unsigned NumRanges = 0);
 };
 
@@ -191,8 +191,7 @@ class DiagnosticClient {
 protected:
   std::string FormatDiagnostic(Diagnostic &Diags, Diagnostic::Level Level,
                                diag::kind ID,
-                               const std::string *Strs,
-                               unsigned NumStrs);
+                               const std::string **Strs, unsigned NumStrs);
 public:
   virtual ~DiagnosticClient();
 
@@ -202,7 +201,7 @@ public:
                                 Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
                                 diag::kind ID,
-                                const std::string *Strs,
+                                const std::string **Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges) = 0;
index 28f2287c675afaa67a5fb56dc38b5a5446298379..9933308368b166253f3595dd348a0793c6ef41b0 100644 (file)
@@ -43,7 +43,7 @@ public:
                                 Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
                                 diag::kind ID,
-                                const std::string *Strs,
+                                const std::string **Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges);
index 1d609ced4d1014d4fd168b1f290a14841f27a05a..7c6bce58bbb13e88b06cb99ca1dfadacc8786a1b 100644 (file)
@@ -45,7 +45,7 @@ public:
                                 Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
                                 diag::kind ID,
-                                const std::string *Strs,
+                                const std::string **Strs,
                                 unsigned NumStrs,
                                 const SourceRange *Ranges, 
                                 unsigned NumRanges);
index 971e751b8dc3539712f5c9628ccd93bce21b69e3..02cfe1e341b8ce0660cf8051aa70d8a6b28ea770 100644 (file)
@@ -24,7 +24,7 @@ void PathDiagnosticClient::HandleDiagnostic(Diagnostic &Diags,
                                             Diagnostic::Level DiagLevel,
                                             FullSourceLoc Pos,
                                             diag::kind ID,
-                                            const std::string *Strs,
+                                            const std::string **Strs,
                                             unsigned NumStrs,
                                             const SourceRange *Ranges, 
                                             unsigned NumRanges) {
index 533a6a76ecd2bde5cc07d1ec6cd39c2ceee1a2c3..2076b16db08ad2aafd1a634a2b345aa5084be3c5 100644 (file)
@@ -214,7 +214,7 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
 ///  DiagID is a member of the diag::kind enum.  
 void Diagnostic::Report(DiagnosticClient* C,
                         FullSourceLoc Loc, unsigned DiagID,
-                        const std::string *Strs, unsigned NumStrs,
+                        const std::string **Strs, unsigned NumStrs,
                         const SourceRange *Ranges, unsigned NumRanges) {
   
   // Figure out the diagnostic level of this message.
@@ -260,7 +260,7 @@ DiagnosticClient::~DiagnosticClient() {}
 std::string DiagnosticClient::FormatDiagnostic(Diagnostic &Diags,
                                                Diagnostic::Level Level,
                                                diag::kind ID,
-                                               const std::string *Strs,
+                                               const std::string **Strs,
                                                unsigned NumStrs) {
   std::string Msg = Diags.getDescription(ID);
   
@@ -269,7 +269,7 @@ std::string DiagnosticClient::FormatDiagnostic(Diagnostic &Diags,
     if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
       unsigned StrNo = Msg[i + 1] - '0';
       Msg = std::string(Msg.begin(), Msg.begin() + i) +
-            (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
+            (StrNo < NumStrs ? *Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
             std::string(Msg.begin() + i + 2, Msg.end());
     }
   }
index a101e389b28c732f4bcb661b39adee252b932535..d7d732997b603a61568c292e2ead614d753d0987 100644 (file)
@@ -108,8 +108,9 @@ void CodeGenModule::ErrorUnsupported(const Stmt *S, const char *Type,
                                                "cannot codegen this %0 yet");
   SourceRange Range = S->getSourceRange();
   std::string Msg = Type;
+  const std::string *Strs[] = { &Msg };
   getDiags().Report(Context.getFullLoc(S->getLocStart()), DiagID,
-                    &Msg, 1, &Range, 1);
+                    Strs, 1, &Range, 1);
 }
 
 /// ErrorUnsupported - Print out an error that codegen doesn't support the
@@ -121,8 +122,8 @@ void CodeGenModule::ErrorUnsupported(const Decl *D, const char *Type,
   unsigned DiagID = getDiags().getCustomDiagID(Diagnostic::Error, 
                                                "cannot codegen this %0 yet");
   std::string Msg = Type;
-  getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID,
-                    &Msg, 1);
+  const std::string *Strs[] = { &Msg };
+  getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID, Strs, 1);
 }
 
 /// setGlobalVisibility - Set the visibility for the given LLVM
index 26ac879dd04a64772ca51fb7bb34c711dbad3884..ef7ac6d408c29feec809ebc9b10a46e978d949fe 100644 (file)
@@ -21,7 +21,7 @@ void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic &Diags,
                                             Diagnostic::Level Level,
                                             FullSourceLoc Pos,
                                             diag::kind ID,
-                                            const std::string *Strs,
+                                            const std::string **Strs,
                                             unsigned NumStrs,
                                             const SourceRange *,
                                             unsigned) {
index e0faf478d1a5bc15892279dd8d7c90eec8f32ce2..e03588b98996a7139ea00d20cf1f584f61d47e76 100644 (file)
@@ -96,7 +96,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
                                              Diagnostic::Level Level, 
                                              FullSourceLoc Pos,
                                              diag::kind ID,
-                                             const std::string *Strs,
+                                             const std::string **Strs,
                                              unsigned NumStrs,
                                              const SourceRange *Ranges,
                                              unsigned NumRanges) {
index c65b5462098987f71926ff1522b61df485e3cb3c..dc4dd877b67390451f4fe88a7d72977ccf479514 100644 (file)
@@ -124,14 +124,16 @@ void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
 
 void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID, 
                         const std::string &Msg) {
-  Diags.Report(getFullLoc(Loc), DiagID, &Msg, 1);
+  const std::string *Strs[] = { &Msg };
+  Diags.Report(getFullLoc(Loc), DiagID, Strs, 1);
 }
 
 void Preprocessor::Diag(SourceLocation Loc, unsigned DiagID,
                         const std::string &Msg,
                         const SourceRange &R1, const SourceRange &R2) {
+  const std::string *Strs[] = { &Msg };
   SourceRange R[] = {R1, R2};
-  Diags.Report(getFullLoc(Loc), DiagID, &Msg, 1, R, 2);
+  Diags.Report(getFullLoc(Loc), DiagID, Strs, 1, R, 2);
 }
 
 
index e80076127d847696acc8481c5f24185299e81470..733c37cb4f99d83c0c443e47a0ed2d495e18f1ea 100644 (file)
@@ -311,6 +311,7 @@ void DeclSpec::Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr,
 }
   
 void DeclSpec::Diag(Diagnostic &D, SourceLocation Loc, SourceManager& SrcMgr,
-          unsigned DiagID, const std::string &info) {
-  D.Report(FullSourceLoc(Loc,SrcMgr), DiagID, &info, 1);
+          unsigned DiagID, const std::string &Info) {
+  const std::string *Strs[] = { &Info };
+  D.Report(FullSourceLoc(Loc,SrcMgr), DiagID, Strs, 1);
 }
index 3b36ebec7b954db465a1670f7a5905a3b7d1a15a..dfabc9b16a50f08cb88937d6db53b1e7ef1ca6e9 100644 (file)
@@ -43,13 +43,15 @@ Action::~Action() {}
 
 bool Parser::Diag(SourceLocation Loc, unsigned DiagID,
                   const std::string &Msg) {
-  Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID, &Msg, 1);
+  const std::string *Strs[] = { &Msg };
+  Diags.Report(FullSourceLoc(Loc,PP.getSourceManager()), DiagID, Strs, 1);
   return true;
 }
 
 bool Parser::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
                   const SourceRange& Range) {
-  Diags.Report(PP.getFullLoc(Loc), DiagID, &Msg, 1, &Range,1);
+  const std::string *Strs[] = { &Msg };
+  Diags.Report(PP.getFullLoc(Loc), DiagID, Strs, 1, &Range,1);
   return true;
 }
 
index 649594952691c7922fdb05157447d6c46abd9d02..5ea27c979b14d0ce606f8d733d51526cf3040b40 100644 (file)
@@ -176,13 +176,14 @@ bool Sema::Diag(SourceLocation Loc, unsigned DiagID) {
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg) {
-  PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID,  &Msg, 1);
+  const std::string *Strs[] = { &Msg };
+  PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, Strs, 1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
                 const std::string &Msg2) {
-  std::string MsgArr[] = { Msg1, Msg2 };
+  const std::string *MsgArr[] = { &Msg1, &Msg2 };
   PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID,  MsgArr, 2);
   return true;
 }
@@ -194,21 +195,22 @@ bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const SourceRange& Range) {
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
                 const SourceRange& Range) {
-  PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, &Msg, 1, &Range,1);
+  const std::string *Strs[] = { &Msg };
+  PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, Strs, 1, &Range,1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
                 const std::string &Msg2, const SourceRange& Range) {
-  std::string MsgArr[] = { Msg1, Msg2 };
+  const std::string *MsgArr[] = { &Msg1, &Msg2 };
   PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 2, &Range, 1);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1, 
                 const std::string &Msg2, const std::string &Msg3, 
-                const SourceRangeR1) {
-  std::string MsgArr[] = { Msg1, Msg2, Msg3 };
+                const SourceRange &R1) {
+  const std::string *MsgArr[] = { &Msg1, &Msg2, &Msg3 };
   PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, MsgArr, 3, &R1, 1);
   return true;
 }
@@ -223,14 +225,15 @@ bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
 bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
                 const SourceRange& R1, const SourceRange& R2) {
   SourceRange RangeArr[] = { R1, R2 };
-  PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID,  &Msg, 1, RangeArr, 2);
+  const std::string *Strs[] = { &Msg };
+  PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID, Strs, 1, RangeArr, 2);
   return true;
 }
 
 bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1,
                 const std::string &Msg2, const SourceRange& R1,
                 const SourceRange& R2) {
-  std::string MsgArr[] = { Msg1, Msg2 };
+  const std::string *MsgArr[] = { &Msg1, &Msg2 };
   SourceRange RangeArr[] = { R1, R2 };
   PP.getDiagnostics().Report(PP.getFullLoc(Range),DiagID, MsgArr,2,RangeArr, 2);
   return true;