diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-18 04:56:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-18 04:56:44 +0000 |
commit | 2383b7f6aea2cb2bf2b5bfc0ec730f9354fecbbf (patch) | |
tree | 13bdae5f244e4365dc659a6d5c94e84e910b626f /lib | |
parent | c5c8d7d57dbfb2ecb7c7db51711e3b198e379d6a (diff) |
Change the diagnostics interface to take an array of pointers to
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/PathDiagnostic.cpp | 2 | ||||
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 7 | ||||
-rw-r--r-- | lib/Driver/TextDiagnosticBuffer.cpp | 2 | ||||
-rw-r--r-- | lib/Driver/TextDiagnosticPrinter.cpp | 2 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 6 | ||||
-rw-r--r-- | lib/Parse/DeclSpec.cpp | 5 | ||||
-rw-r--r-- | lib/Parse/Parser.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 19 |
9 files changed, 32 insertions, 23 deletions
diff --git a/lib/Analysis/PathDiagnostic.cpp b/lib/Analysis/PathDiagnostic.cpp index 971e751b8d..02cfe1e341 100644 --- a/lib/Analysis/PathDiagnostic.cpp +++ b/lib/Analysis/PathDiagnostic.cpp @@ -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) { diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 533a6a76ec..2076b16db0 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -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()); } } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index a101e389b2..d7d732997b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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 diff --git a/lib/Driver/TextDiagnosticBuffer.cpp b/lib/Driver/TextDiagnosticBuffer.cpp index 26ac879dd0..ef7ac6d408 100644 --- a/lib/Driver/TextDiagnosticBuffer.cpp +++ b/lib/Driver/TextDiagnosticBuffer.cpp @@ -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) { diff --git a/lib/Driver/TextDiagnosticPrinter.cpp b/lib/Driver/TextDiagnosticPrinter.cpp index e0faf478d1..e03588b989 100644 --- a/lib/Driver/TextDiagnosticPrinter.cpp +++ b/lib/Driver/TextDiagnosticPrinter.cpp @@ -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) { diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index c65b546209..dc4dd877b6 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -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); } diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp index e80076127d..733c37cb4f 100644 --- a/lib/Parse/DeclSpec.cpp +++ b/lib/Parse/DeclSpec.cpp @@ -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); } diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 3b36ebec7b..dfabc9b16a 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -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; } diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 6495949526..5ea27c979b 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -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 SourceRange& R1) { - 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; |