diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-02 17:35:06 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-02 17:35:06 +0000 |
commit | bdcd637c29ec1540f912ea6860c88b910e78c329 (patch) | |
tree | 05002c136b0c19e0a6e9625b3f12750d2f89e806 /lib/AST/Type.cpp | |
parent | 987798ad1d5db2a8ec26cd5bbe434b35ad32659c (diff) |
add a common base class "PointerLikeType" for PointerType and ReferenceType,
allowing them to be treated the same in some contexts. A suggestion for a
better name is welcome :)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49100 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 9411cd8be6..40b376bbd9 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -155,6 +155,24 @@ const FunctionType *Type::getAsFunctionType() const { return getDesugaredType()->getAsFunctionType(); } +const PointerLikeType *Type::getAsPointerLikeType() const { + // If this is directly a pointer-like type, return it. + if (const PointerLikeType *PTy = dyn_cast<PointerLikeType>(this)) + return PTy; + + // If the canonical form of this type isn't the right kind, reject it. + if (!isa<PointerLikeType>(CanonicalType)) { + // Look through type qualifiers + if (isa<PointerLikeType>(CanonicalType.getUnqualifiedType())) + return CanonicalType.getUnqualifiedType()->getAsPointerLikeType(); + return 0; + } + + // If this is a typedef for a pointer type, strip the typedef off without + // losing all typedef information. + return getDesugaredType()->getAsPointerLikeType(); +} + const PointerType *Type::getAsPointerType() const { // If this is directly a pointer type, return it. if (const PointerType *PTy = dyn_cast<PointerType>(this)) @@ -796,10 +814,10 @@ void PointerType::getAsStringInternal(std::string &S) const { // Handle things like 'int (*A)[4];' correctly. // FIXME: this should include vectors, but vectors use attributes I guess. - if (isa<ArrayType>(PointeeType.getTypePtr())) + if (isa<ArrayType>(getPointeeType())) S = '(' + S + ')'; - PointeeType.getAsStringInternal(S); + getPointeeType().getAsStringInternal(S); } void ReferenceType::getAsStringInternal(std::string &S) const { @@ -807,10 +825,10 @@ void ReferenceType::getAsStringInternal(std::string &S) const { // Handle things like 'int (&A)[4];' correctly. // FIXME: this should include vectors, but vectors use attributes I guess. - if (isa<ArrayType>(ReferenceeType.getTypePtr())) + if (isa<ArrayType>(getPointeeType())) S = '(' + S + ')'; - ReferenceeType.getAsStringInternal(S); + getPointeeType().getAsStringInternal(S); } void ConstantArrayType::getAsStringInternal(std::string &S) const { |