/// and errors.
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info);
+
+ /// \brief Clone the diagnostic consumer, producing an equivalent consumer
+ /// that can be used in a different context.
+ virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const = 0;
+};
+
+/// IgnoringDiagConsumer - This is a diagnostic client that just ignores all
+/// diags.
+class IgnoringDiagConsumer : public DiagnosticConsumer {
+ void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+ const Diagnostic &Info) {
+ // Just ignore it.
+ }
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
+ return new IgnoringDiagConsumer();
+ }
};
} // end namespace clang
Primary->HandleDiagnostic(DiagLevel, Info);
Secondary->HandleDiagnostic(DiagLevel, Info);
}
+
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
+ return new ChainedDiagnosticConsumer(Primary->clone(Diags),
+ Secondary->clone(Diags));
+ }
+
};
} // end namspace clang
///
/// \param ShouldOwnClient If Client is non-NULL, specifies whether
/// the diagnostic object should take ownership of the client.
+ ///
+ /// \param ShouldCloneClient If Client is non-NULL, specifies whether that
+ /// client should be cloned.
void createDiagnostics(int Argc, const char* const *Argv,
DiagnosticConsumer *Client = 0,
- bool ShouldOwnClient = true);
+ bool ShouldOwnClient = true,
+ bool ShouldCloneClient = true);
/// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter.
///
const char* const *Argv,
DiagnosticConsumer *Client = 0,
bool ShouldOwnClient = true,
+ bool ShouldCloneClient = true,
const CodeGenOptions *CodeGenOpts = 0);
/// Create the file manager and replace any existing one with it.
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info);
+
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
};
} // end namespace clang
/// FlushDiagnostics - Flush the buffered diagnostics to an given
/// diagnostic engine.
void FlushDiagnostics(DiagnosticsEngine &Diags) const;
+
+ virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
};
} // end namspace clang
virtual void HandleDiagnostic(DiagnosticsEngine::Level Level,
const Diagnostic &Info);
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
+
private:
void EmitDiagnosticLoc(DiagnosticsEngine::Level Level,
const Diagnostic &Info,
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info);
+
+ virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
};
} // end namspace clang
/// \brief Emit a diagnostic via the adapted diagnostic client.
void Diag(SourceLocation Loc, unsigned DiagID);
+
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
};
}
SourceMgr = &SM;
LangOpts = &LO;
}
- SourceManager &getSourceMgr() { return *SourceMgr; }
- const LangOptions &getLangOpts() { return *LangOpts; }
+ SourceManager &getSourceMgr() const { return *SourceMgr; }
+ const LangOptions &getLangOpts() const { return *LangOpts; }
/// isRewritable - Return true if this location is a raw file location, which
/// is rewritable. Locations from macros, etc are not rewritable.
CapturedDiagList &CapturedDiags;
public:
CaptureDiagnosticConsumer(DiagnosticsEngine &diags,
- CapturedDiagList &capturedDiags)
+ CapturedDiagList &capturedDiags)
: Diags(diags), CapturedDiags(capturedDiags) { }
virtual void HandleDiagnostic(DiagnosticsEngine::Level level,
// Non-ARC warnings are ignored.
Diags.setLastDiagnosticIgnored();
}
+
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
+ // Just drop any diagnostics that come from cloned consumers; they'll
+ // have different source managers anyway.
+ return new IgnoringDiagConsumer();
+ }
};
} // end anonymous namespace
virtual void HandleDiagnostic(DiagnosticsEngine::Level Level,
const Diagnostic &Info);
+
+ DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
+ // Just drop any diagnostics that come from cloned consumers; they'll
+ // have different source managers anyway.
+ return new IgnoringDiagConsumer();
+ }
};
/// \brief RAII object that optionally captures diagnostics, if
void CompilerInstance::createDiagnostics(int Argc, const char* const *Argv,
DiagnosticConsumer *Client,
- bool ShouldOwnClient) {
+ bool ShouldOwnClient,
+ bool ShouldCloneClient) {
Diagnostics = createDiagnostics(getDiagnosticOpts(), Argc, Argv, Client,
- ShouldOwnClient, &getCodeGenOpts());
+ ShouldOwnClient, ShouldCloneClient,
+ &getCodeGenOpts());
}
llvm::IntrusiveRefCntPtr<DiagnosticsEngine>
int Argc, const char* const *Argv,
DiagnosticConsumer *Client,
bool ShouldOwnClient,
+ bool ShouldCloneClient,
const CodeGenOptions *CodeGenOpts) {
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
llvm::IntrusiveRefCntPtr<DiagnosticsEngine>
// Create the diagnostic client for reporting errors or for
// implementing -verify.
- if (Client)
- Diags->setClient(Client, ShouldOwnClient);
- else
+ if (Client) {
+ if (ShouldCloneClient)
+ Diags->setClient(Client->clone(*Diags), ShouldOwnClient);
+ else
+ Diags->setClient(Client, ShouldOwnClient);
+ } else
Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts));
// Chain in -verify checker, if requested.
Instance.setInvocation(&*Invocation);
Instance.createDiagnostics(/*argc=*/0, /*argv=*/0,
&ImportingInstance.getDiagnosticClient(),
- /*ShouldOwnClient=*/false);
+ /*ShouldOwnClient=*/true,
+ /*ShouldCloneClient=*/true);
// Construct a module-generating action.
GeneratePCHAction CreateModuleAction(true);
// Execute the action to actually build the module in-place.
// FIXME: Need to synchronize when multiple processes do this.
Instance.ExecuteAction(CreateModuleAction);
-
- // Tell the diagnostic client that it's (re-)starting to process a source
- // file.
- // FIXME: This is a hack. We probably want to clone the diagnostic client.
- ImportingInstance.getDiagnosticClient()
- .BeginSourceFile(ImportingInstance.getLangOpts(),
- &ImportingInstance.getPreprocessor());
}
ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
// Record the diagnostic entry.
Entries.push_back(DE);
}
+
+DiagnosticConsumer *
+LogDiagnosticPrinter::clone(DiagnosticsEngine &Diags) const {
+ return new LogDiagnosticPrinter(OS, *DiagOpts, /*OwnsOutputStream=*/false);
+}
+
Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note,
it->second.c_str()));
}
+
+DiagnosticConsumer *TextDiagnosticBuffer::clone(DiagnosticsEngine &) const {
+ return new TextDiagnosticBuffer();
+}
OS.flush();
}
+
+DiagnosticConsumer *
+TextDiagnosticPrinter::clone(DiagnosticsEngine &Diags) const {
+ return new TextDiagnosticPrinter(OS, *DiagOpts, /*OwnsOutputStream=*/false);
+}
Buffer.reset(new TextDiagnosticBuffer());
}
+DiagnosticConsumer *
+VerifyDiagnosticConsumer::clone(DiagnosticsEngine &Diags) const {
+ if (!Diags.getClient())
+ Diags.setClient(PrimaryClient->clone(Diags));
+
+ return new VerifyDiagnosticConsumer(Diags);
+}
+
Directive* Directive::Create(bool RegexKind, const SourceLocation &Location,
const std::string &Text, unsigned Count) {
if (RegexKind)
Diags.setClient(this);
}
+DiagnosticConsumer *FixItRewriter::clone(DiagnosticsEngine &Diags) const {
+ return new FixItRewriter(Diags, Diags.getSourceManager(),
+ Rewrite.getLangOpts(), FixItOpts);
+}
+
FixItOptions::~FixItOptions() {}
}
}
-namespace {
-/// IgnoringDiagConsumer - This is a diagnostic client that just ignores all
-/// diags.
-class IgnoringDiagConsumer : public DiagnosticConsumer {
- void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
- const Diagnostic &Info) {
- // Just ignore it.
- }
-};
-}
-
/// HighlightMacros - This uses the macro table state from the end of the
/// file, to re-expand macros and insert (into the HTML) information about the
/// macro expansions. This won't be perfectly perfect, but it will be