Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Type.cpp - Type representation and manipulation ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements type-related functionality. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Nuno Lopes | a7bbf56 | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 15 | #include "clang/AST/Type.h" |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Steve Naroff | 3fafa10 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Douglas Gregor | 279272e | 2009-02-04 19:02:06 +0000 | [diff] [blame^] | 18 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
Ted Kremenek | bb7a3d9 | 2008-09-18 23:09:54 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 24 | bool QualType::isConstant(ASTContext &Ctx) const { |
Nuno Lopes | a7bbf56 | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 25 | if (isConstQualified()) |
| 26 | return true; |
| 27 | |
| 28 | if (getTypePtr()->isArrayType()) |
| 29 | return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx); |
| 30 | |
| 31 | return false; |
| 32 | } |
| 33 | |
Ted Kremenek | c70e7d0 | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 34 | void Type::Destroy(ASTContext& C) { |
| 35 | this->~Type(); |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 36 | C.Deallocate(this); |
Ted Kremenek | db4d597 | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void VariableArrayType::Destroy(ASTContext& C) { |
| 40 | SizeExpr->Destroy(C); |
Ted Kremenek | c70e7d0 | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 41 | this->~VariableArrayType(); |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 42 | C.Deallocate(this); |
Ted Kremenek | db4d597 | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 43 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 44 | |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 45 | void DependentSizedArrayType::Destroy(ASTContext& C) { |
| 46 | SizeExpr->Destroy(C); |
Ted Kremenek | c70e7d0 | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 47 | this->~DependentSizedArrayType(); |
Steve Naroff | 5abb028 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 48 | C.Deallocate(this); |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 49 | } |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 50 | |
| 51 | /// getArrayElementTypeNoTypeQual - If this is an array type, return the |
| 52 | /// element type of the array, potentially with type qualifiers missing. |
| 53 | /// This method should never be used when type qualifiers are meaningful. |
| 54 | const Type *Type::getArrayElementTypeNoTypeQual() const { |
| 55 | // If this is directly an array type, return it. |
| 56 | if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) |
| 57 | return ATy->getElementType().getTypePtr(); |
| 58 | |
| 59 | // If the canonical form of this type isn't the right kind, reject it. |
| 60 | if (!isa<ArrayType>(CanonicalType)) { |
| 61 | // Look through type qualifiers |
| 62 | if (ArrayType *AT = dyn_cast<ArrayType>(CanonicalType.getUnqualifiedType())) |
| 63 | return AT->getElementType().getTypePtr(); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | // If this is a typedef for an array type, strip the typedef off without |
| 68 | // losing all typedef information. |
| 69 | return getDesugaredType()->getArrayElementTypeNoTypeQual(); |
| 70 | } |
| 71 | |
| 72 | /// getDesugaredType - Return the specified type with any "sugar" removed from |
| 73 | /// type type. This takes off typedefs, typeof's etc. If the outer level of |
| 74 | /// the type is already concrete, it returns it unmodified. This is similar |
| 75 | /// to getting the canonical type, but it doesn't remove *all* typedefs. For |
| 76 | /// example, it return "T*" as "T*", (not as "int*"), because the pointer is |
| 77 | /// concrete. |
| 78 | QualType Type::getDesugaredType() const { |
| 79 | if (const TypedefType *TDT = dyn_cast<TypedefType>(this)) |
| 80 | return TDT->LookThroughTypedefs(); |
| 81 | if (const TypeOfExpr *TOE = dyn_cast<TypeOfExpr>(this)) |
| 82 | return TOE->getUnderlyingExpr()->getType(); |
| 83 | if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this)) |
| 84 | return TOT->getUnderlyingType(); |
| 85 | // FIXME: remove this cast. |
| 86 | return QualType(const_cast<Type*>(this), 0); |
| 87 | } |
| 88 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 89 | /// isVoidType - Helper method to determine if this is the 'void' type. |
| 90 | bool Type::isVoidType() const { |
| 91 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 92 | return BT->getKind() == BuiltinType::Void; |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 93 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 94 | return AS->getBaseType()->isVoidType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool Type::isObjectType() const { |
| 99 | if (isa<FunctionType>(CanonicalType)) |
| 100 | return false; |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 101 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 102 | return AS->getBaseType()->isObjectType(); |
| 103 | return !CanonicalType->isIncompleteType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | bool Type::isDerivedType() const { |
| 107 | switch (CanonicalType->getTypeClass()) { |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 108 | case ASQual: |
| 109 | return cast<ASQualType>(CanonicalType)->getBaseType()->isDerivedType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 110 | case Pointer: |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 111 | case VariableArray: |
| 112 | case ConstantArray: |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 113 | case IncompleteArray: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 114 | case FunctionProto: |
| 115 | case FunctionNoProto: |
| 116 | case Reference: |
| 117 | return true; |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 118 | case Tagged: |
| 119 | return !cast<TagType>(CanonicalType)->getDecl()->isEnum(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 120 | default: |
| 121 | return false; |
| 122 | } |
| 123 | } |
| 124 | |
Chris Lattner | 2e78db3 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 125 | bool Type::isClassType() const { |
Chris Lattner | 25de19e | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 126 | if (const RecordType *RT = getAsRecordType()) |
| 127 | return RT->getDecl()->isClass(); |
Chris Lattner | 2e78db3 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 128 | return false; |
| 129 | } |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 130 | bool Type::isStructureType() const { |
Chris Lattner | 25de19e | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 131 | if (const RecordType *RT = getAsRecordType()) |
| 132 | return RT->getDecl()->isStruct(); |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 133 | return false; |
| 134 | } |
| 135 | bool Type::isUnionType() const { |
Chris Lattner | 25de19e | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 136 | if (const RecordType *RT = getAsRecordType()) |
| 137 | return RT->getDecl()->isUnion(); |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 138 | return false; |
| 139 | } |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 7a85fa1 | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 141 | bool Type::isComplexType() const { |
Steve Naroff | 4300121 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 142 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 143 | return CT->getElementType()->isFloatingType(); |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 144 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 145 | return AS->getBaseType()->isComplexType(); |
Steve Naroff | 4300121 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 146 | return false; |
Chris Lattner | 7a85fa1 | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Steve Naroff | 36e35e6 | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 149 | bool Type::isComplexIntegerType() const { |
| 150 | // Check for GCC complex integer extension. |
| 151 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 152 | return CT->getElementType()->isIntegerType(); |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 153 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 154 | return AS->getBaseType()->isComplexIntegerType(); |
Steve Naroff | 36e35e6 | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 155 | return false; |
| 156 | } |
| 157 | |
| 158 | const ComplexType *Type::getAsComplexIntegerType() const { |
| 159 | // Are we directly a complex type? |
| 160 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) { |
| 161 | if (CTy->getElementType()->isIntegerType()) |
| 162 | return CTy; |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 163 | return 0; |
Steve Naroff | 36e35e6 | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 164 | } |
Chris Lattner | 976692a | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 166 | // If the canonical form of this type isn't what we want, reject it. |
| 167 | if (!isa<ComplexType>(CanonicalType)) { |
| 168 | // Look through type qualifiers (e.g. ASQualType's). |
| 169 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 170 | return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType(); |
Steve Naroff | 36e35e6 | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 171 | return 0; |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Steve Naroff | 36e35e6 | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 174 | // If this is a typedef for a complex type, strip the typedef off without |
| 175 | // losing all typedef information. |
| 176 | return getDesugaredType()->getAsComplexIntegerType(); |
| 177 | } |
| 178 | |
Steve Naroff | c33c060 | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 179 | const BuiltinType *Type::getAsBuiltinType() const { |
| 180 | // If this is directly a builtin type, return it. |
| 181 | if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this)) |
| 182 | return BTy; |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 183 | |
| 184 | // If the canonical form of this type isn't a builtin type, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 185 | if (!isa<BuiltinType>(CanonicalType)) { |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 186 | // Look through type qualifiers (e.g. ASQualType's). |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 187 | if (isa<BuiltinType>(CanonicalType.getUnqualifiedType())) |
| 188 | return CanonicalType.getUnqualifiedType()->getAsBuiltinType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 189 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 190 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 191 | |
Steve Naroff | c33c060 | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 192 | // If this is a typedef for a builtin type, strip the typedef off without |
| 193 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 194 | return getDesugaredType()->getAsBuiltinType(); |
Steve Naroff | c33c060 | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 197 | const FunctionType *Type::getAsFunctionType() const { |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 198 | // If this is directly a function type, return it. |
| 199 | if (const FunctionType *FTy = dyn_cast<FunctionType>(this)) |
| 200 | return FTy; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 201 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 202 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 203 | if (!isa<FunctionType>(CanonicalType)) { |
| 204 | // Look through type qualifiers |
| 205 | if (isa<FunctionType>(CanonicalType.getUnqualifiedType())) |
| 206 | return CanonicalType.getUnqualifiedType()->getAsFunctionType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 207 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 208 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 209 | |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 210 | // If this is a typedef for a function type, strip the typedef off without |
| 211 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 212 | return getDesugaredType()->getAsFunctionType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Chris Lattner | d5a56aa | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 215 | const FunctionTypeProto *Type::getAsFunctionTypeProto() const { |
| 216 | return dyn_cast_or_null<FunctionTypeProto>(getAsFunctionType()); |
| 217 | } |
| 218 | |
| 219 | |
Chris Lattner | cfac88d | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 220 | const PointerLikeType *Type::getAsPointerLikeType() const { |
| 221 | // If this is directly a pointer-like type, return it. |
| 222 | if (const PointerLikeType *PTy = dyn_cast<PointerLikeType>(this)) |
| 223 | return PTy; |
| 224 | |
| 225 | // If the canonical form of this type isn't the right kind, reject it. |
| 226 | if (!isa<PointerLikeType>(CanonicalType)) { |
| 227 | // Look through type qualifiers |
| 228 | if (isa<PointerLikeType>(CanonicalType.getUnqualifiedType())) |
| 229 | return CanonicalType.getUnqualifiedType()->getAsPointerLikeType(); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | // If this is a typedef for a pointer type, strip the typedef off without |
| 234 | // losing all typedef information. |
| 235 | return getDesugaredType()->getAsPointerLikeType(); |
| 236 | } |
| 237 | |
Chris Lattner | 7931f4a | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 238 | const PointerType *Type::getAsPointerType() const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 239 | // If this is directly a pointer type, return it. |
| 240 | if (const PointerType *PTy = dyn_cast<PointerType>(this)) |
| 241 | return PTy; |
| 242 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 243 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 244 | if (!isa<PointerType>(CanonicalType)) { |
| 245 | // Look through type qualifiers |
| 246 | if (isa<PointerType>(CanonicalType.getUnqualifiedType())) |
| 247 | return CanonicalType.getUnqualifiedType()->getAsPointerType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 248 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 249 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 250 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 251 | // If this is a typedef for a pointer type, strip the typedef off without |
| 252 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 253 | return getDesugaredType()->getAsPointerType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 256 | const BlockPointerType *Type::getAsBlockPointerType() const { |
| 257 | // If this is directly a block pointer type, return it. |
| 258 | if (const BlockPointerType *PTy = dyn_cast<BlockPointerType>(this)) |
| 259 | return PTy; |
| 260 | |
| 261 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 262 | if (!isa<BlockPointerType>(CanonicalType)) { |
| 263 | // Look through type qualifiers |
| 264 | if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType())) |
| 265 | return CanonicalType.getUnqualifiedType()->getAsBlockPointerType(); |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 266 | return 0; |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 267 | } |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 268 | |
| 269 | // If this is a typedef for a block pointer type, strip the typedef off |
| 270 | // without losing all typedef information. |
| 271 | return getDesugaredType()->getAsBlockPointerType(); |
| 272 | } |
| 273 | |
Chris Lattner | f0c4a0a | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 274 | const ReferenceType *Type::getAsReferenceType() const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 275 | // If this is directly a reference type, return it. |
| 276 | if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this)) |
| 277 | return RTy; |
| 278 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 279 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 280 | if (!isa<ReferenceType>(CanonicalType)) { |
| 281 | // Look through type qualifiers |
| 282 | if (isa<ReferenceType>(CanonicalType.getUnqualifiedType())) |
| 283 | return CanonicalType.getUnqualifiedType()->getAsReferenceType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 284 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 285 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 286 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 287 | // If this is a typedef for a reference type, strip the typedef off without |
| 288 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 289 | return getDesugaredType()->getAsReferenceType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Sebastian Redl | 7555503 | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 292 | const MemberPointerType *Type::getAsMemberPointerType() const { |
| 293 | // If this is directly a member pointer type, return it. |
| 294 | if (const MemberPointerType *MTy = dyn_cast<MemberPointerType>(this)) |
| 295 | return MTy; |
| 296 | |
| 297 | // If the canonical form of this type isn't the right kind, reject it. |
| 298 | if (!isa<MemberPointerType>(CanonicalType)) { |
| 299 | // Look through type qualifiers |
| 300 | if (isa<MemberPointerType>(CanonicalType.getUnqualifiedType())) |
| 301 | return CanonicalType.getUnqualifiedType()->getAsMemberPointerType(); |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | // If this is a typedef for a member pointer type, strip the typedef off |
| 306 | // without losing all typedef information. |
| 307 | return getDesugaredType()->getAsMemberPointerType(); |
| 308 | } |
| 309 | |
Eli Friedman | 043e42a | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 310 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 311 | /// array types and types that contain variable array types in their |
| 312 | /// declarator |
Steve Naroff | 5eb879b | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 313 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 314 | // A VLA is a variably modified type. |
| 315 | if (isVariableArrayType()) |
Eli Friedman | 043e42a | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 316 | return true; |
| 317 | |
| 318 | // An array can contain a variably modified type |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 319 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 320 | return T->isVariablyModifiedType(); |
Eli Friedman | 043e42a | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 321 | |
Sebastian Redl | 7555503 | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 322 | // A pointer can point to a variably modified type. |
| 323 | // Also, C++ references and member pointers can point to a variably modified |
| 324 | // type, where VLAs appear as an extension to C++, and should be treated |
| 325 | // correctly. |
| 326 | if (const PointerLikeType *PT = getAsPointerLikeType()) |
Eli Friedman | 043e42a | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 327 | return PT->getPointeeType()->isVariablyModifiedType(); |
Sebastian Redl | 18cffee | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 328 | if (const MemberPointerType *PT = getAsMemberPointerType()) |
| 329 | return PT->getPointeeType()->isVariablyModifiedType(); |
Eli Friedman | 043e42a | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 330 | |
| 331 | // A function can return a variably modified type |
| 332 | // This one isn't completely obvious, but it follows from the |
| 333 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 334 | // illegal to declare a function returning a variably modified type. |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 335 | if (const FunctionType *FT = getAsFunctionType()) |
Eli Friedman | 043e42a | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 336 | return FT->getResultType()->isVariablyModifiedType(); |
| 337 | |
Steve Naroff | 5eb879b | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 341 | const RecordType *Type::getAsRecordType() const { |
Steve Naroff | 2cb6638 | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 342 | // If this is directly a reference type, return it. |
| 343 | if (const RecordType *RTy = dyn_cast<RecordType>(this)) |
| 344 | return RTy; |
| 345 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 346 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 347 | if (!isa<RecordType>(CanonicalType)) { |
| 348 | // Look through type qualifiers |
| 349 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 350 | return CanonicalType.getUnqualifiedType()->getAsRecordType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 351 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 352 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 353 | |
| 354 | // If this is a typedef for a record type, strip the typedef off without |
Steve Naroff | 2cb6638 | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 355 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 356 | return getDesugaredType()->getAsRecordType(); |
Steve Naroff | 2cb6638 | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 359 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 360 | // If this is directly a structure type, return it. |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 361 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 362 | if (RT->getDecl()->isStruct()) |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 363 | return RT; |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 364 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 365 | |
| 366 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 367 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 368 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 369 | return 0; |
| 370 | |
| 371 | // If this is a typedef for a structure type, strip the typedef off without |
| 372 | // losing all typedef information. |
| 373 | return getDesugaredType()->getAsStructureType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 374 | } |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 375 | // Look through type qualifiers |
| 376 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 377 | return CanonicalType.getUnqualifiedType()->getAsStructureType(); |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 378 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 381 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 382 | // If this is directly a union type, return it. |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 383 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 384 | if (RT->getDecl()->isUnion()) |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 385 | return RT; |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 386 | } |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 387 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 388 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 389 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 390 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 391 | return 0; |
| 392 | |
| 393 | // If this is a typedef for a union type, strip the typedef off without |
| 394 | // losing all typedef information. |
| 395 | return getDesugaredType()->getAsUnionType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 396 | } |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 397 | |
| 398 | // Look through type qualifiers |
| 399 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 400 | return CanonicalType.getUnqualifiedType()->getAsUnionType(); |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 401 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 402 | } |
| 403 | |
Eli Friedman | 0832dbc | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 404 | const EnumType *Type::getAsEnumType() const { |
| 405 | // Check the canonicalized unqualified type directly; the more complex |
| 406 | // version is unnecessary because there isn't any typedef information |
| 407 | // to preserve. |
| 408 | return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType()); |
| 409 | } |
| 410 | |
Chris Lattner | 7a85fa1 | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 411 | const ComplexType *Type::getAsComplexType() const { |
| 412 | // Are we directly a complex type? |
| 413 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |
| 414 | return CTy; |
| 415 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 416 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 417 | if (!isa<ComplexType>(CanonicalType)) { |
| 418 | // Look through type qualifiers |
| 419 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 420 | return CanonicalType.getUnqualifiedType()->getAsComplexType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 421 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 422 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 423 | |
Chris Lattner | 7a85fa1 | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 424 | // If this is a typedef for a complex type, strip the typedef off without |
| 425 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 426 | return getDesugaredType()->getAsComplexType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Chris Lattner | e35a104 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 429 | const VectorType *Type::getAsVectorType() const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 430 | // Are we directly a vector type? |
| 431 | if (const VectorType *VTy = dyn_cast<VectorType>(this)) |
| 432 | return VTy; |
| 433 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 434 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 435 | if (!isa<VectorType>(CanonicalType)) { |
| 436 | // Look through type qualifiers |
| 437 | if (isa<VectorType>(CanonicalType.getUnqualifiedType())) |
| 438 | return CanonicalType.getUnqualifiedType()->getAsVectorType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 439 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 440 | } |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 441 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 442 | // If this is a typedef for a vector type, strip the typedef off without |
| 443 | // losing all typedef information. |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 444 | return getDesugaredType()->getAsVectorType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 447 | const ExtVectorType *Type::getAsExtVectorType() const { |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 448 | // Are we directly an OpenCU vector type? |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 449 | if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this)) |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 450 | return VTy; |
| 451 | |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 452 | // If the canonical form of this type isn't the right kind, reject it. |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 453 | if (!isa<ExtVectorType>(CanonicalType)) { |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 454 | // Look through type qualifiers |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 455 | if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType())) |
| 456 | return CanonicalType.getUnqualifiedType()->getAsExtVectorType(); |
Chris Lattner | 2afc72b | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 457 | return 0; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 458 | } |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 459 | |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 460 | // If this is a typedef for an extended vector type, strip the typedef off |
| 461 | // without losing all typedef information. |
| 462 | return getDesugaredType()->getAsExtVectorType(); |
Steve Naroff | 806b319 | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Chris Lattner | b06cf30b | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 465 | const ObjCInterfaceType *Type::getAsObjCInterfaceType() const { |
Chris Lattner | fe1f403 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 466 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 467 | // type pointer if it is the right class. There is no typedef information to |
| 468 | // return and these cannot be Address-space qualified. |
Chris Lattner | fe1f403 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 469 | return dyn_cast<ObjCInterfaceType>(CanonicalType); |
Chris Lattner | b06cf30b | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | const ObjCQualifiedInterfaceType * |
| 473 | Type::getAsObjCQualifiedInterfaceType() const { |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 474 | // There is no sugar for ObjCQualifiedInterfaceType's, just return the |
| 475 | // canonical type pointer if it is the right class. |
Chris Lattner | fe1f403 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 476 | return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType); |
| 477 | } |
| 478 | |
| 479 | const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const { |
| 480 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 481 | // type pointer if it is the right class. |
| 482 | return dyn_cast<ObjCQualifiedIdType>(CanonicalType); |
Chris Lattner | b06cf30b | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 485 | const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const { |
| 486 | // There is no sugar for template type parameters, so just return |
| 487 | // the canonical type pointer if it is the right class. |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 488 | // FIXME: can these be address-space qualified? |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 489 | return dyn_cast<TemplateTypeParmType>(CanonicalType); |
| 490 | } |
Chris Lattner | b06cf30b | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 491 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 492 | bool Type::isIntegerType() const { |
| 493 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 494 | return BT->getKind() >= BuiltinType::Bool && |
| 495 | BT->getKind() <= BuiltinType::LongLong; |
| 496 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | e02e440 | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 497 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 498 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | e02e440 | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 499 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 500 | return true; |
| 501 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 502 | return VT->getElementType()->isIntegerType(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 503 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 504 | return ASQT->getBaseType()->isIntegerType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 505 | return false; |
| 506 | } |
| 507 | |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 508 | bool Type::isIntegralType() const { |
| 509 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 510 | return BT->getKind() >= BuiltinType::Bool && |
| 511 | BT->getKind() <= BuiltinType::LongLong; |
| 512 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | e02e440 | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 513 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 514 | return true; // Complete enum types are integral. |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 515 | // FIXME: In C++, enum types are never integral. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 516 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 517 | return ASQT->getBaseType()->isIntegralType(); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 518 | return false; |
| 519 | } |
| 520 | |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 521 | bool Type::isEnumeralType() const { |
| 522 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 523 | return TT->getDecl()->isEnum(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 524 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 525 | return ASQT->getBaseType()->isEnumeralType(); |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 526 | return false; |
| 527 | } |
| 528 | |
| 529 | bool Type::isBooleanType() const { |
| 530 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 531 | return BT->getKind() == BuiltinType::Bool; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 532 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 533 | return ASQT->getBaseType()->isBooleanType(); |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 534 | return false; |
| 535 | } |
| 536 | |
| 537 | bool Type::isCharType() const { |
| 538 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 539 | return BT->getKind() == BuiltinType::Char_U || |
| 540 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | 25baae4 | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 541 | BT->getKind() == BuiltinType::Char_S || |
| 542 | BT->getKind() == BuiltinType::SChar; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 543 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 544 | return ASQT->getBaseType()->isCharType(); |
Steve Naroff | 8d3b170 | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 545 | return false; |
| 546 | } |
| 547 | |
Douglas Gregor | 1815b3b | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 548 | bool Type::isWideCharType() const { |
| 549 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 550 | return BT->getKind() == BuiltinType::WChar; |
| 551 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 552 | return ASQT->getBaseType()->isWideCharType(); |
| 553 | return false; |
| 554 | } |
| 555 | |
Chris Lattner | bbe686b | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 556 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 557 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 558 | /// an enum decl which has a signed representation, or a vector of signed |
| 559 | /// integer element type. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 560 | bool Type::isSignedIntegerType() const { |
| 561 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 562 | return BT->getKind() >= BuiltinType::Char_S && |
| 563 | BT->getKind() <= BuiltinType::LongLong; |
| 564 | } |
Chris Lattner | bbe686b | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 565 | |
Chris Lattner | b89a74c | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 566 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 567 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Chris Lattner | bbe686b | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 568 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 569 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 570 | return VT->getElementType()->isSignedIntegerType(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 571 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 572 | return ASQT->getBaseType()->isSignedIntegerType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 573 | return false; |
| 574 | } |
| 575 | |
Chris Lattner | bbe686b | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 576 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 577 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 578 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 579 | /// element type. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 580 | bool Type::isUnsignedIntegerType() const { |
| 581 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 582 | return BT->getKind() >= BuiltinType::Bool && |
| 583 | BT->getKind() <= BuiltinType::ULongLong; |
| 584 | } |
Chris Lattner | bbe686b | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 585 | |
Chris Lattner | b89a74c | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 586 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 587 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | bbe686b | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 588 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 589 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 590 | return VT->getElementType()->isUnsignedIntegerType(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 591 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 592 | return ASQT->getBaseType()->isUnsignedIntegerType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | |
| 596 | bool Type::isFloatingType() const { |
| 597 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 598 | return BT->getKind() >= BuiltinType::Float && |
| 599 | BT->getKind() <= BuiltinType::LongDouble; |
| 600 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 9661435 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 601 | return CT->getElementType()->isFloatingType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 602 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 603 | return VT->getElementType()->isFloatingType(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 604 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 605 | return ASQT->getBaseType()->isFloatingType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 606 | return false; |
| 607 | } |
| 608 | |
| 609 | bool Type::isRealFloatingType() const { |
| 610 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 611 | return BT->getKind() >= BuiltinType::Float && |
| 612 | BT->getKind() <= BuiltinType::LongDouble; |
| 613 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 614 | return VT->getElementType()->isRealFloatingType(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 615 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 616 | return ASQT->getBaseType()->isRealFloatingType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 617 | return false; |
| 618 | } |
| 619 | |
| 620 | bool Type::isRealType() const { |
| 621 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 622 | return BT->getKind() >= BuiltinType::Bool && |
| 623 | BT->getKind() <= BuiltinType::LongDouble; |
| 624 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | e02e440 | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 625 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 626 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 627 | return VT->getElementType()->isRealType(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 628 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 629 | return ASQT->getBaseType()->isRealType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 630 | return false; |
| 631 | } |
| 632 | |
| 633 | bool Type::isArithmeticType() const { |
| 634 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | ea5bd34 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 635 | return BT->getKind() >= BuiltinType::Bool && |
| 636 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | b89a74c | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 637 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 638 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 639 | // If a body isn't seen by the time we get here, return false. |
| 640 | return ET->getDecl()->isDefinition(); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 641 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 642 | return ASQT->getBaseType()->isArithmeticType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 643 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 644 | } |
| 645 | |
| 646 | bool Type::isScalarType() const { |
| 647 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 648 | return BT->getKind() != BuiltinType::Void; |
| 649 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | e02e440 | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 650 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 651 | // are not treated as scalar types. |
| 652 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 653 | return true; |
| 654 | return false; |
| 655 | } |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 656 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 657 | return ASQT->getBaseType()->isScalarType(); |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 658 | return isa<PointerType>(CanonicalType) || |
| 659 | isa<BlockPointerType>(CanonicalType) || |
Sebastian Redl | 7555503 | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 660 | isa<MemberPointerType>(CanonicalType) || |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 661 | isa<ComplexType>(CanonicalType) || |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 662 | isa<ObjCQualifiedIdType>(CanonicalType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Douglas Gregor | e7ef500 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 665 | /// \brief Determines whether the type is a C++ aggregate type or C |
| 666 | /// aggregate or union type. |
| 667 | /// |
| 668 | /// An aggregate type is an array or a class type (struct, union, or |
| 669 | /// class) that has no user-declared constructors, no private or |
| 670 | /// protected non-static data members, no base classes, and no virtual |
| 671 | /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type |
| 672 | /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also |
| 673 | /// includes union types. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 674 | bool Type::isAggregateType() const { |
Douglas Gregor | e7ef500 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 675 | if (const CXXRecordType *CXXClassType = dyn_cast<CXXRecordType>(CanonicalType)) |
| 676 | return CXXClassType->getDecl()->isAggregate(); |
| 677 | if (isa<RecordType>(CanonicalType)) |
| 678 | return true; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 679 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 680 | return ASQT->getBaseType()->isAggregateType(); |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 681 | return isa<ArrayType>(CanonicalType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 682 | } |
| 683 | |
Chris Lattner | 0448b4f | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 684 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 685 | /// according to the rules of C99 6.7.5p3. It is not legal to call this on |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 686 | /// incomplete types or dependent types. |
Eli Friedman | 62f67fd | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 687 | bool Type::isConstantSizeType() const { |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 688 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
Eli Friedman | 62f67fd | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 689 | return ASQT->getBaseType()->isConstantSizeType(); |
Chris Lattner | d34599a | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 690 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 691 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 0448b4f | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 692 | // The VAT must have a size, as it is known to be complete. |
| 693 | return !isa<VariableArrayType>(CanonicalType); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 697 | /// - a type that can describe objects, but which lacks information needed to |
| 698 | /// determine its size. |
| 699 | bool Type::isIncompleteType() const { |
| 700 | switch (CanonicalType->getTypeClass()) { |
| 701 | default: return false; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 702 | case ASQual: |
| 703 | return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 704 | case Builtin: |
| 705 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 706 | // be completed. |
| 707 | return isVoidType(); |
| 708 | case Tagged: |
| 709 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 710 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 711 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 712 | case IncompleteArray: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 713 | // An array of unknown size is an incomplete type (C99 6.2.5p22). |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 714 | return true; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
Sebastian Redl | 39c0f6f | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 718 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 719 | bool Type::isPODType() const { |
| 720 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 721 | // We return false for that case. |
| 722 | if (isIncompleteType()) |
| 723 | return false; |
| 724 | |
| 725 | switch (CanonicalType->getTypeClass()) { |
| 726 | // Everything not explicitly mentioned is not POD. |
| 727 | default: return false; |
| 728 | case ASQual: |
| 729 | return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType(); |
| 730 | case VariableArray: |
| 731 | case ConstantArray: |
| 732 | // IncompleteArray is caught by isIncompleteType() above. |
| 733 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 734 | |
| 735 | case Builtin: |
| 736 | case Complex: |
| 737 | case Pointer: |
Sebastian Redl | 7555503 | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 738 | case MemberPointer: |
Sebastian Redl | 39c0f6f | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 739 | case Vector: |
| 740 | case ExtVector: |
Sebastian Redl | 39c0f6f | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 741 | return true; |
| 742 | |
| 743 | case Tagged: |
| 744 | if (isEnumeralType()) |
| 745 | return true; |
| 746 | if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>( |
| 747 | cast<TagType>(CanonicalType)->getDecl())) |
| 748 | return RDecl->isPOD(); |
| 749 | // C struct/union is POD. |
| 750 | return true; |
| 751 | } |
| 752 | } |
| 753 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 754 | bool Type::isPromotableIntegerType() const { |
Chris Lattner | 0f29fa1 | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 755 | if (const BuiltinType *BT = getAsBuiltinType()) |
| 756 | switch (BT->getKind()) { |
| 757 | case BuiltinType::Bool: |
| 758 | case BuiltinType::Char_S: |
| 759 | case BuiltinType::Char_U: |
| 760 | case BuiltinType::SChar: |
| 761 | case BuiltinType::UChar: |
| 762 | case BuiltinType::Short: |
| 763 | case BuiltinType::UShort: |
| 764 | return true; |
| 765 | default: |
| 766 | return false; |
| 767 | } |
| 768 | return false; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | const char *BuiltinType::getName() const { |
| 772 | switch (getKind()) { |
| 773 | default: assert(0 && "Unknown builtin type!"); |
| 774 | case Void: return "void"; |
| 775 | case Bool: return "_Bool"; |
| 776 | case Char_S: return "char"; |
| 777 | case Char_U: return "char"; |
| 778 | case SChar: return "signed char"; |
| 779 | case Short: return "short"; |
| 780 | case Int: return "int"; |
| 781 | case Long: return "long"; |
| 782 | case LongLong: return "long long"; |
| 783 | case UChar: return "unsigned char"; |
| 784 | case UShort: return "unsigned short"; |
| 785 | case UInt: return "unsigned int"; |
| 786 | case ULong: return "unsigned long"; |
| 787 | case ULongLong: return "unsigned long long"; |
| 788 | case Float: return "float"; |
| 789 | case Double: return "double"; |
| 790 | case LongDouble: return "long double"; |
Argiris Kirtzidis | 1f9e210 | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 791 | case WChar: return "wchar_t"; |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 792 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 793 | case Dependent: return "<dependent type>"; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
| 797 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
| 798 | arg_type_iterator ArgTys, |
Argiris Kirtzidis | 4b269b4 | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 799 | unsigned NumArgs, bool isVariadic, |
| 800 | unsigned TypeQuals) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 801 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 802 | for (unsigned i = 0; i != NumArgs; ++i) |
| 803 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 804 | ID.AddInteger(isVariadic); |
Argiris Kirtzidis | 4b269b4 | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 805 | ID.AddInteger(TypeQuals); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) { |
Argiris Kirtzidis | 4b269b4 | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 809 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
| 810 | getTypeQuals()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 811 | } |
| 812 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 813 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | fd5690f | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 814 | const ObjCInterfaceDecl *Decl, |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 815 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 816 | unsigned NumProtocols) { |
Chris Lattner | fd5690f | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 817 | ID.AddPointer(Decl); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 818 | for (unsigned i = 0; i != NumProtocols; i++) |
| 819 | ID.AddPointer(protocols[i]); |
| 820 | } |
| 821 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 822 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | fd5690f | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 823 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 826 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 4a68fe0 | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 827 | ObjCProtocolDecl **protocols, |
| 828 | unsigned NumProtocols) { |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 829 | for (unsigned i = 0; i != NumProtocols; i++) |
| 830 | ID.AddPointer(protocols[i]); |
| 831 | } |
| 832 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 833 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 834 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 835 | } |
| 836 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 837 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 838 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 839 | /// sum of the type qualifiers, so if you have: |
| 840 | /// typedef const int A; |
| 841 | /// typedef volatile A B; |
| 842 | /// looking through the typedefs for B will give you "const volatile A". |
| 843 | /// |
| 844 | QualType TypedefType::LookThroughTypedefs() const { |
| 845 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 846 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 847 | if (!isa<TypedefType>(FirstType)) |
| 848 | return FirstType; |
| 849 | |
| 850 | // Otherwise, do the fully general loop. |
| 851 | unsigned TypeQuals = 0; |
| 852 | const TypedefType *TDT = this; |
| 853 | while (1) { |
| 854 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
Chris Lattner | 35fef52 | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 855 | |
| 856 | |
| 857 | /// FIXME: |
| 858 | /// FIXME: This is incorrect for ASQuals! |
| 859 | /// FIXME: |
| 860 | TypeQuals |= CurType.getCVRQualifiers(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 861 | |
| 862 | TDT = dyn_cast<TypedefType>(CurType); |
| 863 | if (TDT == 0) |
| 864 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 865 | } |
| 866 | } |
| 867 | |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 868 | TypeOfExpr::TypeOfExpr(Expr *E, QualType can) |
| 869 | : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) { |
| 870 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 871 | } |
| 872 | |
Chris Lattner | eae0eaa | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 873 | bool RecordType::classof(const TagType *TT) { |
| 874 | return isa<RecordDecl>(TT->getDecl()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 877 | bool CXXRecordType::classof(const TagType *TT) { |
| 878 | return isa<CXXRecordDecl>(TT->getDecl()); |
| 879 | } |
| 880 | |
Chris Lattner | eae0eaa | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 881 | bool EnumType::classof(const TagType *TT) { |
| 882 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 1baaf13 | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Anders Carlsson | 0dd0e37 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 885 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 886 | //===----------------------------------------------------------------------===// |
| 887 | // Type Printing |
| 888 | //===----------------------------------------------------------------------===// |
| 889 | |
| 890 | void QualType::dump(const char *msg) const { |
Chris Lattner | a92a2b6 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 891 | std::string R = "identifier"; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 892 | getAsStringInternal(R); |
| 893 | if (msg) |
| 894 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 895 | else |
| 896 | fprintf(stderr, "%s\n", R.c_str()); |
| 897 | } |
Chris Lattner | a55e321 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 898 | void QualType::dump() const { |
| 899 | dump(""); |
| 900 | } |
| 901 | |
| 902 | void Type::dump() const { |
| 903 | std::string S = "identifier"; |
| 904 | getAsStringInternal(S); |
| 905 | fprintf(stderr, "%s\n", S.c_str()); |
| 906 | } |
| 907 | |
| 908 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 909 | |
| 910 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 911 | // Note: funkiness to ensure we get a space only between quals. |
| 912 | bool NonePrinted = true; |
| 913 | if (TypeQuals & QualType::Const) |
| 914 | S += "const", NonePrinted = false; |
| 915 | if (TypeQuals & QualType::Volatile) |
| 916 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 917 | if (TypeQuals & QualType::Restrict) |
| 918 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 919 | } |
| 920 | |
| 921 | void QualType::getAsStringInternal(std::string &S) const { |
| 922 | if (isNull()) { |
Douglas Gregor | 62ae25a | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 923 | S += "NULL TYPE"; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 924 | return; |
| 925 | } |
| 926 | |
| 927 | // Print qualifiers as appropriate. |
Gabor Greif | e85f79b | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 928 | if (unsigned Tq = getCVRQualifiers()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 929 | std::string TQS; |
Gabor Greif | e85f79b | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 930 | AppendTypeQualList(TQS, Tq); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 931 | if (!S.empty()) |
| 932 | S = TQS + ' ' + S; |
| 933 | else |
| 934 | S = TQS; |
| 935 | } |
| 936 | |
| 937 | getTypePtr()->getAsStringInternal(S); |
| 938 | } |
| 939 | |
| 940 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 941 | if (S.empty()) { |
| 942 | S = getName(); |
| 943 | } else { |
| 944 | // Prefix the basic type, e.g. 'int X'. |
| 945 | S = ' ' + S; |
| 946 | S = getName() + S; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 951 | ElementType->getAsStringInternal(S); |
| 952 | S = "_Complex " + S; |
| 953 | } |
| 954 | |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 955 | void ASQualType::getAsStringInternal(std::string &S) const { |
| 956 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
| 957 | BaseType->getAsStringInternal(S); |
| 958 | } |
| 959 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 960 | void PointerType::getAsStringInternal(std::string &S) const { |
| 961 | S = '*' + S; |
| 962 | |
| 963 | // Handle things like 'int (*A)[4];' correctly. |
| 964 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | cfac88d | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 965 | if (isa<ArrayType>(getPointeeType())) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 966 | S = '(' + S + ')'; |
| 967 | |
Chris Lattner | cfac88d | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 968 | getPointeeType().getAsStringInternal(S); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 971 | void BlockPointerType::getAsStringInternal(std::string &S) const { |
| 972 | S = '^' + S; |
| 973 | PointeeType.getAsStringInternal(S); |
| 974 | } |
| 975 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 976 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 977 | S = '&' + S; |
| 978 | |
| 979 | // Handle things like 'int (&A)[4];' correctly. |
| 980 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | cfac88d | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 981 | if (isa<ArrayType>(getPointeeType())) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 982 | S = '(' + S + ')'; |
| 983 | |
Chris Lattner | cfac88d | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 984 | getPointeeType().getAsStringInternal(S); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Sebastian Redl | 7555503 | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 987 | void MemberPointerType::getAsStringInternal(std::string &S) const { |
| 988 | std::string C; |
| 989 | Class->getAsStringInternal(C); |
| 990 | C += "::*"; |
| 991 | S = C + S; |
| 992 | |
| 993 | // Handle things like 'int (&A)[4];' correctly. |
| 994 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 995 | if (isa<ArrayType>(getPointeeType())) |
| 996 | S = '(' + S + ')'; |
| 997 | |
| 998 | getPointeeType().getAsStringInternal(S); |
| 999 | } |
| 1000 | |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1001 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 1002 | S += '['; |
Steve Naroff | 6dfe761 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 1003 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1004 | S += ']'; |
| 1005 | |
| 1006 | getElementType().getAsStringInternal(S); |
| 1007 | } |
| 1008 | |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 1009 | void IncompleteArrayType::getAsStringInternal(std::string &S) const { |
| 1010 | S += "[]"; |
| 1011 | |
| 1012 | getElementType().getAsStringInternal(S); |
| 1013 | } |
| 1014 | |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1015 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1016 | S += '['; |
| 1017 | |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1018 | if (getIndexTypeQualifier()) { |
| 1019 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1020 | S += ' '; |
| 1021 | } |
| 1022 | |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1023 | if (getSizeModifier() == Static) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1024 | S += "static"; |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1025 | else if (getSizeModifier() == Star) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1026 | S += '*'; |
| 1027 | |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1028 | if (getSizeExpr()) { |
Ted Kremenek | 7b6f67b | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1029 | std::string SStr; |
| 1030 | llvm::raw_string_ostream s(SStr); |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1031 | getSizeExpr()->printPretty(s); |
| 1032 | S += s.str(); |
| 1033 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1034 | S += ']'; |
| 1035 | |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1036 | getElementType().getAsStringInternal(S); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1039 | void DependentSizedArrayType::getAsStringInternal(std::string &S) const { |
| 1040 | S += '['; |
| 1041 | |
| 1042 | if (getIndexTypeQualifier()) { |
| 1043 | AppendTypeQualList(S, getIndexTypeQualifier()); |
| 1044 | S += ' '; |
| 1045 | } |
| 1046 | |
| 1047 | if (getSizeModifier() == Static) |
| 1048 | S += "static"; |
| 1049 | else if (getSizeModifier() == Star) |
| 1050 | S += '*'; |
| 1051 | |
| 1052 | if (getSizeExpr()) { |
| 1053 | std::string SStr; |
| 1054 | llvm::raw_string_ostream s(SStr); |
| 1055 | getSizeExpr()->printPretty(s); |
| 1056 | S += s.str(); |
| 1057 | } |
| 1058 | S += ']'; |
| 1059 | |
| 1060 | getElementType().getAsStringInternal(S); |
| 1061 | } |
| 1062 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1063 | void VectorType::getAsStringInternal(std::string &S) const { |
Daniel Dunbar | ce4a679 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1064 | // FIXME: We prefer to print the size directly here, but have no way |
| 1065 | // to get the size of the type. |
Chris Lattner | c4856a6 | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1066 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | ce4a679 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1067 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1068 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1071 | void ExtVectorType::getAsStringInternal(std::string &S) const { |
| 1072 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | c11705f | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1073 | S += llvm::utostr_32(NumElements); |
| 1074 | S += ")))"; |
| 1075 | ElementType.getAsStringInternal(S); |
| 1076 | } |
| 1077 | |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1078 | void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 5b52892 | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1079 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1080 | InnerString = ' ' + InnerString; |
Ted Kremenek | 7b6f67b | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1081 | std::string Str; |
| 1082 | llvm::raw_string_ostream s(Str); |
Chris Lattner | 9557878 | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1083 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 6e8227b | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 1084 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Steve Naroff | 5b52892 | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1087 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 1088 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1089 | InnerString = ' ' + InnerString; |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1090 | std::string Tmp; |
| 1091 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 5b52892 | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1092 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1095 | void FunctionTypeNoProto::getAsStringInternal(std::string &S) const { |
| 1096 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1097 | if (!S.empty()) |
| 1098 | S = "(" + S + ")"; |
| 1099 | |
| 1100 | S += "()"; |
| 1101 | getResultType().getAsStringInternal(S); |
| 1102 | } |
| 1103 | |
| 1104 | void FunctionTypeProto::getAsStringInternal(std::string &S) const { |
| 1105 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1106 | if (!S.empty()) |
| 1107 | S = "(" + S + ")"; |
| 1108 | |
| 1109 | S += "("; |
| 1110 | std::string Tmp; |
| 1111 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1112 | if (i) S += ", "; |
| 1113 | getArgType(i).getAsStringInternal(Tmp); |
| 1114 | S += Tmp; |
| 1115 | Tmp.clear(); |
| 1116 | } |
| 1117 | |
| 1118 | if (isVariadic()) { |
| 1119 | if (getNumArgs()) |
| 1120 | S += ", "; |
| 1121 | S += "..."; |
| 1122 | } else if (getNumArgs() == 0) { |
| 1123 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1124 | S += "void"; |
| 1125 | } |
| 1126 | |
| 1127 | S += ")"; |
| 1128 | getResultType().getAsStringInternal(S); |
| 1129 | } |
| 1130 | |
| 1131 | |
| 1132 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 1133 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1134 | InnerString = ' ' + InnerString; |
| 1135 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1136 | } |
| 1137 | |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1138 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const { |
| 1139 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1140 | InnerString = ' ' + InnerString; |
| 1141 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1142 | } |
| 1143 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1144 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1145 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1146 | InnerString = ' ' + InnerString; |
| 1147 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1148 | } |
| 1149 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1150 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1151 | std::string &InnerString) const { |
Fariborz Jahanian | 84a34f5 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 1152 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1153 | InnerString = ' ' + InnerString; |
Chris Lattner | 6c5ec62 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1154 | std::string ObjCQIString = getDecl()->getNameAsString(); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1155 | ObjCQIString += '<'; |
Chris Lattner | a006ffc | 2008-07-21 05:19:23 +0000 | [diff] [blame] | 1156 | bool isFirst = true; |
| 1157 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1158 | if (isFirst) |
| 1159 | isFirst = false; |
| 1160 | else |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1161 | ObjCQIString += ','; |
Chris Lattner | 6c5ec62 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1162 | ObjCQIString += (*I)->getNameAsString(); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1163 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1164 | ObjCQIString += '>'; |
| 1165 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Chris Lattner | 4b639c0 | 2008-07-25 23:07:18 +0000 | [diff] [blame] | 1168 | void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const { |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1169 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1170 | InnerString = ' ' + InnerString; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1171 | std::string ObjCQIString = "id"; |
| 1172 | ObjCQIString += '<'; |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1173 | int num = getNumProtocols(); |
| 1174 | for (int i = 0; i < num; i++) { |
Chris Lattner | 6c5ec62 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1175 | ObjCQIString += getProtocols(i)->getNameAsString(); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1176 | if (i < num-1) |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1177 | ObjCQIString += ','; |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1178 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1179 | ObjCQIString += '>'; |
| 1180 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1183 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 1184 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1185 | InnerString = ' ' + InnerString; |
| 1186 | |
| 1187 | const char *Kind = getDecl()->getKindName(); |
| 1188 | const char *ID; |
| 1189 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 1190 | ID = II->getName(); |
| 1191 | else |
| 1192 | ID = "<anonymous>"; |
| 1193 | |
| 1194 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 1195 | } |