[cfe-commits] r86108 - in /cfe/trunk: include/clang/Analysis/PathDiagnostic.h include/clang/Frontend/PathDiagnosticClients.h lib/Frontend/AnalysisConsumer.cpp lib/Frontend/HTMLDiagnostics.cpp lib/Frontend/PlistDiagnostics.cpp
Ted Kremenek
kremenek at apple.com
Wed Nov 4 18:09:23 PST 2009
Author: kremenek
Date: Wed Nov 4 20:09:23 2009
New Revision: 86108
URL: http://llvm.org/viewvc/llvm-project?rev=86108&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Analysis/PathDiagnostic.h
cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h
cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp
cfe/trunk/lib/Frontend/PlistDiagnostics.cpp
Modified: cfe/trunk/include/clang/Analysis/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathDiagnostic.h?rev=86108&r1=86107&r2=86108&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/Analysis/PathDiagnostic.h Wed Nov 4 20:09:23 2009
@@ -43,7 +43,18 @@
class PathDiagnosticClient : public DiagnosticClient {
public:
PathDiagnosticClient() {}
- virtual ~PathDiagnosticClient() {}
+
+ virtual ~PathDiagnosticClient() {};
+
+ virtual void
+ FlushDiagnostics(llvm::SmallVectorImpl<std::string> *FilesMade = 0) = 0;
+
+ void FlushDiagnostics(llvm::SmallVectorImpl<std::string> &FilesMade) {
+ FlushDiagnostics(&FilesMade);
+ }
+
+ virtual llvm::StringRef getName() const = 0;
+
virtual void SetPreprocessor(Preprocessor *PP) {}
virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
const DiagnosticInfo &Info);
Modified: cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h?rev=86108&r1=86107&r2=86108&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h (original)
+++ cfe/trunk/include/clang/Frontend/PathDiagnosticClients.h Wed Nov 4 20:09:23 2009
@@ -23,28 +23,12 @@
class PathDiagnosticClient;
class Preprocessor;
-class PathDiagnosticClientFactory {
-public:
- PathDiagnosticClientFactory() {}
- virtual ~PathDiagnosticClientFactory() {}
-
- virtual const char *getName() const = 0;
-
- virtual PathDiagnosticClient*
- createPathDiagnosticClient(llvm::SmallVectorImpl<std::string> *FilesMade) = 0;
-};
-
PathDiagnosticClient*
-CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP = 0,
- llvm::SmallVectorImpl<std::string>* 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
Modified: cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/AnalysisConsumer.cpp?rev=86108&r1=86107&r2=86108&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Wed Nov 4 20:09:23 2009
@@ -54,9 +54,8 @@
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);
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp?rev=86108&r1=86107&r2=86108&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/Frontend/HTMLDiagnostics.cpp Wed Nov 4 20:09:23 2009
@@ -39,16 +39,20 @@
bool createdDir, noDir;
Preprocessor* PP;
std::vector<const PathDiagnostic*> BatchedDiags;
- llvm::SmallVectorImpl<std::string> *FilesMade;
public:
- HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
- llvm::SmallVectorImpl<std::string> *filesMade = 0);
-
- virtual ~HTMLDiagnostics();
+ HTMLDiagnostics(const std::string& prefix, Preprocessor* pp);
+
+ virtual ~HTMLDiagnostics() { FlushDiagnostics(NULL); }
+
+ virtual void FlushDiagnostics(llvm::SmallVectorImpl<std::string> *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 @@
const char *HighlightStart = "<span class=\"mrange\">",
const char *HighlightEnd = "</span>");
- void ReportDiag(const PathDiagnostic& D);
+ void ReportDiag(const PathDiagnostic& D,
+ llvm::SmallVectorImpl<std::string> *FilesMade);
};
} // end anonymous namespace
-HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
- llvm::SmallVectorImpl<std::string>* 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<std::string>* 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<std::string> *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 @@
BatchedDiags.push_back(D);
}
-HTMLDiagnostics::~HTMLDiagnostics() {
+void
+HTMLDiagnostics::FlushDiagnostics(llvm::SmallVectorImpl<std::string> *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<std::string> *FilesMade){
// Create the HTML directory if it is missing.
if (!createdDir) {
createdDir = true;
Modified: cfe/trunk/lib/Frontend/PlistDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PlistDiagnostics.cpp?rev=86108&r1=86107&r2=86108&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PlistDiagnostics.cpp (original)
+++ cfe/trunk/lib/Frontend/PlistDiagnostics.cpp Wed Nov 4 20:09:23 2009
@@ -36,14 +36,20 @@
std::vector<const PathDiagnostic*> BatchedDiags;
const std::string OutputFile;
const LangOptions &LangOpts;
- llvm::OwningPtr<PathDiagnosticClientFactory> PF;
- llvm::OwningPtr<PathDiagnosticClient> SubPDC;
- llvm::SmallVector<std::string, 1> FilesMade;
+ llvm::OwningPtr<PathDiagnosticClient> SubPD;
public:
PlistDiagnostics(const std::string& prefix, const LangOptions &LangOpts,
- PathDiagnosticClientFactory *pf);
- ~PlistDiagnostics();
+ PathDiagnosticClient *subPD);
+
+ ~PlistDiagnostics() { FlushDiagnostics(NULL); }
+
+ void FlushDiagnostics(llvm::SmallVectorImpl<std::string> *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 @@
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 @@
BatchedDiags.push_back(D);
}
-PlistDiagnostics::~PlistDiagnostics() {
+void PlistDiagnostics::FlushDiagnostics(llvm::SmallVectorImpl<std::string>
+ *FilesMade) {
// Build up a set of FIDs that we use by scanning the locations and
// ranges of the diagnostics.
@@ -395,19 +398,16 @@
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<std::string, 1> SubFilesMade;
+ SubPD->FlushDiagnostics(SubFilesMade);
- if (!FilesMade.empty()) {
- o << " <key>" << PF->getName() << "_files</key>\n";
+ if (!SubFilesMade.empty()) {
+ o << " <key>" << SubPD->getName() << "_files</key>\n";
o << " <array>\n";
- for (size_t i = 0, n = FilesMade.size(); i < n ; ++i)
- o << " <string>" << FilesMade[i] << "</string>\n";
+ for (size_t i = 0, n = SubFilesMade.size(); i < n ; ++i)
+ o << " <string>" << SubFilesMade[i] << "</string>\n";
o << " </array>\n";
}
}
@@ -420,4 +420,7 @@
// Finish.
o << "</dict>\n</plist>";
+
+ if (FilesMade)
+ FilesMade->push_back(OutputFile);
}
More information about the cfe-commits
mailing list