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" |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
Ted Kremenek | 7360fda | 2008-09-18 23:09:54 +0000 | [diff] [blame] | 21 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 24 | bool QualType::isConstant(ASTContext &Ctx) const { |
Nuno Lopes | b381aac | 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 | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 34 | void Type::Destroy(ASTContext& C) { |
| 35 | this->~Type(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 36 | C.Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void VariableArrayType::Destroy(ASTContext& C) { |
| 40 | SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 41 | this->~VariableArrayType(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 42 | C.Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 43 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 45 | void DependentSizedArrayType::Destroy(ASTContext& C) { |
| 46 | SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 47 | this->~DependentSizedArrayType(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 48 | C.Deallocate(this); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 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(); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 81 | if (const TypeOfExprType *TOE = dyn_cast<TypeOfExprType>(this)) |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 82 | return TOE->getUnderlyingExpr()->getType(); |
| 83 | if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this)) |
| 84 | return TOT->getUnderlyingType(); |
Douglas Gregor | 5cdf821 | 2009-02-12 00:15:05 +0000 | [diff] [blame] | 85 | if (const ClassTemplateSpecializationType *Spec |
| 86 | = dyn_cast<ClassTemplateSpecializationType>(this)) |
| 87 | return Spec->getCanonicalTypeInternal(); |
| 88 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 89 | // FIXME: remove this cast. |
| 90 | return QualType(const_cast<Type*>(this), 0); |
| 91 | } |
| 92 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 93 | /// isVoidType - Helper method to determine if this is the 'void' type. |
| 94 | bool Type::isVoidType() const { |
| 95 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 96 | return BT->getKind() == BuiltinType::Void; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 97 | if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType)) |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 98 | return AS->getBaseType()->isVoidType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 99 | return false; |
| 100 | } |
| 101 | |
| 102 | bool Type::isObjectType() const { |
Sebastian Redl | 00e68e2 | 2009-02-09 18:24:27 +0000 | [diff] [blame] | 103 | if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 104 | return false; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 105 | if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType)) |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 106 | return AS->getBaseType()->isObjectType(); |
| 107 | return !CanonicalType->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool Type::isDerivedType() const { |
| 111 | switch (CanonicalType->getTypeClass()) { |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 112 | case ExtQual: |
| 113 | return cast<ExtQualType>(CanonicalType)->getBaseType()->isDerivedType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 114 | case Pointer: |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 115 | case VariableArray: |
| 116 | case ConstantArray: |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 117 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 118 | case FunctionProto: |
| 119 | case FunctionNoProto: |
| 120 | case Reference: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 121 | case Record: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 122 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 123 | default: |
| 124 | return false; |
| 125 | } |
| 126 | } |
| 127 | |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 128 | bool Type::isClassType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 129 | if (const RecordType *RT = getAsRecordType()) |
| 130 | return RT->getDecl()->isClass(); |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 131 | return false; |
| 132 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 133 | bool Type::isStructureType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 134 | if (const RecordType *RT = getAsRecordType()) |
| 135 | return RT->getDecl()->isStruct(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | bool Type::isUnionType() const { |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 139 | if (const RecordType *RT = getAsRecordType()) |
| 140 | return RT->getDecl()->isUnion(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 141 | return false; |
| 142 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 143 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 144 | bool Type::isComplexType() const { |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 145 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 146 | return CT->getElementType()->isFloatingType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 147 | if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType)) |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 148 | return AS->getBaseType()->isComplexType(); |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 149 | return false; |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 152 | bool Type::isComplexIntegerType() const { |
| 153 | // Check for GCC complex integer extension. |
| 154 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 155 | return CT->getElementType()->isIntegerType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 156 | if (const ExtQualType *AS = dyn_cast<ExtQualType>(CanonicalType)) |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 157 | return AS->getBaseType()->isComplexIntegerType(); |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 158 | return false; |
| 159 | } |
| 160 | |
| 161 | const ComplexType *Type::getAsComplexIntegerType() const { |
| 162 | // Are we directly a complex type? |
| 163 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) { |
| 164 | if (CTy->getElementType()->isIntegerType()) |
| 165 | return CTy; |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 166 | return 0; |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 167 | } |
Chris Lattner | 4bbce99 | 2009-01-12 00:10:42 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 169 | // If the canonical form of this type isn't what we want, reject it. |
| 170 | if (!isa<ComplexType>(CanonicalType)) { |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 171 | // Look through type qualifiers (e.g. ExtQualType's). |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 172 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 173 | return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType(); |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 174 | return 0; |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 177 | // If this is a typedef for a complex type, strip the typedef off without |
| 178 | // losing all typedef information. |
| 179 | return getDesugaredType()->getAsComplexIntegerType(); |
| 180 | } |
| 181 | |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 182 | const BuiltinType *Type::getAsBuiltinType() const { |
| 183 | // If this is directly a builtin type, return it. |
| 184 | if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this)) |
| 185 | return BTy; |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 186 | |
| 187 | // 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] | 188 | if (!isa<BuiltinType>(CanonicalType)) { |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 189 | // Look through type qualifiers (e.g. ExtQualType's). |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 190 | if (isa<BuiltinType>(CanonicalType.getUnqualifiedType())) |
| 191 | return CanonicalType.getUnqualifiedType()->getAsBuiltinType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 192 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 193 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 194 | |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 195 | // If this is a typedef for a builtin type, strip the typedef off without |
| 196 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 197 | return getDesugaredType()->getAsBuiltinType(); |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 200 | const FunctionType *Type::getAsFunctionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 201 | // If this is directly a function type, return it. |
| 202 | if (const FunctionType *FTy = dyn_cast<FunctionType>(this)) |
| 203 | return FTy; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 204 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 205 | // 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] | 206 | if (!isa<FunctionType>(CanonicalType)) { |
| 207 | // Look through type qualifiers |
| 208 | if (isa<FunctionType>(CanonicalType.getUnqualifiedType())) |
| 209 | return CanonicalType.getUnqualifiedType()->getAsFunctionType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 210 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 211 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 212 | |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 213 | // If this is a typedef for a function type, strip the typedef off without |
| 214 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 215 | return getDesugaredType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 218 | const FunctionNoProtoType *Type::getAsFunctionNoProtoType() const { |
| 219 | return dyn_cast_or_null<FunctionNoProtoType>(getAsFunctionType()); |
Daniel Dunbar | afa7444 | 2009-02-19 07:11:26 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 222 | const FunctionProtoType *Type::getAsFunctionProtoType() const { |
| 223 | return dyn_cast_or_null<FunctionProtoType>(getAsFunctionType()); |
Chris Lattner | b77792e | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 227 | const PointerType *Type::getAsPointerType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 228 | // If this is directly a pointer type, return it. |
| 229 | if (const PointerType *PTy = dyn_cast<PointerType>(this)) |
| 230 | return PTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 231 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 232 | // 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] | 233 | if (!isa<PointerType>(CanonicalType)) { |
| 234 | // Look through type qualifiers |
| 235 | if (isa<PointerType>(CanonicalType.getUnqualifiedType())) |
| 236 | return CanonicalType.getUnqualifiedType()->getAsPointerType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 237 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 238 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 239 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 240 | // If this is a typedef for a pointer type, strip the typedef off without |
| 241 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 242 | return getDesugaredType()->getAsPointerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 245 | const BlockPointerType *Type::getAsBlockPointerType() const { |
| 246 | // If this is directly a block pointer type, return it. |
| 247 | if (const BlockPointerType *PTy = dyn_cast<BlockPointerType>(this)) |
| 248 | return PTy; |
| 249 | |
| 250 | // 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] | 251 | if (!isa<BlockPointerType>(CanonicalType)) { |
| 252 | // Look through type qualifiers |
| 253 | if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType())) |
| 254 | return CanonicalType.getUnqualifiedType()->getAsBlockPointerType(); |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 255 | return 0; |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 256 | } |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 257 | |
| 258 | // If this is a typedef for a block pointer type, strip the typedef off |
| 259 | // without losing all typedef information. |
| 260 | return getDesugaredType()->getAsBlockPointerType(); |
| 261 | } |
| 262 | |
Chris Lattner | a1d9fde | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 263 | const ReferenceType *Type::getAsReferenceType() const { |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 264 | // If this is directly a reference type, return it. |
| 265 | if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this)) |
| 266 | return RTy; |
| 267 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 268 | // 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] | 269 | if (!isa<ReferenceType>(CanonicalType)) { |
| 270 | // Look through type qualifiers |
| 271 | if (isa<ReferenceType>(CanonicalType.getUnqualifiedType())) |
| 272 | return CanonicalType.getUnqualifiedType()->getAsReferenceType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 273 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 274 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 275 | |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 276 | // If this is a typedef for a reference type, strip the typedef off without |
| 277 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 278 | return getDesugaredType()->getAsReferenceType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 281 | const MemberPointerType *Type::getAsMemberPointerType() const { |
| 282 | // If this is directly a member pointer type, return it. |
| 283 | if (const MemberPointerType *MTy = dyn_cast<MemberPointerType>(this)) |
| 284 | return MTy; |
| 285 | |
| 286 | // If the canonical form of this type isn't the right kind, reject it. |
| 287 | if (!isa<MemberPointerType>(CanonicalType)) { |
| 288 | // Look through type qualifiers |
| 289 | if (isa<MemberPointerType>(CanonicalType.getUnqualifiedType())) |
| 290 | return CanonicalType.getUnqualifiedType()->getAsMemberPointerType(); |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | // If this is a typedef for a member pointer type, strip the typedef off |
| 295 | // without losing all typedef information. |
| 296 | return getDesugaredType()->getAsMemberPointerType(); |
| 297 | } |
| 298 | |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 299 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 300 | /// array types and types that contain variable array types in their |
| 301 | /// declarator |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 302 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 303 | // A VLA is a variably modified type. |
| 304 | if (isVariableArrayType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 305 | return true; |
| 306 | |
| 307 | // An array can contain a variably modified type |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 308 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 309 | return T->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 310 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 311 | // A pointer can point to a variably modified type. |
| 312 | // Also, C++ references and member pointers can point to a variably modified |
| 313 | // type, where VLAs appear as an extension to C++, and should be treated |
| 314 | // correctly. |
Daniel Dunbar | 68694ad | 2009-02-26 19:54:52 +0000 | [diff] [blame] | 315 | if (const PointerType *PT = getAsPointerType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 316 | return PT->getPointeeType()->isVariablyModifiedType(); |
Daniel Dunbar | 68694ad | 2009-02-26 19:54:52 +0000 | [diff] [blame] | 317 | if (const ReferenceType *RT = getAsReferenceType()) |
| 318 | return RT->getPointeeType()->isVariablyModifiedType(); |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 319 | if (const MemberPointerType *PT = getAsMemberPointerType()) |
| 320 | return PT->getPointeeType()->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 321 | |
| 322 | // A function can return a variably modified type |
| 323 | // This one isn't completely obvious, but it follows from the |
| 324 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 325 | // illegal to declare a function returning a variably modified type. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 326 | if (const FunctionType *FT = getAsFunctionType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 327 | return FT->getResultType()->isVariablyModifiedType(); |
| 328 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 329 | return false; |
| 330 | } |
| 331 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 332 | const RecordType *Type::getAsRecordType() const { |
Douglas Gregor | fc705b8 | 2009-02-26 22:19:44 +0000 | [diff] [blame] | 333 | // If this is directly a record type, return it. |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 334 | if (const RecordType *RTy = dyn_cast<RecordType>(this)) |
| 335 | return RTy; |
| 336 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 337 | // 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] | 338 | if (!isa<RecordType>(CanonicalType)) { |
| 339 | // Look through type qualifiers |
| 340 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 341 | return CanonicalType.getUnqualifiedType()->getAsRecordType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 342 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 343 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 344 | |
| 345 | // 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] | 346 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 347 | return getDesugaredType()->getAsRecordType(); |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Douglas Gregor | fc705b8 | 2009-02-26 22:19:44 +0000 | [diff] [blame] | 350 | const TagType *Type::getAsTagType() const { |
| 351 | // If this is directly a tag type, return it. |
| 352 | if (const TagType *TagTy = dyn_cast<TagType>(this)) |
| 353 | return TagTy; |
| 354 | |
| 355 | // If the canonical form of this type isn't the right kind, reject it. |
| 356 | if (!isa<TagType>(CanonicalType)) { |
| 357 | // Look through type qualifiers |
| 358 | if (isa<TagType>(CanonicalType.getUnqualifiedType())) |
| 359 | return CanonicalType.getUnqualifiedType()->getAsTagType(); |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | // If this is a typedef for a tag type, strip the typedef off without |
| 364 | // losing all typedef information. |
| 365 | return getDesugaredType()->getAsTagType(); |
| 366 | } |
| 367 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 368 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 369 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 370 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 371 | if (RT->getDecl()->isStruct()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 372 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 373 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 374 | |
| 375 | // 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] | 376 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 377 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 378 | return 0; |
| 379 | |
| 380 | // If this is a typedef for a structure type, strip the typedef off without |
| 381 | // losing all typedef information. |
| 382 | return getDesugaredType()->getAsStructureType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 383 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 384 | // Look through type qualifiers |
| 385 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 386 | return CanonicalType.getUnqualifiedType()->getAsStructureType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 387 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 390 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 391 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 392 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 393 | if (RT->getDecl()->isUnion()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 394 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 395 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 396 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 397 | // 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] | 398 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 399 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 400 | return 0; |
| 401 | |
| 402 | // If this is a typedef for a union type, strip the typedef off without |
| 403 | // losing all typedef information. |
| 404 | return getDesugaredType()->getAsUnionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 405 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 406 | |
| 407 | // Look through type qualifiers |
| 408 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 409 | return CanonicalType.getUnqualifiedType()->getAsUnionType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 410 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Eli Friedman | ad74a75 | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 413 | const EnumType *Type::getAsEnumType() const { |
| 414 | // Check the canonicalized unqualified type directly; the more complex |
| 415 | // version is unnecessary because there isn't any typedef information |
| 416 | // to preserve. |
| 417 | return dyn_cast<EnumType>(CanonicalType.getUnqualifiedType()); |
| 418 | } |
| 419 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 420 | const ComplexType *Type::getAsComplexType() const { |
| 421 | // Are we directly a complex type? |
| 422 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |
| 423 | return CTy; |
| 424 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 425 | // 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] | 426 | if (!isa<ComplexType>(CanonicalType)) { |
| 427 | // Look through type qualifiers |
| 428 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 429 | return CanonicalType.getUnqualifiedType()->getAsComplexType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 430 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 431 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 432 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 433 | // If this is a typedef for a complex type, strip the typedef off without |
| 434 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 435 | return getDesugaredType()->getAsComplexType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 438 | const VectorType *Type::getAsVectorType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 439 | // Are we directly a vector type? |
| 440 | if (const VectorType *VTy = dyn_cast<VectorType>(this)) |
| 441 | return VTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 442 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 443 | // 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] | 444 | if (!isa<VectorType>(CanonicalType)) { |
| 445 | // Look through type qualifiers |
| 446 | if (isa<VectorType>(CanonicalType.getUnqualifiedType())) |
| 447 | return CanonicalType.getUnqualifiedType()->getAsVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 448 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 449 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 450 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 451 | // If this is a typedef for a vector type, strip the typedef off without |
| 452 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 453 | return getDesugaredType()->getAsVectorType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 456 | const ExtVectorType *Type::getAsExtVectorType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 457 | // Are we directly an OpenCU vector type? |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 458 | if (const ExtVectorType *VTy = dyn_cast<ExtVectorType>(this)) |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 459 | return VTy; |
| 460 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 461 | // 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] | 462 | if (!isa<ExtVectorType>(CanonicalType)) { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 463 | // Look through type qualifiers |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 464 | if (isa<ExtVectorType>(CanonicalType.getUnqualifiedType())) |
| 465 | return CanonicalType.getUnqualifiedType()->getAsExtVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 466 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 467 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 468 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 469 | // If this is a typedef for an extended vector type, strip the typedef off |
| 470 | // without losing all typedef information. |
| 471 | return getDesugaredType()->getAsExtVectorType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 474 | const ObjCInterfaceType *Type::getAsObjCInterfaceType() const { |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 475 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 476 | // type pointer if it is the right class. There is no typedef information to |
| 477 | // return and these cannot be Address-space qualified. |
Fariborz Jahanian | fb41ca8 | 2009-02-26 23:05:51 +0000 | [diff] [blame] | 478 | return dyn_cast<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | const ObjCQualifiedInterfaceType * |
| 482 | Type::getAsObjCQualifiedInterfaceType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 483 | // There is no sugar for ObjCQualifiedInterfaceType's, just return the |
| 484 | // canonical type pointer if it is the right class. |
Fariborz Jahanian | fb41ca8 | 2009-02-26 23:05:51 +0000 | [diff] [blame] | 485 | return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | const ObjCQualifiedIdType *Type::getAsObjCQualifiedIdType() const { |
| 489 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 490 | // type pointer if it is the right class. |
Fariborz Jahanian | fb41ca8 | 2009-02-26 23:05:51 +0000 | [diff] [blame] | 491 | return dyn_cast<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 494 | const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const { |
| 495 | // There is no sugar for template type parameters, so just return |
| 496 | // the canonical type pointer if it is the right class. |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 497 | // FIXME: can these be address-space qualified? |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 498 | return dyn_cast<TemplateTypeParmType>(CanonicalType); |
| 499 | } |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 500 | |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 501 | const ClassTemplateSpecializationType * |
| 502 | Type::getClassTemplateSpecializationType() const { |
| 503 | // There is no sugar for class template specialization types, so |
| 504 | // just return the canonical type pointer if it is the right class. |
| 505 | return dyn_cast<ClassTemplateSpecializationType>(CanonicalType); |
| 506 | } |
| 507 | |
| 508 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 509 | bool Type::isIntegerType() const { |
| 510 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 511 | return BT->getKind() >= BuiltinType::Bool && |
| 512 | BT->getKind() <= BuiltinType::LongLong; |
| 513 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 514 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 515 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 516 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 517 | return true; |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 518 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 519 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 520 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 521 | return VT->getElementType()->isIntegerType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 522 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 523 | return EXTQT->getBaseType()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 524 | return false; |
| 525 | } |
| 526 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 527 | bool Type::isIntegralType() const { |
| 528 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 529 | return BT->getKind() >= BuiltinType::Bool && |
| 530 | BT->getKind() <= BuiltinType::LongLong; |
| 531 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 532 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 533 | return true; // Complete enum types are integral. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 534 | // FIXME: In C++, enum types are never integral. |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 535 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 536 | return true; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 537 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 538 | return EXTQT->getBaseType()->isIntegralType(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 539 | return false; |
| 540 | } |
| 541 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 542 | bool Type::isEnumeralType() const { |
| 543 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 544 | return TT->getDecl()->isEnum(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 545 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 546 | return EXTQT->getBaseType()->isEnumeralType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 547 | return false; |
| 548 | } |
| 549 | |
| 550 | bool Type::isBooleanType() const { |
| 551 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 552 | return BT->getKind() == BuiltinType::Bool; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 553 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 554 | return EXTQT->getBaseType()->isBooleanType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 555 | return false; |
| 556 | } |
| 557 | |
| 558 | bool Type::isCharType() const { |
| 559 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 560 | return BT->getKind() == BuiltinType::Char_U || |
| 561 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 562 | BT->getKind() == BuiltinType::Char_S || |
| 563 | BT->getKind() == BuiltinType::SChar; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 564 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 565 | return EXTQT->getBaseType()->isCharType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 566 | return false; |
| 567 | } |
| 568 | |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 569 | bool Type::isWideCharType() const { |
| 570 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 571 | return BT->getKind() == BuiltinType::WChar; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 572 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 573 | return EXTQT->getBaseType()->isWideCharType(); |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 574 | return false; |
| 575 | } |
| 576 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 577 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 578 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 579 | /// an enum decl which has a signed representation, or a vector of signed |
| 580 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 581 | bool Type::isSignedIntegerType() const { |
| 582 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 583 | return BT->getKind() >= BuiltinType::Char_S && |
| 584 | BT->getKind() <= BuiltinType::LongLong; |
| 585 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 586 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 587 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 588 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 589 | |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 590 | if (const FixedWidthIntType *FWIT = |
| 591 | dyn_cast<FixedWidthIntType>(CanonicalType)) |
| 592 | return FWIT->isSigned(); |
| 593 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 594 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 595 | return VT->getElementType()->isSignedIntegerType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 596 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 597 | return EXTQT->getBaseType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 601 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 602 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 603 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 604 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 605 | bool Type::isUnsignedIntegerType() const { |
| 606 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 607 | return BT->getKind() >= BuiltinType::Bool && |
| 608 | BT->getKind() <= BuiltinType::ULongLong; |
| 609 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 610 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 611 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 612 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 613 | |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 614 | if (const FixedWidthIntType *FWIT = |
| 615 | dyn_cast<FixedWidthIntType>(CanonicalType)) |
| 616 | return !FWIT->isSigned(); |
| 617 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 618 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 619 | return VT->getElementType()->isUnsignedIntegerType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 620 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 621 | return EXTQT->getBaseType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 622 | return false; |
| 623 | } |
| 624 | |
| 625 | bool Type::isFloatingType() const { |
| 626 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 627 | return BT->getKind() >= BuiltinType::Float && |
| 628 | BT->getKind() <= BuiltinType::LongDouble; |
| 629 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 630 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 631 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 632 | return VT->getElementType()->isFloatingType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 633 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 634 | return EXTQT->getBaseType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | |
| 638 | bool Type::isRealFloatingType() const { |
| 639 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 640 | return BT->getKind() >= BuiltinType::Float && |
| 641 | BT->getKind() <= BuiltinType::LongDouble; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 642 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 643 | return VT->getElementType()->isRealFloatingType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 644 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 645 | return EXTQT->getBaseType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 646 | return false; |
| 647 | } |
| 648 | |
| 649 | bool Type::isRealType() const { |
| 650 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 651 | return BT->getKind() >= BuiltinType::Bool && |
| 652 | BT->getKind() <= BuiltinType::LongDouble; |
| 653 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 654 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 655 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 656 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 657 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 658 | return VT->getElementType()->isRealType(); |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 659 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 660 | return EXTQT->getBaseType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 661 | return false; |
| 662 | } |
| 663 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 664 | bool Type::isArithmeticType() const { |
| 665 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | a7fbf72 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 666 | return BT->getKind() >= BuiltinType::Bool && |
| 667 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 668 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 669 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 670 | // If a body isn't seen by the time we get here, return false. |
| 671 | return ET->getDecl()->isDefinition(); |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 672 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 673 | return true; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 674 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 675 | return EXTQT->getBaseType()->isArithmeticType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 676 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 677 | } |
| 678 | |
| 679 | bool Type::isScalarType() const { |
| 680 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 681 | return BT->getKind() != BuiltinType::Void; |
| 682 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 683 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 684 | // are not treated as scalar types. |
| 685 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 686 | return true; |
| 687 | return false; |
| 688 | } |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 689 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 690 | return EXTQT->getBaseType()->isScalarType(); |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 691 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 692 | return true; |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 693 | return isa<PointerType>(CanonicalType) || |
| 694 | isa<BlockPointerType>(CanonicalType) || |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 695 | isa<MemberPointerType>(CanonicalType) || |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 696 | isa<ComplexType>(CanonicalType) || |
Steve Naroff | f7f52e7 | 2009-02-21 21:17:01 +0000 | [diff] [blame] | 697 | isa<ObjCQualifiedIdType>(CanonicalType) || |
| 698 | isa<ObjCQualifiedClassType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 701 | /// \brief Determines whether the type is a C++ aggregate type or C |
| 702 | /// aggregate or union type. |
| 703 | /// |
| 704 | /// An aggregate type is an array or a class type (struct, union, or |
| 705 | /// class) that has no user-declared constructors, no private or |
| 706 | /// protected non-static data members, no base classes, and no virtual |
| 707 | /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type |
| 708 | /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also |
| 709 | /// includes union types. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 710 | bool Type::isAggregateType() const { |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 711 | if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { |
| 712 | if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) |
| 713 | return ClassDecl->isAggregate(); |
| 714 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 715 | return true; |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 718 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 719 | return EXTQT->getBaseType()->isAggregateType(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 720 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 723 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 724 | /// 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] | 725 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 726 | bool Type::isConstantSizeType() const { |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 727 | if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(CanonicalType)) |
| 728 | return EXTQT->getBaseType()->isConstantSizeType(); |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 729 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 730 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 731 | // The VAT must have a size, as it is known to be complete. |
| 732 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 736 | /// - a type that can describe objects, but which lacks information needed to |
| 737 | /// determine its size. |
| 738 | bool Type::isIncompleteType() const { |
| 739 | switch (CanonicalType->getTypeClass()) { |
| 740 | default: return false; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 741 | case ExtQual: |
| 742 | return cast<ExtQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 743 | case Builtin: |
| 744 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 745 | // be completed. |
| 746 | return isVoidType(); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 747 | case Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 748 | case Enum: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 749 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 750 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 751 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 752 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 753 | // 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] | 754 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 758 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 759 | bool Type::isPODType() const { |
| 760 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 761 | // We return false for that case. |
| 762 | if (isIncompleteType()) |
| 763 | return false; |
| 764 | |
| 765 | switch (CanonicalType->getTypeClass()) { |
| 766 | // Everything not explicitly mentioned is not POD. |
| 767 | default: return false; |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 768 | case ExtQual: |
| 769 | return cast<ExtQualType>(CanonicalType)->getBaseType()->isPODType(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 770 | case VariableArray: |
| 771 | case ConstantArray: |
| 772 | // IncompleteArray is caught by isIncompleteType() above. |
| 773 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 774 | |
| 775 | case Builtin: |
| 776 | case Complex: |
| 777 | case Pointer: |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 778 | case MemberPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 779 | case Vector: |
| 780 | case ExtVector: |
Anders Carlsson | 672c91d | 2009-02-09 21:53:01 +0000 | [diff] [blame] | 781 | case ObjCQualifiedId: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 782 | return true; |
| 783 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 784 | case Enum: |
| 785 | return true; |
| 786 | |
| 787 | case Record: |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 788 | if (CXXRecordDecl *ClassDecl |
| 789 | = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) |
| 790 | return ClassDecl->isPOD(); |
| 791 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 792 | // C struct/union is POD. |
| 793 | return true; |
| 794 | } |
| 795 | } |
| 796 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 797 | bool Type::isPromotableIntegerType() const { |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 798 | if (const BuiltinType *BT = getAsBuiltinType()) |
| 799 | switch (BT->getKind()) { |
| 800 | case BuiltinType::Bool: |
| 801 | case BuiltinType::Char_S: |
| 802 | case BuiltinType::Char_U: |
| 803 | case BuiltinType::SChar: |
| 804 | case BuiltinType::UChar: |
| 805 | case BuiltinType::Short: |
| 806 | case BuiltinType::UShort: |
| 807 | return true; |
| 808 | default: |
| 809 | return false; |
| 810 | } |
| 811 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | const char *BuiltinType::getName() const { |
| 815 | switch (getKind()) { |
| 816 | default: assert(0 && "Unknown builtin type!"); |
| 817 | case Void: return "void"; |
| 818 | case Bool: return "_Bool"; |
| 819 | case Char_S: return "char"; |
| 820 | case Char_U: return "char"; |
| 821 | case SChar: return "signed char"; |
| 822 | case Short: return "short"; |
| 823 | case Int: return "int"; |
| 824 | case Long: return "long"; |
| 825 | case LongLong: return "long long"; |
| 826 | case UChar: return "unsigned char"; |
| 827 | case UShort: return "unsigned short"; |
| 828 | case UInt: return "unsigned int"; |
| 829 | case ULong: return "unsigned long"; |
| 830 | case ULongLong: return "unsigned long long"; |
| 831 | case Float: return "float"; |
| 832 | case Double: return "double"; |
| 833 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 834 | case WChar: return "wchar_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 835 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 836 | case Dependent: return "<dependent type>"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 840 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 841 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 842 | unsigned NumArgs, bool isVariadic, |
| 843 | unsigned TypeQuals) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 844 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 845 | for (unsigned i = 0; i != NumArgs; ++i) |
| 846 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 847 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 848 | ID.AddInteger(TypeQuals); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 851 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 852 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
| 853 | getTypeQuals()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 856 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 857 | const ObjCInterfaceDecl *Decl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 858 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 859 | unsigned NumProtocols) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 860 | ID.AddPointer(Decl); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 861 | for (unsigned i = 0; i != NumProtocols; i++) |
| 862 | ID.AddPointer(protocols[i]); |
| 863 | } |
| 864 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 865 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | 1ee0700 | 2008-04-07 06:37:47 +0000 | [diff] [blame] | 866 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 869 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
Chris Lattner | 62f5f7f | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 870 | ObjCProtocolDecl **protocols, |
| 871 | unsigned NumProtocols) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 872 | for (unsigned i = 0; i != NumProtocols; i++) |
| 873 | ID.AddPointer(protocols[i]); |
| 874 | } |
| 875 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 876 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 877 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 878 | } |
| 879 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 880 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 881 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 882 | /// sum of the type qualifiers, so if you have: |
| 883 | /// typedef const int A; |
| 884 | /// typedef volatile A B; |
| 885 | /// looking through the typedefs for B will give you "const volatile A". |
| 886 | /// |
| 887 | QualType TypedefType::LookThroughTypedefs() const { |
| 888 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 889 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 890 | if (!isa<TypedefType>(FirstType)) |
| 891 | return FirstType; |
| 892 | |
| 893 | // Otherwise, do the fully general loop. |
| 894 | unsigned TypeQuals = 0; |
| 895 | const TypedefType *TDT = this; |
| 896 | while (1) { |
| 897 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
Chris Lattner | f46699c | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 898 | |
| 899 | |
| 900 | /// FIXME: |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 901 | /// FIXME: This is incorrect for ExtQuals! |
Chris Lattner | f46699c | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 902 | /// FIXME: |
| 903 | TypeQuals |= CurType.getCVRQualifiers(); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 904 | |
| 905 | TDT = dyn_cast<TypedefType>(CurType); |
| 906 | if (TDT == 0) |
| 907 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 908 | } |
| 909 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 910 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 911 | TypeOfExprType::TypeOfExprType(Expr *E, QualType can) |
| 912 | : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 913 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 914 | } |
| 915 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 916 | bool RecordType::classof(const TagType *TT) { |
| 917 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 918 | } |
| 919 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 920 | bool EnumType::classof(const TagType *TT) { |
| 921 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 924 | bool |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 925 | ClassTemplateSpecializationType:: |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 926 | anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) { |
| 927 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) { |
| 928 | switch (Args[Idx].getKind()) { |
| 929 | case TemplateArgument::Type: |
| 930 | if (Args[Idx].getAsType()->isDependentType()) |
| 931 | return true; |
| 932 | break; |
| 933 | |
| 934 | case TemplateArgument::Declaration: |
| 935 | case TemplateArgument::Integral: |
| 936 | // Never dependent |
| 937 | break; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 938 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 939 | case TemplateArgument::Expression: |
| 940 | if (Args[Idx].getAsExpr()->isTypeDependent() || |
| 941 | Args[Idx].getAsExpr()->isValueDependent()) |
| 942 | return true; |
| 943 | break; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 944 | } |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 945 | } |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 946 | |
| 947 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | ClassTemplateSpecializationType:: |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 951 | ClassTemplateSpecializationType(TemplateDecl *T, const TemplateArgument *Args, |
| 952 | unsigned NumArgs, QualType Canon) |
| 953 | : Type(ClassTemplateSpecialization, |
| 954 | Canon.isNull()? QualType(this, 0) : Canon, |
| 955 | /*FIXME: Check for dependent template */ |
| 956 | anyDependentTemplateArguments(Args, NumArgs)), |
| 957 | Template(T), NumArgs(NumArgs) |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 958 | { |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 959 | assert((!Canon.isNull() || |
| 960 | anyDependentTemplateArguments(Args, NumArgs)) && |
| 961 | "No canonical type for non-dependent class template specialization"); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 962 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 963 | TemplateArgument *TemplateArgs |
| 964 | = reinterpret_cast<TemplateArgument *>(this + 1); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 965 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 966 | new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Douglas Gregor | 5908e9f | 2009-02-09 19:34:22 +0000 | [diff] [blame] | 969 | void ClassTemplateSpecializationType::Destroy(ASTContext& C) { |
| 970 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 971 | if (Expr *E = getArg(Arg).getAsExpr()) |
| 972 | E->Destroy(C); |
Douglas Gregor | 5908e9f | 2009-02-09 19:34:22 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 975 | ClassTemplateSpecializationType::iterator |
| 976 | ClassTemplateSpecializationType::end() const { |
| 977 | return begin() + getNumArgs(); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 980 | const TemplateArgument & |
| 981 | ClassTemplateSpecializationType::getArg(unsigned Idx) const { |
| 982 | assert(Idx < getNumArgs() && "Template argument out of range"); |
| 983 | return getArgs()[Idx]; |
| 984 | } |
| 985 | |
| 986 | void |
| 987 | ClassTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, |
| 988 | TemplateDecl *T, |
| 989 | const TemplateArgument *Args, |
| 990 | unsigned NumArgs) { |
| 991 | ID.AddPointer(T); |
| 992 | |
| 993 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
| 994 | Args[Idx].Profile(ID); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 995 | } |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 996 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 997 | //===----------------------------------------------------------------------===// |
| 998 | // Type Printing |
| 999 | //===----------------------------------------------------------------------===// |
| 1000 | |
| 1001 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 1002 | std::string R = "identifier"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1003 | getAsStringInternal(R); |
| 1004 | if (msg) |
| 1005 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 1006 | else |
| 1007 | fprintf(stderr, "%s\n", R.c_str()); |
| 1008 | } |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 1009 | void QualType::dump() const { |
| 1010 | dump(""); |
| 1011 | } |
| 1012 | |
| 1013 | void Type::dump() const { |
| 1014 | std::string S = "identifier"; |
| 1015 | getAsStringInternal(S); |
| 1016 | fprintf(stderr, "%s\n", S.c_str()); |
| 1017 | } |
| 1018 | |
| 1019 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1020 | |
| 1021 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 1022 | // Note: funkiness to ensure we get a space only between quals. |
| 1023 | bool NonePrinted = true; |
| 1024 | if (TypeQuals & QualType::Const) |
| 1025 | S += "const", NonePrinted = false; |
| 1026 | if (TypeQuals & QualType::Volatile) |
| 1027 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 1028 | if (TypeQuals & QualType::Restrict) |
| 1029 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 1030 | } |
| 1031 | |
| 1032 | void QualType::getAsStringInternal(std::string &S) const { |
| 1033 | if (isNull()) { |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 1034 | S += "NULL TYPE"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | // Print qualifiers as appropriate. |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 1039 | if (unsigned Tq = getCVRQualifiers()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1040 | std::string TQS; |
Gabor Greif | 3513e13 | 2008-02-21 17:40:55 +0000 | [diff] [blame] | 1041 | AppendTypeQualList(TQS, Tq); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1042 | if (!S.empty()) |
| 1043 | S = TQS + ' ' + S; |
| 1044 | else |
| 1045 | S = TQS; |
| 1046 | } |
| 1047 | |
| 1048 | getTypePtr()->getAsStringInternal(S); |
| 1049 | } |
| 1050 | |
| 1051 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 1052 | if (S.empty()) { |
| 1053 | S = getName(); |
| 1054 | } else { |
| 1055 | // Prefix the basic type, e.g. 'int X'. |
| 1056 | S = ' ' + S; |
| 1057 | S = getName() + S; |
| 1058 | } |
| 1059 | } |
| 1060 | |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 1061 | void FixedWidthIntType::getAsStringInternal(std::string &S) const { |
| 1062 | // FIXME: Once we get bitwidth attribute, write as |
| 1063 | // "int __attribute__((bitwidth(x)))". |
| 1064 | std::string prefix = "__clang_fixedwidth"; |
| 1065 | prefix += llvm::utostr_32(Width); |
| 1066 | prefix += (char)(Signed ? 'S' : 'U'); |
| 1067 | if (S.empty()) { |
| 1068 | S = prefix; |
| 1069 | } else { |
| 1070 | // Prefix the basic type, e.g. 'int X'. |
| 1071 | S = prefix + S; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1076 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 1077 | ElementType->getAsStringInternal(S); |
| 1078 | S = "_Complex " + S; |
| 1079 | } |
| 1080 | |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 1081 | void ExtQualType::getAsStringInternal(std::string &S) const { |
Chris Lattner | 3b6b83b | 2009-02-18 22:58:38 +0000 | [diff] [blame] | 1082 | bool NeedsSpace = false; |
Fariborz Jahanian | 4886a42 | 2009-02-17 21:45:36 +0000 | [diff] [blame] | 1083 | if (AddressSpace) { |
Fariborz Jahanian | 59d16d1 | 2009-02-17 20:16:45 +0000 | [diff] [blame] | 1084 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
Chris Lattner | 3b6b83b | 2009-02-18 22:58:38 +0000 | [diff] [blame] | 1085 | NeedsSpace = true; |
Fariborz Jahanian | 59d16d1 | 2009-02-17 20:16:45 +0000 | [diff] [blame] | 1086 | } |
Fariborz Jahanian | d33d9c0 | 2009-02-18 05:09:49 +0000 | [diff] [blame] | 1087 | if (GCAttrType != QualType::GCNone) { |
Chris Lattner | 3b6b83b | 2009-02-18 22:58:38 +0000 | [diff] [blame] | 1088 | if (NeedsSpace) |
Fariborz Jahanian | 59d16d1 | 2009-02-17 20:16:45 +0000 | [diff] [blame] | 1089 | S += ' '; |
| 1090 | S += "__attribute__((objc_gc("; |
Fariborz Jahanian | d33d9c0 | 2009-02-18 05:09:49 +0000 | [diff] [blame] | 1091 | if (GCAttrType == QualType::Weak) |
Fariborz Jahanian | 59d16d1 | 2009-02-17 20:16:45 +0000 | [diff] [blame] | 1092 | S += "weak"; |
| 1093 | else |
| 1094 | S += "strong"; |
| 1095 | S += ")))"; |
| 1096 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 1097 | BaseType->getAsStringInternal(S); |
| 1098 | } |
| 1099 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1100 | void PointerType::getAsStringInternal(std::string &S) const { |
| 1101 | S = '*' + S; |
| 1102 | |
| 1103 | // Handle things like 'int (*A)[4];' correctly. |
| 1104 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 1105 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1106 | S = '(' + S + ')'; |
| 1107 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 1108 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 1111 | void BlockPointerType::getAsStringInternal(std::string &S) const { |
| 1112 | S = '^' + S; |
| 1113 | PointeeType.getAsStringInternal(S); |
| 1114 | } |
| 1115 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1116 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 1117 | S = '&' + S; |
| 1118 | |
| 1119 | // Handle things like 'int (&A)[4];' correctly. |
| 1120 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 1121 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1122 | S = '(' + S + ')'; |
| 1123 | |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 1124 | getPointeeType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 1127 | void MemberPointerType::getAsStringInternal(std::string &S) const { |
| 1128 | std::string C; |
| 1129 | Class->getAsStringInternal(C); |
| 1130 | C += "::*"; |
| 1131 | S = C + S; |
| 1132 | |
| 1133 | // Handle things like 'int (&A)[4];' correctly. |
| 1134 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 1135 | if (isa<ArrayType>(getPointeeType())) |
| 1136 | S = '(' + S + ')'; |
| 1137 | |
| 1138 | getPointeeType().getAsStringInternal(S); |
| 1139 | } |
| 1140 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1141 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 1142 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 1143 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1144 | S += ']'; |
| 1145 | |
| 1146 | getElementType().getAsStringInternal(S); |
| 1147 | } |
| 1148 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 1149 | void IncompleteArrayType::getAsStringInternal(std::string &S) const { |
| 1150 | S += "[]"; |
| 1151 | |
| 1152 | getElementType().getAsStringInternal(S); |
| 1153 | } |
| 1154 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1155 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1156 | S += '['; |
| 1157 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1158 | if (getIndexTypeQualifier()) { |
| 1159 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1160 | S += ' '; |
| 1161 | } |
| 1162 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1163 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1164 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1165 | else if (getSizeModifier() == Star) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1166 | S += '*'; |
| 1167 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1168 | if (getSizeExpr()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1169 | std::string SStr; |
| 1170 | llvm::raw_string_ostream s(SStr); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1171 | getSizeExpr()->printPretty(s); |
| 1172 | S += s.str(); |
| 1173 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1174 | S += ']'; |
| 1175 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1176 | getElementType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1179 | void DependentSizedArrayType::getAsStringInternal(std::string &S) const { |
| 1180 | S += '['; |
| 1181 | |
| 1182 | if (getIndexTypeQualifier()) { |
| 1183 | AppendTypeQualList(S, getIndexTypeQualifier()); |
| 1184 | S += ' '; |
| 1185 | } |
| 1186 | |
| 1187 | if (getSizeModifier() == Static) |
| 1188 | S += "static"; |
| 1189 | else if (getSizeModifier() == Star) |
| 1190 | S += '*'; |
| 1191 | |
| 1192 | if (getSizeExpr()) { |
| 1193 | std::string SStr; |
| 1194 | llvm::raw_string_ostream s(SStr); |
| 1195 | getSizeExpr()->printPretty(s); |
| 1196 | S += s.str(); |
| 1197 | } |
| 1198 | S += ']'; |
| 1199 | |
| 1200 | getElementType().getAsStringInternal(S); |
| 1201 | } |
| 1202 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1203 | void VectorType::getAsStringInternal(std::string &S) const { |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1204 | // FIXME: We prefer to print the size directly here, but have no way |
| 1205 | // to get the size of the type. |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1206 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1207 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1208 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Chris Lattner | 08eddd9 | 2009-02-19 23:42:29 +0000 | [diff] [blame] | 1209 | ElementType.getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1212 | void ExtVectorType::getAsStringInternal(std::string &S) const { |
| 1213 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1214 | S += llvm::utostr_32(NumElements); |
| 1215 | S += ")))"; |
| 1216 | ElementType.getAsStringInternal(S); |
| 1217 | } |
| 1218 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1219 | void TypeOfExprType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1220 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1221 | InnerString = ' ' + InnerString; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1222 | std::string Str; |
| 1223 | llvm::raw_string_ostream s(Str); |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 1224 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 1bfd5cc | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 1225 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1228 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 1229 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1230 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1231 | std::string Tmp; |
| 1232 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1233 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1236 | void FunctionNoProtoType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1237 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1238 | if (!S.empty()) |
| 1239 | S = "(" + S + ")"; |
| 1240 | |
| 1241 | S += "()"; |
| 1242 | getResultType().getAsStringInternal(S); |
| 1243 | } |
| 1244 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1245 | void FunctionProtoType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1246 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1247 | if (!S.empty()) |
| 1248 | S = "(" + S + ")"; |
| 1249 | |
| 1250 | S += "("; |
| 1251 | std::string Tmp; |
| 1252 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1253 | if (i) S += ", "; |
| 1254 | getArgType(i).getAsStringInternal(Tmp); |
| 1255 | S += Tmp; |
| 1256 | Tmp.clear(); |
| 1257 | } |
| 1258 | |
| 1259 | if (isVariadic()) { |
| 1260 | if (getNumArgs()) |
| 1261 | S += ", "; |
| 1262 | S += "..."; |
| 1263 | } else if (getNumArgs() == 0) { |
| 1264 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1265 | S += "void"; |
| 1266 | } |
| 1267 | |
| 1268 | S += ")"; |
| 1269 | getResultType().getAsStringInternal(S); |
| 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 1274 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1275 | InnerString = ' ' + InnerString; |
| 1276 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1277 | } |
| 1278 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1279 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString) const { |
| 1280 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1281 | InnerString = ' ' + InnerString; |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 1282 | |
| 1283 | if (!Name) |
| 1284 | InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' + |
| 1285 | llvm::utostr_32(Index) + InnerString; |
| 1286 | else |
| 1287 | InnerString = Name->getName() + InnerString; |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1290 | void |
| 1291 | ClassTemplateSpecializationType:: |
| 1292 | getAsStringInternal(std::string &InnerString) const { |
| 1293 | std::string SpecString = Template->getNameAsString(); |
| 1294 | SpecString += '<'; |
| 1295 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { |
| 1296 | if (Arg) |
| 1297 | SpecString += ", "; |
| 1298 | |
| 1299 | // Print the argument into a string. |
| 1300 | std::string ArgString; |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1301 | switch (getArg(Arg).getKind()) { |
| 1302 | case TemplateArgument::Type: |
| 1303 | getArg(Arg).getAsType().getAsStringInternal(ArgString); |
| 1304 | break; |
| 1305 | |
| 1306 | case TemplateArgument::Declaration: |
| 1307 | ArgString = cast<NamedDecl>(getArg(Arg).getAsDecl())->getNameAsString(); |
| 1308 | break; |
| 1309 | |
| 1310 | case TemplateArgument::Integral: |
| 1311 | ArgString = getArg(Arg).getAsIntegral()->toString(10, true); |
| 1312 | break; |
| 1313 | |
| 1314 | case TemplateArgument::Expression: { |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1315 | llvm::raw_string_ostream s(ArgString); |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1316 | getArg(Arg).getAsExpr()->printPretty(s); |
| 1317 | break; |
| 1318 | } |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | // If this is the first argument and its string representation |
| 1322 | // begins with the global scope specifier ('::foo'), add a space |
| 1323 | // to avoid printing the diagraph '<:'. |
| 1324 | if (!Arg && !ArgString.empty() && ArgString[0] == ':') |
| 1325 | SpecString += ' '; |
| 1326 | |
| 1327 | SpecString += ArgString; |
| 1328 | } |
| 1329 | |
| 1330 | // If the last character of our string is '>', add another space to |
| 1331 | // keep the two '>''s separate tokens. We don't *have* to do this in |
| 1332 | // C++0x, but it's still good hygiene. |
| 1333 | if (SpecString[SpecString.size() - 1] == '>') |
| 1334 | SpecString += ' '; |
| 1335 | |
| 1336 | SpecString += '>'; |
| 1337 | |
| 1338 | if (InnerString.empty()) |
| 1339 | InnerString.swap(SpecString); |
| 1340 | else |
| 1341 | InnerString = SpecString + ' ' + InnerString; |
| 1342 | } |
| 1343 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1344 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1345 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1346 | InnerString = ' ' + InnerString; |
| 1347 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 1348 | } |
| 1349 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1350 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1351 | std::string &InnerString) const { |
Fariborz Jahanian | dfbcce2 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 1352 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1353 | InnerString = ' ' + InnerString; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1354 | std::string ObjCQIString = getDecl()->getNameAsString(); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1355 | ObjCQIString += '<'; |
Chris Lattner | cdce6d1 | 2008-07-21 05:19:23 +0000 | [diff] [blame] | 1356 | bool isFirst = true; |
| 1357 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1358 | if (isFirst) |
| 1359 | isFirst = false; |
| 1360 | else |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1361 | ObjCQIString += ','; |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1362 | ObjCQIString += (*I)->getNameAsString(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1363 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1364 | ObjCQIString += '>'; |
| 1365 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
Chris Lattner | e8e4f92 | 2008-07-25 23:07:18 +0000 | [diff] [blame] | 1368 | void ObjCQualifiedIdType::getAsStringInternal(std::string &InnerString) const { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1369 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1370 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1371 | std::string ObjCQIString = "id"; |
| 1372 | ObjCQIString += '<'; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1373 | int num = getNumProtocols(); |
| 1374 | for (int i = 0; i < num; i++) { |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1375 | ObjCQIString += getProtocols(i)->getNameAsString(); |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1376 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1377 | ObjCQIString += ','; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1378 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1379 | ObjCQIString += '>'; |
| 1380 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1383 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 1384 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1385 | InnerString = ' ' + InnerString; |
| 1386 | |
| 1387 | const char *Kind = getDecl()->getKindName(); |
| 1388 | const char *ID; |
| 1389 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 1390 | ID = II->getName(); |
Douglas Gregor | 4e16d04 | 2009-03-10 18:11:21 +0000 | [diff] [blame^] | 1391 | else if (TypedefDecl *Typedef = getDecl()->getTypedefForAnonDecl()) { |
| 1392 | Kind = 0; |
| 1393 | assert(Typedef->getIdentifier() && "Typedef without identifier?"); |
| 1394 | ID = Typedef->getIdentifier()->getName(); |
| 1395 | } else |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1396 | ID = "<anonymous>"; |
| 1397 | |
Douglas Gregor | 4e16d04 | 2009-03-10 18:11:21 +0000 | [diff] [blame^] | 1398 | if (Kind) |
| 1399 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 1400 | else |
| 1401 | InnerString = ID + InnerString; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1402 | } |