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 | |
Douglas Gregor | f540305 | 2010-03-30 18:56:13 +0000 | [diff] [blame] | 25 | #ifndef NDEBUG |
| 26 | llvm::Statistic clang::objc_type_checks = |
| 27 | { "clang", "Number of checks for Objective-C type nodes", 0, 0 }; |
| 28 | llvm::Statistic clang::cxx_type_checks = |
| 29 | { "clang", "Number of checks for C++ type nodes", 0, 0 }; |
| 30 | #endif |
| 31 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 32 | bool QualType::isConstant(QualType T, ASTContext &Ctx) { |
| 33 | if (T.isConstQualified()) |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 34 | return true; |
| 35 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 36 | if (const ArrayType *AT = Ctx.getAsArrayType(T)) |
| 37 | return AT->getElementType().isConstant(Ctx); |
Nuno Lopes | b381aac | 2008-09-01 11:33:04 +0000 | [diff] [blame] | 38 | |
| 39 | return false; |
| 40 | } |
| 41 | |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 42 | void Type::Destroy(ASTContext& C) { |
| 43 | this->~Type(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 44 | C.Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void VariableArrayType::Destroy(ASTContext& C) { |
Eli Friedman | f91f5c8 | 2009-04-26 21:57:51 +0000 | [diff] [blame] | 48 | if (SizeExpr) |
| 49 | SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 50 | this->~VariableArrayType(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 51 | C.Deallocate(this); |
Ted Kremenek | 4b05b1d | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 52 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 53 | |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 54 | void DependentSizedArrayType::Destroy(ASTContext& C) { |
Argyrios Kyrtzidis | e7f3840 | 2009-07-18 21:18:10 +0000 | [diff] [blame] | 55 | // FIXME: Resource contention like in ConstantArrayWithExprType ? |
| 56 | // May crash, depending on platform or a particular build. |
| 57 | // SizeExpr->Destroy(C); |
Ted Kremenek | 566c2ba | 2009-01-19 21:31:22 +0000 | [diff] [blame] | 58 | this->~DependentSizedArrayType(); |
Steve Naroff | 3e97049 | 2009-01-27 21:25:57 +0000 | [diff] [blame] | 59 | C.Deallocate(this); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 60 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 61 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | 04d4bee | 2009-07-31 00:23:35 +0000 | [diff] [blame] | 63 | ASTContext &Context, |
| 64 | QualType ET, |
| 65 | ArraySizeModifier SizeMod, |
| 66 | unsigned TypeQuals, |
| 67 | Expr *E) { |
| 68 | ID.AddPointer(ET.getAsOpaquePtr()); |
| 69 | ID.AddInteger(SizeMod); |
| 70 | ID.AddInteger(TypeQuals); |
| 71 | E->Profile(ID, Context, true); |
| 72 | } |
| 73 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 74 | void |
| 75 | DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | 2ec09f1 | 2009-07-31 03:54:25 +0000 | [diff] [blame] | 76 | ASTContext &Context, |
| 77 | QualType ElementType, Expr *SizeExpr) { |
| 78 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
| 79 | SizeExpr->Profile(ID, Context, true); |
| 80 | } |
| 81 | |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 82 | void DependentSizedExtVectorType::Destroy(ASTContext& C) { |
Douglas Gregor | bd1099e | 2009-07-23 16:36:45 +0000 | [diff] [blame] | 83 | // FIXME: Deallocate size expression, once we're cloning properly. |
| 84 | // if (SizeExpr) |
| 85 | // SizeExpr->Destroy(C); |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 86 | this->~DependentSizedExtVectorType(); |
| 87 | C.Deallocate(this); |
| 88 | } |
| 89 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 90 | /// getArrayElementTypeNoTypeQual - If this is an array type, return the |
| 91 | /// element type of the array, potentially with type qualifiers missing. |
| 92 | /// This method should never be used when type qualifiers are meaningful. |
| 93 | const Type *Type::getArrayElementTypeNoTypeQual() const { |
| 94 | // If this is directly an array type, return it. |
| 95 | if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) |
| 96 | return ATy->getElementType().getTypePtr(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 98 | // 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] | 99 | if (!isa<ArrayType>(CanonicalType)) |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 100 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 102 | // If this is a typedef for an array type, strip the typedef off without |
| 103 | // losing all typedef information. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 104 | return cast<ArrayType>(getUnqualifiedDesugaredType()) |
| 105 | ->getElementType().getTypePtr(); |
Chris Lattner | 2fa8c25 | 2009-03-17 22:51:02 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Douglas Gregor | fa1a06e | 2009-11-17 00:55:50 +0000 | [diff] [blame] | 108 | /// \brief Retrieve the unqualified variant of the given type, removing as |
| 109 | /// little sugar as possible. |
| 110 | /// |
| 111 | /// This routine looks through various kinds of sugar to find the |
| 112 | /// least-desuraged type that is unqualified. For example, given: |
| 113 | /// |
| 114 | /// \code |
| 115 | /// typedef int Integer; |
| 116 | /// typedef const Integer CInteger; |
| 117 | /// typedef CInteger DifferenceType; |
| 118 | /// \endcode |
| 119 | /// |
| 120 | /// Executing \c getUnqualifiedTypeSlow() on the type \c DifferenceType will |
| 121 | /// desugar until we hit the type \c Integer, which has no qualifiers on it. |
| 122 | QualType QualType::getUnqualifiedTypeSlow() const { |
| 123 | QualType Cur = *this; |
| 124 | while (true) { |
| 125 | if (!Cur.hasQualifiers()) |
| 126 | return Cur; |
| 127 | |
| 128 | const Type *CurTy = Cur.getTypePtr(); |
| 129 | switch (CurTy->getTypeClass()) { |
| 130 | #define ABSTRACT_TYPE(Class, Parent) |
| 131 | #define TYPE(Class, Parent) \ |
| 132 | case Type::Class: { \ |
| 133 | const Class##Type *Ty = cast<Class##Type>(CurTy); \ |
| 134 | if (!Ty->isSugared()) \ |
| 135 | return Cur.getLocalUnqualifiedType(); \ |
| 136 | Cur = Ty->desugar(); \ |
| 137 | break; \ |
| 138 | } |
| 139 | #include "clang/AST/TypeNodes.def" |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return Cur.getUnqualifiedType(); |
| 144 | } |
| 145 | |
Chris Lattner | 2fa8c25 | 2009-03-17 22:51:02 +0000 | [diff] [blame] | 146 | /// getDesugaredType - Return the specified type with any "sugar" removed from |
| 147 | /// the type. This takes off typedefs, typeof's etc. If the outer level of |
| 148 | /// the type is already concrete, it returns it unmodified. This is similar |
| 149 | /// to getting the canonical type, but it doesn't remove *all* typedefs. For |
| 150 | /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is |
| 151 | /// concrete. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 152 | QualType QualType::getDesugaredType(QualType T) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 153 | QualifierCollector Qs; |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 154 | |
| 155 | QualType Cur = T; |
| 156 | while (true) { |
| 157 | const Type *CurTy = Qs.strip(Cur); |
| 158 | switch (CurTy->getTypeClass()) { |
| 159 | #define ABSTRACT_TYPE(Class, Parent) |
| 160 | #define TYPE(Class, Parent) \ |
| 161 | case Type::Class: { \ |
| 162 | const Class##Type *Ty = cast<Class##Type>(CurTy); \ |
| 163 | if (!Ty->isSugared()) \ |
| 164 | return Qs.apply(Cur); \ |
| 165 | Cur = Ty->desugar(); \ |
| 166 | break; \ |
| 167 | } |
| 168 | #include "clang/AST/TypeNodes.def" |
| 169 | } |
| 170 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 171 | } |
| 172 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 173 | /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic |
| 174 | /// sugar off the given type. This should produce an object of the |
| 175 | /// same dynamic type as the canonical type. |
| 176 | const Type *Type::getUnqualifiedDesugaredType() const { |
| 177 | const Type *Cur = this; |
Douglas Gregor | 969c689 | 2009-04-01 15:47:24 +0000 | [diff] [blame] | 178 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 179 | while (true) { |
| 180 | switch (Cur->getTypeClass()) { |
| 181 | #define ABSTRACT_TYPE(Class, Parent) |
| 182 | #define TYPE(Class, Parent) \ |
| 183 | case Class: { \ |
| 184 | const Class##Type *Ty = cast<Class##Type>(Cur); \ |
| 185 | if (!Ty->isSugared()) return Cur; \ |
| 186 | Cur = Ty->desugar().getTypePtr(); \ |
| 187 | break; \ |
| 188 | } |
| 189 | #include "clang/AST/TypeNodes.def" |
| 190 | } |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 191 | } |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 194 | /// isVoidType - Helper method to determine if this is the 'void' type. |
| 195 | bool Type::isVoidType() const { |
| 196 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 197 | return BT->getKind() == BuiltinType::Void; |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | bool Type::isObjectType() const { |
Douglas Gregor | bad0e65 | 2009-03-24 20:32:41 +0000 | [diff] [blame] | 202 | if (isa<FunctionType>(CanonicalType) || isa<ReferenceType>(CanonicalType) || |
| 203 | isa<IncompleteArrayType>(CanonicalType) || isVoidType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 204 | return false; |
Douglas Gregor | bad0e65 | 2009-03-24 20:32:41 +0000 | [diff] [blame] | 205 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | bool Type::isDerivedType() const { |
| 209 | switch (CanonicalType->getTypeClass()) { |
| 210 | case Pointer: |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 211 | case VariableArray: |
| 212 | case ConstantArray: |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 213 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 214 | case FunctionProto: |
| 215 | case FunctionNoProto: |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 216 | case LValueReference: |
| 217 | case RValueReference: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 218 | case Record: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 219 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 220 | default: |
| 221 | return false; |
| 222 | } |
| 223 | } |
| 224 | |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 225 | bool Type::isClassType() 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()->isClass(); |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 228 | return false; |
| 229 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 230 | bool Type::isStructureType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 231 | if (const RecordType *RT = getAs<RecordType>()) |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 232 | return RT->getDecl()->isStruct(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 233 | return false; |
| 234 | } |
Steve Naroff | 7154a77 | 2009-07-01 14:36:47 +0000 | [diff] [blame] | 235 | bool Type::isVoidPointerType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 236 | if (const PointerType *PT = getAs<PointerType>()) |
Steve Naroff | 7154a77 | 2009-07-01 14:36:47 +0000 | [diff] [blame] | 237 | return PT->getPointeeType()->isVoidType(); |
| 238 | return false; |
| 239 | } |
| 240 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 241 | bool Type::isUnionType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 242 | if (const RecordType *RT = getAs<RecordType>()) |
Chris Lattner | f728a4a | 2009-01-11 23:59:49 +0000 | [diff] [blame] | 243 | return RT->getDecl()->isUnion(); |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 244 | return false; |
| 245 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 246 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 247 | bool Type::isComplexType() const { |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 248 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 249 | return CT->getElementType()->isFloatingType(); |
| 250 | return false; |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 253 | bool Type::isComplexIntegerType() const { |
| 254 | // Check for GCC complex integer extension. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 255 | return getAsComplexIntegerType(); |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | const ComplexType *Type::getAsComplexIntegerType() const { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 259 | if (const ComplexType *Complex = getAs<ComplexType>()) |
| 260 | if (Complex->getElementType()->isIntegerType()) |
| 261 | return Complex; |
| 262 | return 0; |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 265 | QualType Type::getPointeeType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 266 | if (const PointerType *PT = getAs<PointerType>()) |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 267 | return PT->getPointeeType(); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 268 | if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 269 | return OPT->getPointeeType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 270 | if (const BlockPointerType *BPT = getAs<BlockPointerType>()) |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 271 | return BPT->getPointeeType(); |
Mike Stump | 9c21289 | 2009-11-03 19:03:17 +0000 | [diff] [blame] | 272 | if (const ReferenceType *RT = getAs<ReferenceType>()) |
| 273 | return RT->getPointeeType(); |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 274 | return QualType(); |
| 275 | } |
Chris Lattner | b77792e | 2008-07-26 22:17:49 +0000 | [diff] [blame] | 276 | |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 277 | /// isVariablyModifiedType (C99 6.7.5p3) - Return true for variable length |
| 278 | /// array types and types that contain variable array types in their |
| 279 | /// declarator |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 280 | bool Type::isVariablyModifiedType() const { |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 281 | // A VLA is a variably modified type. |
| 282 | if (isVariableArrayType()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 283 | return true; |
| 284 | |
| 285 | // An array can contain a variably modified type |
Chris Lattner | c63a1f2 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 286 | if (const Type *T = getArrayElementTypeNoTypeQual()) |
| 287 | return T->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 288 | |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 289 | // A pointer can point to a variably modified type. |
| 290 | // Also, C++ references and member pointers can point to a variably modified |
| 291 | // type, where VLAs appear as an extension to C++, and should be treated |
| 292 | // correctly. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 293 | if (const PointerType *PT = getAs<PointerType>()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 294 | return PT->getPointeeType()->isVariablyModifiedType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 295 | if (const ReferenceType *RT = getAs<ReferenceType>()) |
Daniel Dunbar | 68694ad | 2009-02-26 19:54:52 +0000 | [diff] [blame] | 296 | return RT->getPointeeType()->isVariablyModifiedType(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 297 | if (const MemberPointerType *PT = getAs<MemberPointerType>()) |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 298 | return PT->getPointeeType()->isVariablyModifiedType(); |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 299 | |
| 300 | // A function can return a variably modified type |
| 301 | // This one isn't completely obvious, but it follows from the |
| 302 | // definition in C99 6.7.5p3. Because of this rule, it's |
| 303 | // illegal to declare a function returning a variably modified type. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 304 | if (const FunctionType *FT = getAs<FunctionType>()) |
Eli Friedman | d3f2f79 | 2008-02-17 00:59:11 +0000 | [diff] [blame] | 305 | return FT->getResultType()->isVariablyModifiedType(); |
| 306 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 307 | return false; |
| 308 | } |
| 309 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 310 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 311 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 312 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 313 | if (RT->getDecl()->isStruct()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 314 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 315 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 316 | |
| 317 | // 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] | 318 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 319 | if (!RT->getDecl()->isStruct()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 320 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 321 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 322 | // If this is a typedef for a structure type, strip the typedef off without |
| 323 | // losing all typedef information. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 324 | return cast<RecordType>(getUnqualifiedDesugaredType()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 325 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 326 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 329 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 330 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 331 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 332 | if (RT->getDecl()->isUnion()) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 333 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 334 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 335 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 336 | // 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] | 337 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 338 | if (!RT->getDecl()->isUnion()) |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 339 | return 0; |
| 340 | |
| 341 | // If this is a typedef for a union type, strip the typedef off without |
| 342 | // losing all typedef information. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 343 | return cast<RecordType>(getUnqualifiedDesugaredType()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 344 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 346 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 349 | ObjCInterfaceType::ObjCInterfaceType(QualType Canonical, |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 350 | ObjCInterfaceDecl *D, |
| 351 | ObjCProtocolDecl **Protos, unsigned NumP) : |
| 352 | Type(ObjCInterface, Canonical, /*Dependent=*/false), |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 353 | Decl(D), NumProtocols(NumP) |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 354 | { |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 355 | if (NumProtocols) |
| 356 | memcpy(reinterpret_cast<ObjCProtocolDecl**>(this + 1), Protos, |
| 357 | NumProtocols * sizeof(*Protos)); |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void ObjCInterfaceType::Destroy(ASTContext& C) { |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 361 | this->~ObjCInterfaceType(); |
| 362 | C.Deallocate(this); |
| 363 | } |
| 364 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 365 | const ObjCInterfaceType *Type::getAsObjCQualifiedInterfaceType() const { |
| 366 | // There is no sugar for ObjCInterfaceType's, just return the canonical |
| 367 | // type pointer if it is the right class. There is no typedef information to |
| 368 | // return and these cannot be Address-space qualified. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 369 | if (const ObjCInterfaceType *OIT = getAs<ObjCInterfaceType>()) |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 370 | if (OIT->getNumProtocols()) |
| 371 | return OIT; |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | bool Type::isObjCQualifiedInterfaceType() const { |
Steve Naroff | e61ad0b | 2009-07-18 15:38:31 +0000 | [diff] [blame] | 376 | return getAsObjCQualifiedInterfaceType() != 0; |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 379 | ObjCObjectPointerType::ObjCObjectPointerType(QualType Canonical, QualType T, |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 380 | ObjCProtocolDecl **Protos, |
| 381 | unsigned NumP) : |
| 382 | Type(ObjCObjectPointer, Canonical, /*Dependent=*/false), |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 383 | PointeeType(T), NumProtocols(NumP) |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 384 | { |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 385 | if (NumProtocols) |
| 386 | memcpy(reinterpret_cast<ObjCProtocolDecl **>(this + 1), Protos, |
| 387 | NumProtocols * sizeof(*Protos)); |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | void ObjCObjectPointerType::Destroy(ASTContext& C) { |
Ted Kremenek | 71842cc | 2010-01-21 19:22:34 +0000 | [diff] [blame] | 391 | this->~ObjCObjectPointerType(); |
| 392 | C.Deallocate(this); |
| 393 | } |
| 394 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 395 | const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { |
Chris Lattner | eca7be6 | 2008-04-07 05:30:13 +0000 | [diff] [blame] | 396 | // There is no sugar for ObjCQualifiedIdType's, just return the canonical |
| 397 | // type pointer if it is the right class. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 398 | if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 399 | if (OPT->isObjCQualifiedIdType()) |
| 400 | return OPT; |
| 401 | } |
| 402 | return 0; |
Chris Lattner | 368eefa | 2008-04-07 00:27:04 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 405 | const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 406 | if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) { |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 407 | if (OPT->getInterfaceType()) |
| 408 | return OPT; |
| 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
Fariborz Jahanian | a91d6a6 | 2009-07-29 00:44:13 +0000 | [diff] [blame] | 413 | const CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 414 | if (const PointerType *PT = getAs<PointerType>()) |
| 415 | if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>()) |
Fariborz Jahanian | a91d6a6 | 2009-07-29 00:44:13 +0000 | [diff] [blame] | 416 | return dyn_cast<CXXRecordDecl>(RT->getDecl()); |
| 417 | return 0; |
| 418 | } |
| 419 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 420 | bool Type::isIntegerType() const { |
| 421 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 422 | return BT->getKind() >= BuiltinType::Bool && |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 423 | BT->getKind() <= BuiltinType::Int128; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 424 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 425 | // Incomplete enum types are not treated as integer types. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 426 | // FIXME: In C++, enum types are never integer types. |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 427 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 428 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 429 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 430 | return VT->getElementType()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 431 | return false; |
| 432 | } |
| 433 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 434 | bool Type::isIntegralType() const { |
| 435 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 436 | return BT->getKind() >= BuiltinType::Bool && |
Anders Carlsson | f5f7d86 | 2009-12-29 07:07:36 +0000 | [diff] [blame] | 437 | BT->getKind() <= BuiltinType::Int128; |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 438 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 439 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
| 440 | return true; // Complete enum types are integral. |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 441 | // FIXME: In C++, enum types are never integral. |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 442 | return false; |
| 443 | } |
| 444 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 445 | bool Type::isEnumeralType() const { |
| 446 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Argyrios Kyrtzidis | 39ba4ae | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 447 | return TT->getDecl()->isEnum(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 448 | return false; |
| 449 | } |
| 450 | |
| 451 | bool Type::isBooleanType() const { |
| 452 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 453 | return BT->getKind() == BuiltinType::Bool; |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | bool Type::isCharType() const { |
| 458 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 459 | return BT->getKind() == BuiltinType::Char_U || |
| 460 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 461 | BT->getKind() == BuiltinType::Char_S || |
| 462 | BT->getKind() == BuiltinType::SChar; |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 463 | return false; |
| 464 | } |
| 465 | |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 466 | bool Type::isWideCharType() const { |
| 467 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 468 | return BT->getKind() == BuiltinType::WChar; |
Douglas Gregor | 77a5223 | 2008-09-12 00:47:35 +0000 | [diff] [blame] | 469 | return false; |
| 470 | } |
| 471 | |
Douglas Gregor | 20093b4 | 2009-12-09 23:02:17 +0000 | [diff] [blame] | 472 | /// \brief Determine whether this type is any of the built-in character |
| 473 | /// types. |
| 474 | bool Type::isAnyCharacterType() const { |
| 475 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 476 | return (BT->getKind() >= BuiltinType::Char_U && |
| 477 | BT->getKind() <= BuiltinType::Char32) || |
| 478 | (BT->getKind() >= BuiltinType::Char_S && |
| 479 | BT->getKind() <= BuiltinType::WChar); |
| 480 | |
| 481 | return false; |
| 482 | } |
| 483 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 484 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 485 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 486 | /// an enum decl which has a signed representation, or a vector of signed |
| 487 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 488 | bool Type::isSignedIntegerType() const { |
| 489 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 490 | return BT->getKind() >= BuiltinType::Char_S && |
Anders Carlsson | f5f7d86 | 2009-12-29 07:07:36 +0000 | [diff] [blame] | 491 | BT->getKind() <= BuiltinType::Int128; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 492 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 494 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 495 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 497 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 498 | return VT->getElementType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 499 | return false; |
| 500 | } |
| 501 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 502 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 503 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 504 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 505 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 506 | bool Type::isUnsignedIntegerType() const { |
| 507 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 508 | return BT->getKind() >= BuiltinType::Bool && |
Anders Carlsson | 1c03ca3 | 2009-11-09 17:34:18 +0000 | [diff] [blame] | 509 | BT->getKind() <= BuiltinType::UInt128; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 510 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 511 | |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 512 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 513 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 514 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 515 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 516 | return VT->getElementType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 517 | return false; |
| 518 | } |
| 519 | |
| 520 | bool Type::isFloatingType() const { |
| 521 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 522 | return BT->getKind() >= BuiltinType::Float && |
| 523 | BT->getKind() <= BuiltinType::LongDouble; |
| 524 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 525 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 526 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 527 | return VT->getElementType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 528 | return false; |
| 529 | } |
| 530 | |
| 531 | bool Type::isRealFloatingType() const { |
| 532 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
John McCall | 680523a | 2009-11-07 03:30:10 +0000 | [diff] [blame] | 533 | return BT->isFloatingPoint(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 534 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 535 | return VT->getElementType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 536 | return false; |
| 537 | } |
| 538 | |
| 539 | bool Type::isRealType() const { |
| 540 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 541 | return BT->getKind() >= BuiltinType::Bool && |
| 542 | BT->getKind() <= BuiltinType::LongDouble; |
| 543 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 544 | return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 545 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 546 | return VT->getElementType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 547 | return false; |
| 548 | } |
| 549 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 550 | bool Type::isArithmeticType() const { |
| 551 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
Douglas Gregor | a7fbf72 | 2008-10-30 13:47:07 +0000 | [diff] [blame] | 552 | return BT->getKind() >= BuiltinType::Bool && |
| 553 | BT->getKind() <= BuiltinType::LongDouble; |
Chris Lattner | 37c1b78 | 2008-04-06 22:29:16 +0000 | [diff] [blame] | 554 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 555 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
| 556 | // If a body isn't seen by the time we get here, return false. |
| 557 | return ET->getDecl()->isDefinition(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 558 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 559 | } |
| 560 | |
| 561 | bool Type::isScalarType() const { |
| 562 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 563 | return BT->getKind() != BuiltinType::Void; |
| 564 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 565 | // Enums are scalar types, but only if they are defined. Incomplete enums |
| 566 | // are not treated as scalar types. |
| 567 | if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 568 | return true; |
| 569 | return false; |
| 570 | } |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 571 | return isa<PointerType>(CanonicalType) || |
| 572 | isa<BlockPointerType>(CanonicalType) || |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 573 | isa<MemberPointerType>(CanonicalType) || |
Steve Naroff | 5618bd4 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 574 | isa<ComplexType>(CanonicalType) || |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 575 | isa<ObjCObjectPointerType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 578 | /// \brief Determines whether the type is a C++ aggregate type or C |
| 579 | /// aggregate or union type. |
| 580 | /// |
| 581 | /// An aggregate type is an array or a class type (struct, union, or |
| 582 | /// class) that has no user-declared constructors, no private or |
| 583 | /// protected non-static data members, no base classes, and no virtual |
| 584 | /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type |
| 585 | /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also |
| 586 | /// includes union types. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 587 | bool Type::isAggregateType() const { |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 588 | if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) { |
| 589 | if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) |
| 590 | return ClassDecl->isAggregate(); |
| 591 | |
Douglas Gregor | d7eb846 | 2009-01-30 17:31:00 +0000 | [diff] [blame] | 592 | return true; |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 595 | return isa<ArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 598 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 599 | /// 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] | 600 | /// incomplete types or dependent types. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 601 | bool Type::isConstantSizeType() const { |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 602 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 603 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 604 | // The VAT must have a size, as it is known to be complete. |
| 605 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 609 | /// - a type that can describe objects, but which lacks information needed to |
| 610 | /// determine its size. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 611 | bool Type::isIncompleteType() const { |
| 612 | switch (CanonicalType->getTypeClass()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 613 | default: return false; |
| 614 | case Builtin: |
| 615 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 616 | // be completed. |
| 617 | return isVoidType(); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 618 | case Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 619 | case Enum: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 620 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 621 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 622 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Sebastian Redl | 923d56d | 2009-11-05 15:52:31 +0000 | [diff] [blame] | 623 | case ConstantArray: |
| 624 | // An array is incomplete if its element type is incomplete |
| 625 | // (C++ [dcl.array]p1). |
| 626 | // We don't handle variable arrays (they're not allowed in C++) or |
| 627 | // dependent-sized arrays (dependent types are never treated as incomplete). |
| 628 | return cast<ArrayType>(CanonicalType)->getElementType()->isIncompleteType(); |
Eli Friedman | c5773c4 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 629 | case IncompleteArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 630 | // 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] | 631 | return true; |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 632 | case ObjCInterface: |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 633 | // ObjC interfaces are incomplete if they are @class, not @interface. |
| 634 | return cast<ObjCInterfaceType>(this)->getDecl()->isForwardDecl(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 638 | /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10) |
| 639 | bool Type::isPODType() const { |
| 640 | // The compiler shouldn't query this for incomplete types, but the user might. |
| 641 | // We return false for that case. |
| 642 | if (isIncompleteType()) |
| 643 | return false; |
| 644 | |
| 645 | switch (CanonicalType->getTypeClass()) { |
| 646 | // Everything not explicitly mentioned is not POD. |
| 647 | default: return false; |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 648 | case VariableArray: |
| 649 | case ConstantArray: |
| 650 | // IncompleteArray is caught by isIncompleteType() above. |
| 651 | return cast<ArrayType>(CanonicalType)->getElementType()->isPODType(); |
| 652 | |
| 653 | case Builtin: |
| 654 | case Complex: |
| 655 | case Pointer: |
Sebastian Redl | f30208a | 2009-01-24 21:16:55 +0000 | [diff] [blame] | 656 | case MemberPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 657 | case Vector: |
| 658 | case ExtVector: |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 659 | case ObjCObjectPointer: |
Fariborz Jahanian | 2263f82 | 2010-03-09 18:34:52 +0000 | [diff] [blame] | 660 | case BlockPointer: |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 661 | return true; |
| 662 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 663 | case Enum: |
| 664 | return true; |
| 665 | |
| 666 | case Record: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 667 | if (CXXRecordDecl *ClassDecl |
Douglas Gregor | c1efaec | 2009-02-28 01:32:25 +0000 | [diff] [blame] | 668 | = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) |
| 669 | return ClassDecl->isPOD(); |
| 670 | |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 671 | // C struct/union is POD. |
| 672 | return true; |
| 673 | } |
| 674 | } |
| 675 | |
Sebastian Redl | ccf4350 | 2009-12-03 00:13:20 +0000 | [diff] [blame] | 676 | bool Type::isLiteralType() const { |
| 677 | if (isIncompleteType()) |
| 678 | return false; |
| 679 | |
| 680 | // C++0x [basic.types]p10: |
| 681 | // A type is a literal type if it is: |
| 682 | switch (CanonicalType->getTypeClass()) { |
| 683 | // We're whitelisting |
| 684 | default: return false; |
| 685 | |
| 686 | // -- a scalar type |
| 687 | case Builtin: |
| 688 | case Complex: |
| 689 | case Pointer: |
| 690 | case MemberPointer: |
| 691 | case Vector: |
| 692 | case ExtVector: |
| 693 | case ObjCObjectPointer: |
| 694 | case Enum: |
| 695 | return true; |
| 696 | |
| 697 | // -- a class type with ... |
| 698 | case Record: |
| 699 | // FIXME: Do the tests |
| 700 | return false; |
| 701 | |
| 702 | // -- an array of literal type |
| 703 | // Extension: variable arrays cannot be literal types, since they're |
| 704 | // runtime-sized. |
| 705 | case ConstantArray: |
| 706 | return cast<ArrayType>(CanonicalType)->getElementType()->isLiteralType(); |
| 707 | } |
| 708 | } |
| 709 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 710 | bool Type::isPromotableIntegerType() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 711 | if (const BuiltinType *BT = getAs<BuiltinType>()) |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 712 | switch (BT->getKind()) { |
| 713 | case BuiltinType::Bool: |
| 714 | case BuiltinType::Char_S: |
| 715 | case BuiltinType::Char_U: |
| 716 | case BuiltinType::SChar: |
| 717 | case BuiltinType::UChar: |
| 718 | case BuiltinType::Short: |
| 719 | case BuiltinType::UShort: |
| 720 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 721 | default: |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 722 | return false; |
| 723 | } |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 724 | |
| 725 | // Enumerated types are promotable to their compatible integer types |
| 726 | // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2). |
| 727 | if (const EnumType *ET = getAs<EnumType>()){ |
| 728 | if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull()) |
| 729 | return false; |
| 730 | |
| 731 | const BuiltinType *BT |
| 732 | = ET->getDecl()->getPromotionType()->getAs<BuiltinType>(); |
| 733 | return BT->getKind() == BuiltinType::Int |
| 734 | || BT->getKind() == BuiltinType::UInt; |
| 735 | } |
| 736 | |
Chris Lattner | 2a18dfe | 2009-01-12 00:21:19 +0000 | [diff] [blame] | 737 | return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 740 | bool Type::isNullPtrType() const { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 741 | if (const BuiltinType *BT = getAs<BuiltinType>()) |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 742 | return BT->getKind() == BuiltinType::NullPtr; |
| 743 | return false; |
| 744 | } |
| 745 | |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 746 | bool Type::isSpecifierType() const { |
| 747 | // Note that this intentionally does not use the canonical type. |
| 748 | switch (getTypeClass()) { |
| 749 | case Builtin: |
| 750 | case Record: |
| 751 | case Enum: |
| 752 | case Typedef: |
Eli Friedman | c8f2c61 | 2009-05-30 01:45:29 +0000 | [diff] [blame] | 753 | case Complex: |
| 754 | case TypeOfExpr: |
| 755 | case TypeOf: |
| 756 | case TemplateTypeParm: |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 757 | case SubstTemplateTypeParm: |
Eli Friedman | c8f2c61 | 2009-05-30 01:45:29 +0000 | [diff] [blame] | 758 | case TemplateSpecialization: |
| 759 | case QualifiedName: |
| 760 | case Typename: |
| 761 | case ObjCInterface: |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 762 | case ObjCObjectPointer: |
Douglas Gregor | 7c67395 | 2009-12-15 16:28:32 +0000 | [diff] [blame] | 763 | case Elaborated: |
Eli Friedman | 22b61e9 | 2009-05-30 00:10:16 +0000 | [diff] [blame] | 764 | return true; |
| 765 | default: |
| 766 | return false; |
| 767 | } |
| 768 | } |
| 769 | |
Argyrios Kyrtzidis | cd01f17 | 2009-09-29 19:41:13 +0000 | [diff] [blame] | 770 | const char *Type::getTypeClassName() const { |
| 771 | switch (TC) { |
| 772 | default: assert(0 && "Type class not in TypeNodes.def!"); |
| 773 | #define ABSTRACT_TYPE(Derived, Base) |
| 774 | #define TYPE(Derived, Base) case Derived: return #Derived; |
| 775 | #include "clang/AST/TypeNodes.def" |
| 776 | } |
| 777 | } |
| 778 | |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 779 | const char *BuiltinType::getName(const LangOptions &LO) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 780 | switch (getKind()) { |
| 781 | default: assert(0 && "Unknown builtin type!"); |
| 782 | case Void: return "void"; |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 783 | case Bool: return LO.Bool ? "bool" : "_Bool"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 784 | case Char_S: return "char"; |
| 785 | case Char_U: return "char"; |
| 786 | case SChar: return "signed char"; |
| 787 | case Short: return "short"; |
| 788 | case Int: return "int"; |
| 789 | case Long: return "long"; |
| 790 | case LongLong: return "long long"; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 791 | case Int128: return "__int128_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 792 | case UChar: return "unsigned char"; |
| 793 | case UShort: return "unsigned short"; |
| 794 | case UInt: return "unsigned int"; |
| 795 | case ULong: return "unsigned long"; |
| 796 | case ULongLong: return "unsigned long long"; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 797 | case UInt128: return "__uint128_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 798 | case Float: return "float"; |
| 799 | case Double: return "double"; |
| 800 | case LongDouble: return "long double"; |
Argyrios Kyrtzidis | 46713ef | 2008-08-09 17:11:33 +0000 | [diff] [blame] | 801 | case WChar: return "wchar_t"; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 802 | case Char16: return "char16_t"; |
| 803 | case Char32: return "char32_t"; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 804 | case NullPtr: return "nullptr_t"; |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 805 | case Overload: return "<overloaded function type>"; |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 806 | case Dependent: return "<dependent type>"; |
Anders Carlsson | 6a75cd9 | 2009-07-11 00:34:39 +0000 | [diff] [blame] | 807 | case UndeducedAuto: return "auto"; |
Steve Naroff | de2e22d | 2009-07-15 18:40:39 +0000 | [diff] [blame] | 808 | case ObjCId: return "id"; |
| 809 | case ObjCClass: return "Class"; |
Fariborz Jahanian | 04765ac | 2009-11-23 18:04:25 +0000 | [diff] [blame] | 810 | case ObjCSel: return "SEL"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 814 | llvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { |
| 815 | switch (CC) { |
| 816 | case CC_Default: llvm_unreachable("no name for default cc"); |
| 817 | default: return ""; |
| 818 | |
| 819 | case CC_C: return "cdecl"; |
| 820 | case CC_X86StdCall: return "stdcall"; |
| 821 | case CC_X86FastCall: return "fastcall"; |
| 822 | } |
| 823 | } |
| 824 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 825 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 826 | arg_type_iterator ArgTys, |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 827 | unsigned NumArgs, bool isVariadic, |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 828 | unsigned TypeQuals, bool hasExceptionSpec, |
| 829 | bool anyExceptionSpec, unsigned NumExceptions, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame^] | 830 | exception_iterator Exs, |
| 831 | const FunctionType::ExtInfo &Info) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 832 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 833 | for (unsigned i = 0; i != NumArgs; ++i) |
| 834 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 835 | ID.AddInteger(isVariadic); |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 836 | ID.AddInteger(TypeQuals); |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 837 | ID.AddInteger(hasExceptionSpec); |
| 838 | if (hasExceptionSpec) { |
| 839 | ID.AddInteger(anyExceptionSpec); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 840 | for (unsigned i = 0; i != NumExceptions; ++i) |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 841 | ID.AddPointer(Exs[i].getAsOpaquePtr()); |
| 842 | } |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame^] | 843 | ID.AddInteger(Info.getNoReturn()); |
| 844 | ID.AddInteger(Info.getCC()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 847 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID) { |
Argyrios Kyrtzidis | 971c4fa | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 848 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic(), |
Sebastian Redl | 465226e | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 849 | getTypeQuals(), hasExceptionSpec(), hasAnyExceptionSpec(), |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame^] | 850 | getNumExceptions(), exception_begin(), |
| 851 | getExtInfo()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 854 | void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 855 | QualType OIT, |
| 856 | ObjCProtocolDecl * const *protocols, |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 857 | unsigned NumProtocols) { |
Steve Naroff | 14108da | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 858 | ID.AddPointer(OIT.getAsOpaquePtr()); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 859 | for (unsigned i = 0; i != NumProtocols; i++) |
| 860 | ID.AddPointer(protocols[i]); |
| 861 | } |
| 862 | |
| 863 | void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) { |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 864 | Profile(ID, getPointeeType(), qual_begin(), getNumProtocols()); |
Steve Naroff | d1b3c2d | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 865 | } |
| 866 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 867 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 868 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 869 | /// sum of the type qualifiers, so if you have: |
| 870 | /// typedef const int A; |
| 871 | /// typedef volatile A B; |
| 872 | /// looking through the typedefs for B will give you "const volatile A". |
| 873 | /// |
| 874 | QualType TypedefType::LookThroughTypedefs() const { |
| 875 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 876 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 877 | if (!isa<TypedefType>(FirstType)) |
| 878 | return FirstType; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 880 | // Otherwise, do the fully general loop. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 881 | QualifierCollector Qs; |
| 882 | |
| 883 | QualType CurType; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 884 | const TypedefType *TDT = this; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 885 | do { |
| 886 | CurType = TDT->getDecl()->getUnderlyingType(); |
| 887 | TDT = dyn_cast<TypedefType>(Qs.strip(CurType)); |
| 888 | } while (TDT); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 889 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 890 | return Qs.apply(CurType); |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 891 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 892 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 893 | QualType TypedefType::desugar() const { |
| 894 | return getDecl()->getUnderlyingType(); |
| 895 | } |
| 896 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 897 | TypeOfExprType::TypeOfExprType(Expr *E, QualType can) |
| 898 | : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { |
Douglas Gregor | 898574e | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 899 | } |
| 900 | |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 901 | QualType TypeOfExprType::desugar() const { |
| 902 | return getUnderlyingExpr()->getType(); |
| 903 | } |
| 904 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | b197572 | 2009-07-30 23:18:24 +0000 | [diff] [blame] | 906 | ASTContext &Context, Expr *E) { |
| 907 | E->Profile(ID, Context, true); |
| 908 | } |
| 909 | |
Anders Carlsson | 563a03b | 2009-07-10 19:20:26 +0000 | [diff] [blame] | 910 | DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | : Type(Decltype, can, E->isTypeDependent()), E(E), |
Anders Carlsson | 563a03b | 2009-07-10 19:20:26 +0000 | [diff] [blame] | 912 | UnderlyingType(underlyingType) { |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Douglas Gregor | 9d702ae | 2009-07-30 23:36:40 +0000 | [diff] [blame] | 915 | DependentDecltypeType::DependentDecltypeType(ASTContext &Context, Expr *E) |
| 916 | : DecltypeType(E, Context.DependentTy), Context(Context) { } |
| 917 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 918 | void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, |
Douglas Gregor | 9d702ae | 2009-07-30 23:36:40 +0000 | [diff] [blame] | 919 | ASTContext &Context, Expr *E) { |
| 920 | E->Profile(ID, Context, true); |
| 921 | } |
| 922 | |
John McCall | 19c8576 | 2010-02-16 03:57:14 +0000 | [diff] [blame] | 923 | TagType::TagType(TypeClass TC, const TagDecl *D, QualType can) |
| 924 | : Type(TC, can, D->isDependentType()), |
| 925 | decl(const_cast<TagDecl*>(D), 0) {} |
Douglas Gregor | 7da97d0 | 2009-05-10 22:57:19 +0000 | [diff] [blame] | 926 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 927 | bool RecordType::classof(const TagType *TT) { |
| 928 | return isa<RecordDecl>(TT->getDecl()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 929 | } |
| 930 | |
Chris Lattner | 2daa5df | 2008-04-06 22:04:54 +0000 | [diff] [blame] | 931 | bool EnumType::classof(const TagType *TT) { |
| 932 | return isa<EnumDecl>(TT->getDecl()); |
Chris Lattner | 5edb8bf | 2008-04-06 21:58:47 +0000 | [diff] [blame] | 933 | } |
| 934 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 935 | static bool isDependent(const TemplateArgument &Arg) { |
| 936 | switch (Arg.getKind()) { |
| 937 | case TemplateArgument::Null: |
| 938 | assert(false && "Should not have a NULL template argument"); |
| 939 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 940 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 941 | case TemplateArgument::Type: |
| 942 | return Arg.getAsType()->isDependentType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 943 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 944 | case TemplateArgument::Template: |
| 945 | return Arg.getAsTemplate().isDependent(); |
| 946 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 947 | case TemplateArgument::Declaration: |
| 948 | case TemplateArgument::Integral: |
| 949 | // Never dependent |
| 950 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 951 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 952 | case TemplateArgument::Expression: |
| 953 | return (Arg.getAsExpr()->isTypeDependent() || |
| 954 | Arg.getAsExpr()->isValueDependent()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 956 | case TemplateArgument::Pack: |
| 957 | assert(0 && "FIXME: Implement!"); |
| 958 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 959 | } |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 960 | |
| 961 | return false; |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 962 | } |
| 963 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 964 | bool TemplateSpecializationType:: |
John McCall | d5532b6 | 2009-11-23 01:53:49 +0000 | [diff] [blame] | 965 | anyDependentTemplateArguments(const TemplateArgumentListInfo &Args) { |
| 966 | return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size()); |
| 967 | } |
| 968 | |
| 969 | bool TemplateSpecializationType:: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 970 | anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N) { |
| 971 | for (unsigned i = 0; i != N; ++i) |
| 972 | if (isDependent(Args[i].getArgument())) |
| 973 | return true; |
| 974 | return false; |
| 975 | } |
| 976 | |
| 977 | bool TemplateSpecializationType:: |
| 978 | anyDependentTemplateArguments(const TemplateArgument *Args, unsigned N) { |
| 979 | for (unsigned i = 0; i != N; ++i) |
| 980 | if (isDependent(Args[i])) |
| 981 | return true; |
| 982 | return false; |
| 983 | } |
| 984 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 985 | TemplateSpecializationType:: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | TemplateSpecializationType(ASTContext &Context, TemplateName T, |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 987 | const TemplateArgument *Args, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 988 | unsigned NumArgs, QualType Canon) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | : Type(TemplateSpecialization, |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 990 | Canon.isNull()? QualType(this, 0) : Canon, |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 991 | T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)), |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 992 | Context(Context), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 993 | Template(T), NumArgs(NumArgs) { |
| 994 | assert((!Canon.isNull() || |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 995 | T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)) && |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 996 | "No canonical type for non-dependent class template specialization"); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 997 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | TemplateArgument *TemplateArgs |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 999 | = reinterpret_cast<TemplateArgument *>(this + 1); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1000 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1001 | new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1004 | void TemplateSpecializationType::Destroy(ASTContext& C) { |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 1005 | for (unsigned Arg = 0; Arg < NumArgs; ++Arg) { |
| 1006 | // FIXME: Not all expressions get cloned, so we can't yet perform |
| 1007 | // this destruction. |
| 1008 | // if (Expr *E = getArg(Arg).getAsExpr()) |
| 1009 | // E->Destroy(C); |
| 1010 | } |
Douglas Gregor | 5908e9f | 2009-02-09 19:34:22 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1013 | TemplateSpecializationType::iterator |
| 1014 | TemplateSpecializationType::end() const { |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1015 | return begin() + getNumArgs(); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1018 | const TemplateArgument & |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1019 | TemplateSpecializationType::getArg(unsigned Idx) const { |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1020 | assert(Idx < getNumArgs() && "Template argument out of range"); |
| 1021 | return getArgs()[Idx]; |
| 1022 | } |
| 1023 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 | void |
| 1025 | TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, |
| 1026 | TemplateName T, |
| 1027 | const TemplateArgument *Args, |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 1028 | unsigned NumArgs, |
| 1029 | ASTContext &Context) { |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 1030 | T.Profile(ID); |
Douglas Gregor | 40808ce | 2009-03-09 23:48:35 +0000 | [diff] [blame] | 1031 | for (unsigned Idx = 0; Idx < NumArgs; ++Idx) |
Douglas Gregor | 828e226 | 2009-07-29 16:09:57 +0000 | [diff] [blame] | 1032 | Args[Idx].Profile(ID, Context); |
Douglas Gregor | 55f6b14 | 2009-02-09 18:46:07 +0000 | [diff] [blame] | 1033 | } |
Anders Carlsson | 97e0179 | 2008-12-21 00:16:32 +0000 | [diff] [blame] | 1034 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1035 | QualType QualifierCollector::apply(QualType QT) const { |
| 1036 | if (!hasNonFastQualifiers()) |
| 1037 | return QT.withFastQualifiers(getFastQualifiers()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1039 | assert(Context && "extended qualifiers but no context!"); |
| 1040 | return Context->getQualifiedType(QT, *this); |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1043 | QualType QualifierCollector::apply(const Type *T) const { |
| 1044 | if (!hasNonFastQualifiers()) |
| 1045 | return QualType(T, getFastQualifiers()); |
| 1046 | |
| 1047 | assert(Context && "extended qualifiers but no context!"); |
| 1048 | return Context->getQualifiedType(T, *this); |
Douglas Gregor | 5e03f9e | 2009-07-23 23:49:00 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 1051 | void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
| 1052 | const ObjCInterfaceDecl *Decl, |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 1053 | ObjCProtocolDecl * const *protocols, |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 1054 | unsigned NumProtocols) { |
| 1055 | ID.AddPointer(Decl); |
| 1056 | for (unsigned i = 0; i != NumProtocols; i++) |
| 1057 | ID.AddPointer(protocols[i]); |
| 1058 | } |
| 1059 | |
| 1060 | void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Douglas Gregor | fd6a088 | 2010-02-08 22:59:26 +0000 | [diff] [blame] | 1061 | Profile(ID, getDecl(), qual_begin(), getNumProtocols()); |
Steve Naroff | c15cb2a | 2009-07-18 15:33:26 +0000 | [diff] [blame] | 1062 | } |
Douglas Gregor | 0b6bc8b | 2010-02-03 09:33:45 +0000 | [diff] [blame] | 1063 | |
| 1064 | Linkage Type::getLinkage() const { |
| 1065 | // C++ [basic.link]p8: |
| 1066 | // Names not covered by these rules have no linkage. |
| 1067 | if (this != CanonicalType.getTypePtr()) |
| 1068 | return CanonicalType->getLinkage(); |
| 1069 | |
| 1070 | return NoLinkage; |
| 1071 | } |
| 1072 | |
| 1073 | Linkage BuiltinType::getLinkage() const { |
| 1074 | // C++ [basic.link]p8: |
| 1075 | // A type is said to have linkage if and only if: |
| 1076 | // - it is a fundamental type (3.9.1); or |
| 1077 | return ExternalLinkage; |
| 1078 | } |
| 1079 | |
| 1080 | Linkage TagType::getLinkage() const { |
| 1081 | // C++ [basic.link]p8: |
| 1082 | // - it is a class or enumeration type that is named (or has a name for |
| 1083 | // linkage purposes (7.1.3)) and the name has linkage; or |
| 1084 | // - it is a specialization of a class template (14); or |
| 1085 | return getDecl()->getLinkage(); |
| 1086 | } |
| 1087 | |
| 1088 | // C++ [basic.link]p8: |
| 1089 | // - it is a compound type (3.9.2) other than a class or enumeration, |
| 1090 | // compounded exclusively from types that have linkage; or |
| 1091 | Linkage ComplexType::getLinkage() const { |
| 1092 | return ElementType->getLinkage(); |
| 1093 | } |
| 1094 | |
| 1095 | Linkage PointerType::getLinkage() const { |
| 1096 | return PointeeType->getLinkage(); |
| 1097 | } |
| 1098 | |
| 1099 | Linkage BlockPointerType::getLinkage() const { |
| 1100 | return PointeeType->getLinkage(); |
| 1101 | } |
| 1102 | |
| 1103 | Linkage ReferenceType::getLinkage() const { |
| 1104 | return PointeeType->getLinkage(); |
| 1105 | } |
| 1106 | |
| 1107 | Linkage MemberPointerType::getLinkage() const { |
| 1108 | return minLinkage(Class->getLinkage(), PointeeType->getLinkage()); |
| 1109 | } |
| 1110 | |
| 1111 | Linkage ArrayType::getLinkage() const { |
| 1112 | return ElementType->getLinkage(); |
| 1113 | } |
| 1114 | |
| 1115 | Linkage VectorType::getLinkage() const { |
| 1116 | return ElementType->getLinkage(); |
| 1117 | } |
| 1118 | |
| 1119 | Linkage FunctionNoProtoType::getLinkage() const { |
| 1120 | return getResultType()->getLinkage(); |
| 1121 | } |
| 1122 | |
| 1123 | Linkage FunctionProtoType::getLinkage() const { |
| 1124 | Linkage L = getResultType()->getLinkage(); |
| 1125 | for (arg_type_iterator A = arg_type_begin(), AEnd = arg_type_end(); |
| 1126 | A != AEnd; ++A) |
| 1127 | L = minLinkage(L, (*A)->getLinkage()); |
| 1128 | |
| 1129 | return L; |
| 1130 | } |
| 1131 | |
| 1132 | Linkage ObjCInterfaceType::getLinkage() const { |
| 1133 | return ExternalLinkage; |
| 1134 | } |
| 1135 | |
| 1136 | Linkage ObjCObjectPointerType::getLinkage() const { |
| 1137 | return ExternalLinkage; |
| 1138 | } |