[cfe-commits] r86113 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Frontend/TextDiagnosticPrinter.h lib/Frontend/TextDiagnosticPrinter.cpp tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Wed Nov 4 18:42:12 PST 2009
Author: ddunbar
Date: Wed Nov 4 20:42:12 2009
New Revision: 86113
URL: http://llvm.org/viewvc/llvm-project?rev=86113&view=rev
Log:
Replace DiagnosticClient::setLangOptions with {Begin,End}SourceFile, and clarify
invariants (diagnostics with source informations must occur between
{Begin,End}SourceFile).
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=86113&r1=86112&r2=86113&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Nov 4 20:42:12 2009
@@ -769,17 +769,28 @@
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
Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=86113&r1=86112&r2=86113&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Wed Nov 4 20:42:12 2009
@@ -39,8 +39,12 @@
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);
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=86113&r1=86112&r2=86113&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Nov 4 20:42:12 2009
@@ -268,6 +268,7 @@
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
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86113&r1=86112&r2=86113&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 4 20:42:12 2009
@@ -1545,9 +1545,14 @@
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 {
@@ -2080,7 +2085,9 @@
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.
@@ -2230,7 +2237,6 @@
// Initialize language options, inferring file types from input filenames.
LangOptions LangInfo;
- DiagClient->setLangOptions(&LangInfo);
InitializeLangOptions(LangInfo, LK);
InitializeLanguageStandard(LangInfo, LK, Target.get(), Features);
@@ -2276,10 +2282,11 @@
}
// Process the source file.
+ DiagClient->BeginSourceFile(LangInfo);
ProcessInputFile(*PP, InFile, ProgAction, Features, Context);
+ DiagClient->EndSourceFile();
HeaderInfo.ClearFileInfo();
- DiagClient->setLangOptions(0);
}
if (!NoCaretDiagnostics)
More information about the cfe-commits
mailing list