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 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 14 | #include "clang/AST/Type.h" |
| 15 | #include "clang/AST/Decl.h" |
Steve Naroff | 980e508 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Chris Lattner | c7229c3 | 2007-10-07 08:58:51 +0000 | [diff] [blame] | 18 | #include "clang/Basic/IdentifierTable.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "clang/Basic/TargetInfo.h" |
| 20 | #include "llvm/Support/Streams.h" |
| 21 | #include "llvm/ADT/StringExtras.h" |
Steve Naroff | 8d1a3b8 | 2007-08-01 17:20:42 +0000 | [diff] [blame] | 22 | #include <sstream> |
| 23 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
| 26 | Type::~Type() {} |
| 27 | |
| 28 | /// isVoidType - Helper method to determine if this is the 'void' type. |
| 29 | bool Type::isVoidType() const { |
| 30 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 31 | return BT->getKind() == BuiltinType::Void; |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | bool Type::isObjectType() const { |
| 36 | if (isa<FunctionType>(CanonicalType)) |
| 37 | return false; |
| 38 | else if (CanonicalType->isIncompleteType()) |
| 39 | return false; |
| 40 | else |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | bool Type::isDerivedType() const { |
| 45 | switch (CanonicalType->getTypeClass()) { |
| 46 | case Pointer: |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 47 | case VariableArray: |
| 48 | case ConstantArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 49 | case FunctionProto: |
| 50 | case FunctionNoProto: |
| 51 | case Reference: |
| 52 | return true; |
| 53 | case Tagged: { |
| 54 | const TagType *TT = cast<TagType>(CanonicalType); |
| 55 | const Decl::Kind Kind = TT->getDecl()->getKind(); |
| 56 | return Kind == Decl::Struct || Kind == Decl::Union; |
| 57 | } |
| 58 | default: |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 63 | bool Type::isStructureType() const { |
Seo Sanghyeon | 2de3b3a | 2007-12-02 16:57:27 +0000 | [diff] [blame] | 64 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 65 | if (RT->getDecl()->getKind() == Decl::Struct) |
| 66 | return true; |
| 67 | return false; |
| 68 | } |
| 69 | bool Type::isUnionType() const { |
Seo Sanghyeon | 2de3b3a | 2007-12-02 16:57:27 +0000 | [diff] [blame] | 70 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 71 | if (RT->getDecl()->getKind() == Decl::Union) |
| 72 | return true; |
| 73 | return false; |
| 74 | } |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 75 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 76 | bool Type::isComplexType() const { |
Steve Naroff | 02f62a9 | 2008-01-15 19:36:10 +0000 | [diff] [blame] | 77 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 78 | return CT->getElementType()->isFloatingType(); |
| 79 | return false; |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Steve Naroff | 4cdec1c | 2008-01-15 01:41:59 +0000 | [diff] [blame] | 82 | bool Type::isComplexIntegerType() const { |
| 83 | // Check for GCC complex integer extension. |
| 84 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
| 85 | return CT->getElementType()->isIntegerType(); |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | const ComplexType *Type::getAsComplexIntegerType() const { |
| 90 | // Are we directly a complex type? |
| 91 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) { |
| 92 | if (CTy->getElementType()->isIntegerType()) |
| 93 | return CTy; |
| 94 | } |
| 95 | // If the canonical form of this type isn't the right kind, reject it. |
| 96 | const ComplexType *CTy = dyn_cast<ComplexType>(CanonicalType); |
| 97 | if (!CTy || !CTy->getElementType()->isIntegerType()) |
| 98 | return 0; |
| 99 | |
| 100 | // If this is a typedef for a complex type, strip the typedef off without |
| 101 | // losing all typedef information. |
| 102 | return getDesugaredType()->getAsComplexIntegerType(); |
| 103 | } |
| 104 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 105 | /// getDesugaredType - Return the specified type with any "sugar" removed from |
| 106 | /// type type. This takes off typedefs, typeof's etc. If the outer level of |
| 107 | /// the type is already concrete, it returns it unmodified. This is similar |
| 108 | /// to getting the canonical type, but it doesn't remove *all* typedefs. For |
| 109 | /// example, it return "T*" as "T*", (not as "int*"), because the pointer is |
| 110 | /// concrete. |
| 111 | const Type *Type::getDesugaredType() const { |
| 112 | if (const TypedefType *TDT = dyn_cast<TypedefType>(this)) |
| 113 | return TDT->LookThroughTypedefs().getTypePtr(); |
| 114 | if (const TypeOfExpr *TOE = dyn_cast<TypeOfExpr>(this)) |
| 115 | return TOE->getUnderlyingExpr()->getType().getTypePtr(); |
| 116 | if (const TypeOfType *TOT = dyn_cast<TypeOfType>(this)) |
| 117 | return TOT->getUnderlyingType().getTypePtr(); |
| 118 | return this; |
| 119 | } |
| 120 | |
| 121 | |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 122 | const BuiltinType *Type::getAsBuiltinType() const { |
| 123 | // If this is directly a builtin type, return it. |
| 124 | if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this)) |
| 125 | return BTy; |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 126 | |
| 127 | // If the canonical form of this type isn't a builtin type, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 128 | if (!isa<BuiltinType>(CanonicalType)) { |
| 129 | // Look through type qualifiers |
| 130 | if (isa<BuiltinType>(CanonicalType.getUnqualifiedType())) |
| 131 | return CanonicalType.getUnqualifiedType()->getAsBuiltinType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 132 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 133 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 134 | |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 135 | // If this is a typedef for a builtin type, strip the typedef off without |
| 136 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 137 | return getDesugaredType()->getAsBuiltinType(); |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 140 | const FunctionType *Type::getAsFunctionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 141 | // If this is directly a function type, return it. |
| 142 | if (const FunctionType *FTy = dyn_cast<FunctionType>(this)) |
| 143 | return FTy; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 144 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 145 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 146 | if (!isa<FunctionType>(CanonicalType)) { |
| 147 | // Look through type qualifiers |
| 148 | if (isa<FunctionType>(CanonicalType.getUnqualifiedType())) |
| 149 | return CanonicalType.getUnqualifiedType()->getAsFunctionType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 150 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 151 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 152 | |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 153 | // If this is a typedef for a function type, strip the typedef off without |
| 154 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 155 | return getDesugaredType()->getAsFunctionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Chris Lattner | befee48 | 2007-07-31 16:53:04 +0000 | [diff] [blame] | 158 | const PointerType *Type::getAsPointerType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 159 | // If this is directly a pointer type, return it. |
| 160 | if (const PointerType *PTy = dyn_cast<PointerType>(this)) |
| 161 | return PTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 162 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 163 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 164 | if (!isa<PointerType>(CanonicalType)) { |
| 165 | // Look through type qualifiers |
| 166 | if (isa<PointerType>(CanonicalType.getUnqualifiedType())) |
| 167 | return CanonicalType.getUnqualifiedType()->getAsPointerType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 168 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 169 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 170 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 171 | // If this is a typedef for a pointer type, strip the typedef off without |
| 172 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 173 | return getDesugaredType()->getAsPointerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Chris Lattner | a1d9fde | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 176 | const ReferenceType *Type::getAsReferenceType() const { |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 177 | // If this is directly a reference type, return it. |
| 178 | if (const ReferenceType *RTy = dyn_cast<ReferenceType>(this)) |
| 179 | return RTy; |
| 180 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 181 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 182 | if (!isa<ReferenceType>(CanonicalType)) { |
| 183 | // Look through type qualifiers |
| 184 | if (isa<ReferenceType>(CanonicalType.getUnqualifiedType())) |
| 185 | return CanonicalType.getUnqualifiedType()->getAsReferenceType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 186 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 187 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 188 | |
Bill Wendling | ea5e79f | 2007-07-17 04:16:47 +0000 | [diff] [blame] | 189 | // If this is a typedef for a reference type, strip the typedef off without |
| 190 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 191 | return getDesugaredType()->getAsReferenceType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 194 | const ArrayType *Type::getAsArrayType() const { |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 195 | // If this is directly an array type, return it. |
Steve Naroff | 700204c | 2007-07-24 21:46:40 +0000 | [diff] [blame] | 196 | if (const ArrayType *ATy = dyn_cast<ArrayType>(this)) |
| 197 | return ATy; |
| 198 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 199 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 200 | if (!isa<ArrayType>(CanonicalType)) { |
| 201 | // Look through type qualifiers |
| 202 | if (isa<ArrayType>(CanonicalType.getUnqualifiedType())) |
| 203 | return CanonicalType.getUnqualifiedType()->getAsArrayType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 204 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 205 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 206 | |
Steve Naroff | 700204c | 2007-07-24 21:46:40 +0000 | [diff] [blame] | 207 | // If this is a typedef for an array type, strip the typedef off without |
| 208 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 209 | return getDesugaredType()->getAsArrayType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 212 | const ConstantArrayType *Type::getAsConstantArrayType() const { |
| 213 | // If this is directly a constant array type, return it. |
| 214 | if (const ConstantArrayType *ATy = dyn_cast<ConstantArrayType>(this)) |
| 215 | return ATy; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 216 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 217 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 218 | if (!isa<ConstantArrayType>(CanonicalType)) { |
| 219 | // Look through type qualifiers |
| 220 | if (isa<ConstantArrayType>(CanonicalType.getUnqualifiedType())) |
| 221 | return CanonicalType.getUnqualifiedType()->getAsConstantArrayType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 222 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 223 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 224 | |
| 225 | // If this is a typedef for a constant array type, strip the typedef off |
| 226 | // without losing all typedef information. |
| 227 | return getDesugaredType()->getAsConstantArrayType(); |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | const VariableArrayType *Type::getAsVariableArrayType() const { |
| 231 | // If this is directly a variable array type, return it. |
| 232 | if (const VariableArrayType *ATy = dyn_cast<VariableArrayType>(this)) |
| 233 | return ATy; |
| 234 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 235 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 236 | if (!isa<VariableArrayType>(CanonicalType)) { |
| 237 | // Look through type qualifiers |
| 238 | if (isa<VariableArrayType>(CanonicalType.getUnqualifiedType())) |
| 239 | return CanonicalType.getUnqualifiedType()->getAsVariableArrayType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 240 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 241 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 242 | |
| 243 | // If this is a typedef for a variable array type, strip the typedef off |
| 244 | // without losing all typedef information. |
| 245 | return getDesugaredType()->getAsVariableArrayType(); |
Steve Naroff | d7444aa | 2007-08-31 17:20:07 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array |
| 249 | /// types that have a non-constant expression. This does not include "[]". |
| 250 | bool Type::isVariablyModifiedType() const { |
| 251 | if (const VariableArrayType *VAT = getAsVariableArrayType()) { |
| 252 | if (VAT->getSizeExpr()) |
| 253 | return true; |
| 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | const VariableArrayType *Type::getAsVariablyModifiedType() const { |
| 259 | if (const VariableArrayType *VAT = getAsVariableArrayType()) { |
| 260 | if (VAT->getSizeExpr()) |
| 261 | return VAT; |
| 262 | } |
| 263 | return 0; |
| 264 | } |
| 265 | |
Steve Naroff | 5c06a69 | 2008-01-21 22:59:18 +0000 | [diff] [blame] | 266 | bool Type::isIncompleteArrayType() const { |
| 267 | if (const VariableArrayType *VAT = getAsVariableArrayType()) { |
| 268 | if (!VAT->getSizeExpr()) |
| 269 | return true; |
| 270 | } |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | const VariableArrayType *Type::getAsIncompleteArrayType() const { |
| 275 | if (const VariableArrayType *VAT = getAsVariableArrayType()) { |
| 276 | if (!VAT->getSizeExpr()) |
| 277 | return VAT; |
| 278 | } |
| 279 | return 0; |
| 280 | } |
| 281 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 282 | const RecordType *Type::getAsRecordType() const { |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 283 | // If this is directly a reference type, return it. |
| 284 | if (const RecordType *RTy = dyn_cast<RecordType>(this)) |
| 285 | return RTy; |
| 286 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 287 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 288 | if (!isa<RecordType>(CanonicalType)) { |
| 289 | // Look through type qualifiers |
| 290 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 291 | return CanonicalType.getUnqualifiedType()->getAsRecordType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 292 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 293 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 294 | |
| 295 | // If this is a typedef for a record type, strip the typedef off without |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 296 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 297 | return getDesugaredType()->getAsRecordType(); |
Steve Naroff | dfa6aae | 2007-07-26 03:11:44 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 300 | const RecordType *Type::getAsStructureType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 301 | // If this is directly a structure type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 302 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
| 303 | if (RT->getDecl()->getKind() == Decl::Struct) |
| 304 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 305 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 306 | |
| 307 | // 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] | 308 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 309 | if (RT->getDecl()->getKind() != Decl::Struct) |
| 310 | return 0; |
| 311 | |
| 312 | // If this is a typedef for a structure type, strip the typedef off without |
| 313 | // losing all typedef information. |
| 314 | return getDesugaredType()->getAsStructureType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 315 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 316 | // Look through type qualifiers |
| 317 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 318 | return CanonicalType.getUnqualifiedType()->getAsStructureType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 319 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 322 | const RecordType *Type::getAsUnionType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 323 | // If this is directly a union type, return it. |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 324 | if (const RecordType *RT = dyn_cast<RecordType>(this)) { |
| 325 | if (RT->getDecl()->getKind() == Decl::Union) |
| 326 | return RT; |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 327 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 328 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 329 | // 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] | 330 | if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) { |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 331 | if (RT->getDecl()->getKind() != Decl::Union) |
| 332 | return 0; |
| 333 | |
| 334 | // If this is a typedef for a union type, strip the typedef off without |
| 335 | // losing all typedef information. |
| 336 | return getDesugaredType()->getAsUnionType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 337 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 338 | |
| 339 | // Look through type qualifiers |
| 340 | if (isa<RecordType>(CanonicalType.getUnqualifiedType())) |
| 341 | return CanonicalType.getUnqualifiedType()->getAsUnionType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 342 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 345 | const ComplexType *Type::getAsComplexType() const { |
| 346 | // Are we directly a complex type? |
| 347 | if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) |
| 348 | return CTy; |
| 349 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 350 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 351 | if (!isa<ComplexType>(CanonicalType)) { |
| 352 | // Look through type qualifiers |
| 353 | if (isa<ComplexType>(CanonicalType.getUnqualifiedType())) |
| 354 | return CanonicalType.getUnqualifiedType()->getAsComplexType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 355 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 356 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 357 | |
Chris Lattner | c6fb90a | 2007-08-21 16:54:08 +0000 | [diff] [blame] | 358 | // If this is a typedef for a complex type, strip the typedef off without |
| 359 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 360 | return getDesugaredType()->getAsComplexType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 363 | const VectorType *Type::getAsVectorType() const { |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 364 | // Are we directly a vector type? |
| 365 | if (const VectorType *VTy = dyn_cast<VectorType>(this)) |
| 366 | return VTy; |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 367 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 368 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 369 | if (!isa<VectorType>(CanonicalType)) { |
| 370 | // Look through type qualifiers |
| 371 | if (isa<VectorType>(CanonicalType.getUnqualifiedType())) |
| 372 | return CanonicalType.getUnqualifiedType()->getAsVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 373 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 374 | } |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 375 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 376 | // If this is a typedef for a vector type, strip the typedef off without |
| 377 | // losing all typedef information. |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 378 | return getDesugaredType()->getAsVectorType(); |
Chris Lattner | 7a2e047 | 2007-07-16 00:23:25 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Chris Lattner | c862963 | 2007-07-31 19:29:30 +0000 | [diff] [blame] | 381 | const OCUVectorType *Type::getAsOCUVectorType() const { |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 382 | // Are we directly an OpenCU vector type? |
| 383 | if (const OCUVectorType *VTy = dyn_cast<OCUVectorType>(this)) |
| 384 | return VTy; |
| 385 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 386 | // If the canonical form of this type isn't the right kind, reject it. |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 387 | if (!isa<OCUVectorType>(CanonicalType)) { |
| 388 | // Look through type qualifiers |
| 389 | if (isa<OCUVectorType>(CanonicalType.getUnqualifiedType())) |
| 390 | return CanonicalType.getUnqualifiedType()->getAsOCUVectorType(); |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 391 | return 0; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 392 | } |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 393 | |
Chris Lattner | dea6146 | 2007-10-29 03:41:11 +0000 | [diff] [blame] | 394 | // If this is a typedef for an ocuvector type, strip the typedef off without |
| 395 | // losing all typedef information. |
| 396 | return getDesugaredType()->getAsOCUVectorType(); |
Steve Naroff | 7064f5c | 2007-07-26 18:32:01 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 399 | bool Type::isIntegerType() const { |
| 400 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 401 | return BT->getKind() >= BuiltinType::Bool && |
| 402 | BT->getKind() <= BuiltinType::LongLong; |
| 403 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
| 404 | if (TT->getDecl()->getKind() == Decl::Enum) |
| 405 | return true; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 406 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 407 | return VT->getElementType()->isIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 408 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 409 | return ASQT->getBaseType()->isIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 410 | return false; |
| 411 | } |
| 412 | |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 413 | bool Type::isIntegralType() const { |
| 414 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 415 | return BT->getKind() >= BuiltinType::Bool && |
| 416 | BT->getKind() <= BuiltinType::LongLong; |
| 417 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
| 418 | if (TT->getDecl()->getKind() == Decl::Enum) |
| 419 | return true; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 420 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 421 | return ASQT->getBaseType()->isIntegralType(); |
Fariborz Jahanian | 33e1d64 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 422 | return false; |
| 423 | } |
| 424 | |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 425 | bool Type::isEnumeralType() const { |
| 426 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
| 427 | return TT->getDecl()->getKind() == Decl::Enum; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 428 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 429 | return ASQT->getBaseType()->isEnumeralType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 430 | return false; |
| 431 | } |
| 432 | |
| 433 | bool Type::isBooleanType() const { |
| 434 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 435 | return BT->getKind() == BuiltinType::Bool; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 436 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 437 | return ASQT->getBaseType()->isBooleanType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 438 | return false; |
| 439 | } |
| 440 | |
| 441 | bool Type::isCharType() const { |
| 442 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 443 | return BT->getKind() == BuiltinType::Char_U || |
| 444 | BT->getKind() == BuiltinType::UChar || |
Anders Carlsson | c67ad5f | 2007-10-29 02:52:18 +0000 | [diff] [blame] | 445 | BT->getKind() == BuiltinType::Char_S || |
| 446 | BT->getKind() == BuiltinType::SChar; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 447 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 448 | return ASQT->getBaseType()->isCharType(); |
Steve Naroff | 13b7c5f | 2007-08-08 22:15:55 +0000 | [diff] [blame] | 449 | return false; |
| 450 | } |
| 451 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 452 | /// isSignedIntegerType - Return true if this is an integer type that is |
| 453 | /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], |
| 454 | /// an enum decl which has a signed representation, or a vector of signed |
| 455 | /// integer element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 456 | bool Type::isSignedIntegerType() const { |
| 457 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 458 | return BT->getKind() >= BuiltinType::Char_S && |
| 459 | BT->getKind() <= BuiltinType::LongLong; |
| 460 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 461 | |
| 462 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
| 463 | if (const EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) |
| 464 | return ED->getIntegerType()->isSignedIntegerType(); |
| 465 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 466 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 467 | return VT->getElementType()->isSignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 468 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 469 | return ASQT->getBaseType()->isSignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 470 | return false; |
| 471 | } |
| 472 | |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 473 | /// isUnsignedIntegerType - Return true if this is an integer type that is |
| 474 | /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum |
| 475 | /// decl which has an unsigned representation, or a vector of unsigned integer |
| 476 | /// element type. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 477 | bool Type::isUnsignedIntegerType() const { |
| 478 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 479 | return BT->getKind() >= BuiltinType::Bool && |
| 480 | BT->getKind() <= BuiltinType::ULongLong; |
| 481 | } |
Chris Lattner | d5bbce4 | 2007-08-29 17:48:46 +0000 | [diff] [blame] | 482 | |
| 483 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
| 484 | if (const EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) |
| 485 | return ED->getIntegerType()->isUnsignedIntegerType(); |
| 486 | |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 487 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 488 | return VT->getElementType()->isUnsignedIntegerType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 489 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 490 | return ASQT->getBaseType()->isUnsignedIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 491 | return false; |
| 492 | } |
| 493 | |
| 494 | bool Type::isFloatingType() const { |
| 495 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 496 | return BT->getKind() >= BuiltinType::Float && |
| 497 | BT->getKind() <= BuiltinType::LongDouble; |
| 498 | if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType)) |
Chris Lattner | 729a213 | 2007-08-30 06:19:11 +0000 | [diff] [blame] | 499 | return CT->getElementType()->isFloatingType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 500 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 501 | return VT->getElementType()->isFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 502 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 503 | return ASQT->getBaseType()->isFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 504 | return false; |
| 505 | } |
| 506 | |
| 507 | bool Type::isRealFloatingType() const { |
| 508 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 509 | return BT->getKind() >= BuiltinType::Float && |
| 510 | BT->getKind() <= BuiltinType::LongDouble; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 511 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 512 | return VT->getElementType()->isRealFloatingType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 513 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 514 | return ASQT->getBaseType()->isRealFloatingType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 515 | return false; |
| 516 | } |
| 517 | |
| 518 | bool Type::isRealType() const { |
| 519 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 520 | return BT->getKind() >= BuiltinType::Bool && |
| 521 | BT->getKind() <= BuiltinType::LongDouble; |
| 522 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
| 523 | return TT->getDecl()->getKind() == Decl::Enum; |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 524 | if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType)) |
| 525 | return VT->getElementType()->isRealType(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 526 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 527 | return ASQT->getBaseType()->isRealType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 528 | return false; |
| 529 | } |
| 530 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 531 | bool Type::isArithmeticType() const { |
| 532 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 533 | return BT->getKind() != BuiltinType::Void; |
| 534 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) |
Steve Naroff | 67c49e8 | 2008-01-16 23:54:22 +0000 | [diff] [blame] | 535 | if (const EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl())) |
| 536 | // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2). |
Steve Naroff | 494783a | 2008-01-16 23:56:32 +0000 | [diff] [blame] | 537 | // If a body isn't seen by the time we get here, return false. |
Steve Naroff | 67c49e8 | 2008-01-16 23:54:22 +0000 | [diff] [blame] | 538 | return ED->isDefinition(); |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 539 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 540 | return ASQT->getBaseType()->isArithmeticType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 541 | return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType); |
| 542 | } |
| 543 | |
| 544 | bool Type::isScalarType() const { |
| 545 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 546 | return BT->getKind() != BuiltinType::Void; |
| 547 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
| 548 | if (TT->getDecl()->getKind() == Decl::Enum) |
| 549 | return true; |
| 550 | return false; |
| 551 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 552 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 553 | return ASQT->getBaseType()->isScalarType(); |
Steve Naroff | c63b96a | 2007-07-12 21:46:55 +0000 | [diff] [blame] | 554 | return isa<PointerType>(CanonicalType) || isa<ComplexType>(CanonicalType) || |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 555 | isa<ObjCQualifiedIdType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | bool Type::isAggregateType() const { |
| 559 | if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) { |
| 560 | if (TT->getDecl()->getKind() == Decl::Struct) |
| 561 | return true; |
| 562 | return false; |
| 563 | } |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 564 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 565 | return ASQT->getBaseType()->isAggregateType(); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 566 | return CanonicalType->getTypeClass() == ConstantArray || |
| 567 | CanonicalType->getTypeClass() == VariableArray; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 570 | /// isConstantSizeType - Return true if this is not a variable sized type, |
| 571 | /// according to the rules of C99 6.7.5p3. It is not legal to call this on |
| 572 | /// incomplete types. |
| 573 | bool Type::isConstantSizeType(ASTContext &Ctx) const { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 574 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 575 | return ASQT->getBaseType()->isConstantSizeType(Ctx); |
Chris Lattner | d52a457 | 2007-12-18 07:03:30 +0000 | [diff] [blame] | 576 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
Chris Lattner | 9bfa73c | 2007-12-18 07:18:16 +0000 | [diff] [blame] | 577 | // The VAT must have a size, as it is known to be complete. |
| 578 | return !isa<VariableArrayType>(CanonicalType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1) |
| 582 | /// - a type that can describe objects, but which lacks information needed to |
| 583 | /// determine its size. |
| 584 | bool Type::isIncompleteType() const { |
| 585 | switch (CanonicalType->getTypeClass()) { |
| 586 | default: return false; |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 587 | case ASQual: |
| 588 | return cast<ASQualType>(CanonicalType)->getBaseType()->isIncompleteType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 589 | case Builtin: |
| 590 | // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never |
| 591 | // be completed. |
| 592 | return isVoidType(); |
| 593 | case Tagged: |
| 594 | // A tagged type (struct/union/enum/class) is incomplete if the decl is a |
| 595 | // forward declaration, but not a full definition (C99 6.2.5p22). |
| 596 | return !cast<TagType>(CanonicalType)->getDecl()->isDefinition(); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 597 | case VariableArray: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 598 | // An array of unknown size is an incomplete type (C99 6.2.5p22). |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 599 | return cast<VariableArrayType>(CanonicalType)->getSizeExpr() == 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
| 603 | bool Type::isPromotableIntegerType() const { |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 604 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType)) |
| 605 | return ASQT->getBaseType()->isPromotableIntegerType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 606 | const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType); |
| 607 | if (!BT) return false; |
| 608 | switch (BT->getKind()) { |
| 609 | case BuiltinType::Bool: |
| 610 | case BuiltinType::Char_S: |
| 611 | case BuiltinType::Char_U: |
| 612 | case BuiltinType::SChar: |
| 613 | case BuiltinType::UChar: |
| 614 | case BuiltinType::Short: |
| 615 | case BuiltinType::UShort: |
| 616 | return true; |
| 617 | default: |
| 618 | return false; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | const char *BuiltinType::getName() const { |
| 623 | switch (getKind()) { |
| 624 | default: assert(0 && "Unknown builtin type!"); |
| 625 | case Void: return "void"; |
| 626 | case Bool: return "_Bool"; |
| 627 | case Char_S: return "char"; |
| 628 | case Char_U: return "char"; |
| 629 | case SChar: return "signed char"; |
| 630 | case Short: return "short"; |
| 631 | case Int: return "int"; |
| 632 | case Long: return "long"; |
| 633 | case LongLong: return "long long"; |
| 634 | case UChar: return "unsigned char"; |
| 635 | case UShort: return "unsigned short"; |
| 636 | case UInt: return "unsigned int"; |
| 637 | case ULong: return "unsigned long"; |
| 638 | case ULongLong: return "unsigned long long"; |
| 639 | case Float: return "float"; |
| 640 | case Double: return "double"; |
| 641 | case LongDouble: return "long double"; |
| 642 | } |
| 643 | } |
| 644 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 645 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 646 | arg_type_iterator ArgTys, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 647 | unsigned NumArgs, bool isVariadic) { |
| 648 | ID.AddPointer(Result.getAsOpaquePtr()); |
| 649 | for (unsigned i = 0; i != NumArgs; ++i) |
| 650 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
| 651 | ID.AddInteger(isVariadic); |
| 652 | } |
| 653 | |
| 654 | void FunctionTypeProto::Profile(llvm::FoldingSetNodeID &ID) { |
Chris Lattner | 942cfd3 | 2007-07-20 18:48:28 +0000 | [diff] [blame] | 655 | Profile(ID, getResultType(), arg_type_begin(), NumArgs, isVariadic()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 658 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID, |
| 659 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 660 | unsigned NumProtocols) { |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 661 | for (unsigned i = 0; i != NumProtocols; i++) |
| 662 | ID.AddPointer(protocols[i]); |
| 663 | } |
| 664 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 665 | void ObjCQualifiedInterfaceType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | 06cef25 | 2007-12-13 20:47:42 +0000 | [diff] [blame] | 666 | Profile(ID, &Protocols[0], getNumProtocols()); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 669 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID, |
| 670 | ObjCProtocolDecl **protocols, |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 671 | unsigned NumProtocols) { |
| 672 | for (unsigned i = 0; i != NumProtocols; i++) |
| 673 | ID.AddPointer(protocols[i]); |
| 674 | } |
| 675 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 676 | void ObjCQualifiedIdType::Profile(llvm::FoldingSetNodeID &ID) { |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 677 | Profile(ID, &Protocols[0], getNumProtocols()); |
| 678 | } |
| 679 | |
Chris Lattner | a2c7767 | 2007-07-16 22:05:22 +0000 | [diff] [blame] | 680 | /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to |
| 681 | /// potentially looking through *all* consequtive typedefs. This returns the |
| 682 | /// sum of the type qualifiers, so if you have: |
| 683 | /// typedef const int A; |
| 684 | /// typedef volatile A B; |
| 685 | /// looking through the typedefs for B will give you "const volatile A". |
| 686 | /// |
| 687 | QualType TypedefType::LookThroughTypedefs() const { |
| 688 | // Usually, there is only a single level of typedefs, be fast in that case. |
| 689 | QualType FirstType = getDecl()->getUnderlyingType(); |
| 690 | if (!isa<TypedefType>(FirstType)) |
| 691 | return FirstType; |
| 692 | |
| 693 | // Otherwise, do the fully general loop. |
| 694 | unsigned TypeQuals = 0; |
| 695 | const TypedefType *TDT = this; |
| 696 | while (1) { |
| 697 | QualType CurType = TDT->getDecl()->getUnderlyingType(); |
| 698 | TypeQuals |= CurType.getQualifiers(); |
| 699 | |
| 700 | TDT = dyn_cast<TypedefType>(CurType); |
| 701 | if (TDT == 0) |
| 702 | return QualType(CurType.getTypePtr(), TypeQuals); |
| 703 | } |
| 704 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 705 | |
| 706 | bool RecordType::classof(const Type *T) { |
| 707 | if (const TagType *TT = dyn_cast<TagType>(T)) |
| 708 | return isa<RecordDecl>(TT->getDecl()); |
| 709 | return false; |
| 710 | } |
| 711 | |
| 712 | |
| 713 | //===----------------------------------------------------------------------===// |
| 714 | // Type Printing |
| 715 | //===----------------------------------------------------------------------===// |
| 716 | |
| 717 | void QualType::dump(const char *msg) const { |
Chris Lattner | 39caea9 | 2007-12-06 04:20:07 +0000 | [diff] [blame] | 718 | std::string R = "identifier"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 719 | getAsStringInternal(R); |
| 720 | if (msg) |
| 721 | fprintf(stderr, "%s: %s\n", msg, R.c_str()); |
| 722 | else |
| 723 | fprintf(stderr, "%s\n", R.c_str()); |
| 724 | } |
| 725 | |
| 726 | static void AppendTypeQualList(std::string &S, unsigned TypeQuals) { |
| 727 | // Note: funkiness to ensure we get a space only between quals. |
| 728 | bool NonePrinted = true; |
| 729 | if (TypeQuals & QualType::Const) |
| 730 | S += "const", NonePrinted = false; |
| 731 | if (TypeQuals & QualType::Volatile) |
| 732 | S += (NonePrinted+" volatile"), NonePrinted = false; |
| 733 | if (TypeQuals & QualType::Restrict) |
| 734 | S += (NonePrinted+" restrict"), NonePrinted = false; |
| 735 | } |
| 736 | |
| 737 | void QualType::getAsStringInternal(std::string &S) const { |
| 738 | if (isNull()) { |
| 739 | S += "NULL TYPE\n"; |
| 740 | return; |
| 741 | } |
| 742 | |
| 743 | // Print qualifiers as appropriate. |
Anton Korobeynikov | b7b50bc | 2007-07-13 00:48:55 +0000 | [diff] [blame] | 744 | unsigned TQ = getQualifiers(); |
| 745 | if (TQ) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 746 | std::string TQS; |
| 747 | AppendTypeQualList(TQS, TQ); |
| 748 | if (!S.empty()) |
| 749 | S = TQS + ' ' + S; |
| 750 | else |
| 751 | S = TQS; |
| 752 | } |
| 753 | |
| 754 | getTypePtr()->getAsStringInternal(S); |
| 755 | } |
| 756 | |
| 757 | void BuiltinType::getAsStringInternal(std::string &S) const { |
| 758 | if (S.empty()) { |
| 759 | S = getName(); |
| 760 | } else { |
| 761 | // Prefix the basic type, e.g. 'int X'. |
| 762 | S = ' ' + S; |
| 763 | S = getName() + S; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | void ComplexType::getAsStringInternal(std::string &S) const { |
| 768 | ElementType->getAsStringInternal(S); |
| 769 | S = "_Complex " + S; |
| 770 | } |
| 771 | |
Christopher Lamb | ebb97e9 | 2008-02-04 02:31:56 +0000 | [diff] [blame^] | 772 | void ASQualType::getAsStringInternal(std::string &S) const { |
| 773 | S = "__attribute__((address_space("+llvm::utostr_32(AddressSpace)+")))" + S; |
| 774 | BaseType->getAsStringInternal(S); |
| 775 | } |
| 776 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 777 | void PointerType::getAsStringInternal(std::string &S) const { |
| 778 | S = '*' + S; |
| 779 | |
| 780 | // Handle things like 'int (*A)[4];' correctly. |
| 781 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 782 | if (isa<ArrayType>(PointeeType.getTypePtr())) |
| 783 | S = '(' + S + ')'; |
| 784 | |
| 785 | PointeeType.getAsStringInternal(S); |
| 786 | } |
| 787 | |
| 788 | void ReferenceType::getAsStringInternal(std::string &S) const { |
| 789 | S = '&' + S; |
| 790 | |
| 791 | // Handle things like 'int (&A)[4];' correctly. |
| 792 | // FIXME: this should include vectors, but vectors use attributes I guess. |
| 793 | if (isa<ArrayType>(ReferenceeType.getTypePtr())) |
| 794 | S = '(' + S + ')'; |
| 795 | |
| 796 | ReferenceeType.getAsStringInternal(S); |
| 797 | } |
| 798 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 799 | void ConstantArrayType::getAsStringInternal(std::string &S) const { |
| 800 | S += '['; |
Steve Naroff | 6b91cd9 | 2007-08-30 18:45:57 +0000 | [diff] [blame] | 801 | S += llvm::utostr(getSize().getZExtValue()); |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 802 | S += ']'; |
| 803 | |
| 804 | getElementType().getAsStringInternal(S); |
| 805 | } |
| 806 | |
| 807 | void VariableArrayType::getAsStringInternal(std::string &S) const { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 808 | S += '['; |
| 809 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 810 | if (getIndexTypeQualifier()) { |
| 811 | AppendTypeQualList(S, getIndexTypeQualifier()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 812 | S += ' '; |
| 813 | } |
| 814 | |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 815 | if (getSizeModifier() == Static) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 816 | S += "static"; |
Steve Naroff | c940612 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 817 | else if (getSizeModifier() == Star) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 818 | S += '*'; |
| 819 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 820 | if (getSizeExpr()) { |
| 821 | std::ostringstream s; |
| 822 | getSizeExpr()->printPretty(s); |
| 823 | S += s.str(); |
| 824 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 825 | S += ']'; |
| 826 | |
Steve Naroff | fb22d96 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 827 | getElementType().getAsStringInternal(S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | void VectorType::getAsStringInternal(std::string &S) const { |
Chris Lattner | 7ee261c | 2007-11-27 07:28:18 +0000 | [diff] [blame] | 831 | S += " __attribute__((__vector_size__("; |
Chris Lattner | e107b5d | 2007-07-13 21:01:17 +0000 | [diff] [blame] | 832 | // FIXME: should multiply by element size somehow. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 833 | S += llvm::utostr_32(NumElements*4); // convert back to bytes. |
Chris Lattner | e107b5d | 2007-07-13 21:01:17 +0000 | [diff] [blame] | 834 | S += ")))"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 835 | ElementType.getAsStringInternal(S); |
| 836 | } |
| 837 | |
Steve Naroff | 31a4584 | 2007-07-28 23:10:27 +0000 | [diff] [blame] | 838 | void OCUVectorType::getAsStringInternal(std::string &S) const { |
| 839 | S += " __attribute__((ocu_vector_type("; |
| 840 | S += llvm::utostr_32(NumElements); |
| 841 | S += ")))"; |
| 842 | ElementType.getAsStringInternal(S); |
| 843 | } |
| 844 | |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 845 | void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 846 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(e) X'. |
| 847 | InnerString = ' ' + InnerString; |
Steve Naroff | 8d1a3b8 | 2007-08-01 17:20:42 +0000 | [diff] [blame] | 848 | std::ostringstream s; |
Chris Lattner | 6000dac | 2007-08-08 22:51:59 +0000 | [diff] [blame] | 849 | getUnderlyingExpr()->printPretty(s); |
Steve Naroff | 1bfd5cc | 2007-08-05 03:24:45 +0000 | [diff] [blame] | 850 | InnerString = "typeof(" + s.str() + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 853 | void TypeOfType::getAsStringInternal(std::string &InnerString) const { |
| 854 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typeof(t) X'. |
| 855 | InnerString = ' ' + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 856 | std::string Tmp; |
| 857 | getUnderlyingType().getAsStringInternal(Tmp); |
Steve Naroff | 363bcff | 2007-08-01 23:45:51 +0000 | [diff] [blame] | 858 | InnerString = "typeof(" + Tmp + ")" + InnerString; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 861 | void FunctionTypeNoProto::getAsStringInternal(std::string &S) const { |
| 862 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 863 | if (!S.empty()) |
| 864 | S = "(" + S + ")"; |
| 865 | |
| 866 | S += "()"; |
| 867 | getResultType().getAsStringInternal(S); |
| 868 | } |
| 869 | |
| 870 | void FunctionTypeProto::getAsStringInternal(std::string &S) const { |
| 871 | // If needed for precedence reasons, wrap the inner part in grouping parens. |
| 872 | if (!S.empty()) |
| 873 | S = "(" + S + ")"; |
| 874 | |
| 875 | S += "("; |
| 876 | std::string Tmp; |
| 877 | for (unsigned i = 0, e = getNumArgs(); i != e; ++i) { |
| 878 | if (i) S += ", "; |
| 879 | getArgType(i).getAsStringInternal(Tmp); |
| 880 | S += Tmp; |
| 881 | Tmp.clear(); |
| 882 | } |
| 883 | |
| 884 | if (isVariadic()) { |
| 885 | if (getNumArgs()) |
| 886 | S += ", "; |
| 887 | S += "..."; |
| 888 | } else if (getNumArgs() == 0) { |
| 889 | // Do not emit int() if we have a proto, emit 'int(void)'. |
| 890 | S += "void"; |
| 891 | } |
| 892 | |
| 893 | S += ")"; |
| 894 | getResultType().getAsStringInternal(S); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | void TypedefType::getAsStringInternal(std::string &InnerString) const { |
| 899 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 900 | InnerString = ' ' + InnerString; |
| 901 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 902 | } |
| 903 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 904 | void ObjCInterfaceType::getAsStringInternal(std::string &InnerString) const { |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 905 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 906 | InnerString = ' ' + InnerString; |
| 907 | InnerString = getDecl()->getIdentifier()->getName() + InnerString; |
| 908 | } |
| 909 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 910 | void ObjCQualifiedInterfaceType::getAsStringInternal( |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 911 | std::string &InnerString) const { |
Fariborz Jahanian | dfbcce2 | 2007-10-11 18:08:47 +0000 | [diff] [blame] | 912 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 913 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 914 | std::string ObjCQIString = getDecl()->getName(); |
| 915 | ObjCQIString += '<'; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 916 | int num = getNumProtocols(); |
| 917 | for (int i = 0; i < num; i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 918 | ObjCQIString += getProtocols(i)->getName(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 919 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 920 | ObjCQIString += ','; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 921 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 922 | ObjCQIString += '>'; |
| 923 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 924 | } |
| 925 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 926 | void ObjCQualifiedIdType::getAsStringInternal( |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 927 | std::string &InnerString) const { |
| 928 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 929 | InnerString = ' ' + InnerString; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 930 | std::string ObjCQIString = "id"; |
| 931 | ObjCQIString += '<'; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 932 | int num = getNumProtocols(); |
| 933 | for (int i = 0; i < num; i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 934 | ObjCQIString += getProtocols(i)->getName(); |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 935 | if (i < num-1) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 936 | ObjCQIString += ','; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 937 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 938 | ObjCQIString += '>'; |
| 939 | InnerString = ObjCQIString + InnerString; |
Fariborz Jahanian | c569249 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 942 | void TagType::getAsStringInternal(std::string &InnerString) const { |
| 943 | if (!InnerString.empty()) // Prefix the basic type, e.g. 'typedefname X'. |
| 944 | InnerString = ' ' + InnerString; |
| 945 | |
| 946 | const char *Kind = getDecl()->getKindName(); |
| 947 | const char *ID; |
| 948 | if (const IdentifierInfo *II = getDecl()->getIdentifier()) |
| 949 | ID = II->getName(); |
| 950 | else |
| 951 | ID = "<anonymous>"; |
| 952 | |
| 953 | InnerString = std::string(Kind) + " " + ID + InnerString; |
| 954 | } |