From: Ted Kremenek Date: Thu, 5 Nov 2009 02:09:23 +0000 (+0000) Subject: Acting on Daniel's nagging, remove PathDiagnosticClientFactory() and X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b697a4e4118d2d59dc0f38463c8417ddaf58a11f;p=clang Acting on Daniel's nagging, remove PathDiagnosticClientFactory() and migrate work in the destructors of PathDiagnosticClients from their destructors to FlushReports(). The destructors now currently call FlushReports(); this will be fixed in a subsequent patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86108 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathDiagnostic.h b/include/clang/Analysis/PathDiagnostic.h index a08afe2bb9..62763d923e 100644 --- a/include/clang/Analysis/PathDiagnostic.h +++ b/include/clang/Analysis/PathDiagnostic.h @@ -43,7 +43,18 @@ class Preprocessor; class PathDiagnosticClient : public DiagnosticClient { public: PathDiagnosticClient() {} - virtual ~PathDiagnosticClient() {} + + virtual ~PathDiagnosticClient() {}; + + virtual void + FlushDiagnostics(llvm::SmallVectorImpl *FilesMade = 0) = 0; + + void FlushDiagnostics(llvm::SmallVectorImpl &FilesMade) { + FlushDiagnostics(&FilesMade); + } + + virtual llvm::StringRef getName() const = 0; + virtual void SetPreprocessor(Preprocessor *PP) {} virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info); diff --git a/include/clang/Frontend/PathDiagnosticClients.h b/include/clang/Frontend/PathDiagnosticClients.h index 06ce0bed71..11c660c3dc 100644 --- a/include/clang/Frontend/PathDiagnosticClients.h +++ b/include/clang/Frontend/PathDiagnosticClients.h @@ -23,28 +23,12 @@ namespace clang { class PathDiagnosticClient; class Preprocessor; -class PathDiagnosticClientFactory { -public: - PathDiagnosticClientFactory() {} - virtual ~PathDiagnosticClientFactory() {} - - virtual const char *getName() const = 0; - - virtual PathDiagnosticClient* - createPathDiagnosticClient(llvm::SmallVectorImpl *FilesMade) = 0; -}; - PathDiagnosticClient* -CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP = 0, - llvm::SmallVectorImpl* FilesMade = 0); - -PathDiagnosticClientFactory* -CreateHTMLDiagnosticClientFactory(const std::string& prefix, - Preprocessor* PP = 0); +CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP = 0); PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix, Preprocessor* PP, - PathDiagnosticClientFactory *PF = 0); + PathDiagnosticClient *SubPD = 0); } // end clang namespace #endif diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp index 714ede4a6d..64a6926da3 100644 --- a/lib/Frontend/AnalysisConsumer.cpp +++ b/lib/Frontend/AnalysisConsumer.cpp @@ -54,9 +54,8 @@ namespace { static PathDiagnosticClient* CreatePlistHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP) { llvm::sys::Path F(prefix); - PathDiagnosticClientFactory *PF = - CreateHTMLDiagnosticClientFactory(F.getDirname(), PP); - return CreatePlistDiagnosticClient(prefix, PP, PF); + PathDiagnosticClient *PD = CreateHTMLDiagnosticClient(F.getDirname(), PP); + return CreatePlistDiagnosticClient(prefix, PP, PD); } //===----------------------------------------------------------------------===// diff --git a/lib/Frontend/HTMLDiagnostics.cpp b/lib/Frontend/HTMLDiagnostics.cpp index 648ecac3bf..935b6da626 100644 --- a/lib/Frontend/HTMLDiagnostics.cpp +++ b/lib/Frontend/HTMLDiagnostics.cpp @@ -39,16 +39,20 @@ class VISIBILITY_HIDDEN HTMLDiagnostics : public PathDiagnosticClient { bool createdDir, noDir; Preprocessor* PP; std::vector BatchedDiags; - llvm::SmallVectorImpl *FilesMade; public: - HTMLDiagnostics(const std::string& prefix, Preprocessor* pp, - llvm::SmallVectorImpl *filesMade = 0); - - virtual ~HTMLDiagnostics(); + HTMLDiagnostics(const std::string& prefix, Preprocessor* pp); + + virtual ~HTMLDiagnostics() { FlushDiagnostics(NULL); } + + virtual void FlushDiagnostics(llvm::SmallVectorImpl *FilesMade); virtual void SetPreprocessor(Preprocessor *pp) { PP = pp; } virtual void HandlePathDiagnostic(const PathDiagnostic* D); + + virtual llvm::StringRef getName() const { + return "HTMLDiagnostics"; + } unsigned ProcessMacroPiece(llvm::raw_ostream& os, const PathDiagnosticMacroPiece& P, @@ -61,57 +65,22 @@ public: const char *HighlightStart = "", const char *HighlightEnd = ""); - void ReportDiag(const PathDiagnostic& D); + void ReportDiag(const PathDiagnostic& D, + llvm::SmallVectorImpl *FilesMade); }; } // end anonymous namespace -HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp, - llvm::SmallVectorImpl* filesMade) +HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp) : Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false), - PP(pp), FilesMade(filesMade) { - + PP(pp) { // All html files begin with "report" FilePrefix.appendComponent("report"); } PathDiagnosticClient* -clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP, - llvm::SmallVectorImpl* FilesMade) -{ - return new HTMLDiagnostics(prefix, PP, FilesMade); -} - -//===----------------------------------------------------------------------===// -// Factory for HTMLDiagnosticClients -//===----------------------------------------------------------------------===// - -namespace { -class VISIBILITY_HIDDEN HTMLDiagnosticsFactory - : public PathDiagnosticClientFactory { - - std::string Prefix; - Preprocessor *PP; -public: - HTMLDiagnosticsFactory(const std::string& prefix, Preprocessor* pp) - : Prefix(prefix), PP(pp) {} - - virtual ~HTMLDiagnosticsFactory() {} - - const char *getName() const { return "HTMLDiagnostics"; } - - PathDiagnosticClient* - createPathDiagnosticClient(llvm::SmallVectorImpl *FilesMade) { - - return new HTMLDiagnostics(Prefix, PP, FilesMade); - } -}; -} // end anonymous namespace - -PathDiagnosticClientFactory* -clang::CreateHTMLDiagnosticClientFactory(const std::string& prefix, - Preprocessor* PP) { - return new HTMLDiagnosticsFactory(prefix, PP); +clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP) { + return new HTMLDiagnostics(prefix, PP); } //===----------------------------------------------------------------------===// @@ -131,16 +100,19 @@ void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) { BatchedDiags.push_back(D); } -HTMLDiagnostics::~HTMLDiagnostics() { +void +HTMLDiagnostics::FlushDiagnostics(llvm::SmallVectorImpl *FilesMade) +{ while (!BatchedDiags.empty()) { const PathDiagnostic* D = BatchedDiags.back(); BatchedDiags.pop_back(); - ReportDiag(*D); + ReportDiag(*D, FilesMade); delete D; } } -void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) { +void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D, + llvm::SmallVectorImpl *FilesMade){ // Create the HTML directory if it is missing. if (!createdDir) { createdDir = true; diff --git a/lib/Frontend/PlistDiagnostics.cpp b/lib/Frontend/PlistDiagnostics.cpp index a10ecd4a20..1579badc72 100644 --- a/lib/Frontend/PlistDiagnostics.cpp +++ b/lib/Frontend/PlistDiagnostics.cpp @@ -36,14 +36,20 @@ namespace { std::vector BatchedDiags; const std::string OutputFile; const LangOptions &LangOpts; - llvm::OwningPtr PF; - llvm::OwningPtr SubPDC; - llvm::SmallVector FilesMade; + llvm::OwningPtr SubPD; public: PlistDiagnostics(const std::string& prefix, const LangOptions &LangOpts, - PathDiagnosticClientFactory *pf); - ~PlistDiagnostics(); + PathDiagnosticClient *subPD); + + ~PlistDiagnostics() { FlushDiagnostics(NULL); } + + void FlushDiagnostics(llvm::SmallVectorImpl *FilesMade); + void HandlePathDiagnostic(const PathDiagnostic* D); + + virtual llvm::StringRef getName() const { + return "PlistDiagnostics"; + } PathGenerationScheme getGenerationScheme() const; bool supportsLogicalOpControlFlow() const { return true; } @@ -54,22 +60,18 @@ namespace { PlistDiagnostics::PlistDiagnostics(const std::string& output, const LangOptions &LO, - PathDiagnosticClientFactory *pf) - : OutputFile(output), LangOpts(LO), PF(pf) { - - if (PF) - SubPDC.reset(PF->createPathDiagnosticClient(&FilesMade)); -} + PathDiagnosticClient *subPD) + : OutputFile(output), LangOpts(LO), SubPD(subPD) {} PathDiagnosticClient* clang::CreatePlistDiagnosticClient(const std::string& s, Preprocessor *PP, - PathDiagnosticClientFactory *PF) { - return new PlistDiagnostics(s, PP->getLangOptions(), PF); + PathDiagnosticClient *subPD) { + return new PlistDiagnostics(s, PP->getLangOptions(), subPD); } PathDiagnosticClient::PathGenerationScheme PlistDiagnostics::getGenerationScheme() const { - if (const PathDiagnosticClient *PD = SubPDC.get()) + if (const PathDiagnosticClient *PD = SubPD.get()) return PD->getGenerationScheme(); return Extensive; @@ -306,7 +308,8 @@ void PlistDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) { BatchedDiags.push_back(D); } -PlistDiagnostics::~PlistDiagnostics() { +void PlistDiagnostics::FlushDiagnostics(llvm::SmallVectorImpl + *FilesMade) { // Build up a set of FIDs that we use by scanning the locations and // ranges of the diagnostics. @@ -395,19 +398,16 @@ PlistDiagnostics::~PlistDiagnostics() { EmitLocation(o, *SM, LangOpts, D->getLocation(), FM, 2); // Output the diagnostic to the sub-diagnostic client, if any. - if (PF) { - if (!SubPDC.get()) - SubPDC.reset(PF->createPathDiagnosticClient(&FilesMade)); - - FilesMade.clear(); - SubPDC->HandlePathDiagnostic(OwnedD.take()); - SubPDC.reset(0); + if (SubPD) { + SubPD->HandlePathDiagnostic(OwnedD.take()); + llvm::SmallVector SubFilesMade; + SubPD->FlushDiagnostics(SubFilesMade); - if (!FilesMade.empty()) { - o << " " << PF->getName() << "_files\n"; + if (!SubFilesMade.empty()) { + o << " " << SubPD->getName() << "_files\n"; o << " \n"; - for (size_t i = 0, n = FilesMade.size(); i < n ; ++i) - o << " " << FilesMade[i] << "\n"; + for (size_t i = 0, n = SubFilesMade.size(); i < n ; ++i) + o << " " << SubFilesMade[i] << "\n"; o << " \n"; } } @@ -420,4 +420,7 @@ PlistDiagnostics::~PlistDiagnostics() { // Finish. o << "\n"; + + if (FilesMade) + FilesMade->push_back(OutputFile); }