diff options
author | Christof Douma <Christof.Douma@arm.com> | 2017-06-19 12:41:22 +0000 |
---|---|---|
committer | Christof Douma <Christof.Douma@arm.com> | 2017-06-19 12:41:22 +0000 |
commit | 27337711cd7156c2c7f48abe33b4e1f6771a261e (patch) | |
tree | ea627c7205ac4ed0ebf73cff0aef7d78a52d7566 /include | |
parent | 87050d0737fcc08eda133cf0eb20ed4a71173efd (diff) |
Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"
This reverts commit 305684.
This patch breaks extra/tools/clang-tidy
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305688 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Basic/SourceLocation.h | 122 | ||||
-rw-r--r-- | include/clang/Frontend/DiagnosticRenderer.h | 81 | ||||
-rw-r--r-- | include/clang/Frontend/TextDiagnostic.h | 43 |
3 files changed, 118 insertions, 128 deletions
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index 12aa0e4f57..f0fe4c2706 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -262,65 +262,6 @@ public: bool isInvalid() const { return !isValid(); } }; -/// \brief Represents an unpacked "presumed" location which can be presented -/// to the user. -/// -/// A 'presumed' location can be modified by \#line and GNU line marker -/// directives and is always the expansion point of a normal location. -/// -/// You can get a PresumedLoc from a SourceLocation with SourceManager. -class PresumedLoc { - const char *Filename; - unsigned Line, Col; - SourceLocation IncludeLoc; - -public: - PresumedLoc() : Filename(nullptr) {} - PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL) - : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {} - - /// \brief Return true if this object is invalid or uninitialized. - /// - /// This occurs when created with invalid source locations or when walking - /// off the top of a \#include stack. - bool isInvalid() const { return Filename == nullptr; } - bool isValid() const { return Filename != nullptr; } - - /// \brief Return the presumed filename of this location. - /// - /// This can be affected by \#line etc. - const char *getFilename() const { - assert(isValid()); - return Filename; - } - - /// \brief Return the presumed line number of this location. - /// - /// This can be affected by \#line etc. - unsigned getLine() const { - assert(isValid()); - return Line; - } - - /// \brief Return the presumed column number of this location. - /// - /// This cannot be affected by \#line, but is packaged here for convenience. - unsigned getColumn() const { - assert(isValid()); - return Col; - } - - /// \brief Return the presumed include location of this location. - /// - /// This can be affected by GNU linemarker directives. - SourceLocation getIncludeLoc() const { - assert(isValid()); - return IncludeLoc; - } -}; - -class FileEntry; - /// \brief A SourceLocation and its associated SourceManager. /// /// This is useful for argument passing to functions that expect both objects. @@ -333,12 +274,6 @@ public: explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM) : SourceLocation(Loc), SrcMgr(&SM) {} - bool hasManager() const { - bool hasSrcMgr = SrcMgr != nullptr; - assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no manager"); - return hasSrcMgr; - } - /// \pre This FullSourceLoc has an associated SourceManager. const SourceManager &getManager() const { assert(SrcMgr && "SourceManager is NULL."); @@ -349,13 +284,6 @@ public: FullSourceLoc getExpansionLoc() const; FullSourceLoc getSpellingLoc() const; - FullSourceLoc getFileLoc() const; - std::pair<FullSourceLoc, FullSourceLoc> getImmediateExpansionRange() const; - PresumedLoc getPresumedLoc(bool UseLineDirectives = true) const; - bool isMacroArgExpansion(FullSourceLoc *StartLoc = nullptr) const; - FullSourceLoc getImmediateMacroCallerLoc() const; - std::pair<FullSourceLoc, StringRef> getModuleImportLoc() const; - unsigned getFileOffset() const; unsigned getExpansionLineNumber(bool *Invalid = nullptr) const; unsigned getExpansionColumnNumber(bool *Invalid = nullptr) const; @@ -365,12 +293,6 @@ public: const char *getCharacterData(bool *Invalid = nullptr) const; - unsigned getLineNumber(bool *Invalid = nullptr) const; - unsigned getColumnNumber(bool *Invalid = nullptr) const; - - std::pair<FullSourceLoc, FullSourceLoc> getExpansionRange() const; - - const FileEntry *getFileEntry() const; /// \brief Return a StringRef to the source buffer data for the /// specified FileID. @@ -423,6 +345,50 @@ public: }; +/// \brief Represents an unpacked "presumed" location which can be presented +/// to the user. +/// +/// A 'presumed' location can be modified by \#line and GNU line marker +/// directives and is always the expansion point of a normal location. +/// +/// You can get a PresumedLoc from a SourceLocation with SourceManager. +class PresumedLoc { + const char *Filename; + unsigned Line, Col; + SourceLocation IncludeLoc; +public: + PresumedLoc() : Filename(nullptr) {} + PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL) + : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) { + } + + /// \brief Return true if this object is invalid or uninitialized. + /// + /// This occurs when created with invalid source locations or when walking + /// off the top of a \#include stack. + bool isInvalid() const { return Filename == nullptr; } + bool isValid() const { return Filename != nullptr; } + + /// \brief Return the presumed filename of this location. + /// + /// This can be affected by \#line etc. + const char *getFilename() const { assert(isValid()); return Filename; } + + /// \brief Return the presumed line number of this location. + /// + /// This can be affected by \#line etc. + unsigned getLine() const { assert(isValid()); return Line; } + + /// \brief Return the presumed column number of this location. + /// + /// This cannot be affected by \#line, but is packaged here for convenience. + unsigned getColumn() const { assert(isValid()); return Col; } + + /// \brief Return the presumed include location of this location. + /// + /// This can be affected by GNU linemarker directives. + SourceLocation getIncludeLoc() const { assert(isValid()); return IncludeLoc; } +}; } // end namespace clang diff --git a/include/clang/Frontend/DiagnosticRenderer.h b/include/clang/Frontend/DiagnosticRenderer.h index 54a3d692b3..2588feb2b8 100644 --- a/include/clang/Frontend/DiagnosticRenderer.h +++ b/include/clang/Frontend/DiagnosticRenderer.h @@ -70,27 +70,33 @@ protected: DiagnosticOptions *DiagOpts); virtual ~DiagnosticRenderer(); - - virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, + + virtual void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<CharSourceRange> Ranges, + const SourceManager *SM, DiagOrStoredDiag Info) = 0; - - virtual void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, + + virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef<CharSourceRange> Ranges) = 0; + ArrayRef<CharSourceRange> Ranges, + const SourceManager &SM) = 0; - virtual void emitCodeContext(FullSourceLoc Loc, + virtual void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level, - SmallVectorImpl<CharSourceRange> &Ranges, - ArrayRef<FixItHint> Hints) = 0; - - virtual void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) = 0; - virtual void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName) = 0; - virtual void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName) = 0; + SmallVectorImpl<CharSourceRange>& Ranges, + ArrayRef<FixItHint> Hints, + const SourceManager &SM) = 0; + + virtual void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, + const SourceManager &SM) = 0; + virtual void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) = 0; + virtual void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) = 0; virtual void beginDiagnostic(DiagOrStoredDiag D, DiagnosticsEngine::Level Level) {} @@ -100,21 +106,25 @@ protected: private: void emitBasicNote(StringRef Message); - void emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc, - DiagnosticsEngine::Level Level); - void emitIncludeStackRecursively(FullSourceLoc Loc); - void emitImportStack(FullSourceLoc Loc); - void emitImportStackRecursively(FullSourceLoc Loc, StringRef ModuleName); + void emitIncludeStack(SourceLocation Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, const SourceManager &SM); + void emitIncludeStackRecursively(SourceLocation Loc, const SourceManager &SM); + void emitImportStack(SourceLocation Loc, const SourceManager &SM); + void emitImportStackRecursively(SourceLocation Loc, StringRef ModuleName, + const SourceManager &SM); void emitModuleBuildStack(const SourceManager &SM); - void emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, - ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints); - void emitSingleMacroExpansion(FullSourceLoc Loc, + void emitCaret(SourceLocation Loc, DiagnosticsEngine::Level Level, + ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints, + const SourceManager &SM); + void emitSingleMacroExpansion(SourceLocation Loc, DiagnosticsEngine::Level Level, - ArrayRef<CharSourceRange> Ranges); - void emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + ArrayRef<CharSourceRange> Ranges, + const SourceManager &SM); + void emitMacroExpansions(SourceLocation Loc, + DiagnosticsEngine::Level Level, ArrayRef<CharSourceRange> Ranges, - ArrayRef<FixItHint> Hints); - + ArrayRef<FixItHint> Hints, + const SourceManager &SM); public: /// \brief Emit a diagnostic. /// @@ -130,9 +140,10 @@ public: /// \param FixItHints The FixIt hints active for this diagnostic. /// \param SM The SourceManager; will be null if the diagnostic came from the /// frontend, thus \p Loc will be invalid. - void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level, + void emitDiagnostic(SourceLocation Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> FixItHints, + const SourceManager *SM, DiagOrStoredDiag D = (Diagnostic *)nullptr); void emitStoredDiagnostic(StoredDiagnostic &Diag); @@ -148,15 +159,19 @@ public: ~DiagnosticNoteRenderer() override; - void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override; + void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, + const SourceManager &SM) override; - void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName) override; + void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) override; - void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName) override; + void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) override; - virtual void emitNote(FullSourceLoc Loc, StringRef Message) = 0; + virtual void emitNote(SourceLocation Loc, StringRef Message, + const SourceManager *SM) = 0; }; } // end clang namespace #endif diff --git a/include/clang/Frontend/TextDiagnostic.h b/include/clang/Frontend/TextDiagnostic.h index 1bbfe9fa02..9b108c28bd 100644 --- a/include/clang/Frontend/TextDiagnostic.h +++ b/include/clang/Frontend/TextDiagnostic.h @@ -75,35 +75,44 @@ public: unsigned Columns, bool ShowColors); protected: - void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, - DiagnosticsEngine::Level Level, StringRef Message, + void emitDiagnosticMessage(SourceLocation Loc,PresumedLoc PLoc, + DiagnosticsEngine::Level Level, + StringRef Message, ArrayRef<CharSourceRange> Ranges, + const SourceManager *SM, DiagOrStoredDiag D) override; - void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, + void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, - ArrayRef<CharSourceRange> Ranges) override; - - void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, - SmallVectorImpl<CharSourceRange> &Ranges, - ArrayRef<FixItHint> Hints) override { - emitSnippetAndCaret(Loc, Level, Ranges, Hints); + ArrayRef<CharSourceRange> Ranges, + const SourceManager &SM) override; + + void emitCodeContext(SourceLocation Loc, + DiagnosticsEngine::Level Level, + SmallVectorImpl<CharSourceRange>& Ranges, + ArrayRef<FixItHint> Hints, + const SourceManager &SM) override { + emitSnippetAndCaret(Loc, Level, Ranges, Hints, SM); } - void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override; + void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc, + const SourceManager &SM) override; - void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName) override; + void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) override; - void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, - StringRef ModuleName) override; + void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc, + StringRef ModuleName, + const SourceManager &SM) override; private: void emitFilename(StringRef Filename, const SourceManager &SM); - void emitSnippetAndCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, - SmallVectorImpl<CharSourceRange> &Ranges, - ArrayRef<FixItHint> Hints); + void emitSnippetAndCaret(SourceLocation Loc, DiagnosticsEngine::Level Level, + SmallVectorImpl<CharSourceRange>& Ranges, + ArrayRef<FixItHint> Hints, + const SourceManager &SM); void emitSnippet(StringRef SourceLine); |