diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-16 23:03:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-16 23:03:56 +0000 |
commit | a50bd54164393ca3cd08016e7099bdeb531b5014 (patch) | |
tree | ba85ec33df5eae9428ebba46c7b338ac196fdf59 /include/clang/Basic/SourceLocation.h | |
parent | 4abb87ef149b98b5762eadaaf10c1ccf35dc7c41 (diff) |
Make FullSourceLoc derive from SourceLocation instead of
containing one. Containment is generally better than derivation,
but in this case FullSourceLoc really 'isa' SourceLocation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62375 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceLocation.h')
-rw-r--r-- | include/clang/Basic/SourceLocation.h | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h index 22d5ff5d3a..b3cb787544 100644 --- a/include/clang/Basic/SourceLocation.h +++ b/include/clang/Basic/SourceLocation.h @@ -207,24 +207,18 @@ public: static SourceRange ReadVal(llvm::Deserializer& D); }; -/// FullSourceLoc - A tuple containing both a SourceLocation -/// and its associated SourceManager. Useful for argument passing to functions -/// that expect both objects. -class FullSourceLoc { - SourceLocation Loc; +/// FullSourceLoc - A SourceLocation and its associated SourceManager. Useful +/// for argument passing to functions that expect both objects. +class FullSourceLoc : public SourceLocation { SourceManager* SrcMgr; public: // Creates a FullSourceLoc where isValid() returns false. - explicit FullSourceLoc() - : Loc(SourceLocation()), SrcMgr((SourceManager*) 0) {} + explicit FullSourceLoc() : SrcMgr((SourceManager*) 0) {} - explicit FullSourceLoc(SourceLocation loc, SourceManager& smgr) - : Loc(loc), SrcMgr(&smgr) {} + explicit FullSourceLoc(SourceLocation Loc, SourceManager &SM) + : SourceLocation(Loc), SrcMgr(&SM) {} - bool isValid() const { return Loc.isValid(); } - bool isInvalid() const { return Loc.isInvalid(); } - - SourceLocation getLocation() const { return Loc; } + SourceLocation getLocation() const { return *this; } SourceManager& getManager() { assert (SrcMgr && "SourceManager is NULL."); @@ -258,19 +252,20 @@ public: bool isInSystemHeader() const; - bool operator==(const FullSourceLoc& RHS) const { - return SrcMgr == RHS.SrcMgr && Loc == RHS.Loc; - } - - bool operator!=(const FullSourceLoc& RHS) const { - return SrcMgr != RHS.SrcMgr || Loc != RHS.Loc; - } - /// Prints information about this FullSourceLoc to stderr. Useful for /// debugging. void dump() const; }; +inline bool operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { + return LHS.getRawEncoding() == RHS.getRawEncoding() && + &LHS.getManager() == &RHS.getManager(); +} + +inline bool operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { + return !(LHS == RHS); +} + } // end namespace clang #endif |