public:
virtual ~DiagnosticClient();
- /// setLangOptions - This is set by clients of diagnostics when they know the
- /// language parameters of the diagnostics that may be sent through. Note
- /// that this can change over time if a DiagClient has multiple languages sent
- /// through it. It may also be set to null (e.g. when processing command line
- /// options).
- virtual void setLangOptions(const LangOptions *LO) {}
+ /// BeginSourceFile - Callback to inform the diagnostic client that processing
+ /// of a source file is beginning.
+ ///
+ /// Note that diagnostics may be emitted outside the processing of a source
+ /// file, for example during the parsing of command line options. However,
+ /// diagnostics with source range information are required to only be emitted
+ /// in between BeginSourceFile() and EndSourceFile().
+ ///
+ /// \arg LO - The language options for the source file being processed.
+ /// \arg PP - The preprocessor object being used for the source; this optional
+ /// and may not be present, for example when processing AST source files.
+ virtual void BeginSourceFile(const LangOptions &LangOpts) {}
+
+ /// EndSourceFile - Callback to inform the diagnostic client that processing
+ /// of a source file has ended. The diagnostic client should assume that any
+ /// objects made available via \see BeginSourceFile() are inaccessible.
+ virtual void EndSourceFile() {}
/// IncludeInDiagnosticCounts - This method (whose default implementation
- /// returns true) indicates whether the diagnostics handled by this
- /// DiagnosticClient should be included in the number of diagnostics
- /// reported by Diagnostic.
+ /// returns true) indicates whether the diagnostics handled by this
+ /// DiagnosticClient should be included in the number of diagnostics reported
+ /// by Diagnostic.
virtual bool IncludeInDiagnosticCounts() const;
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
public:
TextDiagnosticPrinter(llvm::raw_ostream &os, const DiagnosticOptions &diags);
- void setLangOptions(const LangOptions *LO) {
- LangOpts = LO;
+ void BeginSourceFile(const LangOptions &LO) {
+ LangOpts = &LO;
+ }
+
+ void EndSourceFile() {
+ LangOpts = 0;
}
void PrintIncludeStack(SourceLocation Loc, const SourceManager &SM);
const CodeModificationHint *Hints,
unsigned NumHints,
unsigned Columns) {
+ assert(LangOpts && "Unexpected diagnostic outside source file processing");
assert(!Loc.isInvalid() && "must have a valid source location here");
// If this is a macro ID, first emit information about where this was
Chain2.reset(new TextDiagnosticPrinter(*BuildLogFile, DiagOpts));
}
- virtual void setLangOptions(const LangOptions *LO) {
- Chain1->setLangOptions(LO);
- Chain2->setLangOptions(LO);
+ virtual void BeginSourceFile(const LangOptions &LO) {
+ Chain1->BeginSourceFile(LO);
+ Chain2->BeginSourceFile(LO);
+ }
+
+ virtual void EndSourceFile() {
+ Chain1->EndSourceFile();
+ Chain2->EndSourceFile();
}
virtual bool IncludeInDiagnosticCounts() const {
AST->getSourceManager().createMainFileIDForMemBuffer(SB);
// Stream the input AST to the consumer.
+ Diags.getClient()->BeginSourceFile(PP.getLangOptions());
ParseAST(PP, Consumer.get(), AST->getASTContext(), Stats);
+ Diags.getClient()->EndSourceFile();
// Release the consumer and the AST, in that order since the consumer may
// perform actions in its destructor which require the context.
// Initialize language options, inferring file types from input filenames.
LangOptions LangInfo;
- DiagClient->setLangOptions(&LangInfo);
InitializeLangOptions(LangInfo, LK);
InitializeLanguageStandard(LangInfo, LK, Target.get(), Features);
}
// Process the source file.
+ DiagClient->BeginSourceFile(LangInfo);
ProcessInputFile(*PP, InFile, ProgAction, Features, Context);
+ DiagClient->EndSourceFile();
HeaderInfo.ClearFileInfo();
- DiagClient->setLangOptions(0);
}
if (!NoCaretDiagnostics)