summaryrefslogtreecommitdiffstats
path: root/include/clang/Basic/SourceLocation.h
diff options
context:
space:
mode:
authorChristof Douma <Christof.Douma@arm.com>2017-06-27 09:50:38 +0000
committerChristof Douma <Christof.Douma@arm.com>2017-06-27 09:50:38 +0000
commit8aeb339f3264950654be882dbcf83ad0d47e5ffa (patch)
treeedf9f7f3f56462aeb88982a019763fb8220fd804 /include/clang/Basic/SourceLocation.h
parent701e513011cbfa9004b16038f3b72bef1bdc6dd2 (diff)
Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc""
This reverts commit r305688 meaning it reintroduces r305684. To repeat: [NFC] Refactor DiagnosticRenderer to use FullSourceLoc Move the DiagnosticRenderer and its dependents to using FullSourceLocs instead of a SourceLocation and SourceManager pointer. The changeset is rather large but entirely mechanical. This is step one to allow DiagnosticRenderer to take either llvm::SMLocs or clang::SourceLocations. This breaks clang-tidy and clng-query which will be fixed in a commit soon after. Patch by Sanne Wouda Differential Revision: https://reviews.llvm.org/D31709 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306384 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceLocation.h')
-rw-r--r--include/clang/Basic/SourceLocation.h122
1 files changed, 78 insertions, 44 deletions
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h
index f0fe4c2706..12aa0e4f57 100644
--- a/include/clang/Basic/SourceLocation.h
+++ b/include/clang/Basic/SourceLocation.h
@@ -262,6 +262,65 @@ 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.
@@ -274,6 +333,12 @@ 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.");
@@ -284,6 +349,13 @@ 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;
@@ -293,6 +365,12 @@ 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.
@@ -345,50 +423,6 @@ 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