diff options
author | John McCall <rjmccall@apple.com> | 2009-10-15 22:37:38 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-10-15 22:37:38 +0000 |
commit | a6f56429aa9a02e71426e99db8b0ae94d0115215 (patch) | |
tree | 8acfe9a5ce326b456f500a77d9dfdfa925574e7e | |
parent | e622554767b56d9dbe61ae07dda839db1803df34 (diff) |
ConcreteTypeLoc subclasses which call getInnerTypeLoc() should get a
compile-time error now; moreover, remove the need for an explicit hasInnerType()
call. Thanks to Doug Gregor for the metaprogramming approach.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84215 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/TypeLoc.h | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 3735eee476..d97886961d 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -196,9 +196,10 @@ public: /// getExtraLocalDataSize(); getExtraLocalData() will then point to /// this extra memory. /// -/// TypeLocs with an inner type should override hasInnerType() and -/// getInnerType(); getInnerTypeLoc() will then point to this inner -/// type's location data. +/// TypeLocs with an inner type should define +/// QualType getInnerType() const +/// and getInnerTypeLoc() will then point to this inner type's +/// location data. template <class Base, class Derived, class TypeClass, class LocalData> class ConcreteTypeLoc : public Base { @@ -253,26 +254,24 @@ protected: return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize(); } - bool hasInnerType() const { - return false; - } + struct HasNoInnerType {}; + HasNoInnerType getInnerType() const { return HasNoInnerType(); } TypeLoc getInnerTypeLoc() const { - assert(asDerived()->hasInnerType()); return TypeLoc(asDerived()->getInnerType(), getNonLocalData()); } private: unsigned getInnerTypeSize() const { - if (asDerived()->hasInnerType()) - return getInnerTypeLoc().getFullDataSize(); + return getInnerTypeSize(asDerived()->getInnerType()); + } + + unsigned getInnerTypeSize(HasNoInnerType _) const { return 0; } - // Required here because my metaprogramming is too weak to avoid it. - QualType getInnerType() const { - assert(0 && "getInnerType() not overridden"); - return QualType(); + unsigned getInnerTypeSize(QualType _) const { + return getInnerTypeLoc().getFullDataSize(); } }; @@ -413,7 +412,6 @@ public: return getNumProtocols() * sizeof(SourceLocation); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getBaseType(); } }; @@ -448,7 +446,6 @@ public: return SourceRange(getStarLoc(), getStarLoc()); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getPointeeType(); } }; @@ -483,7 +480,6 @@ public: return SourceRange(getCaretLoc(), getCaretLoc()); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getPointeeType(); } }; @@ -518,7 +514,6 @@ public: return SourceRange(getStarLoc(), getStarLoc()); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getPointeeType(); } }; @@ -553,7 +548,6 @@ public: return SourceRange(getAmpLoc(), getAmpLoc()); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getPointeeType(); } }; @@ -615,7 +609,6 @@ public: return getNumArgs() * sizeof(ParmVarDecl*); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getResultType(); } }; @@ -664,7 +657,6 @@ public: return SourceRange(getLBracketLoc(), getRBracketLoc()); } - bool hasInnerType() const { return true; } QualType getInnerType() const { return getTypePtr()->getElementType(); } }; |