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