diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-07-16 19:58:26 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-07-16 19:58:26 +0000 |
commit | 1a1a6e2bd4c5aefd7fd643cf25915f9623a02e59 (patch) | |
tree | 333652f464e28debc770fc4b30bc5b8f74254d28 /lib/AST/Type.cpp | |
parent | e41611aa2237d06a0ef61db4528fb2883a8defcd (diff) |
Add member template 'Type::getAs<T>', which converts a Type* to a respective T*.
This method is intended to eventually replace the individual
Type::getAsXXXType<> methods.
The motivation behind this change is twofold:
1) Reduce redundant implementations of Type::getAsXXXType() methods. Most of
them are basically copy-and-paste.
2) By centralizing the implementation of the getAs<Type> logic we can more
smoothly move over to Doug Gregor's proposed canonical type smart pointer
scheme.
Along with this patch:
a) Removed 'Type::getAsPointerType()'; now clients use getAs<PointerType>.
b) Removed 'Type::getAsBlockPointerTypE()'; now clients use getAs<BlockPointerType>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76098 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 44 |
1 files changed, 4 insertions, 40 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 18fa76bf25..13d0cb03e8 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -202,7 +202,7 @@ bool Type::isStructureType() const { return false; } bool Type::isVoidPointerType() const { - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs<PointerType>()) return PT->getPointeeType()->isVoidType(); return false; } @@ -296,51 +296,15 @@ const FunctionProtoType *Type::getAsFunctionProtoType() const { } QualType Type::getPointeeType() const { - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs<PointerType>()) return PT->getPointeeType(); if (const ObjCObjectPointerType *OPT = getAsObjCObjectPointerType()) return OPT->getPointeeType(); - if (const BlockPointerType *BPT = getAsBlockPointerType()) + if (const BlockPointerType *BPT = getAs<BlockPointerType>()) return BPT->getPointeeType(); return QualType(); } -const PointerType *Type::getAsPointerType() const { - // If this is directly a pointer type, return it. - if (const PointerType *PTy = dyn_cast<PointerType>(this)) - return PTy; - - // If the canonical form of this type isn't the right kind, reject it. - if (!isa<PointerType>(CanonicalType)) { - // Look through type qualifiers - if (isa<PointerType>(CanonicalType.getUnqualifiedType())) - return CanonicalType.getUnqualifiedType()->getAsPointerType(); - return 0; - } - - // If this is a typedef for a pointer type, strip the typedef off without - // losing all typedef information. - return cast<PointerType>(getDesugaredType()); -} - -const BlockPointerType *Type::getAsBlockPointerType() const { - // If this is directly a block pointer type, return it. - if (const BlockPointerType *PTy = dyn_cast<BlockPointerType>(this)) - return PTy; - - // If the canonical form of this type isn't the right kind, reject it. - if (!isa<BlockPointerType>(CanonicalType)) { - // Look through type qualifiers - if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType())) - return CanonicalType.getUnqualifiedType()->getAsBlockPointerType(); - return 0; - } - - // If this is a typedef for a block pointer type, strip the typedef off - // without losing all typedef information. - return cast<BlockPointerType>(getDesugaredType()); -} - const ReferenceType *Type::getAsReferenceType() const { // If this is directly a reference type, return it. if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this)) @@ -429,7 +393,7 @@ bool Type::isVariablyModifiedType() const { // Also, C++ references and member pointers can point to a variably modified // type, where VLAs appear as an extension to C++, and should be treated // correctly. - if (const PointerType *PT = getAsPointerType()) + if (const PointerType *PT = getAs<PointerType>()) return PT->getPointeeType()->isVariablyModifiedType(); if (const ReferenceType *RT = getAsReferenceType()) return RT->getPointeeType()->isVariablyModifiedType(); |