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