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" |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 20 | #include "clang/AST/PrettyPrinter.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 25 | bool QualType::isConstant(QualType T, ASTContext &Ctx) { |
| 26 | if (T.isConstQualified()) |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 27 | return true; |
| 28 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 29 | if (const ArrayType *AT = Ctx.getAsArrayType(T)) |
| 30 | return AT->getElementType().isConstant(Ctx); |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 31 | |
| 32 | return false; |
| 33 | } |
| 34 | |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 35 | void Type::Destroy(ASTContext& C) { |
| 36 | this->~Type(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 37 | C.Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void VariableArrayType::Destroy(ASTContext& C) { |
Eli Friedman | f91f5c8 | 2009-04-26 21:57:51 +0000 | [diff] [blame] | 41 | if (SizeExpr) |
| 42 | SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 43 | this->~VariableArrayType(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 44 | C.Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 45 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 47 | void DependentSizedArrayType::Destroy(ASTContext& C) { |
Argyrios Kyrtzidis | e7f3840 | 2009-07-18 21:18:10 +0000 | [diff] [blame] | 48 | // FIXME: Resource contention like in ConstantArrayWithExprType ? |
| 49 | // May crash, depending on platform or a particular build. |
| 50 | // SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 51 | this->~DependentSizedArrayType(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 52 | C.Deallocate(this); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 53 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 54 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 55 | void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | 04d4bee | 2009-07-31 00:23:35 +0000 | [diff] [blame] | 56 | ASTContext &Context, |
| 57 | QualType ET, |
| 58 | ArraySizeModifier SizeMod, |
| 59 | unsigned TypeQuals, |
| 60 | Expr *E) { |
| 61 | ID.AddPointer(ET.getAsOpaquePtr()); |
| 62 | ID.AddInteger(SizeMod); |
| 63 | ID.AddInteger(TypeQuals); |
| 64 | E->Profile(ID, Context, true); |
| 65 | } |
| 66 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 67 | void |
| 68 | DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | 2ec09f1 | 2009-07-31 03:54:25 +0000 | [diff] [blame] | 69 | ASTContext &Context, |
| 70 | QualType ElementType, Expr *SizeExpr) { |
| 71 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
| 72 | SizeExpr->Profile(ID, Context, true); |
| 73 | } |
| 74 | |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 75 | void DependentSizedExtVectorType::Destroy(ASTContext& C) { |
Douglas Gregor | bd1099e | 2009-07-23 16:36:45 +0000 | [diff] [blame] | 76 | // FIXME: Deallocate size expression, once we're cloning properly. |
| 77 | // if (SizeExpr) |
| 78 | // SizeExpr->Destroy(C); |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 79 | this->~DependentSizedExtVectorType(); |
| 80 | C.Deallocate(this); |
| 81 | } |
| 82 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 83 | /// getArrayElementTypeNoTypeQual - If this is an array type, return the |
| 84 | /// element type of the array, potentially with type qualifiers missing. |
| 85 | /// This method should never be used when type qualifiers are meaningful. |
| 86 | const Type *Type::getArrayElementTypeNoTypeQual() const { |
| 87 | // If this is directly an array type, return it. |
| 88 | if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) |
| 89 | return ATy->getElementType().getTypePtr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 91 | // If the canonical form of this type isn't the right kind, reject it. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 92 | if (!isa<ArrayType>(CanonicalType)) |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 93 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 95 | // If this is a typedef for an array type, strip the typedef off without |
| 96 | // losing all typedef information. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 97 | return cast<ArrayType>(getUnqualifiedDesugaredType()) |
| 98 | ->getElementType().getTypePtr(); |
Chris Lattner | 2fa8c25 | 2009-03-17 22:51:02 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /// getDesugaredType - Return the specified type with any "sugar" removed from |
| 102 | /// the type. This takes off typedefs, typeof's etc. If the outer level of |
| 103 | /// the type is already concrete, it returns it unmodified. This is similar |
| 104 | /// to getting the canonical type, but it doesn't remove *all* typedefs. For |
| 105 | /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is |
| 106 | /// concrete. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 107 | QualType QualType::getDesugaredType(QualType T) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 108 | QualifierCollector Qs; |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 109 | |
| 110 | QualType Cur = T; |
| 111 | while (true) { |
| 112 | const Type *CurTy = Qs.strip(Cur); |
| 113 | switch (CurTy->getTypeClass()) { |
| 114 | #define ABSTRACT_TYPE(Class, Parent) |
| 115 | #define TYPE(Class, Parent) \ |
| 116 | case Type::Class: { \ |
| 117 | const Class##Type *Ty = cast<Class##Type>(CurTy); \ |
| 118 | if (!Ty->isSugared()) \ |
| 119 | return Qs.apply(Cur); \ |
| 120 | Cur = Ty->desugar(); \ |
| 121 | break; \ |
| 122 | } |
| 123 | #include "clang/AST/TypeNodes.def" |
| 124 | } |
| 125 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 126 | } |
| 127 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 128 | /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic |
| 129 | /// sugar off the given type. This should produce an object of the |
| 130 | /// same dynamic type as the canonical type. |
| 131 | const Type *Type::getUnqualifiedDesugaredType() const { |
| 132 | const Type *Cur = this; |
Douglas Gregor | 969c689 | 2009-04-01 15:47:24 +0000 | [diff] [blame] | 133 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 134 | while (true) { |
| 135 | switch (Cur->getTypeClass()) { |
| 136 | #define ABSTRACT_TYPE(Class, Parent) |
| 137 | #define TYPE(Class, Parent) \ |
| 138 | case Class: { \ |
| 139 | const Class##Type *Ty = cast<Class##Type>(Cur); \ |
| 140 | if (!Ty->isSugared()) return Cur; \ |
| 141 | Cur = Ty->desugar().getTypePtr(); \ |
| 142 | break; \ |
| 143 | } |
| 144 | #include "clang/AST/TypeNodes.def" |
| 145 | } |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 146 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 149 | /// isVoidType - Helper method to determine if this is the 'void' type. |
| 150 | bool Type::isVoidType() const { |
| 151 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 152 | return BT->getKind() == BuiltinType::Void; |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | bool Type::isObjectType() const { |
Douglas Gregor | bad0e65 | 2009-03-24 20:32:41 +0000 | [diff] [blame] | 157 | if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType) || |
| 158 | isa<IncompleteArrayType>(CanonicalType) || isVoidType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 159 | return false; |
Douglas Gregor | bad0e65 | 2009-03-24 20:32:41 +0000 | [diff] [blame] | 160 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | bool Type::isDerivedType() const { |
| 164 | switch (CanonicalType->getTypeClass()) { |
| 165 | case Pointer: |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 166 | case VariableArray: |
| 167 | case ConstantArray: |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 168 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 169 | case FunctionProto: |
| 170 | case FunctionNoProto: |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 171 | case LValueReference: |
| 172 | case RValueReference: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 173 | case Record: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 174 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 175 | default: |
| 176 | return false; |
| 177 | } |
| 178 | } |
| 179 | |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 180 | bool Type::isClassType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 181 | if (const RecordType *RT = getAs<RecordType>()) |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 182 | return RT->getDecl()->isClass(); |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 183 | return false; |
| 184 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 185 | bool Type::isStructureType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 186 | if (const RecordType *RT = getAs<RecordType>()) |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 187 | return RT->getDecl()->isStruct(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 188 | return false; |
| 189 | } |
Steve Naroff | 7154a77 | 2009-07-01 14:36:47 +0000 | [diff] [blame] | 190 | bool Type::isVoidPointerType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 191 | if (const PointerType *PT = getAs<PointerType>()) |
Steve Naroff | 7154a77 | 2009-07-01 14:36:47 +0000 | [diff] [blame] | 192 | return PT->getPointeeType()->isVoidType(); |
| 193 | return false; |
| 194 | } |
| 195 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 196 | bool Type::isUnionType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 197 | if (const RecordType *RT = getAs<RecordType>()) |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 198 | return RT->getDecl()->isUnion(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 199 | return false; |
| 200 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 201 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 202 | bool Type::isComplexType() const { |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 203 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 204 | return CT->getElementType()->isFloatingType(); |
| 205 | return false; |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 208 | bool Type::isComplexIntegerType() const { |
| 209 | // Check for GCC complex integer extension. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 210 | return getAsComplexIntegerType(); |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | const ComplexType *Type::getAsComplexIntegerType() const { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 214 | if (const ComplexType *Complex = getAs<ComplexType>()) |
| 215 | if (Complex->getElementType()->isIntegerType()) |
| 216 | return Complex; |
| 217 | return 0; |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 220 | QualType Type::getPointeeType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 221 | if (const PointerType *PT = getAs<PointerType>()) |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 222 | return PT->getPointeeType(); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 223 | if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 224 | return OPT->getPointeeType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 225 | if (const BlockPointerType *BPT = getAs<BlockPointerType>()) |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 226 | return BPT->getPointeeType(); |
Mike Stump | 9c21289 | 2009-11-03 19:03:17 +0000 | [diff] [blame] | 227 | if (const ReferenceType *RT = getAs<ReferenceType>()) |
| 228 | return RT->getPointeeType(); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 229 | return QualType(); |
| 230 | } |
Chris Lattner | b77792e | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 231 | |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 232 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 233 | /// array types and types that contain variable array types in their |
| 234 | /// declarator |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 235 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 236 | // A VLA is a variably modified type. |
| 237 | if (isVariableArrayType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 238 | return true; |
| 239 | |
| 240 | // An array can contain a variably modified type |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 241 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 242 | return T->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 243 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 244 | // A pointer can point to a variably modified type. |
| 245 | // Also, C++ references and member pointers can point to a variably modified |
| 246 | // type, where VLAs appear as an extension to C++, and should be treated |
| 247 | // correctly. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 248 | if (const PointerType *PT = getAs<PointerType>()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 249 | return PT->getPointeeType()->isVariablyModifiedType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 250 | if (const ReferenceType *RT = getAs<ReferenceType>()) |
Daniel Dunbar | 68694ad | 2009-02-26 19:54:52 +0000 | [diff] [blame] | 251 | return RT->getPointeeType()->isVariablyModifiedType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 252 | if (const MemberPointerType *PT = getAs<MemberPointerType>()) |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 253 | return PT->getPointeeType()->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 254 | |
| 255 | // A function can return a variably modified type |
| 256 | // This one isn't completely obvious, but it follows from the |
| 257 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 258 | // illegal to declare a function returning a variably modified type. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 259 | if (const FunctionType *FT = getAs<FunctionType>()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 260 | return FT->getResultType()->isVariablyModifiedType(); |
| 261 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 262 | return false; |
| 263 | } |
| 264 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 265 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 266 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 267 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 268 | if (RT->getDecl()->isStruct()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 269 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 270 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 271 | |
| 272 | // 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] | 273 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 274 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 275 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 277 | // If this is a typedef for a structure type, strip the typedef off without |
| 278 | // losing all typedef information. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 279 | return cast<RecordType>(getUnqualifiedDesugaredType()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 280 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 281 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 285 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 286 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 287 | if (RT->getDecl()->isUnion()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 288 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 289 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 291 | // 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] | 292 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 293 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 294 | return 0; |
| 295 | |
| 296 | // If this is a typedef for a union type, strip the typedef off without |
| 297 | // losing all typedef information. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 298 | return cast<RecordType>(getUnqualifiedDesugaredType()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 299 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 300 | |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 301 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 304 | const ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const { |
| 305 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
| 306 | // type pointer if it is the right class. There is no typedef information to |
| 307 | // return and these cannot be Address-space qualified. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 308 | if (const ObjCInterfaceType *OIT = getAs<ObjCInterfaceType>()) |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 309 | if (OIT->getNumProtocols()) |
| 310 | return OIT; |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | bool Type::isObjCQualifiedInterfaceType() const { |
Steve Naroff | e61ad0b | 2009-07-18 15:38:31 +0000 | [diff] [blame] | 315 | return getAsObjCQualifiedInterfaceType() != 0; |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 318 | const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 319 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 320 | // type pointer if it is the right class. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 321 | if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 322 | if (OPT->isObjCQualifiedIdType()) |
| 323 | return OPT; |
| 324 | } |
| 325 | return 0; |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 328 | const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 329 | if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 330 | if (OPT->getInterfaceType()) |
| 331 | return OPT; |
| 332 | } |
| 333 | return 0; |
| 334 | } |
| 335 | |
Fariborz Jahanian | a91d6a6 | 2009-07-29 00:44:13 +0000 | [diff] [blame] | 336 | const CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 337 | if (const PointerType *PT = getAs<PointerType>()) |
| 338 | if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) |
Fariborz Jahanian | a91d6a6 | 2009-07-29 00:44:13 +0000 | [diff] [blame] | 339 | return dyn_cast<CXXRecordDecl>(RT->getDecl()); |
| 340 | return 0; |
| 341 | } |
| 342 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 343 | bool Type::isIntegerType() const { |
| 344 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 345 | return BT->getKind() >= BuiltinType::Bool && |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 346 | BT->getKind() <= BuiltinType::Int128; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 347 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 348 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 349 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 350 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 351 | return true; |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 352 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 353 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 354 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 355 | return VT->getElementType()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 356 | return false; |
| 357 | } |
| 358 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 359 | bool Type::isIntegralType() const { |
| 360 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 361 | return BT->getKind() >= BuiltinType::Bool && |
| 362 | BT->getKind() <= BuiltinType::LongLong; |
| 363 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 364 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 365 | return true; // Complete enum types are integral. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 366 | // FIXME: In C++, enum types are never integral. |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 367 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 368 | return true; |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 369 | return false; |
| 370 | } |
| 371 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 372 | bool Type::isEnumeralType() const { |
| 373 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 374 | return TT->getDecl()->isEnum(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
| 378 | bool Type::isBooleanType() const { |
| 379 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 380 | return BT->getKind() == BuiltinType::Bool; |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | bool Type::isCharType() const { |
| 385 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 386 | return BT->getKind() == BuiltinType::Char_U || |
| 387 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 388 | BT->getKind() == BuiltinType::Char_S || |
| 389 | BT->getKind() == BuiltinType::SChar; |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 390 | return false; |
| 391 | } |
| 392 | |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 393 | bool Type::isWideCharType() const { |
| 394 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 395 | return BT->getKind() == BuiltinType::WChar; |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 396 | return false; |
| 397 | } |
| 398 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 399 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 400 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 401 | /// an enum decl which has a signed representation, or a vector of signed |
| 402 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 403 | bool Type::isSignedIntegerType() const { |
| 404 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 405 | return BT->getKind() >= BuiltinType::Char_S && |
| 406 | BT->getKind() <= BuiltinType::LongLong; |
| 407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 409 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 410 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 412 | if (const FixedWidthIntType *FWIT = |
| 413 | dyn_cast<FixedWidthIntType>(CanonicalType)) |
| 414 | return FWIT->isSigned(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 416 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 417 | return VT->getElementType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 418 | return false; |
| 419 | } |
| 420 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 421 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 422 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 423 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 424 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 425 | bool Type::isUnsignedIntegerType() const { |
| 426 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 427 | return BT->getKind() >= BuiltinType::Bool && |
| 428 | BT->getKind() <= BuiltinType::ULongLong; |
| 429 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 430 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 431 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 432 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 433 | |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 434 | if (const FixedWidthIntType *FWIT = |
| 435 | dyn_cast<FixedWidthIntType>(CanonicalType)) |
| 436 | return !FWIT->isSigned(); |
| 437 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 438 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 439 | return VT->getElementType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 440 | return false; |
| 441 | } |
| 442 | |
| 443 | bool Type::isFloatingType() const { |
| 444 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 445 | return BT->getKind() >= BuiltinType::Float && |
| 446 | BT->getKind() <= BuiltinType::LongDouble; |
| 447 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 448 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 449 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 450 | return VT->getElementType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 451 | return false; |
| 452 | } |
| 453 | |
| 454 | bool Type::isRealFloatingType() const { |
| 455 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 456 | return BT->getKind() >= BuiltinType::Float && |
| 457 | BT->getKind() <= BuiltinType::LongDouble; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 458 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 459 | return VT->getElementType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 460 | return false; |
| 461 | } |
| 462 | |
| 463 | bool Type::isRealType() const { |
| 464 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 465 | return BT->getKind() >= BuiltinType::Bool && |
| 466 | BT->getKind() <= BuiltinType::LongDouble; |
| 467 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 468 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 469 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 470 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 471 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 472 | return VT->getElementType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 473 | return false; |
| 474 | } |
| 475 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 476 | bool Type::isArithmeticType() const { |
| 477 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | a7fbf72 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 478 | return BT->getKind() >= BuiltinType::Bool && |
| 479 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 480 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 481 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 482 | // If a body isn't seen by the time we get here, return false. |
| 483 | return ET->getDecl()->isDefinition(); |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 484 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 485 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 486 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 487 | } |
| 488 | |
| 489 | bool Type::isScalarType() const { |
| 490 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 491 | return BT->getKind() != BuiltinType::Void; |
| 492 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 493 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 494 | // are not treated as scalar types. |
| 495 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 496 | return true; |
| 497 | return false; |
| 498 | } |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 499 | if (isa<FixedWidthIntType>(CanonicalType)) |
| 500 | return true; |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 501 | return isa<PointerType>(CanonicalType) || |
| 502 | isa<BlockPointerType>(CanonicalType) || |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 503 | isa<MemberPointerType>(CanonicalType) || |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 504 | isa<ComplexType>(CanonicalType) || |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 505 | isa<ObjCObjectPointerType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 508 | /// \brief Determines whether the type is a C++ aggregate type or C |
| 509 | /// aggregate or union type. |
| 510 | /// |
| 511 | /// An aggregate type is an array or a class type (struct, union, or |
| 512 | /// class) that has no user-declared constructors, no private or |
| 513 | /// protected non-static data members, no base classes, and no virtual |
| 514 | /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type |
| 515 | /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also |
| 516 | /// includes union types. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 517 | bool Type::isAggregateType() const { |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 518 | if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { |
| 519 | if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) |
| 520 | return ClassDecl->isAggregate(); |
| 521 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 522 | return true; |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 525 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 528 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 529 | /// 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] | 530 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 531 | bool Type::isConstantSizeType() const { |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 532 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 533 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 534 | // The VAT must have a size, as it is known to be complete. |
| 535 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 539 | /// - a type that can describe objects, but which lacks information needed to |
| 540 | /// determine its size. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 541 | bool Type::isIncompleteType() const { |
| 542 | switch (CanonicalType->getTypeClass()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 543 | default: return false; |
| 544 | case Builtin: |
| 545 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 546 | // be completed. |
| 547 | return isVoidType(); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 548 | case Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 549 | case Enum: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 550 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 551 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 552 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 553 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 554 | // 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] | 555 | return true; |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 556 | case ObjCInterface: |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 557 | // ObjC interfaces are incomplete if they are @class, not @interface. |
| 558 | return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 562 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 563 | bool Type::isPODType() const { |
| 564 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 565 | // We return false for that case. |
| 566 | if (isIncompleteType()) |
| 567 | return false; |
| 568 | |
| 569 | switch (CanonicalType->getTypeClass()) { |
| 570 | // Everything not explicitly mentioned is not POD. |
| 571 | default: return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 572 | case VariableArray: |
| 573 | case ConstantArray: |
| 574 | // IncompleteArray is caught by isIncompleteType() above. |
| 575 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 576 | |
| 577 | case Builtin: |
| 578 | case Complex: |
| 579 | case Pointer: |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 580 | case MemberPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 581 | case Vector: |
| 582 | case ExtVector: |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 583 | case ObjCObjectPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 584 | return true; |
| 585 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 586 | case Enum: |
| 587 | return true; |
| 588 | |
| 589 | case Record: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 590 | if (CXXRecordDecl *ClassDecl |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 591 | = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) |
| 592 | return ClassDecl->isPOD(); |
| 593 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 594 | // C struct/union is POD. |
| 595 | return true; |
| 596 | } |
| 597 | } |
| 598 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 599 | bool Type::isPromotableIntegerType() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 600 | if (const BuiltinType *BT = getAs<BuiltinType>()) |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 601 | switch (BT->getKind()) { |
| 602 | case BuiltinType::Bool: |
| 603 | case BuiltinType::Char_S: |
| 604 | case BuiltinType::Char_U: |
| 605 | case BuiltinType::SChar: |
| 606 | case BuiltinType::UChar: |
| 607 | case BuiltinType::Short: |
| 608 | case BuiltinType::UShort: |
| 609 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | default: |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 611 | return false; |
| 612 | } |
| 613 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 616 | bool Type::isNullPtrType() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 617 | if (const BuiltinType *BT = getAs<BuiltinType>()) |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 618 | return BT->getKind() == BuiltinType::NullPtr; |
| 619 | return false; |
| 620 | } |
| 621 | |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 622 | bool Type::isSpecifierType() const { |
| 623 | // Note that this intentionally does not use the canonical type. |
| 624 | switch (getTypeClass()) { |
| 625 | case Builtin: |
| 626 | case Record: |
| 627 | case Enum: |
| 628 | case Typedef: |
Eli Friedman | c8f2c61 | 2009-05-30 01:45:29 +0000 | [diff] [blame] | 629 | case Complex: |
| 630 | case TypeOfExpr: |
| 631 | case TypeOf: |
| 632 | case TemplateTypeParm: |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 633 | case SubstTemplateTypeParm: |
Eli Friedman | c8f2c61 | 2009-05-30 01:45:29 +0000 | [diff] [blame] | 634 | case TemplateSpecialization: |
| 635 | case QualifiedName: |
| 636 | case Typename: |
| 637 | case ObjCInterface: |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 638 | case ObjCObjectPointer: |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 639 | return true; |
| 640 | default: |
| 641 | return false; |
| 642 | } |
| 643 | } |
| 644 | |
Argyrios Kyrtzidis | cd01f17 | 2009-09-29 19:41:13 +0000 | [diff] [blame] | 645 | const char *Type::getTypeClassName() const { |
| 646 | switch (TC) { |
| 647 | default: assert(0 && "Type class not in TypeNodes.def!"); |
| 648 | #define ABSTRACT_TYPE(Derived, Base) |
| 649 | #define TYPE(Derived, Base) case Derived: return #Derived; |
| 650 | #include "clang/AST/TypeNodes.def" |
| 651 | } |
| 652 | } |
| 653 | |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 654 | const char *BuiltinType::getName(const LangOptions &LO) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 655 | switch (getKind()) { |
| 656 | default: assert(0 && "Unknown builtin type!"); |
| 657 | case Void: return "void"; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 658 | case Bool: return LO.Bool ? "bool" : "_Bool"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 659 | case Char_S: return "char"; |
| 660 | case Char_U: return "char"; |
| 661 | case SChar: return "signed char"; |
| 662 | case Short: return "short"; |
| 663 | case Int: return "int"; |
| 664 | case Long: return "long"; |
| 665 | case LongLong: return "long long"; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 666 | case Int128: return "__int128_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 667 | case UChar: return "unsigned char"; |
| 668 | case UShort: return "unsigned short"; |
| 669 | case UInt: return "unsigned int"; |
| 670 | case ULong: return "unsigned long"; |
| 671 | case ULongLong: return "unsigned long long"; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 672 | case UInt128: return "__uint128_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 673 | case Float: return "float"; |
| 674 | case Double: return "double"; |
| 675 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 676 | case WChar: return "wchar_t"; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 677 | case Char16: return "char16_t"; |
| 678 | case Char32: return "char32_t"; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 679 | case NullPtr: return "nullptr_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 680 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 681 | case Dependent: return "<dependent type>"; |
Anders Carlsson | 6a75cd9 | 2009-07-11 00:34:39 +0000 | [diff] [blame] | 682 | case UndeducedAuto: return "auto"; |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 683 | case ObjCId: return "id"; |
| 684 | case ObjCClass: return "Class"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 688 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 689 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 690 | unsigned NumArgs, bool isVariadic, |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 691 | unsigned TypeQuals, bool hasExceptionSpec, |
| 692 | bool anyExceptionSpec, unsigned NumExceptions, |
Mike Stump | 2455636 | 2009-07-25 21:26:53 +0000 | [diff] [blame] | 693 | exception_iterator Exs, bool NoReturn) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 694 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 695 | for (unsigned i = 0; i != NumArgs; ++i) |
| 696 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 697 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 698 | ID.AddInteger(TypeQuals); |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 699 | ID.AddInteger(hasExceptionSpec); |
| 700 | if (hasExceptionSpec) { |
| 701 | ID.AddInteger(anyExceptionSpec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 702 | for (unsigned i = 0; i != NumExceptions; ++i) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 703 | ID.AddPointer(Exs[i].getAsOpaquePtr()); |
| 704 | } |
Mike Stump | 2455636 | 2009-07-25 21:26:53 +0000 | [diff] [blame] | 705 | ID.AddInteger(NoReturn); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 708 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 709 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 710 | getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(), |
Mike Stump | 2455636 | 2009-07-25 21:26:53 +0000 | [diff] [blame] | 711 | getNumExceptions(), exception_begin(), getNoReturnAttr()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 714 | void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID, |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 715 | QualType OIT, ObjCProtocolDecl **protocols, |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 716 | unsigned NumProtocols) { |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 717 | ID.AddPointer(OIT.getAsOpaquePtr()); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 718 | for (unsigned i = 0; i != NumProtocols; i++) |
| 719 | ID.AddPointer(protocols[i]); |
| 720 | } |
| 721 | |
| 722 | void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) { |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 723 | if (getNumProtocols()) |
| 724 | Profile(ID, getPointeeType(), &Protocols[0], getNumProtocols()); |
| 725 | else |
| 726 | Profile(ID, getPointeeType(), 0, 0); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 729 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 730 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 731 | /// sum of the type qualifiers, so if you have: |
| 732 | /// typedef const int A; |
| 733 | /// typedef volatile A B; |
| 734 | /// looking through the typedefs for B will give you "const volatile A". |
| 735 | /// |
| 736 | QualType TypedefType::LookThroughTypedefs() const { |
| 737 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 738 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 739 | if (!isa<TypedefType>(FirstType)) |
| 740 | return FirstType; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 741 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 742 | // Otherwise, do the fully general loop. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 743 | QualifierCollector Qs; |
| 744 | |
| 745 | QualType CurType; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 746 | const TypedefType *TDT = this; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 747 | do { |
| 748 | CurType = TDT->getDecl()->getUnderlyingType(); |
| 749 | TDT = dyn_cast<TypedefType>(Qs.strip(CurType)); |
| 750 | } while (TDT); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 751 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 752 | return Qs.apply(CurType); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 753 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 754 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 755 | QualType TypedefType::desugar() const { |
| 756 | return getDecl()->getUnderlyingType(); |
| 757 | } |
| 758 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 759 | TypeOfExprType::TypeOfExprType(Expr *E, QualType can) |
| 760 | : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 761 | } |
| 762 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 763 | QualType TypeOfExprType::desugar() const { |
| 764 | return getUnderlyingExpr()->getType(); |
| 765 | } |
| 766 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | b197572 | 2009-07-30 23:18:24 +0000 | [diff] [blame] | 768 | ASTContext &Context, Expr *E) { |
| 769 | E->Profile(ID, Context, true); |
| 770 | } |
| 771 | |
Anders Carlsson | 563a03b | 2009-07-10 19:20:26 +0000 | [diff] [blame] | 772 | DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | : Type(Decltype, can, E->isTypeDependent()), E(E), |
Anders Carlsson | 563a03b | 2009-07-10 19:20:26 +0000 | [diff] [blame] | 774 | UnderlyingType(underlyingType) { |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Douglas Gregor | 9d702ae | 2009-07-30 23:36:40 +0000 | [diff] [blame] | 777 | DependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E) |
| 778 | : DecltypeType(E, Context.DependentTy), Context(Context) { } |
| 779 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 780 | void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | 9d702ae | 2009-07-30 23:36:40 +0000 | [diff] [blame] | 781 | ASTContext &Context, Expr *E) { |
| 782 | E->Profile(ID, Context, true); |
| 783 | } |
| 784 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | TagType::TagType(TypeClass TC, TagDecl *D, QualType can) |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 786 | : Type(TC, can, D->isDependentType()), decl(D, 0) {} |
| 787 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 788 | bool RecordType::classof(const TagType *TT) { |
| 789 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 792 | bool EnumType::classof(const TagType *TT) { |
| 793 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 794 | } |
| 795 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 796 | static bool isDependent(const TemplateArgument &Arg) { |
| 797 | switch (Arg.getKind()) { |
| 798 | case TemplateArgument::Null: |
| 799 | assert(false && "Should not have a NULL template argument"); |
| 800 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 802 | case TemplateArgument::Type: |
| 803 | return Arg.getAsType()->isDependentType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 805 | case TemplateArgument::Declaration: |
| 806 | case TemplateArgument::Integral: |
| 807 | // Never dependent |
| 808 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 809 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 810 | case TemplateArgument::Expression: |
| 811 | return (Arg.getAsExpr()->isTypeDependent() || |
| 812 | Arg.getAsExpr()->isValueDependent()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 813 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 814 | case TemplateArgument::Pack: |
| 815 | assert(0 && "FIXME: Implement!"); |
| 816 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 817 | } |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 818 | |
| 819 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 820 | } |
| 821 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 822 | bool TemplateSpecializationType:: |
| 823 | anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { |
| 824 | for (unsigned i = 0; i != N; ++i) |
| 825 | if (isDependent(Args[i].getArgument())) |
| 826 | return true; |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | bool TemplateSpecializationType:: |
| 831 | anyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { |
| 832 | for (unsigned i = 0; i != N; ++i) |
| 833 | if (isDependent(Args[i])) |
| 834 | return true; |
| 835 | return false; |
| 836 | } |
| 837 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 838 | TemplateSpecializationType:: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 839 | TemplateSpecializationType(ASTContext &Context, TemplateName T, |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 840 | const TemplateArgument *Args, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 841 | unsigned NumArgs, QualType Canon) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | : Type(TemplateSpecialization, |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 843 | Canon.isNull()? QualType(this, 0) : Canon, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 844 | T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)), |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 845 | Context(Context), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | Template(T), NumArgs(NumArgs) { |
| 847 | assert((!Canon.isNull() || |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 848 | T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 849 | "No canonical type for non-dependent class template specialization"); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 850 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 851 | TemplateArgument *TemplateArgs |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 852 | = reinterpret_cast<TemplateArgument *>(this + 1); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 853 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 854 | new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 857 | void TemplateSpecializationType::Destroy(ASTContext& C) { |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 858 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { |
| 859 | // FIXME: Not all expressions get cloned, so we can't yet perform |
| 860 | // this destruction. |
| 861 | // if (Expr *E = getArg(Arg).getAsExpr()) |
| 862 | // E->Destroy(C); |
| 863 | } |
Douglas Gregor | 5908e9f | 2009-02-09 19:34:22 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 866 | TemplateSpecializationType::iterator |
| 867 | TemplateSpecializationType::end() const { |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 868 | return begin() + getNumArgs(); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 869 | } |
| 870 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 871 | const TemplateArgument & |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 872 | TemplateSpecializationType::getArg(unsigned Idx) const { |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 873 | assert(Idx < getNumArgs() && "Template argument out of range"); |
| 874 | return getArgs()[Idx]; |
| 875 | } |
| 876 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | void |
| 878 | TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, |
| 879 | TemplateName T, |
| 880 | const TemplateArgument *Args, |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 881 | unsigned NumArgs, |
| 882 | ASTContext &Context) { |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 883 | T.Profile(ID); |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 884 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 885 | Args[Idx].Profile(ID, Context); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 886 | } |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 887 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 888 | QualType QualifierCollector::apply(QualType QT) const { |
| 889 | if (!hasNonFastQualifiers()) |
| 890 | return QT.withFastQualifiers(getFastQualifiers()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 891 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 892 | assert(Context && "extended qualifiers but no context!"); |
| 893 | return Context->getQualifiedType(QT, *this); |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 894 | } |
| 895 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 896 | QualType QualifierCollector::apply(const Type *T) const { |
| 897 | if (!hasNonFastQualifiers()) |
| 898 | return QualType(T, getFastQualifiers()); |
| 899 | |
| 900 | assert(Context && "extended qualifiers but no context!"); |
| 901 | return Context->getQualifiedType(T, *this); |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 905 | //===----------------------------------------------------------------------===// |
| 906 | // Type Printing |
| 907 | //===----------------------------------------------------------------------===// |
| 908 | |
| 909 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 910 | std::string R = "identifier"; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 911 | LangOptions LO; |
| 912 | getAsStringInternal(R, PrintingPolicy(LO)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 913 | if (msg) |
| 914 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 915 | else |
| 916 | fprintf(stderr, "%s\n", R.c_str()); |
| 917 | } |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 918 | void QualType::dump() const { |
| 919 | dump(""); |
| 920 | } |
| 921 | |
| 922 | void Type::dump() const { |
| 923 | std::string S = "identifier"; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 924 | LangOptions LO; |
| 925 | getAsStringInternal(S, PrintingPolicy(LO)); |
Chris Lattner | c36d405 | 2008-07-27 00:48:22 +0000 | [diff] [blame] | 926 | fprintf(stderr, "%s\n", S.c_str()); |
| 927 | } |
| 928 | |
| 929 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 930 | |
| 931 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 932 | if (TypeQuals & Qualifiers::Const) { |
| 933 | if (!S.empty()) S += ' '; |
| 934 | S += "const"; |
| 935 | } |
| 936 | if (TypeQuals & Qualifiers::Volatile) { |
| 937 | if (!S.empty()) S += ' '; |
| 938 | S += "volatile"; |
| 939 | } |
| 940 | if (TypeQuals & Qualifiers::Restrict) { |
| 941 | if (!S.empty()) S += ' '; |
| 942 | S += "restrict"; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | std::string Qualifiers::getAsString() const { |
| 947 | LangOptions LO; |
| 948 | return getAsString(PrintingPolicy(LO)); |
| 949 | } |
| 950 | |
| 951 | // Appends qualifiers to the given string, separated by spaces. Will |
| 952 | // prefix a space if the string is non-empty. Will not append a final |
| 953 | // space. |
| 954 | void Qualifiers::getAsStringInternal(std::string &S, |
| 955 | const PrintingPolicy&) const { |
| 956 | AppendTypeQualList(S, getCVRQualifiers()); |
| 957 | if (unsigned AddressSpace = getAddressSpace()) { |
| 958 | if (!S.empty()) S += ' '; |
| 959 | S += "__attribute__((address_space("; |
| 960 | S += llvm::utostr_32(AddressSpace); |
| 961 | S += ")))"; |
| 962 | } |
| 963 | if (Qualifiers::GC GCAttrType = getObjCGCAttr()) { |
| 964 | if (!S.empty()) S += ' '; |
| 965 | S += "__attribute__((objc_gc("; |
| 966 | if (GCAttrType == Qualifiers::Weak) |
| 967 | S += "weak"; |
| 968 | else |
| 969 | S += "strong"; |
| 970 | S += ")))"; |
| 971 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 974 | std::string QualType::getAsString() const { |
| 975 | std::string S; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 976 | LangOptions LO; |
| 977 | getAsStringInternal(S, PrintingPolicy(LO)); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 978 | return S; |
| 979 | } |
| 980 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | void |
| 982 | QualType::getAsStringInternal(std::string &S, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 983 | const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 984 | if (isNull()) { |
Douglas Gregor | 61366e9 | 2008-12-24 00:01:03 +0000 | [diff] [blame] | 985 | S += "NULL TYPE"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 986 | return; |
| 987 | } |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 988 | |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 989 | if (Policy.SuppressSpecifiers && getTypePtr()->isSpecifierType()) |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 990 | return; |
| 991 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 992 | // Print qualifiers as appropriate. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 993 | Qualifiers Quals = getQualifiers(); |
| 994 | if (!Quals.empty()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 995 | std::string TQS; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 996 | Quals.getAsStringInternal(TQS, Policy); |
| 997 | |
| 998 | if (!S.empty()) { |
| 999 | TQS += ' '; |
| 1000 | TQS += S; |
| 1001 | } |
| 1002 | std::swap(S, TQS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1005 | getTypePtr()->getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | void BuiltinType::getAsStringInternal(std::string &S, |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1009 | const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1010 | if (S.empty()) { |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 1011 | S = getName(Policy.LangOpts); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1012 | } else { |
| 1013 | // Prefix the basic type, e.g. 'int X'. |
| 1014 | S = ' ' + S; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 1015 | S = getName(Policy.LangOpts) + S; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1019 | void FixedWidthIntType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Eli Friedman | f98aba3 | 2009-02-13 02:31:07 +0000 | [diff] [blame] | 1020 | // FIXME: Once we get bitwidth attribute, write as |
| 1021 | // "int __attribute__((bitwidth(x)))". |
| 1022 | std::string prefix = "__clang_fixedwidth"; |
| 1023 | prefix += llvm::utostr_32(Width); |
| 1024 | prefix += (char)(Signed ? 'S' : 'U'); |
| 1025 | if (S.empty()) { |
| 1026 | S = prefix; |
| 1027 | } else { |
| 1028 | // Prefix the basic type, e.g. 'int X'. |
| 1029 | S = prefix + S; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1034 | void ComplexType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
| 1035 | ElementType->getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1036 | S = "_Complex " + S; |
| 1037 | } |
| 1038 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1039 | void PointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1040 | S = '*' + S; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1042 | // Handle things like 'int (*A)[4];' correctly. |
| 1043 | // FIXME: this should include vectors, but vectors use attributes I guess. |
Chris Lattner | bdcd637 | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 1044 | if (isa<ArrayType>(getPointeeType())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1045 | S = '(' + S + ')'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1047 | getPointeeType().getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1050 | void BlockPointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 1051 | S = '^' + S; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1052 | PointeeType.getAsStringInternal(S, Policy); |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1055 | void LValueReferenceType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1056 | S = '&' + S; |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1057 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1058 | // Handle things like 'int (&A)[4];' correctly. |
| 1059 | // FIXME: this should include vectors, but vectors use attributes I guess. |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 1060 | if (isa<ArrayType>(getPointeeTypeAsWritten())) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1061 | S = '(' + S + ')'; |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1062 | |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 1063 | getPointeeTypeAsWritten().getAsStringInternal(S, Policy); |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1066 | void RValueReferenceType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1067 | S = "&&" + S; |
| 1068 | |
| 1069 | // Handle things like 'int (&&A)[4];' correctly. |
| 1070 | // FIXME: this should include vectors, but vectors use attributes I guess. |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 1071 | if (isa<ArrayType>(getPointeeTypeAsWritten())) |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1072 | S = '(' + S + ')'; |
| 1073 | |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 1074 | getPointeeTypeAsWritten().getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1077 | void MemberPointerType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 1078 | std::string C; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1079 | Class->getAsStringInternal(C, Policy); |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 1080 | C += "::*"; |
| 1081 | S = C + S; |
| 1082 | |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 1083 | // Handle things like 'int (Cls::*A)[4];' correctly. |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 1084 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 1085 | if (isa<ArrayType>(getPointeeType())) |
| 1086 | S = '(' + S + ')'; |
| 1087 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1088 | getPointeeType().getAsStringInternal(S, Policy); |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1091 | void ConstantArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1092 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 1093 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1094 | S += ']'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1096 | getElementType().getAsStringInternal(S, Policy); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1099 | void IncompleteArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 1100 | S += "[]"; |
| 1101 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1102 | getElementType().getAsStringInternal(S, Policy); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1105 | void VariableArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1106 | S += '['; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1108 | if (getIndexTypeQualifiers().hasQualifiers()) { |
| 1109 | AppendTypeQualList(S, getIndexTypeCVRQualifiers()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1110 | S += ' '; |
| 1111 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1113 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1114 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 1115 | else if (getSizeModifier() == Star) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1116 | S += '*'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1118 | if (getSizeExpr()) { |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1119 | std::string SStr; |
| 1120 | llvm::raw_string_ostream s(SStr); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1121 | getSizeExpr()->printPretty(s, 0, Policy); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 1122 | S += s.str(); |
| 1123 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1124 | S += ']'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1125 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1126 | getElementType().getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1129 | void DependentSizedArrayType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1130 | S += '['; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1132 | if (getIndexTypeQualifiers().hasQualifiers()) { |
| 1133 | AppendTypeQualList(S, getIndexTypeCVRQualifiers()); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1134 | S += ' '; |
| 1135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1137 | if (getSizeModifier() == Static) |
| 1138 | S += "static"; |
| 1139 | else if (getSizeModifier() == Star) |
| 1140 | S += '*'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1142 | if (getSizeExpr()) { |
| 1143 | std::string SStr; |
| 1144 | llvm::raw_string_ostream s(SStr); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1145 | getSizeExpr()->printPretty(s, 0, Policy); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1146 | S += s.str(); |
| 1147 | } |
| 1148 | S += ']'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1150 | getElementType().getAsStringInternal(S, Policy); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 1153 | void DependentSizedExtVectorType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
| 1154 | getElementType().getAsStringInternal(S, Policy); |
| 1155 | |
Douglas Gregor | f6ddb73 | 2009-06-18 18:45:36 +0000 | [diff] [blame] | 1156 | S += " __attribute__((ext_vector_type("; |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 1157 | if (getSizeExpr()) { |
| 1158 | std::string SStr; |
| 1159 | llvm::raw_string_ostream s(SStr); |
| 1160 | getSizeExpr()->printPretty(s, 0, Policy); |
| 1161 | S += s.str(); |
| 1162 | } |
| 1163 | S += ")))"; |
| 1164 | } |
| 1165 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1166 | void VectorType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1167 | // FIXME: We prefer to print the size directly here, but have no way |
| 1168 | // to get the size of the type. |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 1169 | S += " __attribute__((__vector_size__("; |
Daniel Dunbar | 5620b50 | 2008-10-05 05:43:11 +0000 | [diff] [blame] | 1170 | S += llvm::utostr_32(NumElements); // convert back to bytes. |
| 1171 | S += " * sizeof(" + ElementType.getAsString() + "))))"; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1172 | ElementType.getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1175 | void ExtVectorType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 1176 | S += " __attribute__((ext_vector_type("; |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1177 | S += llvm::utostr_32(NumElements); |
| 1178 | S += ")))"; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1179 | ElementType.getAsStringInternal(S, Policy); |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1182 | void TypeOfExprType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1183 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 1184 | InnerString = ' ' + InnerString; |
Ted Kremenek | a95d375 | 2008-09-13 05:16:45 +0000 | [diff] [blame] | 1185 | std::string Str; |
| 1186 | llvm::raw_string_ostream s(Str); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1187 | getUnderlyingExpr()->printPretty(s, 0, Policy); |
Argyrios Kyrtzidis | 6409625 | 2009-05-22 10:22:18 +0000 | [diff] [blame] | 1188 | InnerString = "typeof " + s.str() + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1191 | void TypeOfType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1192 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 1193 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1194 | std::string Tmp; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1195 | getUnderlyingType().getAsStringInternal(Tmp, Policy); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 1196 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | void DecltypeType::getAsStringInternal(std::string &InnerString, |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 1200 | const PrintingPolicy &Policy) const { |
| 1201 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'decltype(t) X'. |
| 1202 | InnerString = ' ' + InnerString; |
| 1203 | std::string Str; |
| 1204 | llvm::raw_string_ostream s(Str); |
| 1205 | getUnderlyingExpr()->printPretty(s, 0, Policy); |
| 1206 | InnerString = "decltype(" + s.str() + ")" + InnerString; |
| 1207 | } |
| 1208 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1209 | void FunctionNoProtoType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1210 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1211 | if (!S.empty()) |
| 1212 | S = "(" + S + ")"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1214 | S += "()"; |
Mike Stump | 2455636 | 2009-07-25 21:26:53 +0000 | [diff] [blame] | 1215 | if (getNoReturnAttr()) |
| 1216 | S += " __attribute__((noreturn))"; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1217 | getResultType().getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1218 | } |
| 1219 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1220 | void FunctionProtoType::getAsStringInternal(std::string &S, const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1221 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 1222 | if (!S.empty()) |
| 1223 | S = "(" + S + ")"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1225 | S += "("; |
| 1226 | std::string Tmp; |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 1227 | PrintingPolicy ParamPolicy(Policy); |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 1228 | ParamPolicy.SuppressSpecifiers = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1229 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 1230 | if (i) S += ", "; |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 1231 | getArgType(i).getAsStringInternal(Tmp, ParamPolicy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1232 | S += Tmp; |
| 1233 | Tmp.clear(); |
| 1234 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1236 | if (isVariadic()) { |
| 1237 | if (getNumArgs()) |
| 1238 | S += ", "; |
| 1239 | S += "..."; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 1240 | } else if (getNumArgs() == 0 && !Policy.LangOpts.CPlusPlus) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1241 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 1242 | S += "void"; |
| 1243 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1245 | S += ")"; |
Mike Stump | 2455636 | 2009-07-25 21:26:53 +0000 | [diff] [blame] | 1246 | if (getNoReturnAttr()) |
| 1247 | S += " __attribute__((noreturn))"; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1248 | getResultType().getAsStringInternal(S, Policy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1252 | void TypedefType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1253 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1254 | InnerString = ' ' + InnerString; |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 1255 | InnerString = getDecl()->getIdentifier()->getName().str() + InnerString; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1258 | void TemplateTypeParmType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1259 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'parmname X'. |
| 1260 | InnerString = ' ' + InnerString; |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 1261 | |
| 1262 | if (!Name) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | InnerString = "type-parameter-" + llvm::utostr_32(Depth) + '-' + |
Douglas Gregor | fab9d67 | 2009-02-05 23:33:38 +0000 | [diff] [blame] | 1264 | llvm::utostr_32(Index) + InnerString; |
| 1265 | else |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 1266 | InnerString = Name->getName().str() + InnerString; |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 1269 | void SubstTemplateTypeParmType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
| 1270 | getReplacementType().getAsStringInternal(InnerString, Policy); |
| 1271 | } |
| 1272 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1273 | static void PrintTemplateArgument(std::string &Buffer, |
| 1274 | const TemplateArgument &Arg, |
| 1275 | const PrintingPolicy &Policy) { |
| 1276 | switch (Arg.getKind()) { |
| 1277 | case TemplateArgument::Null: |
| 1278 | assert(false && "Null template argument"); |
| 1279 | break; |
| 1280 | |
| 1281 | case TemplateArgument::Type: |
| 1282 | Arg.getAsType().getAsStringInternal(Buffer, Policy); |
| 1283 | break; |
| 1284 | |
| 1285 | case TemplateArgument::Declaration: |
| 1286 | Buffer = cast<NamedDecl>(Arg.getAsDecl())->getNameAsString(); |
| 1287 | break; |
| 1288 | |
| 1289 | case TemplateArgument::Integral: |
| 1290 | Buffer = Arg.getAsIntegral()->toString(10, true); |
| 1291 | break; |
| 1292 | |
| 1293 | case TemplateArgument::Expression: { |
| 1294 | llvm::raw_string_ostream s(Buffer); |
| 1295 | Arg.getAsExpr()->printPretty(s, 0, Policy); |
| 1296 | break; |
| 1297 | } |
| 1298 | |
| 1299 | case TemplateArgument::Pack: |
| 1300 | assert(0 && "FIXME: Implement!"); |
| 1301 | break; |
| 1302 | } |
| 1303 | } |
| 1304 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1305 | std::string |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1306 | TemplateSpecializationType::PrintTemplateArgumentList( |
| 1307 | const TemplateArgument *Args, |
| 1308 | unsigned NumArgs, |
| 1309 | const PrintingPolicy &Policy) { |
Douglas Gregor | 9813753 | 2009-03-10 18:33:27 +0000 | [diff] [blame] | 1310 | std::string SpecString; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1311 | SpecString += '<'; |
| 1312 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { |
| 1313 | if (Arg) |
| 1314 | SpecString += ", "; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1315 | |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1316 | // Print the argument into a string. |
| 1317 | std::string ArgString; |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1318 | PrintTemplateArgument(ArgString, Args[Arg], Policy); |
Douglas Gregor | 3899946 | 2009-06-04 05:28:55 +0000 | [diff] [blame] | 1319 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1320 | // If this is the first argument and its string representation |
| 1321 | // begins with the global scope specifier ('::foo'), add a space |
| 1322 | // to avoid printing the diagraph '<:'. |
| 1323 | if (!Arg && !ArgString.empty() && ArgString[0] == ':') |
| 1324 | SpecString += ' '; |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1325 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1326 | SpecString += ArgString; |
| 1327 | } |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1328 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1329 | // If the last character of our string is '>', add another space to |
| 1330 | // keep the two '>''s separate tokens. We don't *have* to do this in |
| 1331 | // C++0x, but it's still good hygiene. |
| 1332 | if (SpecString[SpecString.size() - 1] == '>') |
| 1333 | SpecString += ' '; |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1334 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 1335 | SpecString += '>'; |
| 1336 | |
| 1337 | return SpecString; |
| 1338 | } |
| 1339 | |
| 1340 | // Sadly, repeat all that with TemplateArgLoc. |
| 1341 | std::string TemplateSpecializationType:: |
| 1342 | PrintTemplateArgumentList(const TemplateArgumentLoc *Args, unsigned NumArgs, |
| 1343 | const PrintingPolicy &Policy) { |
| 1344 | std::string SpecString; |
| 1345 | SpecString += '<'; |
| 1346 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { |
| 1347 | if (Arg) |
| 1348 | SpecString += ", "; |
| 1349 | |
| 1350 | // Print the argument into a string. |
| 1351 | std::string ArgString; |
| 1352 | PrintTemplateArgument(ArgString, Args[Arg].getArgument(), Policy); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1353 | |
| 1354 | // If this is the first argument and its string representation |
| 1355 | // begins with the global scope specifier ('::foo'), add a space |
| 1356 | // to avoid printing the diagraph '<:'. |
| 1357 | if (!Arg && !ArgString.empty() && ArgString[0] == ':') |
| 1358 | SpecString += ' '; |
| 1359 | |
| 1360 | SpecString += ArgString; |
| 1361 | } |
| 1362 | |
| 1363 | // If the last character of our string is '>', add another space to |
| 1364 | // keep the two '>''s separate tokens. We don't *have* to do this in |
| 1365 | // C++0x, but it's still good hygiene. |
| 1366 | if (SpecString[SpecString.size() - 1] == '>') |
| 1367 | SpecString += ' '; |
| 1368 | |
| 1369 | SpecString += '>'; |
| 1370 | |
Douglas Gregor | 9813753 | 2009-03-10 18:33:27 +0000 | [diff] [blame] | 1371 | return SpecString; |
| 1372 | } |
| 1373 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | void |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1375 | TemplateSpecializationType:: |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1376 | getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1377 | std::string SpecString; |
| 1378 | |
| 1379 | { |
| 1380 | llvm::raw_string_ostream OS(SpecString); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1381 | Template.print(OS, Policy); |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1384 | SpecString += PrintTemplateArgumentList(getArgs(), getNumArgs(), Policy); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1385 | if (InnerString.empty()) |
| 1386 | InnerString.swap(SpecString); |
| 1387 | else |
| 1388 | InnerString = SpecString + ' ' + InnerString; |
| 1389 | } |
| 1390 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1391 | void QualifiedNameType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 1392 | std::string MyString; |
| 1393 | |
Douglas Gregor | bad3518 | 2009-03-19 03:51:16 +0000 | [diff] [blame] | 1394 | { |
| 1395 | llvm::raw_string_ostream OS(MyString); |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1396 | NNS->print(OS, Policy); |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 1397 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1398 | |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 1399 | std::string TypeStr; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1400 | PrintingPolicy InnerPolicy(Policy); |
| 1401 | InnerPolicy.SuppressTagKind = true; |
John McCall | 2191b20 | 2009-09-05 06:31:47 +0000 | [diff] [blame] | 1402 | InnerPolicy.SuppressScope = true; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1403 | NamedType.getAsStringInternal(TypeStr, InnerPolicy); |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 1404 | |
| 1405 | MyString += TypeStr; |
| 1406 | if (InnerString.empty()) |
| 1407 | InnerString.swap(MyString); |
| 1408 | else |
| 1409 | InnerString = MyString + ' ' + InnerString; |
| 1410 | } |
| 1411 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1412 | void TypenameType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 1413 | std::string MyString; |
| 1414 | |
| 1415 | { |
| 1416 | llvm::raw_string_ostream OS(MyString); |
| 1417 | OS << "typename "; |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1418 | NNS->print(OS, Policy); |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 1419 | |
| 1420 | if (const IdentifierInfo *Ident = getIdentifier()) |
| 1421 | OS << Ident->getName(); |
| 1422 | else if (const TemplateSpecializationType *Spec = getTemplateId()) { |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1423 | Spec->getTemplateName().print(OS, Policy, true); |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 1424 | OS << TemplateSpecializationType::PrintTemplateArgumentList( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1425 | Spec->getArgs(), |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1426 | Spec->getNumArgs(), |
| 1427 | Policy); |
Douglas Gregor | 1734317 | 2009-04-01 00:28:59 +0000 | [diff] [blame] | 1428 | } |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 1429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 1431 | if (InnerString.empty()) |
| 1432 | InnerString.swap(MyString); |
| 1433 | else |
| 1434 | InnerString = MyString + ' ' + InnerString; |
| 1435 | } |
| 1436 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 1437 | void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
| 1438 | const ObjCInterfaceDecl *Decl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1439 | ObjCProtocolDecl **protocols, |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 1440 | unsigned NumProtocols) { |
| 1441 | ID.AddPointer(Decl); |
| 1442 | for (unsigned i = 0; i != NumProtocols; i++) |
| 1443 | ID.AddPointer(protocols[i]); |
| 1444 | } |
| 1445 | |
| 1446 | void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
| 1447 | if (getNumProtocols()) |
| 1448 | Profile(ID, getDecl(), &Protocols[0], getNumProtocols()); |
| 1449 | else |
| 1450 | Profile(ID, getDecl(), 0, 0); |
| 1451 | } |
| 1452 | |
| 1453 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString, |
| 1454 | const PrintingPolicy &Policy) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1455 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1456 | InnerString = ' ' + InnerString; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1457 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 1458 | std::string ObjCQIString = getDecl()->getNameAsString(); |
| 1459 | if (getNumProtocols()) { |
| 1460 | ObjCQIString += '<'; |
| 1461 | bool isFirst = true; |
| 1462 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1463 | if (isFirst) |
| 1464 | isFirst = false; |
| 1465 | else |
| 1466 | ObjCQIString += ','; |
| 1467 | ObjCQIString += (*I)->getNameAsString(); |
| 1468 | } |
| 1469 | ObjCQIString += '>'; |
| 1470 | } |
| 1471 | InnerString = ObjCQIString + InnerString; |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1472 | } |
| 1473 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1474 | void ObjCObjectPointerType::getAsStringInternal(std::string &InnerString, |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1475 | const PrintingPolicy &Policy) const { |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 1476 | std::string ObjCQIString; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1477 | |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 1478 | if (isObjCIdType() || isObjCQualifiedIdType()) |
| 1479 | ObjCQIString = "id"; |
Steve Naroff | 470301b | 2009-07-22 16:07:01 +0000 | [diff] [blame] | 1480 | else if (isObjCClassType() || isObjCQualifiedClassType()) |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 1481 | ObjCQIString = "Class"; |
| 1482 | else |
| 1483 | ObjCQIString = getInterfaceDecl()->getNameAsString(); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1484 | |
| 1485 | if (!qual_empty()) { |
| 1486 | ObjCQIString += '<'; |
| 1487 | for (qual_iterator I = qual_begin(), E = qual_end(); I != E; ++I) { |
| 1488 | ObjCQIString += (*I)->getNameAsString(); |
| 1489 | if (I+1 != E) |
| 1490 | ObjCQIString += ','; |
| 1491 | } |
| 1492 | ObjCQIString += '>'; |
| 1493 | } |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1494 | |
| 1495 | PointeeType.getQualifiers().getAsStringInternal(ObjCQIString, Policy); |
| 1496 | |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 1497 | if (!isObjCIdType() && !isObjCQualifiedIdType()) |
| 1498 | ObjCQIString += " *"; // Don't forget the implicit pointer. |
| 1499 | else if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1500 | InnerString = ' ' + InnerString; |
| 1501 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 1502 | InnerString = ObjCQIString + InnerString; |
| 1503 | } |
| 1504 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1505 | void ElaboratedType::getAsStringInternal(std::string &InnerString, |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 1506 | const PrintingPolicy &Policy) const { |
| 1507 | std::string TypeStr; |
| 1508 | PrintingPolicy InnerPolicy(Policy); |
| 1509 | InnerPolicy.SuppressTagKind = true; |
| 1510 | UnderlyingType.getAsStringInternal(InnerString, InnerPolicy); |
| 1511 | |
| 1512 | InnerString = std::string(getNameForTagKind(getTagKind())) + ' ' + InnerString; |
| 1513 | } |
| 1514 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1515 | void TagType::getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const { |
Eli Friedman | 42f42c0 | 2009-05-30 04:20:30 +0000 | [diff] [blame] | 1516 | if (Policy.SuppressTag) |
| 1517 | return; |
| 1518 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1519 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 1520 | InnerString = ' ' + InnerString; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1521 | |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1522 | const char *Kind = Policy.SuppressTagKind? 0 : getDecl()->getKindName(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1523 | const char *ID; |
| 1524 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 1525 | ID = II->getNameStart(); |
Douglas Gregor | 4e16d04 | 2009-03-10 18:11:21 +0000 | [diff] [blame] | 1526 | else if (TypedefDecl *Typedef = getDecl()->getTypedefForAnonDecl()) { |
| 1527 | Kind = 0; |
| 1528 | assert(Typedef->getIdentifier() && "Typedef without identifier?"); |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 1529 | ID = Typedef->getIdentifier()->getNameStart(); |
Douglas Gregor | 4e16d04 | 2009-03-10 18:11:21 +0000 | [diff] [blame] | 1530 | } else |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1531 | ID = "<anonymous>"; |
| 1532 | |
Douglas Gregor | 9813753 | 2009-03-10 18:33:27 +0000 | [diff] [blame] | 1533 | // If this is a class template specialization, print the template |
| 1534 | // arguments. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | if (ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | 9813753 | 2009-03-10 18:33:27 +0000 | [diff] [blame] | 1536 | = dyn_cast<ClassTemplateSpecializationDecl>(getDecl())) { |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 1537 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | std::string TemplateArgsStr |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1539 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 1540 | TemplateArgs.getFlatArgumentList(), |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1541 | TemplateArgs.flat_size(), |
| 1542 | Policy); |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 1543 | InnerString = TemplateArgsStr + InnerString; |
Douglas Gregor | 9813753 | 2009-03-10 18:33:27 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
John McCall | 2191b20 | 2009-09-05 06:31:47 +0000 | [diff] [blame] | 1546 | if (!Policy.SuppressScope) { |
Douglas Gregor | 24c46b3 | 2009-03-19 04:25:59 +0000 | [diff] [blame] | 1547 | // Compute the full nested-name-specifier for this type. In C, |
| 1548 | // this will always be empty. |
| 1549 | std::string ContextStr; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1550 | for (DeclContext *DC = getDecl()->getDeclContext(); |
Douglas Gregor | 24c46b3 | 2009-03-19 04:25:59 +0000 | [diff] [blame] | 1551 | !DC->isTranslationUnit(); DC = DC->getParent()) { |
| 1552 | std::string MyPart; |
| 1553 | if (NamespaceDecl *NS = dyn_cast<NamespaceDecl>(DC)) { |
| 1554 | if (NS->getIdentifier()) |
| 1555 | MyPart = NS->getNameAsString(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1556 | } else if (ClassTemplateSpecializationDecl *Spec |
Douglas Gregor | 24c46b3 | 2009-03-19 04:25:59 +0000 | [diff] [blame] | 1557 | = dyn_cast<ClassTemplateSpecializationDecl>(DC)) { |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 1558 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); |
| 1559 | std::string TemplateArgsStr |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1560 | = TemplateSpecializationType::PrintTemplateArgumentList( |
Douglas Gregor | 7e06390 | 2009-05-11 23:53:27 +0000 | [diff] [blame] | 1561 | TemplateArgs.getFlatArgumentList(), |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 1562 | TemplateArgs.flat_size(), |
| 1563 | Policy); |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 1564 | MyPart = Spec->getIdentifier()->getName().str() + TemplateArgsStr; |
Douglas Gregor | 24c46b3 | 2009-03-19 04:25:59 +0000 | [diff] [blame] | 1565 | } else if (TagDecl *Tag = dyn_cast<TagDecl>(DC)) { |
| 1566 | if (TypedefDecl *Typedef = Tag->getTypedefForAnonDecl()) |
| 1567 | MyPart = Typedef->getIdentifier()->getName(); |
| 1568 | else if (Tag->getIdentifier()) |
| 1569 | MyPart = Tag->getIdentifier()->getName(); |
| 1570 | } |
| 1571 | |
| 1572 | if (!MyPart.empty()) |
| 1573 | ContextStr = MyPart + "::" + ContextStr; |
| 1574 | } |
| 1575 | |
John McCall | 2191b20 | 2009-09-05 06:31:47 +0000 | [diff] [blame] | 1576 | if (Kind) |
| 1577 | InnerString = std::string(Kind) + ' ' + ContextStr + ID + InnerString; |
| 1578 | else |
| 1579 | InnerString = ContextStr + ID + InnerString; |
Douglas Gregor | 24c46b3 | 2009-03-19 04:25:59 +0000 | [diff] [blame] | 1580 | } else |
Douglas Gregor | 4e16d04 | 2009-03-10 18:11:21 +0000 | [diff] [blame] | 1581 | InnerString = ID + InnerString; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1582 | } |