Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Type.cpp - Type representation and manipulation ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements type-related functionality. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | #include "clang/AST/Type.h" |
Argyrios Kyrtzidis | 49aa7ff | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Steve Naroff | 980e508 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringExtras.h" |
Ted Kremenek | 7360fda | 2008-09-18 23:09:54 +0000 | [diff] [blame] | 20 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 23 | bool QualType::isConstant(ASTContext &Ctx) const { |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 24 | if (isConstQualified()) |
| 25 | return true; |
| 26 | |
| 27 | if (getTypePtr()->isArrayType()) |
| 28 | return Ctx.getAsArrayType(*this)->getElementType().isConstant(Ctx); |
| 29 | |
| 30 | return false; |
| 31 | } |
| 32 | |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 33 | void Type::Destroy(ASTContext& C) { delete this; } |
| 34 | |
| 35 | void FunctionTypeProto::Destroy(ASTContext& C) { |
| 36 | // Destroy the object, but don't call delete. These are malloc'd. |
| 37 | this->~FunctionTypeProto(); |
| 38 | free(this); |
| 39 | } |
| 40 | |
| 41 | void VariableArrayType::Destroy(ASTContext& C) { |
| 42 | SizeExpr->Destroy(C); |
| 43 | delete this; |
| 44 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 45 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 46 | void DependentSizedArrayType::Destroy(ASTContext& C) { |
| 47 | SizeExpr->Destroy(C); |
| 48 | delete this; |
| 49 | } |
Chris Lattner | c63a1f2 | 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 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +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 | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 93 | if (const ASQualType *AS = dyn_cast<ASQualType>(CanonicalType)) |
| 94 | return AS->getBaseType()->isVoidType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 95 | return false; |
| 96 | } |
| 97 | |
| 98 | bool Type::isObjectType() const { |
| 99 | if (isa<FunctionType>(CanonicalType)) |
| 100 | return false; |
Chris Lattner | 4bbce99 | 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(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | bool Type::isDerivedType() const { |
| 107 | switch (CanonicalType->getTypeClass()) { |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 108 | case ASQual: |
| 109 | return cast<ASQualType>(CanonicalType)->getBaseType()->isDerivedType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 110 | case Pointer: |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 111 | case VariableArray: |
| 112 | case ConstantArray: |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 113 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 114 | case FunctionProto: |
| 115 | case FunctionNoProto: |
| 116 | case Reference: |
| 117 | return true; |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 118 | case Tagged: |
| 119 | return !cast<TagType>(CanonicalType)->getDecl()->isEnum(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 120 | default: |
| 121 | return false; |
| 122 | } |
| 123 | } |
| 124 | |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 125 | bool Type::isClassType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 126 | if (const RecordType *RT = getAsRecordType()) |
| 127 | return RT->getDecl()->isClass(); |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 128 | return false; |
| 129 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 130 | bool Type::isStructureType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 131 | if (const RecordType *RT = getAsRecordType()) |
| 132 | return RT->getDecl()->isStruct(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 133 | return false; |
| 134 | } |
| 135 | bool Type::isUnionType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 136 | if (const RecordType *RT = getAsRecordType()) |
| 137 | return RT->getDecl()->isUnion(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 138 | return false; |
| 139 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 140 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 141 | bool Type::isComplexType() const { |
Steve Naroff | 02f62a9 | 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 | 4bbce99 | 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 | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 146 | return false; |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Steve Naroff | 4cdec1c | 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 | 4bbce99 | 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 | 4cdec1c | 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 | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 163 | return 0; |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 164 | } |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 2a18dfe | 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 | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 171 | return 0; |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 172 | } |
| 173 | |
Steve Naroff | 4cdec1c | 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 | 77878cc | 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 | dea6146 | 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 | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 185 | if (!isa<BuiltinType>(CanonicalType)) { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 186 | // Look through type qualifiers (e.g. ASQualType's). |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 187 | if (isa<BuiltinType>(CanonicalType.getUnqualifiedType())) |
| 188 | return CanonicalType.getUnqualifiedType()->getAsBuiltinType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 189 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 190 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 191 | |
Steve Naroff | 77878cc | 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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 194 | return getDesugaredType()->getAsBuiltinType(); |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 197 | const FunctionType *Type::getAsFunctionType() const { |
Steve Naroff | 7064f5c | 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 | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 201 | |
Chris Lattner | dea6146 | 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 | ebb97e9 | 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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 207 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 208 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 209 | |
Steve Naroff | 7064f5c | 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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 212 | return getDesugaredType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Chris Lattner | b77792e | 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 | bdcd637 | 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 | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 238 | const PointerType *Type::getAsPointerType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +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; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 242 | |
Chris Lattner | dea6146 | 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 | ebb97e9 | 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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 248 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 249 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 250 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 253 | return getDesugaredType()->getAsPointerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Steve Naroff | 5618bd4 | 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 | 2a18dfe | 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 | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 266 | return 0; |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 267 | } |
Steve Naroff | 5618bd4 | 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 | a1d9fde | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 274 | const ReferenceType *Type::getAsReferenceType() const { |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +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 | dea6146 | 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 | ebb97e9 | 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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 284 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 285 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 286 | |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +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 | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 289 | return getDesugaredType()->getAsReferenceType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 292 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 293 | /// array types and types that contain variable array types in their |
| 294 | /// declarator |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 295 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 296 | // A VLA is a variably modified type. |
| 297 | if (isVariableArrayType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 298 | return true; |
| 299 | |
| 300 | // An array can contain a variably modified type |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 301 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 302 | return T->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 303 | |
| 304 | // A pointer can point to a variably modified type |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 305 | if (const PointerType *PT = getAsPointerType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 306 | return PT->getPointeeType()->isVariablyModifiedType(); |
| 307 | |
| 308 | // A function can return a variably modified type |
| 309 | // This one isn't completely obvious, but it follows from the |
| 310 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 311 | // illegal to declare a function returning a variably modified type. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 312 | if (const FunctionType *FT = getAsFunctionType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 313 | return FT->getResultType()->isVariablyModifiedType(); |
| 314 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 315 | return false; |
| 316 | } |
| 317 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 318 | const RecordType *Type::getAsRecordType() const { |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 319 | // If this is directly a reference type, return it. |
| 320 | if (const RecordType *RTy = dyn_cast<RecordType>(this)) |
| 321 | return RTy; |
| 322 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 323 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 324 | if (!isa<RecordType>(CanonicalType)) { |
| 325 | // Look through type qualifiers |
| 326 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 327 | return CanonicalType.getUnqualifiedType()->getAsRecordType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 328 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 329 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 330 | |
| 331 | // If this is a typedef for a record type, strip the typedef off without |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 332 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 333 | return getDesugaredType()->getAsRecordType(); |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 336 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 337 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 338 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 339 | if (RT->getDecl()->isStruct()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 340 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 341 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 342 | |
| 343 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 344 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 345 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 346 | return 0; |
| 347 | |
| 348 | // If this is a typedef for a structure type, strip the typedef off without |
| 349 | // losing all typedef information. |
| 350 | return getDesugaredType()->getAsStructureType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 351 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 352 | // Look through type qualifiers |
| 353 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 354 | return CanonicalType.getUnqualifiedType()->getAsStructureType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 355 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 358 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 359 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 360 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 361 | if (RT->getDecl()->isUnion()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 362 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 363 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 364 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 365 | // If the canonical form of this type isn't the right kind, reject it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 366 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 367 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 368 | return 0; |
| 369 | |
| 370 | // If this is a typedef for a union type, strip the typedef off without |
| 371 | // losing all typedef information. |
| 372 | return getDesugaredType()->getAsUnionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 373 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 374 | |
| 375 | // Look through type qualifiers |
| 376 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 377 | return CanonicalType.getUnqualifiedType()->getAsUnionType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 378 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Eli Friedman | ad74a75 | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 381 | const EnumType *Type::getAsEnumType() const { |
| 382 | // Check the canonicalized unqualified type directly; the more complex |
| 383 | // version is unnecessary because there isn't any typedef information |
| 384 | // to preserve. |
| 385 | return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType()); |
| 386 | } |
| 387 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 388 | const ComplexType *Type::getAsComplexType() const { |
| 389 | // Are we directly a complex type? |
| 390 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |
| 391 | return CTy; |
| 392 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 393 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 394 | if (!isa<ComplexType>(CanonicalType)) { |
| 395 | // Look through type qualifiers |
| 396 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 397 | return CanonicalType.getUnqualifiedType()->getAsComplexType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 398 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 399 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 400 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 401 | // If this is a typedef for a complex type, strip the typedef off without |
| 402 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 403 | return getDesugaredType()->getAsComplexType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 406 | const VectorType *Type::getAsVectorType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 407 | // Are we directly a vector type? |
| 408 | if (const VectorType *VTy = dyn_cast<VectorType>(this)) |
| 409 | return VTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 410 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 411 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 412 | if (!isa<VectorType>(CanonicalType)) { |
| 413 | // Look through type qualifiers |
| 414 | if (isa<VectorType>(CanonicalType.getUnqualifiedType())) |
| 415 | return CanonicalType.getUnqualifiedType()->getAsVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 416 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 417 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 418 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 419 | // If this is a typedef for a vector type, strip the typedef off without |
| 420 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 421 | return getDesugaredType()->getAsVectorType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 424 | const ExtVectorType *Type::getAsExtVectorType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 425 | // Are we directly an OpenCU vector type? |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 426 | if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this)) |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 427 | return VTy; |
| 428 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 429 | // If the canonical form of this type isn't the right kind, reject it. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 430 | if (!isa<ExtVectorType>(CanonicalType)) { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 431 | // Look through type qualifiers |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 432 | if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType())) |
| 433 | return CanonicalType.getUnqualifiedType()->getAsExtVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 434 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 435 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 436 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 437 | // If this is a typedef for an extended vector type, strip the typedef off |
| 438 | // without losing all typedef information. |
| 439 | return getDesugaredType()->getAsExtVectorType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 440 | } |
| 441 | |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 442 | const ObjCInterfaceType *Type::getAsObjCInterfaceType() const { |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 443 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 444 | // type pointer if it is the right class. There is no typedef information to |
| 445 | // return and these cannot be Address-space qualified. |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 446 | return dyn_cast<ObjCInterfaceType>(CanonicalType); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | const ObjCQualifiedInterfaceType * |
| 450 | Type::getAsObjCQualifiedInterfaceType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 451 | // There is no sugar for ObjCQualifiedInterfaceType's, just return the |
| 452 | // canonical type pointer if it is the right class. |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 453 | return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType); |
| 454 | } |
| 455 | |
| 456 | const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const { |
| 457 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 458 | // type pointer if it is the right class. |
| 459 | return dyn_cast<ObjCQualifiedIdType>(CanonicalType); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 462 | const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const { |
| 463 | // There is no sugar for template type parameters, so just return |
| 464 | // the canonical type pointer if it is the right class. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 465 | // FIXME: can these be address-space qualified? |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 466 | return dyn_cast<TemplateTypeParmType>(CanonicalType); |
| 467 | } |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 468 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 469 | bool Type::isIntegerType() const { |
| 470 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 471 | return BT->getKind() >= BuiltinType::Bool && |
| 472 | BT->getKind() <= BuiltinType::LongLong; |
| 473 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 474 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 475 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 476 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 477 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 478 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 479 | return VT->getElementType()->isIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 480 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 481 | return ASQT->getBaseType()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 485 | bool Type::isIntegralType() const { |
| 486 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 487 | return BT->getKind() >= BuiltinType::Bool && |
| 488 | BT->getKind() <= BuiltinType::LongLong; |
| 489 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 490 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 491 | return true; // Complete enum types are integral. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 492 | // FIXME: In C++, enum types are never integral. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 493 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 494 | return ASQT->getBaseType()->isIntegralType(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 495 | return false; |
| 496 | } |
| 497 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 498 | bool Type::isEnumeralType() const { |
| 499 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 500 | return TT->getDecl()->isEnum(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 501 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 502 | return ASQT->getBaseType()->isEnumeralType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 503 | return false; |
| 504 | } |
| 505 | |
| 506 | bool Type::isBooleanType() const { |
| 507 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 508 | return BT->getKind() == BuiltinType::Bool; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 509 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 510 | return ASQT->getBaseType()->isBooleanType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | |
| 514 | bool Type::isCharType() const { |
| 515 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 516 | return BT->getKind() == BuiltinType::Char_U || |
| 517 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 518 | BT->getKind() == BuiltinType::Char_S || |
| 519 | BT->getKind() == BuiltinType::SChar; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 520 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 521 | return ASQT->getBaseType()->isCharType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 522 | return false; |
| 523 | } |
| 524 | |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 525 | bool Type::isWideCharType() const { |
| 526 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 527 | return BT->getKind() == BuiltinType::WChar; |
| 528 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 529 | return ASQT->getBaseType()->isWideCharType(); |
| 530 | return false; |
| 531 | } |
| 532 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 533 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 534 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 535 | /// an enum decl which has a signed representation, or a vector of signed |
| 536 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 537 | bool Type::isSignedIntegerType() const { |
| 538 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 539 | return BT->getKind() >= BuiltinType::Char_S && |
| 540 | BT->getKind() <= BuiltinType::LongLong; |
| 541 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 542 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 543 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 544 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 545 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 546 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 547 | return VT->getElementType()->isSignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 548 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 549 | return ASQT->getBaseType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 550 | return false; |
| 551 | } |
| 552 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 553 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 554 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 555 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 556 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 557 | bool Type::isUnsignedIntegerType() const { |
| 558 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 559 | return BT->getKind() >= BuiltinType::Bool && |
| 560 | BT->getKind() <= BuiltinType::ULongLong; |
| 561 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 562 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 563 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 564 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 565 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 566 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 567 | return VT->getElementType()->isUnsignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 568 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 569 | return ASQT->getBaseType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 570 | return false; |
| 571 | } |
| 572 | |
| 573 | bool Type::isFloatingType() const { |
| 574 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 575 | return BT->getKind() >= BuiltinType::Float && |
| 576 | BT->getKind() <= BuiltinType::LongDouble; |
| 577 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 578 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 579 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 580 | return VT->getElementType()->isFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 581 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 582 | return ASQT->getBaseType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 583 | return false; |
| 584 | } |
| 585 | |
| 586 | bool Type::isRealFloatingType() const { |
| 587 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 588 | return BT->getKind() >= BuiltinType::Float && |
| 589 | BT->getKind() <= BuiltinType::LongDouble; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 590 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 591 | return VT->getElementType()->isRealFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 592 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 593 | return ASQT->getBaseType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 594 | return false; |
| 595 | } |
| 596 | |
| 597 | bool Type::isRealType() const { |
| 598 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 599 | return BT->getKind() >= BuiltinType::Bool && |
| 600 | BT->getKind() <= BuiltinType::LongDouble; |
| 601 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 602 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 603 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 604 | return VT->getElementType()->isRealType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 605 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 606 | return ASQT->getBaseType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 607 | return false; |
| 608 | } |
| 609 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 610 | bool Type::isArithmeticType() const { |
| 611 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | a7fbf72 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 612 | return BT->getKind() >= BuiltinType::Bool && |
| 613 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 614 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 615 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 616 | // If a body isn't seen by the time we get here, return false. |
| 617 | return ET->getDecl()->isDefinition(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 618 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 619 | return ASQT->getBaseType()->isArithmeticType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 620 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 621 | } |
| 622 | |
| 623 | bool Type::isScalarType() const { |
| 624 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 625 | return BT->getKind() != BuiltinType::Void; |
| 626 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 627 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 628 | // are not treated as scalar types. |
| 629 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 630 | return true; |
| 631 | return false; |
| 632 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 633 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 634 | return ASQT->getBaseType()->isScalarType(); |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 635 | return isa<PointerType>(CanonicalType) || |
| 636 | isa<BlockPointerType>(CanonicalType) || |
| 637 | isa<ComplexType>(CanonicalType) || |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 638 | isa<ObjCQualifiedIdType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | bool Type::isAggregateType() const { |
| 642 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 643 | if (TT->getDecl()->isStruct()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 644 | return true; |
| 645 | return false; |
| 646 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 647 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 648 | return ASQT->getBaseType()->isAggregateType(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 649 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 652 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 653 | /// according to the rules of C99 6.7.5p3. It is not legal to call this on |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 654 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 655 | bool Type::isConstantSizeType() const { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 656 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 657 | return ASQT->getBaseType()->isConstantSizeType(); |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 658 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 659 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 660 | // The VAT must have a size, as it is known to be complete. |
| 661 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 665 | /// - a type that can describe objects, but which lacks information needed to |
| 666 | /// determine its size. |
| 667 | bool Type::isIncompleteType() const { |
| 668 | switch (CanonicalType->getTypeClass()) { |
| 669 | default: return false; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 670 | case ASQual: |
| 671 | return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 672 | case Builtin: |
| 673 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 674 | // be completed. |
| 675 | return isVoidType(); |
| 676 | case Tagged: |
| 677 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 678 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 679 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 680 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 681 | // An array of unknown size is an incomplete type (C99 6.2.5p22). |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 682 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 686 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 687 | bool Type::isPODType() const { |
| 688 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 689 | // We return false for that case. |
| 690 | if (isIncompleteType()) |
| 691 | return false; |
| 692 | |
| 693 | switch (CanonicalType->getTypeClass()) { |
| 694 | // Everything not explicitly mentioned is not POD. |
| 695 | default: return false; |
| 696 | case ASQual: |
| 697 | return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType(); |
| 698 | case VariableArray: |
| 699 | case ConstantArray: |
| 700 | // IncompleteArray is caught by isIncompleteType() above. |
| 701 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 702 | |
| 703 | case Builtin: |
| 704 | case Complex: |
| 705 | case Pointer: |
| 706 | case Vector: |
| 707 | case ExtVector: |
| 708 | // FIXME: pointer-to-member |
| 709 | return true; |
| 710 | |
| 711 | case Tagged: |
| 712 | if (isEnumeralType()) |
| 713 | return true; |
| 714 | if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>( |
| 715 | cast<TagType>(CanonicalType)->getDecl())) |
| 716 | return RDecl->isPOD(); |
| 717 | // C struct/union is POD. |
| 718 | return true; |
| 719 | } |
| 720 | } |
| 721 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 722 | bool Type::isPromotableIntegerType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame^] | 723 | if (const BuiltinType *BT = getAsBuiltinType()) |
| 724 | switch (BT->getKind()) { |
| 725 | case BuiltinType::Bool: |
| 726 | case BuiltinType::Char_S: |
| 727 | case BuiltinType::Char_U: |
| 728 | case BuiltinType::SChar: |
| 729 | case BuiltinType::UChar: |
| 730 | case BuiltinType::Short: |
| 731 | case BuiltinType::UShort: |
| 732 | return true; |
| 733 | default: |
| 734 | return false; |
| 735 | } |
| 736 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | const char *BuiltinType::getName() const { |
| 740 | switch (getKind()) { |
| 741 | default: assert(0 && "Unknown builtin type!"); |
| 742 | case Void: return "void"; |
| 743 | case Bool: return "_Bool"; |
| 744 | case Char_S: return "char"; |
| 745 | case Char_U: return "char"; |
| 746 | case SChar: return "signed char"; |
| 747 | case Short: return "short"; |
| 748 | case Int: return "int"; |
| 749 | case Long: return "long"; |
| 750 | case LongLong: return "long long"; |
| 751 | case UChar: return "unsigned char"; |
| 752 | case UShort: return "unsigned short"; |
| 753 | case UInt: return "unsigned int"; |
| 754 | case ULong: return "unsigned long"; |
| 755 | case ULongLong: return "unsigned long long"; |
| 756 | case Float: return "float"; |
| 757 | case Double: return "double"; |
| 758 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 759 | case WChar: return "wchar_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 760 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 761 | case Dependent: return "<dependent type>"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 765 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 766 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 767 | unsigned NumArgs, bool isVariadic, |
| 768 | unsigned TypeQuals) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 769 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 770 | for (unsigned i = 0; i != NumArgs; ++i) |
| 771 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 772 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 773 | ID.AddInteger(TypeQuals); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 777 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
| 778 | getTypeQuals()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 779 | } |
| 780 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 781 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 782 | const ObjCInterfaceDecl *Decl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 783 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 784 | unsigned NumProtocols) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 785 | ID.AddPointer(Decl); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 786 | for (unsigned i = 0; i != NumProtocols; i++) |
| 787 | ID.AddPointer(protocols[i]); |
| 788 | } |
| 789 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 790 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 791 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 794 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 62f5f7f | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 795 | ObjCProtocolDecl **protocols, |
| 796 | unsigned NumProtocols) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 797 | for (unsigned i = 0; i != NumProtocols; i++) |
| 798 | ID.AddPointer(protocols[i]); |
| 799 | } |
| 800 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 801 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 802 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 803 | } |
| 804 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 805 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 806 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 807 | /// sum of the type qualifiers, so if you have: |
| 808 | /// typedef const int A; |
| 809 | /// typedef volatile A B; |
| 810 | /// looking through the typedefs for B will give you "const volatile A". |
| 811 | /// |
| 812 | QualType TypedefType::LookThroughTypedefs() const { |
| 813 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 814 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 815 | if (!isa<TypedefType>(FirstType)) |
| 816 | return FirstType; |
| 817 | |
| 818 | // Otherwise, do the fully general loop. |
| 819 | unsigned TypeQuals = 0; |
| 820 | const TypedefType *TDT = this; |
| 821 | while (1) { |
| 822 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
Chris Lattner | f46699c | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 823 | |
| 824 | |
| 825 | /// FIXME: |
| 826 | /// FIXME: This is incorrect for ASQuals! |
| 827 | /// FIXME: |
| 828 | TypeQuals |= CurType.getCVRQualifiers(); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 829 | |
| 830 | TDT = dyn_cast<TypedefType>(CurType); |
| 831 | if (TDT == 0) |
| 832 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 833 | } |
| 834 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 835 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 836 | TypeOfExpr::TypeOfExpr(Expr *E, QualType can) |
| 837 | : Type(TypeOfExp, can, E->isTypeDependent()), TOExpr(E) { |
| 838 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 839 | } |
| 840 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 841 | bool RecordType::classof(const TagType *TT) { |
| 842 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Argyrios Kyrtzidis | 49aa7ff | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 845 | bool CXXRecordType::classof(const TagType *TT) { |
| 846 | return isa<CXXRecordDecl>(TT->getDecl()); |
| 847 | } |
| 848 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 849 | bool EnumType::classof(const TagType *TT) { |
| 850 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 853 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 854 | //===----------------------------------------------------------------------===// |
| 855 | // Type Printing |
| 856 | //===----------------------------------------------------------------------===// |
| 857 | |
| 858 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 859 | std::string R = "identifier"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 860 | getAsStringInternal(R); |
| 861 | if (msg) |
| 862 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 863 | else |
| 864 | fprintf(stderr, "%s\n", R.c_str()); |
| 865 | } |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 866 | void QualType::dump() const { |
| 867 | dump(""); |
| 868 | } |
| 869 | |
| 870 | void Type::dump() const { |
| 871 | std::string S = "identifier"; |
| 872 | getAsStringInternal(S); |
| 873 | fprintf(stderr, "%s\n", S.c_str()); |
| 874 | } |
| 875 | |
| 876 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 877 | |
| 878 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 879 | // Note: funkiness to ensure we get a space only between quals. |
| 880 | bool NonePrinted = true; |
| 881 | if (TypeQuals & QualType::Const) |
| 882 | S += "const", NonePrinted = false; |
| 883 | if (TypeQuals & QualType::Volatile) |
| 884 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 885 | if (TypeQuals & QualType::Restrict) |
| 886 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 887 | } |
| 888 | |
| 889 | void QualType::getAsStringInternal(std::string &S) const { |
| 890 | if (isNull()) { |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 891 | S += "NULL TYPE"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 892 | return; |
| 893 | } |
| 894 | |
| 895 | // Print qualifiers as appropriate. |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 896 | if (unsigned Tq = getCVRQualifiers()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 897 | std::string TQS; |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 898 | AppendTypeQualList(TQS, Tq); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 899 | if (!S.empty()) |
| 900 | S = TQS + ' ' + S; |
| 901 | else |
| 902 | S = TQS; |
| 903 | } |
| 904 | |
| 905 | getTypePtr()->getAsStringInternal(S); |
| 906 | } |
| 907 | |
| 908 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 909 | if (S.empty()) { |
| 910 | S = getName(); |
| 911 | } else { |
| 912 | // Prefix the basic type, e.g. 'int X'. |
| 913 | S = ' ' + S; |
| 914 | S = getName() + S; |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 919 | ElementType->getAsStringInternal(S); |
| 920 | S = "_Complex " + S; |
| 921 | } |
| 922 | |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 923 | void ASQualType::getAsStringInternal(std::string &S) const { |
| 924 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
| 925 | BaseType->getAsStringInternal(S); |
| 926 | } |
| 927 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 928 | void PointerType::getAsStringInternal(std::string &S) const { |
| 929 | S = '*' + S; |
| 930 | |
| 931 | // Handle things like 'int (*A)[4];' correctly. |
| 932 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 933 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 934 | S = '(' + S + ')'; |
| 935 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 936 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 939 | void BlockPointerType::getAsStringInternal(std::string &S) const { |
| 940 | S = '^' + S; |
| 941 | PointeeType.getAsStringInternal(S); |
| 942 | } |
| 943 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 944 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 945 | S = '&' + S; |
| 946 | |
| 947 | // Handle things like 'int (&A)[4];' correctly. |
| 948 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 949 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 950 | S = '(' + S + ')'; |
| 951 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 952 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 955 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 956 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 957 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 958 | S += ']'; |
| 959 | |
| 960 | getElementType().getAsStringInternal(S); |
| 961 | } |
| 962 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 963 | void IncompleteArrayType::getAsStringInternal(std::string &S) const { |
| 964 | S += "[]"; |
| 965 | |
| 966 | getElementType().getAsStringInternal(S); |
| 967 | } |
| 968 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 969 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 970 | S += '['; |
| 971 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 972 | if (getIndexTypeQualifier()) { |
| 973 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 974 | S += ' '; |
| 975 | } |
| 976 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 977 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 978 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 979 | else if (getSizeModifier() == Star) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 980 | S += '*'; |
| 981 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 982 | if (getSizeExpr()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 983 | std::string SStr; |
| 984 | llvm::raw_string_ostream s(SStr); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 985 | getSizeExpr()->printPretty(s); |
| 986 | S += s.str(); |
| 987 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 988 | S += ']'; |
| 989 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 990 | getElementType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 991 | } |
| 992 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 993 | void DependentSizedArrayType::getAsStringInternal(std::string &S) const { |
| 994 | S += '['; |
| 995 | |
| 996 | if (getIndexTypeQualifier()) { |
| 997 | AppendTypeQualList(S, getIndexTypeQualifier()); |
| 998 | S += ' '; |
| 999 | } |
| 1000 | |
| 1001 | if (getSizeModifier() == Static) |
| 1002 | S += "static"; |
| 1003 | else if (getSizeModifier() == Star) |
| 1004 | S += '*'; |
| 1005 | |
| 1006 | if (getSizeExpr()) { |
| 1007 | std::string SStr; |
| 1008 | llvm::raw_string_ostream s(SStr); |
| 1009 | getSizeExpr()->printPretty(s); |
| 1010 | S += s.str(); |
| 1011 | } |
| 1012 | S += ']'; |
| 1013 | |
| 1014 | getElementType().getAsStringInternal(S); |
| 1015 | } |
| 1016 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1017 | void VectorType::getAsStringInternal(std::string &S) const { |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1018 | // FIXME: We prefer to print the size directly here, but have no way |
| 1019 | // to get the size of the type. |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1020 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1021 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1022 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1025 | void ExtVectorType::getAsStringInternal(std::string &S) const { |
| 1026 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1027 | S += llvm::utostr_32(NumElements); |
| 1028 | S += ")))"; |
| 1029 | ElementType.getAsStringInternal(S); |
| 1030 | } |
| 1031 | |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1032 | void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1033 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1034 | InnerString = ' ' + InnerString; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1035 | std::string Str; |
| 1036 | llvm::raw_string_ostream s(Str); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1037 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 1bfd5cc | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 1038 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1041 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 1042 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1043 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1044 | std::string Tmp; |
| 1045 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1046 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1049 | void FunctionTypeNoProto::getAsStringInternal(std::string &S) const { |
| 1050 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1051 | if (!S.empty()) |
| 1052 | S = "(" + S + ")"; |
| 1053 | |
| 1054 | S += "()"; |
| 1055 | getResultType().getAsStringInternal(S); |
| 1056 | } |
| 1057 | |
| 1058 | void FunctionTypeProto::getAsStringInternal(std::string &S) const { |
| 1059 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1060 | if (!S.empty()) |
| 1061 | S = "(" + S + ")"; |
| 1062 | |
| 1063 | S += "("; |
| 1064 | std::string Tmp; |
| 1065 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1066 | if (i) S += ", "; |
| 1067 | getArgType(i).getAsStringInternal(Tmp); |
| 1068 | S += Tmp; |
| 1069 | Tmp.clear(); |
| 1070 | } |
| 1071 | |
| 1072 | if (isVariadic()) { |
| 1073 | if (getNumArgs()) |
| 1074 | S += ", "; |
| 1075 | S += "..."; |
| 1076 | } else if (getNumArgs() == 0) { |
| 1077 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1078 | S += "void"; |
| 1079 | } |
| 1080 | |
| 1081 | S += ")"; |
| 1082 | getResultType().getAsStringInternal(S); |
| 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 1087 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1088 | InnerString = ' ' + InnerString; |
| 1089 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1090 | } |
| 1091 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1092 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const { |
| 1093 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1094 | InnerString = ' ' + InnerString; |
| 1095 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1096 | } |
| 1097 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1098 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1099 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1100 | InnerString = ' ' + InnerString; |
| 1101 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1102 | } |
| 1103 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1104 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1105 | std::string &InnerString) const { |
Fariborz Jahanian | dfbcce2 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 1106 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1107 | InnerString = ' ' + InnerString; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1108 | std::string ObjCQIString = getDecl()->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1109 | ObjCQIString += '<'; |
Chris Lattner | cdce6d1 | 2008-07-21 05:19:23 +0000 | [diff] [blame] | 1110 | bool isFirst = true; |
| 1111 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1112 | if (isFirst) |
| 1113 | isFirst = false; |
| 1114 | else |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1115 | ObjCQIString += ','; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1116 | ObjCQIString += (*I)->getNameAsString(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1117 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1118 | ObjCQIString += '>'; |
| 1119 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Chris Lattner | e8e4f92 | 2008-07-25 23:07:18 +0000 | [diff] [blame] | 1122 | void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1123 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1124 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1125 | std::string ObjCQIString = "id"; |
| 1126 | ObjCQIString += '<'; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1127 | int num = getNumProtocols(); |
| 1128 | for (int i = 0; i < num; i++) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1129 | ObjCQIString += getProtocols(i)->getNameAsString(); |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1130 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1131 | ObjCQIString += ','; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1132 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1133 | ObjCQIString += '>'; |
| 1134 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1137 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 1138 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1139 | InnerString = ' ' + InnerString; |
| 1140 | |
| 1141 | const char *Kind = getDecl()->getKindName(); |
| 1142 | const char *ID; |
| 1143 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 1144 | ID = II->getName(); |
| 1145 | else |
| 1146 | ID = "<anonymous>"; |
| 1147 | |
| 1148 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 1149 | } |