aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-17 20:40:01 +0000
committerChris Lattner <sabre@nondot.org>2009-04-17 20:40:01 +0000
commit409d4e716a01a71c4fecfaec59ca8348c8a5d275 (patch)
treea17adc0a6bdecbb3df4a40a8756bb0032e2967b1
parent40469651a3f8379dc0f32df69e9bade06a2aad36 (diff)
refactor htmldiags to be created up front like the other diag clients.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69379 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathDiagnostic.h3
-rw-r--r--include/clang/Frontend/PathDiagnosticClients.h4
-rw-r--r--lib/Frontend/HTMLDiagnostics.cpp23
-rw-r--r--tools/clang-cc/clang-cc.cpp48
4 files changed, 33 insertions, 45 deletions
diff --git a/include/clang/Analysis/PathDiagnostic.h b/include/clang/Analysis/PathDiagnostic.h
index 8d53cdb679..0e0b85eb10 100644
--- a/include/clang/Analysis/PathDiagnostic.h
+++ b/include/clang/Analysis/PathDiagnostic.h
@@ -32,12 +32,15 @@ namespace clang {
class PathDiagnostic;
class Stmt;
class Decl;
+class Preprocessor;
class PathDiagnosticClient : public DiagnosticClient {
public:
PathDiagnosticClient() {}
virtual ~PathDiagnosticClient() {}
+ 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 5380de79c6..028cd85492 100644
--- a/include/clang/Frontend/PathDiagnosticClients.h
+++ b/include/clang/Frontend/PathDiagnosticClients.h
@@ -23,8 +23,8 @@ class Preprocessor;
class PreprocessorFactory;
PathDiagnosticClient* CreateHTMLDiagnosticClient(const std::string& prefix,
- Preprocessor* PP,
- PreprocessorFactory* PPF);
+ Preprocessor* PP = 0,
+ PreprocessorFactory* PPF = 0);
PathDiagnosticClient* CreatePlistDiagnosticClient(const std::string& prefix,
Preprocessor* PP,
diff --git a/lib/Frontend/HTMLDiagnostics.cpp b/lib/Frontend/HTMLDiagnostics.cpp
index 752d41fb4c..9cfe0b2a61 100644
--- a/lib/Frontend/HTMLDiagnostics.cpp
+++ b/lib/Frontend/HTMLDiagnostics.cpp
@@ -39,14 +39,14 @@ class VISIBILITY_HIDDEN HTMLDiagnostics : public PathDiagnosticClient {
llvm::sys::Path Directory, FilePrefix;
bool createdDir, noDir;
Preprocessor* PP;
- PreprocessorFactory* PPF;
std::vector<const PathDiagnostic*> BatchedDiags;
public:
- HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
- PreprocessorFactory* ppf);
+ HTMLDiagnostics(const std::string& prefix, Preprocessor* pp);
virtual ~HTMLDiagnostics();
+ virtual void SetPreprocessor(Preprocessor *pp) { PP = pp; }
+
virtual void HandlePathDiagnostic(const PathDiagnostic* D);
unsigned ProcessMacroPiece(llvm::raw_ostream& os,
@@ -65,10 +65,9 @@ public:
} // end anonymous namespace
-HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
- PreprocessorFactory* ppf)
+HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp)
: Directory(prefix), FilePrefix(prefix), createdDir(false), noDir(false),
- PP(pp), PPF(ppf) {
+ PP(pp) {
// All html files begin with "report"
FilePrefix.appendComponent("report");
@@ -76,9 +75,8 @@ HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix, Preprocessor* pp,
PathDiagnosticClient*
clang::CreateHTMLDiagnosticClient(const std::string& prefix, Preprocessor* PP,
- PreprocessorFactory* PPF) {
-
- return new HTMLDiagnostics(prefix, PP, PPF);
+ PreprocessorFactory*) {
+ return new HTMLDiagnostics(prefix, PP);
}
//===----------------------------------------------------------------------===//
@@ -99,7 +97,6 @@ void HTMLDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) {
}
HTMLDiagnostics::~HTMLDiagnostics() {
-
while (!BatchedDiags.empty()) {
const PathDiagnostic* D = BatchedDiags.back();
BatchedDiags.pop_back();
@@ -109,9 +106,7 @@ HTMLDiagnostics::~HTMLDiagnostics() {
}
void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
-
// Create the HTML directory if it is missing.
-
if (!createdDir) {
createdDir = true;
std::string ErrorMsg;
@@ -170,10 +165,8 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D) {
unsigned max = n;
for (PathDiagnostic::const_reverse_iterator I=D.rbegin(), E=D.rend();
- I!=E; ++I, --n) {
-
+ I!=E; ++I, --n)
HandlePiece(R, FID, *I, n, max);
- }
// Add line numbers, header, footer, etc.
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 81d1e39790..ba4d77795f 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -2229,29 +2229,31 @@ int main(int argc, char **argv) {
// Create the diagnostic client for reporting errors or for
// implementing -verify.
- DiagnosticClient* TextDiagClient = 0;
-
- if (!VerifyDiagnostics) {
+ llvm::OwningPtr<DiagnosticClient> DiagClient;
+ if (VerifyDiagnostics) {
+ // When checking diagnostics, just buffer them up.
+ DiagClient.reset(new TextDiagnosticBuffer());
+ if (InputFilenames.size() != 1) {
+ fprintf(stderr, "-verify only works on single input files for now.\n");
+ return 1;
+ }
+ if (!HTMLDiag.empty()) {
+ fprintf(stderr, "-verify and -html-diags don't work together\n");
+ return 1;
+ }
+ } else if (HTMLDiag.empty()) {
// Print diagnostics to stderr by default.
- TextDiagClient = new TextDiagnosticPrinter(llvm::errs(),
+ DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(),
!NoShowColumn,
!NoCaretDiagnostics,
!NoShowLocation,
PrintSourceRangeInfo,
- PrintDiagnosticOption);
+ PrintDiagnosticOption));
} else {
- // When checking diagnostics, just buffer them up.
- TextDiagClient = new TextDiagnosticBuffer();
-
- if (InputFilenames.size() != 1) {
- fprintf(stderr,
- "-verify only works on single input files for now.\n");
- return 1;
- }
+ DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag));
}
// Configure our handling of diagnostics.
- llvm::OwningPtr<DiagnosticClient> DiagClient(TextDiagClient);
Diagnostic Diags(DiagClient.get());
if (ProcessWarningOptions(Diags))
return 1;
@@ -2287,7 +2289,6 @@ int main(int argc, char **argv) {
const std::string &InFile = InputFilenames[i];
if (isSerializedFile(InFile)) {
- Diags.setClient(TextDiagClient);
ProcessSerializedFile(InFile,Diags,FileMgr);
continue;
}
@@ -2301,7 +2302,7 @@ int main(int argc, char **argv) {
// Initialize language options, inferring file types from input filenames.
LangOptions LangInfo;
- TextDiagClient->setLangOptions(&LangInfo);
+ DiagClient->setLangOptions(&LangInfo);
InitializeBaseLanguage();
LangKind LK = GetLanguage(InFile);
@@ -2327,23 +2328,14 @@ int main(int argc, char **argv) {
InitializeSourceManager(*PP.get(), InFile))
continue;
- // Create the HTMLDiagnosticsClient if we are using one. Otherwise,
- // always reset to using TextDiagClient.
- llvm::OwningPtr<DiagnosticClient> TmpClient;
-
- if (!HTMLDiag.empty()) {
- TmpClient.reset(CreateHTMLDiagnosticClient(HTMLDiag, PP.get(),
- &PPFactory));
- Diags.setClient(TmpClient.get());
- }
- else
- Diags.setClient(TextDiagClient);
+ if (!HTMLDiag.empty())
+ ((PathDiagnosticClient*)DiagClient.get())->SetPreprocessor(PP.get());
// Process the source file.
ProcessInputFile(*PP, PPFactory, InFile, ProgAction);
HeaderInfo.ClearFileInfo();
- TextDiagClient->setLangOptions(0);
+ DiagClient->setLangOptions(0);
}
if (Verbose)