diff options
Diffstat (limited to 'include/clang/Frontend/VerifyDiagnosticConsumer.h')
-rw-r--r-- | include/clang/Frontend/VerifyDiagnosticConsumer.h | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/include/clang/Frontend/VerifyDiagnosticConsumer.h b/include/clang/Frontend/VerifyDiagnosticConsumer.h index 95d7752517d8..9273fac50910 100644 --- a/include/clang/Frontend/VerifyDiagnosticConsumer.h +++ b/include/clang/Frontend/VerifyDiagnosticConsumer.h @@ -13,10 +13,10 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" #include <climits> +#include <memory> namespace clang { @@ -34,12 +34,12 @@ class FileEntry; /// comment on the line that has the diagnostic, use: /// /// \code -/// expected-{error,warning,note} +/// expected-{error,warning,remark,note} /// \endcode /// -/// to tag if it's an expected error or warning, and place the expected text -/// between {{ and }} markers. The full text doesn't have to be included, only -/// enough to ensure that the correct diagnostic was emitted. +/// to tag if it's an expected error, remark or warning, and place the expected +/// text between {{ and }} markers. The full text doesn't have to be included, +/// only enough to ensure that the correct diagnostic was emitted. /// /// Here's an example: /// @@ -71,7 +71,10 @@ class FileEntry; /// \endcode /// /// The path can be absolute or relative and the same search paths will be used -/// as for #include directives. +/// as for #include directives. The line number in an external file may be +/// substituted with '*' meaning that any line number will match (useful where +/// the included file is, for example, a system header where the actual line +/// number may change and is not critical). /// /// The simple syntax above allows each specification to match exactly one /// error. You can use the extended syntax to customize this. The extended @@ -108,10 +111,11 @@ class FileEntry; /// /// In this example, the diagnostic may appear only once, if at all. /// -/// Regex matching mode may be selected by appending '-re' to type, such as: +/// Regex matching mode may be selected by appending '-re' to type and +/// including regexes wrapped in double curly braces in the directive, such as: /// /// \code -/// expected-error-re +/// expected-error-re {{format specifies type 'wchar_t **' (aka '{{.+}}')}} /// \endcode /// /// Examples matching error: "variable has incomplete type 'struct s'" @@ -120,10 +124,10 @@ class FileEntry; /// // expected-error {{variable has incomplete type 'struct s'}} /// // expected-error {{variable has incomplete type}} /// -/// // expected-error-re {{variable has has type 'struct .'}} -/// // expected-error-re {{variable has has type 'struct .*'}} -/// // expected-error-re {{variable has has type 'struct (.*)'}} -/// // expected-error-re {{variable has has type 'struct[[:space:]](.*)'}} +/// // expected-error-re {{variable has type 'struct {{.}}'}} +/// // expected-error-re {{variable has type 'struct {{.*}}'}} +/// // expected-error-re {{variable has type 'struct {{(.*)}}'}} +/// // expected-error-re {{variable has type 'struct{{[[:space:]](.*)}}'}} /// \endcode /// /// VerifyDiagnosticConsumer expects at least one expected-* directive to @@ -142,7 +146,7 @@ public: class Directive { public: static Directive *create(bool RegexKind, SourceLocation DirectiveLoc, - SourceLocation DiagnosticLoc, + SourceLocation DiagnosticLoc, bool MatchAnyLine, StringRef Text, unsigned Min, unsigned Max); public: /// Constant representing n or more matches. @@ -152,6 +156,7 @@ public: SourceLocation DiagnosticLoc; const std::string Text; unsigned Min, Max; + bool MatchAnyLine; virtual ~Directive() { } @@ -164,9 +169,9 @@ public: protected: Directive(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, - StringRef Text, unsigned Min, unsigned Max) + bool MatchAnyLine, StringRef Text, unsigned Min, unsigned Max) : DirectiveLoc(DirectiveLoc), DiagnosticLoc(DiagnosticLoc), - Text(Text), Min(Min), Max(Max) { + Text(Text), Min(Min), Max(Max), MatchAnyLine(MatchAnyLine) { assert(!DirectiveLoc.isInvalid() && "DirectiveLoc is invalid!"); assert(!DiagnosticLoc.isInvalid() && "DiagnosticLoc is invalid!"); } @@ -183,13 +188,17 @@ public: struct ExpectedData { DirectiveList Errors; DirectiveList Warnings; + DirectiveList Remarks; DirectiveList Notes; - ~ExpectedData() { + void Reset() { llvm::DeleteContainerPointers(Errors); llvm::DeleteContainerPointers(Warnings); + llvm::DeleteContainerPointers(Remarks); llvm::DeleteContainerPointers(Notes); } + + ~ExpectedData() { Reset(); } }; enum DirectiveStatus { @@ -203,7 +212,7 @@ private: DiagnosticsEngine &Diags; DiagnosticConsumer *PrimaryClient; bool OwnsPrimaryClient; - OwningPtr<TextDiagnosticBuffer> Buffer; + std::unique_ptr<TextDiagnosticBuffer> Buffer; const Preprocessor *CurrentPreprocessor; const LangOptions *LangOpts; SourceManager *SrcManager; @@ -217,24 +226,19 @@ private: SrcManager = &SM; } -#ifndef NDEBUG + // These facilities are used for validation in debug builds. class UnparsedFileStatus { llvm::PointerIntPair<const FileEntry *, 1, bool> Data; - public: UnparsedFileStatus(const FileEntry *File, bool FoundDirectives) : Data(File, FoundDirectives) {} - const FileEntry *getFile() const { return Data.getPointer(); } bool foundDirectives() const { return Data.getInt(); } }; - typedef llvm::DenseMap<FileID, const FileEntry *> ParsedFilesMap; typedef llvm::DenseMap<FileID, UnparsedFileStatus> UnparsedFilesMap; - ParsedFilesMap ParsedFiles; UnparsedFilesMap UnparsedFiles; -#endif public: /// Create a new verifying diagnostic client, which will issue errors to @@ -243,10 +247,10 @@ public: VerifyDiagnosticConsumer(DiagnosticsEngine &Diags); ~VerifyDiagnosticConsumer(); - virtual void BeginSourceFile(const LangOptions &LangOpts, - const Preprocessor *PP); + void BeginSourceFile(const LangOptions &LangOpts, + const Preprocessor *PP) override; - virtual void EndSourceFile(); + void EndSourceFile() override; enum ParsedStatus { /// File has been processed via HandleComment. @@ -262,10 +266,10 @@ public: /// \brief Update lists of parsed and unparsed files. void UpdateParsedFileStatus(SourceManager &SM, FileID FID, ParsedStatus PS); - virtual bool HandleComment(Preprocessor &PP, SourceRange Comment); + bool HandleComment(Preprocessor &PP, SourceRange Comment) override; - virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info); + void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, + const Diagnostic &Info) override; }; } // end namspace clang |