Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- ASTContext.cpp - Context to hold long-lived AST nodes ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 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. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the ASTContext interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/ASTContext.h" |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 15 | #include "clang/AST/DeclCXX.h" |
Steve Naroff | 3fafa10 | 2007-10-01 19:00:59 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Daniel Dunbar | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
| 18 | #include "clang/AST/RecordLayout.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 19 | #include "clang/Basic/TargetInfo.h" |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 21 | #include "llvm/Bitcode/Serialize.h" |
| 22 | #include "llvm/Bitcode/Deserialize.h" |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | |
| 26 | enum FloatingRank { |
| 27 | FloatRank, DoubleRank, LongDoubleRank |
| 28 | }; |
| 29 | |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 30 | ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, |
| 31 | TargetInfo &t, |
Daniel Dunbar | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 32 | IdentifierTable &idents, SelectorTable &sels, |
| 33 | unsigned size_reserve) : |
Anders Carlsson | f58cac7 | 2008-08-30 19:34:46 +0000 | [diff] [blame] | 34 | CFConstantStringTypeDecl(0), ObjCFastEnumerationStateTypeDecl(0), |
| 35 | SourceMgr(SM), LangOpts(LOpts), Target(t), |
Douglas Gregor | 24afd4a | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 36 | Idents(idents), Selectors(sels) |
Daniel Dunbar | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 37 | { |
| 38 | if (size_reserve > 0) Types.reserve(size_reserve); |
| 39 | InitBuiltinTypes(); |
| 40 | BuiltinInfo.InitializeBuiltins(idents, Target); |
| 41 | TUDecl = TranslationUnitDecl::Create(*this); |
| 42 | } |
| 43 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 44 | ASTContext::~ASTContext() { |
| 45 | // Deallocate all the types. |
| 46 | while (!Types.empty()) { |
Ted Kremenek | db4d597 | 2008-05-21 16:38:54 +0000 | [diff] [blame] | 47 | Types.back()->Destroy(*this); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 48 | Types.pop_back(); |
| 49 | } |
Eli Friedman | 65489b7 | 2008-05-27 03:08:09 +0000 | [diff] [blame] | 50 | |
Nuno Lopes | 355a868 | 2008-12-17 22:30:25 +0000 | [diff] [blame] | 51 | { |
| 52 | llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator |
| 53 | I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); |
| 54 | while (I != E) { |
| 55 | ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second); |
| 56 | delete R; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | llvm::DenseMap<const ObjCInterfaceDecl*, const ASTRecordLayout*>::iterator |
| 62 | I = ASTObjCInterfaces.begin(), E = ASTObjCInterfaces.end(); |
| 63 | while (I != E) { |
| 64 | ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second); |
| 65 | delete R; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | { |
| 70 | llvm::DenseMap<const ObjCInterfaceDecl*, const RecordDecl*>::iterator |
| 71 | I = ASTRecordForInterface.begin(), E = ASTRecordForInterface.end(); |
| 72 | while (I != E) { |
| 73 | RecordDecl *R = const_cast<RecordDecl*>((I++)->second); |
| 74 | R->Destroy(*this); |
| 75 | } |
| 76 | } |
| 77 | |
Eli Friedman | 65489b7 | 2008-05-27 03:08:09 +0000 | [diff] [blame] | 78 | TUDecl->Destroy(*this); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void ASTContext::PrintStats() const { |
| 82 | fprintf(stderr, "*** AST Context Stats:\n"); |
| 83 | fprintf(stderr, " %d types total.\n", (int)Types.size()); |
| 84 | unsigned NumBuiltin = 0, NumPointer = 0, NumArray = 0, NumFunctionP = 0; |
Daniel Dunbar | 4767734 | 2008-09-26 03:23:00 +0000 | [diff] [blame] | 85 | unsigned NumVector = 0, NumComplex = 0, NumBlockPointer = 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 86 | unsigned NumFunctionNP = 0, NumTypeName = 0, NumTagged = 0, NumReference = 0; |
| 87 | |
| 88 | unsigned NumTagStruct = 0, NumTagUnion = 0, NumTagEnum = 0, NumTagClass = 0; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 89 | unsigned NumObjCInterfaces = 0, NumObjCQualifiedInterfaces = 0; |
| 90 | unsigned NumObjCQualifiedIds = 0; |
Steve Naroff | e043063 | 2008-05-21 15:59:22 +0000 | [diff] [blame] | 91 | unsigned NumTypeOfTypes = 0, NumTypeOfExprs = 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 92 | |
| 93 | for (unsigned i = 0, e = Types.size(); i != e; ++i) { |
| 94 | Type *T = Types[i]; |
| 95 | if (isa<BuiltinType>(T)) |
| 96 | ++NumBuiltin; |
| 97 | else if (isa<PointerType>(T)) |
| 98 | ++NumPointer; |
Daniel Dunbar | 4767734 | 2008-09-26 03:23:00 +0000 | [diff] [blame] | 99 | else if (isa<BlockPointerType>(T)) |
| 100 | ++NumBlockPointer; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 101 | else if (isa<ReferenceType>(T)) |
| 102 | ++NumReference; |
| 103 | else if (isa<ComplexType>(T)) |
| 104 | ++NumComplex; |
| 105 | else if (isa<ArrayType>(T)) |
| 106 | ++NumArray; |
| 107 | else if (isa<VectorType>(T)) |
| 108 | ++NumVector; |
| 109 | else if (isa<FunctionTypeNoProto>(T)) |
| 110 | ++NumFunctionNP; |
| 111 | else if (isa<FunctionTypeProto>(T)) |
| 112 | ++NumFunctionP; |
| 113 | else if (isa<TypedefType>(T)) |
| 114 | ++NumTypeName; |
| 115 | else if (TagType *TT = dyn_cast<TagType>(T)) { |
| 116 | ++NumTagged; |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 117 | switch (TT->getDecl()->getTagKind()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 118 | default: assert(0 && "Unknown tagged type!"); |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 119 | case TagDecl::TK_struct: ++NumTagStruct; break; |
| 120 | case TagDecl::TK_union: ++NumTagUnion; break; |
| 121 | case TagDecl::TK_class: ++NumTagClass; break; |
| 122 | case TagDecl::TK_enum: ++NumTagEnum; break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 123 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 124 | } else if (isa<ObjCInterfaceType>(T)) |
| 125 | ++NumObjCInterfaces; |
| 126 | else if (isa<ObjCQualifiedInterfaceType>(T)) |
| 127 | ++NumObjCQualifiedInterfaces; |
| 128 | else if (isa<ObjCQualifiedIdType>(T)) |
| 129 | ++NumObjCQualifiedIds; |
Steve Naroff | e043063 | 2008-05-21 15:59:22 +0000 | [diff] [blame] | 130 | else if (isa<TypeOfType>(T)) |
| 131 | ++NumTypeOfTypes; |
| 132 | else if (isa<TypeOfExpr>(T)) |
| 133 | ++NumTypeOfExprs; |
Steve Naroff | 948fd37 | 2007-09-17 14:16:13 +0000 | [diff] [blame] | 134 | else { |
Chris Lattner | 8a35b46 | 2007-12-12 06:43:05 +0000 | [diff] [blame] | 135 | QualType(T, 0).dump(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 136 | assert(0 && "Unknown type!"); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | fprintf(stderr, " %d builtin types\n", NumBuiltin); |
| 141 | fprintf(stderr, " %d pointer types\n", NumPointer); |
Daniel Dunbar | 4767734 | 2008-09-26 03:23:00 +0000 | [diff] [blame] | 142 | fprintf(stderr, " %d block pointer types\n", NumBlockPointer); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 143 | fprintf(stderr, " %d reference types\n", NumReference); |
| 144 | fprintf(stderr, " %d complex types\n", NumComplex); |
| 145 | fprintf(stderr, " %d array types\n", NumArray); |
| 146 | fprintf(stderr, " %d vector types\n", NumVector); |
| 147 | fprintf(stderr, " %d function types with proto\n", NumFunctionP); |
| 148 | fprintf(stderr, " %d function types with no proto\n", NumFunctionNP); |
| 149 | fprintf(stderr, " %d typename (typedef) types\n", NumTypeName); |
| 150 | fprintf(stderr, " %d tagged types\n", NumTagged); |
| 151 | fprintf(stderr, " %d struct types\n", NumTagStruct); |
| 152 | fprintf(stderr, " %d union types\n", NumTagUnion); |
| 153 | fprintf(stderr, " %d class types\n", NumTagClass); |
| 154 | fprintf(stderr, " %d enum types\n", NumTagEnum); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 155 | fprintf(stderr, " %d interface types\n", NumObjCInterfaces); |
Chris Lattner | 8a35b46 | 2007-12-12 06:43:05 +0000 | [diff] [blame] | 156 | fprintf(stderr, " %d protocol qualified interface types\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 157 | NumObjCQualifiedInterfaces); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 158 | fprintf(stderr, " %d protocol qualified id types\n", |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 159 | NumObjCQualifiedIds); |
Steve Naroff | e043063 | 2008-05-21 15:59:22 +0000 | [diff] [blame] | 160 | fprintf(stderr, " %d typeof types\n", NumTypeOfTypes); |
| 161 | fprintf(stderr, " %d typeof exprs\n", NumTypeOfExprs); |
| 162 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 163 | fprintf(stderr, "Total bytes = %d\n", int(NumBuiltin*sizeof(BuiltinType)+ |
| 164 | NumPointer*sizeof(PointerType)+NumArray*sizeof(ArrayType)+ |
| 165 | NumComplex*sizeof(ComplexType)+NumVector*sizeof(VectorType)+ |
| 166 | NumFunctionP*sizeof(FunctionTypeProto)+ |
| 167 | NumFunctionNP*sizeof(FunctionTypeNoProto)+ |
Steve Naroff | e043063 | 2008-05-21 15:59:22 +0000 | [diff] [blame] | 168 | NumTypeName*sizeof(TypedefType)+NumTagged*sizeof(TagType)+ |
| 169 | NumTypeOfTypes*sizeof(TypeOfType)+NumTypeOfExprs*sizeof(TypeOfExpr))); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | void ASTContext::InitBuiltinType(QualType &R, BuiltinType::Kind K) { |
| 174 | Types.push_back((R = QualType(new BuiltinType(K),0)).getTypePtr()); |
| 175 | } |
| 176 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 177 | void ASTContext::InitBuiltinTypes() { |
| 178 | assert(VoidTy.isNull() && "Context reinitialized?"); |
| 179 | |
| 180 | // C99 6.2.5p19. |
| 181 | InitBuiltinType(VoidTy, BuiltinType::Void); |
| 182 | |
| 183 | // C99 6.2.5p2. |
| 184 | InitBuiltinType(BoolTy, BuiltinType::Bool); |
| 185 | // C99 6.2.5p3. |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 186 | if (Target.isCharSigned()) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 187 | InitBuiltinType(CharTy, BuiltinType::Char_S); |
| 188 | else |
| 189 | InitBuiltinType(CharTy, BuiltinType::Char_U); |
| 190 | // C99 6.2.5p4. |
| 191 | InitBuiltinType(SignedCharTy, BuiltinType::SChar); |
| 192 | InitBuiltinType(ShortTy, BuiltinType::Short); |
| 193 | InitBuiltinType(IntTy, BuiltinType::Int); |
| 194 | InitBuiltinType(LongTy, BuiltinType::Long); |
| 195 | InitBuiltinType(LongLongTy, BuiltinType::LongLong); |
| 196 | |
| 197 | // C99 6.2.5p6. |
| 198 | InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); |
| 199 | InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); |
| 200 | InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); |
| 201 | InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); |
| 202 | InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); |
| 203 | |
| 204 | // C99 6.2.5p10. |
| 205 | InitBuiltinType(FloatTy, BuiltinType::Float); |
| 206 | InitBuiltinType(DoubleTy, BuiltinType::Double); |
| 207 | InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); |
Argiris Kirtzidis | 1ed03e7 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 208 | |
| 209 | // C++ 3.9.1p5 |
| 210 | InitBuiltinType(WCharTy, BuiltinType::WChar); |
| 211 | |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 212 | // Placeholder type for functions. |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 213 | InitBuiltinType(OverloadTy, BuiltinType::Overload); |
| 214 | |
| 215 | // Placeholder type for type-dependent expressions whose type is |
| 216 | // completely unknown. No code should ever check a type against |
| 217 | // DependentTy and users should never see it; however, it is here to |
| 218 | // help diagnose failures to properly check for type-dependent |
| 219 | // expressions. |
| 220 | InitBuiltinType(DependentTy, BuiltinType::Dependent); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 221 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 222 | // C99 6.2.5p11. |
| 223 | FloatComplexTy = getComplexType(FloatTy); |
| 224 | DoubleComplexTy = getComplexType(DoubleTy); |
| 225 | LongDoubleComplexTy = getComplexType(LongDoubleTy); |
Douglas Gregor | d2baafd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 226 | |
Steve Naroff | 9d12c90 | 2007-10-15 14:41:52 +0000 | [diff] [blame] | 227 | BuiltinVaListType = QualType(); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 228 | ObjCIdType = QualType(); |
Steve Naroff | 9d12c90 | 2007-10-15 14:41:52 +0000 | [diff] [blame] | 229 | IdStructType = 0; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 230 | ObjCClassType = QualType(); |
Anders Carlsson | 7f23e3d | 2007-10-31 02:53:19 +0000 | [diff] [blame] | 231 | ClassStructType = 0; |
| 232 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 233 | ObjCConstantStringType = QualType(); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 234 | |
| 235 | // void * type |
| 236 | VoidPtrTy = getPointerType(VoidTy); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | //===----------------------------------------------------------------------===// |
| 240 | // Type Sizing and Analysis |
| 241 | //===----------------------------------------------------------------------===// |
| 242 | |
Chris Lattner | 2a674dc | 2008-06-30 18:32:54 +0000 | [diff] [blame] | 243 | /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified |
| 244 | /// scalar floating point type. |
| 245 | const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { |
| 246 | const BuiltinType *BT = T->getAsBuiltinType(); |
| 247 | assert(BT && "Not a floating point type!"); |
| 248 | switch (BT->getKind()) { |
| 249 | default: assert(0 && "Not a floating point type!"); |
| 250 | case BuiltinType::Float: return Target.getFloatFormat(); |
| 251 | case BuiltinType::Double: return Target.getDoubleFormat(); |
| 252 | case BuiltinType::LongDouble: return Target.getLongDoubleFormat(); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 257 | /// getTypeSize - Return the size of the specified type, in bits. This method |
| 258 | /// does not work on incomplete types. |
| 259 | std::pair<uint64_t, unsigned> |
Daniel Dunbar | 7d6a5d2 | 2008-11-08 05:48:37 +0000 | [diff] [blame] | 260 | ASTContext::getTypeInfo(const Type *T) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 261 | T = getCanonicalType(T); |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 262 | uint64_t Width; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 263 | unsigned Align; |
| 264 | switch (T->getTypeClass()) { |
| 265 | case Type::TypeName: assert(0 && "Not a canonical type!"); |
| 266 | case Type::FunctionNoProto: |
| 267 | case Type::FunctionProto: |
| 268 | default: |
| 269 | assert(0 && "Incomplete types have no size!"); |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 270 | case Type::VariableArray: |
| 271 | assert(0 && "VLAs not implemented yet!"); |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 272 | case Type::DependentSizedArray: |
| 273 | assert(0 && "Dependently-sized arrays don't have a known size"); |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 274 | case Type::ConstantArray: { |
Daniel Dunbar | 7d6a5d2 | 2008-11-08 05:48:37 +0000 | [diff] [blame] | 275 | const ConstantArrayType *CAT = cast<ConstantArrayType>(T); |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 276 | |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 277 | std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType()); |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 278 | Width = EltInfo.first*CAT->getSize().getZExtValue(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 279 | Align = EltInfo.second; |
| 280 | break; |
Christopher Lamb | 82c758b | 2007-12-29 05:10:55 +0000 | [diff] [blame] | 281 | } |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 282 | case Type::ExtVector: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 283 | case Type::Vector: { |
| 284 | std::pair<uint64_t, unsigned> EltInfo = |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 285 | getTypeInfo(cast<VectorType>(T)->getElementType()); |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 286 | Width = EltInfo.first*cast<VectorType>(T)->getNumElements(); |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 287 | // FIXME: This isn't right for unusual vectors |
| 288 | Align = Width; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 289 | break; |
| 290 | } |
| 291 | |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 292 | case Type::Builtin: |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 293 | switch (cast<BuiltinType>(T)->getKind()) { |
| 294 | default: assert(0 && "Unknown builtin type!"); |
| 295 | case BuiltinType::Void: |
| 296 | assert(0 && "Incomplete types have no size!"); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 297 | case BuiltinType::Bool: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 298 | Width = Target.getBoolWidth(); |
| 299 | Align = Target.getBoolAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 300 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 301 | case BuiltinType::Char_S: |
| 302 | case BuiltinType::Char_U: |
| 303 | case BuiltinType::UChar: |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 304 | case BuiltinType::SChar: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 305 | Width = Target.getCharWidth(); |
| 306 | Align = Target.getCharAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 307 | break; |
Argiris Kirtzidis | 1ed03e7 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 308 | case BuiltinType::WChar: |
| 309 | Width = Target.getWCharWidth(); |
| 310 | Align = Target.getWCharAlign(); |
| 311 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 312 | case BuiltinType::UShort: |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 313 | case BuiltinType::Short: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 314 | Width = Target.getShortWidth(); |
| 315 | Align = Target.getShortAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 316 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 317 | case BuiltinType::UInt: |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 318 | case BuiltinType::Int: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 319 | Width = Target.getIntWidth(); |
| 320 | Align = Target.getIntAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 321 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 322 | case BuiltinType::ULong: |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 323 | case BuiltinType::Long: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 324 | Width = Target.getLongWidth(); |
| 325 | Align = Target.getLongAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 326 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 327 | case BuiltinType::ULongLong: |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 328 | case BuiltinType::LongLong: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 329 | Width = Target.getLongLongWidth(); |
| 330 | Align = Target.getLongLongAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 331 | break; |
| 332 | case BuiltinType::Float: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 333 | Width = Target.getFloatWidth(); |
| 334 | Align = Target.getFloatAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 335 | break; |
| 336 | case BuiltinType::Double: |
Chris Lattner | 1d78a86 | 2008-04-07 07:01:58 +0000 | [diff] [blame] | 337 | Width = Target.getDoubleWidth(); |
| 338 | Align = Target.getDoubleAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 339 | break; |
| 340 | case BuiltinType::LongDouble: |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 341 | Width = Target.getLongDoubleWidth(); |
| 342 | Align = Target.getLongDoubleAlign(); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 343 | break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 344 | } |
| 345 | break; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 346 | case Type::ASQual: |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 347 | // FIXME: Pointers into different addr spaces could have different sizes and |
| 348 | // alignment requirements: getPointerInfo should take an AddrSpace. |
| 349 | return getTypeInfo(QualType(cast<ASQualType>(T)->getBaseType(), 0)); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 350 | case Type::ObjCQualifiedId: |
Chris Lattner | 1d78a86 | 2008-04-07 07:01:58 +0000 | [diff] [blame] | 351 | Width = Target.getPointerWidth(0); |
Chris Lattner | 461a6c5 | 2008-03-08 08:34:58 +0000 | [diff] [blame] | 352 | Align = Target.getPointerAlign(0); |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 353 | break; |
Steve Naroff | 62f09f5 | 2008-09-24 15:05:44 +0000 | [diff] [blame] | 354 | case Type::BlockPointer: { |
| 355 | unsigned AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace(); |
| 356 | Width = Target.getPointerWidth(AS); |
| 357 | Align = Target.getPointerAlign(AS); |
| 358 | break; |
| 359 | } |
Chris Lattner | 461a6c5 | 2008-03-08 08:34:58 +0000 | [diff] [blame] | 360 | case Type::Pointer: { |
| 361 | unsigned AS = cast<PointerType>(T)->getPointeeType().getAddressSpace(); |
Chris Lattner | 1d78a86 | 2008-04-07 07:01:58 +0000 | [diff] [blame] | 362 | Width = Target.getPointerWidth(AS); |
Chris Lattner | 461a6c5 | 2008-03-08 08:34:58 +0000 | [diff] [blame] | 363 | Align = Target.getPointerAlign(AS); |
| 364 | break; |
| 365 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 366 | case Type::Reference: |
| 367 | // "When applied to a reference or a reference type, the result is the size |
| 368 | // of the referenced type." C++98 5.3.3p2: expr.sizeof. |
Chris Lattner | b66237b | 2007-12-19 19:23:28 +0000 | [diff] [blame] | 369 | // FIXME: This is wrong for struct layout: a reference in a struct has |
| 370 | // pointer size. |
Chris Lattner | cfac88d | 2008-04-02 17:35:06 +0000 | [diff] [blame] | 371 | return getTypeInfo(cast<ReferenceType>(T)->getPointeeType()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 372 | |
| 373 | case Type::Complex: { |
| 374 | // Complex types have the same alignment as their elements, but twice the |
| 375 | // size. |
| 376 | std::pair<uint64_t, unsigned> EltInfo = |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 377 | getTypeInfo(cast<ComplexType>(T)->getElementType()); |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 378 | Width = EltInfo.first*2; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 379 | Align = EltInfo.second; |
| 380 | break; |
| 381 | } |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 382 | case Type::ObjCInterface: { |
Daniel Dunbar | 7d6a5d2 | 2008-11-08 05:48:37 +0000 | [diff] [blame] | 383 | const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 384 | const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); |
| 385 | Width = Layout.getSize(); |
| 386 | Align = Layout.getAlignment(); |
| 387 | break; |
| 388 | } |
Chris Lattner | 2bf1d6c | 2008-04-06 22:05:18 +0000 | [diff] [blame] | 389 | case Type::Tagged: { |
Daniel Dunbar | 7d6a5d2 | 2008-11-08 05:48:37 +0000 | [diff] [blame] | 390 | const TagType *TT = cast<TagType>(T); |
| 391 | |
| 392 | if (TT->getDecl()->isInvalidDecl()) { |
Chris Lattner | fd79969 | 2008-08-09 21:35:13 +0000 | [diff] [blame] | 393 | Width = 1; |
| 394 | Align = 1; |
| 395 | break; |
| 396 | } |
| 397 | |
Daniel Dunbar | 7d6a5d2 | 2008-11-08 05:48:37 +0000 | [diff] [blame] | 398 | if (const EnumType *ET = dyn_cast<EnumType>(TT)) |
Chris Lattner | 2bf1d6c | 2008-04-06 22:05:18 +0000 | [diff] [blame] | 399 | return getTypeInfo(ET->getDecl()->getIntegerType()); |
| 400 | |
Daniel Dunbar | 7d6a5d2 | 2008-11-08 05:48:37 +0000 | [diff] [blame] | 401 | const RecordType *RT = cast<RecordType>(TT); |
Chris Lattner | 2bf1d6c | 2008-04-06 22:05:18 +0000 | [diff] [blame] | 402 | const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); |
| 403 | Width = Layout.getSize(); |
| 404 | Align = Layout.getAlignment(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 405 | break; |
| 406 | } |
Chris Lattner | 2bf1d6c | 2008-04-06 22:05:18 +0000 | [diff] [blame] | 407 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 408 | |
| 409 | assert(Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2"); |
Chris Lattner | fc18dcc | 2008-03-08 08:52:55 +0000 | [diff] [blame] | 410 | return std::make_pair(Width, Align); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 413 | /// LayoutField - Field layout. |
| 414 | void ASTRecordLayout::LayoutField(const FieldDecl *FD, unsigned FieldNo, |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 415 | bool IsUnion, unsigned StructPacking, |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 416 | ASTContext &Context) { |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 417 | unsigned FieldPacking = StructPacking; |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 418 | uint64_t FieldOffset = IsUnion ? 0 : Size; |
| 419 | uint64_t FieldSize; |
| 420 | unsigned FieldAlign; |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 421 | |
| 422 | // FIXME: Should this override struct packing? Probably we want to |
| 423 | // take the minimum? |
| 424 | if (const PackedAttr *PA = FD->getAttr<PackedAttr>()) |
| 425 | FieldPacking = PA->getAlignment(); |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 426 | |
| 427 | if (const Expr *BitWidthExpr = FD->getBitWidth()) { |
| 428 | // TODO: Need to check this algorithm on other targets! |
| 429 | // (tested on Linux-X86) |
Daniel Dunbar | 7cbcbf4 | 2008-08-13 23:47:13 +0000 | [diff] [blame] | 430 | FieldSize = |
| 431 | BitWidthExpr->getIntegerConstantExprValue(Context).getZExtValue(); |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 432 | |
| 433 | std::pair<uint64_t, unsigned> FieldInfo = |
| 434 | Context.getTypeInfo(FD->getType()); |
| 435 | uint64_t TypeSize = FieldInfo.first; |
| 436 | |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 437 | // Determine the alignment of this bitfield. The packing |
| 438 | // attributes define a maximum and the alignment attribute defines |
| 439 | // a minimum. |
| 440 | // FIXME: What is the right behavior when the specified alignment |
| 441 | // is smaller than the specified packing? |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 442 | FieldAlign = FieldInfo.second; |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 443 | if (FieldPacking) |
| 444 | FieldAlign = std::min(FieldAlign, FieldPacking); |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 445 | if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>()) |
| 446 | FieldAlign = std::max(FieldAlign, AA->getAlignment()); |
| 447 | |
| 448 | // Check if we need to add padding to give the field the correct |
| 449 | // alignment. |
| 450 | if (FieldSize == 0 || (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize) |
| 451 | FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1); |
| 452 | |
| 453 | // Padding members don't affect overall alignment |
| 454 | if (!FD->getIdentifier()) |
| 455 | FieldAlign = 1; |
| 456 | } else { |
Chris Lattner | fd79969 | 2008-08-09 21:35:13 +0000 | [diff] [blame] | 457 | if (FD->getType()->isIncompleteArrayType()) { |
| 458 | // This is a flexible array member; we can't directly |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 459 | // query getTypeInfo about these, so we figure it out here. |
| 460 | // Flexible array members don't have any size, but they |
| 461 | // have to be aligned appropriately for their element type. |
| 462 | FieldSize = 0; |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 463 | const ArrayType* ATy = Context.getAsArrayType(FD->getType()); |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 464 | FieldAlign = Context.getTypeAlign(ATy->getElementType()); |
| 465 | } else { |
| 466 | std::pair<uint64_t, unsigned> FieldInfo = |
| 467 | Context.getTypeInfo(FD->getType()); |
| 468 | FieldSize = FieldInfo.first; |
| 469 | FieldAlign = FieldInfo.second; |
| 470 | } |
| 471 | |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 472 | // Determine the alignment of this bitfield. The packing |
| 473 | // attributes define a maximum and the alignment attribute defines |
| 474 | // a minimum. Additionally, the packing alignment must be at least |
| 475 | // a byte for non-bitfields. |
| 476 | // |
| 477 | // FIXME: What is the right behavior when the specified alignment |
| 478 | // is smaller than the specified packing? |
| 479 | if (FieldPacking) |
| 480 | FieldAlign = std::min(FieldAlign, std::max(8U, FieldPacking)); |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 481 | if (const AlignedAttr *AA = FD->getAttr<AlignedAttr>()) |
| 482 | FieldAlign = std::max(FieldAlign, AA->getAlignment()); |
| 483 | |
| 484 | // Round up the current record size to the field's alignment boundary. |
| 485 | FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1); |
| 486 | } |
| 487 | |
| 488 | // Place this field at the current location. |
| 489 | FieldOffsets[FieldNo] = FieldOffset; |
| 490 | |
| 491 | // Reserve space for this field. |
| 492 | if (IsUnion) { |
| 493 | Size = std::max(Size, FieldSize); |
| 494 | } else { |
| 495 | Size = FieldOffset + FieldSize; |
| 496 | } |
| 497 | |
| 498 | // Remember max struct/class alignment. |
| 499 | Alignment = std::max(Alignment, FieldAlign); |
| 500 | } |
| 501 | |
Fariborz Jahanian | 0556b15 | 2008-12-17 21:40:49 +0000 | [diff] [blame] | 502 | static void CollectObjCIvars(const ObjCInterfaceDecl *OI, |
| 503 | std::vector<FieldDecl*> &Fields) { |
| 504 | const ObjCInterfaceDecl *SuperClass = OI->getSuperClass(); |
| 505 | if (SuperClass) |
| 506 | CollectObjCIvars(SuperClass, Fields); |
| 507 | for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), |
| 508 | E = OI->ivar_end(); I != E; ++I) { |
| 509 | ObjCIvarDecl *IVDecl = (*I); |
| 510 | if (!IVDecl->isInvalidDecl()) |
| 511 | Fields.push_back(cast<FieldDecl>(IVDecl)); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /// addRecordToClass - produces record info. for the class for its |
| 516 | /// ivars and all those inherited. |
| 517 | /// |
| 518 | const RecordDecl *ASTContext::addRecordToClass(const ObjCInterfaceDecl *D) |
| 519 | { |
| 520 | const RecordDecl *&RD = ASTRecordForInterface[D]; |
| 521 | if (RD) |
| 522 | return RD; |
| 523 | std::vector<FieldDecl*> RecFields; |
| 524 | CollectObjCIvars(D, RecFields); |
| 525 | RecordDecl *NewRD = RecordDecl::Create(*this, TagDecl::TK_struct, 0, |
| 526 | D->getLocation(), |
| 527 | D->getIdentifier()); |
| 528 | /// FIXME! Can do collection of ivars and adding to the record while |
| 529 | /// doing it. |
| 530 | for (unsigned int i = 0; i != RecFields.size(); i++) { |
| 531 | FieldDecl *Field = FieldDecl::Create(*this, NewRD, |
| 532 | RecFields[i]->getLocation(), |
| 533 | RecFields[i]->getIdentifier(), |
| 534 | RecFields[i]->getType(), |
| 535 | RecFields[i]->getBitWidth(), false, 0); |
Douglas Gregor | 03b2ad2 | 2009-01-12 23:27:07 +0000 | [diff] [blame] | 536 | NewRD->addDecl(Field); |
Fariborz Jahanian | 0556b15 | 2008-12-17 21:40:49 +0000 | [diff] [blame] | 537 | } |
| 538 | NewRD->completeDefinition(*this); |
| 539 | RD = NewRD; |
| 540 | return RD; |
| 541 | } |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 542 | |
Fariborz Jahanian | ea94484 | 2008-12-18 17:29:46 +0000 | [diff] [blame] | 543 | /// setFieldDecl - maps a field for the given Ivar reference node. |
| 544 | // |
| 545 | void ASTContext::setFieldDecl(const ObjCInterfaceDecl *OI, |
| 546 | const ObjCIvarDecl *Ivar, |
| 547 | const ObjCIvarRefExpr *MRef) { |
| 548 | FieldDecl *FD = (const_cast<ObjCInterfaceDecl *>(OI))-> |
| 549 | lookupFieldDeclForIvar(*this, Ivar); |
| 550 | ASTFieldForIvarRef[MRef] = FD; |
| 551 | } |
| 552 | |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 553 | /// getASTObjcInterfaceLayout - Get or compute information about the layout of |
| 554 | /// the specified Objective C, which indicates its size and ivar |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 555 | /// position information. |
| 556 | const ASTRecordLayout & |
| 557 | ASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) { |
| 558 | // Look up this layout, if already laid out, return what we have. |
| 559 | const ASTRecordLayout *&Entry = ASTObjCInterfaces[D]; |
| 560 | if (Entry) return *Entry; |
| 561 | |
| 562 | // Allocate and assign into ASTRecordLayouts here. The "Entry" reference can |
| 563 | // be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into. |
Devang Patel | 8682d88 | 2008-06-06 02:14:01 +0000 | [diff] [blame] | 564 | ASTRecordLayout *NewEntry = NULL; |
| 565 | unsigned FieldCount = D->ivar_size(); |
| 566 | if (ObjCInterfaceDecl *SD = D->getSuperClass()) { |
| 567 | FieldCount++; |
| 568 | const ASTRecordLayout &SL = getASTObjCInterfaceLayout(SD); |
| 569 | unsigned Alignment = SL.getAlignment(); |
| 570 | uint64_t Size = SL.getSize(); |
| 571 | NewEntry = new ASTRecordLayout(Size, Alignment); |
| 572 | NewEntry->InitializeLayout(FieldCount); |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 573 | // Super class is at the beginning of the layout. |
| 574 | NewEntry->SetFieldOffset(0, 0); |
Devang Patel | 8682d88 | 2008-06-06 02:14:01 +0000 | [diff] [blame] | 575 | } else { |
| 576 | NewEntry = new ASTRecordLayout(); |
| 577 | NewEntry->InitializeLayout(FieldCount); |
| 578 | } |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 579 | Entry = NewEntry; |
| 580 | |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 581 | unsigned StructPacking = 0; |
| 582 | if (const PackedAttr *PA = D->getAttr<PackedAttr>()) |
| 583 | StructPacking = PA->getAlignment(); |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 584 | |
| 585 | if (const AlignedAttr *AA = D->getAttr<AlignedAttr>()) |
| 586 | NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), |
| 587 | AA->getAlignment())); |
| 588 | |
| 589 | // Layout each ivar sequentially. |
| 590 | unsigned i = 0; |
| 591 | for (ObjCInterfaceDecl::ivar_iterator IVI = D->ivar_begin(), |
| 592 | IVE = D->ivar_end(); IVI != IVE; ++IVI) { |
| 593 | const ObjCIvarDecl* Ivar = (*IVI); |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 594 | NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this); |
Devang Patel | 4b6bf70 | 2008-06-04 21:54:36 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | // Finally, round the size of the total struct up to the alignment of the |
| 598 | // struct itself. |
| 599 | NewEntry->FinalizeLayout(); |
| 600 | return *NewEntry; |
| 601 | } |
| 602 | |
Devang Patel | 7a78e43 | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 603 | /// getASTRecordLayout - Get or compute information about the layout of the |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 604 | /// specified record (struct/union/class), which indicates its size and field |
| 605 | /// position information. |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 606 | const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) { |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 607 | D = D->getDefinition(*this); |
| 608 | assert(D && "Cannot get layout of forward declarations!"); |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 609 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 610 | // Look up this layout, if already laid out, return what we have. |
Devang Patel | 7a78e43 | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 611 | const ASTRecordLayout *&Entry = ASTRecordLayouts[D]; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 612 | if (Entry) return *Entry; |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 613 | |
Devang Patel | 7a78e43 | 2007-11-01 19:11:01 +0000 | [diff] [blame] | 614 | // Allocate and assign into ASTRecordLayouts here. The "Entry" reference can |
| 615 | // be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into. |
| 616 | ASTRecordLayout *NewEntry = new ASTRecordLayout(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 617 | Entry = NewEntry; |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 618 | |
Douglas Gregor | 3967762 | 2008-12-11 20:41:00 +0000 | [diff] [blame] | 619 | // FIXME: Avoid linear walk through the fields, if possible. |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 620 | NewEntry->InitializeLayout(std::distance(D->field_begin(), D->field_end())); |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 621 | bool IsUnion = D->isUnion(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 622 | |
Daniel Dunbar | 2cb762f | 2008-10-16 02:34:03 +0000 | [diff] [blame] | 623 | unsigned StructPacking = 0; |
| 624 | if (const PackedAttr *PA = D->getAttr<PackedAttr>()) |
| 625 | StructPacking = PA->getAlignment(); |
| 626 | |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 627 | if (const AlignedAttr *AA = D->getAttr<AlignedAttr>()) |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 628 | NewEntry->SetAlignment(std::max(NewEntry->getAlignment(), |
| 629 | AA->getAlignment())); |
Anders Carlsson | 058237f | 2008-02-18 07:13:09 +0000 | [diff] [blame] | 630 | |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 631 | // Layout each field, for now, just sequentially, respecting alignment. In |
| 632 | // the future, this will need to be tweakable by targets. |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 633 | unsigned FieldIdx = 0; |
Douglas Gregor | 5d76484 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 634 | for (RecordDecl::field_iterator Field = D->field_begin(), |
| 635 | FieldEnd = D->field_end(); |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 636 | Field != FieldEnd; (void)++Field, ++FieldIdx) |
| 637 | NewEntry->LayoutField(*Field, FieldIdx, IsUnion, StructPacking, *this); |
Eli Friedman | 5949a02 | 2008-05-30 09:31:38 +0000 | [diff] [blame] | 638 | |
| 639 | // Finally, round the size of the total struct up to the alignment of the |
| 640 | // struct itself. |
Devang Patel | bfe323c | 2008-06-04 21:22:16 +0000 | [diff] [blame] | 641 | NewEntry->FinalizeLayout(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 642 | return *NewEntry; |
| 643 | } |
| 644 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 645 | //===----------------------------------------------------------------------===// |
| 646 | // Type creation/memoization methods |
| 647 | //===----------------------------------------------------------------------===// |
| 648 | |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 649 | QualType ASTContext::getASQualType(QualType T, unsigned AddressSpace) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 650 | QualType CanT = getCanonicalType(T); |
| 651 | if (CanT.getAddressSpace() == AddressSpace) |
Chris Lattner | 35fef52 | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 652 | return T; |
| 653 | |
| 654 | // Type's cannot have multiple ASQuals, therefore we know we only have to deal |
| 655 | // with CVR qualifiers from here on out. |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 656 | assert(CanT.getAddressSpace() == 0 && |
Chris Lattner | 35fef52 | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 657 | "Type is already address space qualified"); |
| 658 | |
| 659 | // Check if we've already instantiated an address space qual'd type of this |
| 660 | // type. |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 661 | llvm::FoldingSetNodeID ID; |
Chris Lattner | 35fef52 | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 662 | ASQualType::Profile(ID, T.getTypePtr(), AddressSpace); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 663 | void *InsertPos = 0; |
| 664 | if (ASQualType *ASQy = ASQualTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 665 | return QualType(ASQy, 0); |
| 666 | |
| 667 | // If the base type isn't canonical, this won't be a canonical type either, |
| 668 | // so fill in the canonical type field. |
| 669 | QualType Canonical; |
| 670 | if (!T->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 671 | Canonical = getASQualType(CanT, AddressSpace); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 672 | |
| 673 | // Get the new insert position for the node we care about. |
| 674 | ASQualType *NewIP = ASQualTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 675 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 676 | } |
Chris Lattner | 35fef52 | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 677 | ASQualType *New = new ASQualType(T.getTypePtr(), Canonical, AddressSpace); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 678 | ASQualTypes.InsertNode(New, InsertPos); |
| 679 | Types.push_back(New); |
Chris Lattner | 35fef52 | 2008-02-20 20:55:12 +0000 | [diff] [blame] | 680 | return QualType(New, T.getCVRQualifiers()); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 683 | |
| 684 | /// getComplexType - Return the uniqued reference to the type for a complex |
| 685 | /// number with the specified element type. |
| 686 | QualType ASTContext::getComplexType(QualType T) { |
| 687 | // Unique pointers, to guarantee there is only one pointer of a particular |
| 688 | // structure. |
| 689 | llvm::FoldingSetNodeID ID; |
| 690 | ComplexType::Profile(ID, T); |
| 691 | |
| 692 | void *InsertPos = 0; |
| 693 | if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 694 | return QualType(CT, 0); |
| 695 | |
| 696 | // If the pointee type isn't canonical, this won't be a canonical type either, |
| 697 | // so fill in the canonical type field. |
| 698 | QualType Canonical; |
| 699 | if (!T->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 700 | Canonical = getComplexType(getCanonicalType(T)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 701 | |
| 702 | // Get the new insert position for the node we care about. |
| 703 | ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 704 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 705 | } |
| 706 | ComplexType *New = new ComplexType(T, Canonical); |
| 707 | Types.push_back(New); |
| 708 | ComplexTypes.InsertNode(New, InsertPos); |
| 709 | return QualType(New, 0); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | /// getPointerType - Return the uniqued reference to the type for a pointer to |
| 714 | /// the specified type. |
| 715 | QualType ASTContext::getPointerType(QualType T) { |
| 716 | // Unique pointers, to guarantee there is only one pointer of a particular |
| 717 | // structure. |
| 718 | llvm::FoldingSetNodeID ID; |
| 719 | PointerType::Profile(ID, T); |
| 720 | |
| 721 | void *InsertPos = 0; |
| 722 | if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 723 | return QualType(PT, 0); |
| 724 | |
| 725 | // If the pointee type isn't canonical, this won't be a canonical type either, |
| 726 | // so fill in the canonical type field. |
| 727 | QualType Canonical; |
| 728 | if (!T->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 729 | Canonical = getPointerType(getCanonicalType(T)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 730 | |
| 731 | // Get the new insert position for the node we care about. |
| 732 | PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 733 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 734 | } |
| 735 | PointerType *New = new PointerType(T, Canonical); |
| 736 | Types.push_back(New); |
| 737 | PointerTypes.InsertNode(New, InsertPos); |
| 738 | return QualType(New, 0); |
| 739 | } |
| 740 | |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 741 | /// getBlockPointerType - Return the uniqued reference to the type for |
| 742 | /// a pointer to the specified block. |
| 743 | QualType ASTContext::getBlockPointerType(QualType T) { |
Steve Naroff | fd5b19d | 2008-08-28 19:20:44 +0000 | [diff] [blame] | 744 | assert(T->isFunctionType() && "block of function types only"); |
| 745 | // Unique pointers, to guarantee there is only one block of a particular |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 746 | // structure. |
| 747 | llvm::FoldingSetNodeID ID; |
| 748 | BlockPointerType::Profile(ID, T); |
| 749 | |
| 750 | void *InsertPos = 0; |
| 751 | if (BlockPointerType *PT = |
| 752 | BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 753 | return QualType(PT, 0); |
| 754 | |
Steve Naroff | fd5b19d | 2008-08-28 19:20:44 +0000 | [diff] [blame] | 755 | // If the block pointee type isn't canonical, this won't be a canonical |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 756 | // type either so fill in the canonical type field. |
| 757 | QualType Canonical; |
| 758 | if (!T->isCanonical()) { |
| 759 | Canonical = getBlockPointerType(getCanonicalType(T)); |
| 760 | |
| 761 | // Get the new insert position for the node we care about. |
| 762 | BlockPointerType *NewIP = |
| 763 | BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 764 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Steve Naroff | 7aa5475 | 2008-08-27 16:04:49 +0000 | [diff] [blame] | 765 | } |
| 766 | BlockPointerType *New = new BlockPointerType(T, Canonical); |
| 767 | Types.push_back(New); |
| 768 | BlockPointerTypes.InsertNode(New, InsertPos); |
| 769 | return QualType(New, 0); |
| 770 | } |
| 771 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 772 | /// getReferenceType - Return the uniqued reference to the type for a reference |
| 773 | /// to the specified type. |
| 774 | QualType ASTContext::getReferenceType(QualType T) { |
| 775 | // Unique pointers, to guarantee there is only one pointer of a particular |
| 776 | // structure. |
| 777 | llvm::FoldingSetNodeID ID; |
| 778 | ReferenceType::Profile(ID, T); |
| 779 | |
| 780 | void *InsertPos = 0; |
| 781 | if (ReferenceType *RT = ReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 782 | return QualType(RT, 0); |
| 783 | |
| 784 | // If the referencee type isn't canonical, this won't be a canonical type |
| 785 | // either, so fill in the canonical type field. |
| 786 | QualType Canonical; |
| 787 | if (!T->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 788 | Canonical = getReferenceType(getCanonicalType(T)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 789 | |
| 790 | // Get the new insert position for the node we care about. |
| 791 | ReferenceType *NewIP = ReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 792 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | ReferenceType *New = new ReferenceType(T, Canonical); |
| 796 | Types.push_back(New); |
| 797 | ReferenceTypes.InsertNode(New, InsertPos); |
| 798 | return QualType(New, 0); |
| 799 | } |
| 800 | |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 801 | /// getConstantArrayType - Return the unique reference to the type for an |
| 802 | /// array of the specified element type. |
| 803 | QualType ASTContext::getConstantArrayType(QualType EltTy, |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 804 | const llvm::APInt &ArySize, |
| 805 | ArrayType::ArraySizeModifier ASM, |
| 806 | unsigned EltTypeQuals) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 807 | llvm::FoldingSetNodeID ID; |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 808 | ConstantArrayType::Profile(ID, EltTy, ArySize); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 809 | |
| 810 | void *InsertPos = 0; |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 811 | if (ConstantArrayType *ATP = |
| 812 | ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 813 | return QualType(ATP, 0); |
| 814 | |
| 815 | // If the element type isn't canonical, this won't be a canonical type either, |
| 816 | // so fill in the canonical type field. |
| 817 | QualType Canonical; |
| 818 | if (!EltTy->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 819 | Canonical = getConstantArrayType(getCanonicalType(EltTy), ArySize, |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 820 | ASM, EltTypeQuals); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 821 | // Get the new insert position for the node we care about. |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 822 | ConstantArrayType *NewIP = |
| 823 | ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 824 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 827 | ConstantArrayType *New = new ConstantArrayType(EltTy, Canonical, ArySize, |
| 828 | ASM, EltTypeQuals); |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 829 | ConstantArrayTypes.InsertNode(New, InsertPos); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 830 | Types.push_back(New); |
| 831 | return QualType(New, 0); |
| 832 | } |
| 833 | |
Steve Naroff | e2579e3 | 2007-08-30 18:14:25 +0000 | [diff] [blame] | 834 | /// getVariableArrayType - Returns a non-unique reference to the type for a |
| 835 | /// variable array of the specified element type. |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 836 | QualType ASTContext::getVariableArrayType(QualType EltTy, Expr *NumElts, |
| 837 | ArrayType::ArraySizeModifier ASM, |
| 838 | unsigned EltTypeQuals) { |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 839 | // Since we don't unique expressions, it isn't possible to unique VLA's |
| 840 | // that have an expression provided for their size. |
| 841 | |
| 842 | VariableArrayType *New = new VariableArrayType(EltTy, QualType(), NumElts, |
| 843 | ASM, EltTypeQuals); |
| 844 | |
| 845 | VariableArrayTypes.push_back(New); |
| 846 | Types.push_back(New); |
| 847 | return QualType(New, 0); |
| 848 | } |
| 849 | |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 850 | /// getDependentSizedArrayType - Returns a non-unique reference to |
| 851 | /// the type for a dependently-sized array of the specified element |
| 852 | /// type. FIXME: We will need these to be uniqued, or at least |
| 853 | /// comparable, at some point. |
| 854 | QualType ASTContext::getDependentSizedArrayType(QualType EltTy, Expr *NumElts, |
| 855 | ArrayType::ArraySizeModifier ASM, |
| 856 | unsigned EltTypeQuals) { |
| 857 | assert((NumElts->isTypeDependent() || NumElts->isValueDependent()) && |
| 858 | "Size must be type- or value-dependent!"); |
| 859 | |
| 860 | // Since we don't unique expressions, it isn't possible to unique |
| 861 | // dependently-sized array types. |
| 862 | |
| 863 | DependentSizedArrayType *New |
| 864 | = new DependentSizedArrayType(EltTy, QualType(), NumElts, |
| 865 | ASM, EltTypeQuals); |
| 866 | |
| 867 | DependentSizedArrayTypes.push_back(New); |
| 868 | Types.push_back(New); |
| 869 | return QualType(New, 0); |
| 870 | } |
| 871 | |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 872 | QualType ASTContext::getIncompleteArrayType(QualType EltTy, |
| 873 | ArrayType::ArraySizeModifier ASM, |
| 874 | unsigned EltTypeQuals) { |
| 875 | llvm::FoldingSetNodeID ID; |
| 876 | IncompleteArrayType::Profile(ID, EltTy); |
| 877 | |
| 878 | void *InsertPos = 0; |
| 879 | if (IncompleteArrayType *ATP = |
| 880 | IncompleteArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 881 | return QualType(ATP, 0); |
| 882 | |
| 883 | // If the element type isn't canonical, this won't be a canonical type |
| 884 | // either, so fill in the canonical type field. |
| 885 | QualType Canonical; |
| 886 | |
| 887 | if (!EltTy->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 888 | Canonical = getIncompleteArrayType(getCanonicalType(EltTy), |
Ted Kremenek | 3793e1a | 2007-10-29 23:37:31 +0000 | [diff] [blame] | 889 | ASM, EltTypeQuals); |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 890 | |
| 891 | // Get the new insert position for the node we care about. |
| 892 | IncompleteArrayType *NewIP = |
| 893 | IncompleteArrayTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 894 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Ted Kremenek | 3793e1a | 2007-10-29 23:37:31 +0000 | [diff] [blame] | 895 | } |
Eli Friedman | 8ff0778 | 2008-02-15 18:16:39 +0000 | [diff] [blame] | 896 | |
| 897 | IncompleteArrayType *New = new IncompleteArrayType(EltTy, Canonical, |
| 898 | ASM, EltTypeQuals); |
| 899 | |
| 900 | IncompleteArrayTypes.InsertNode(New, InsertPos); |
| 901 | Types.push_back(New); |
| 902 | return QualType(New, 0); |
Steve Naroff | 83c1301 | 2007-08-30 01:06:46 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 905 | /// getVectorType - Return the unique reference to a vector type of |
| 906 | /// the specified element type and size. VectorType must be a built-in type. |
| 907 | QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts) { |
| 908 | BuiltinType *baseType; |
| 909 | |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 910 | baseType = dyn_cast<BuiltinType>(getCanonicalType(vecType).getTypePtr()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 911 | assert(baseType != 0 && "getVectorType(): Expecting a built-in type"); |
| 912 | |
| 913 | // Check if we've already instantiated a vector of this type. |
| 914 | llvm::FoldingSetNodeID ID; |
| 915 | VectorType::Profile(ID, vecType, NumElts, Type::Vector); |
| 916 | void *InsertPos = 0; |
| 917 | if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 918 | return QualType(VTP, 0); |
| 919 | |
| 920 | // If the element type isn't canonical, this won't be a canonical type either, |
| 921 | // so fill in the canonical type field. |
| 922 | QualType Canonical; |
| 923 | if (!vecType->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 924 | Canonical = getVectorType(getCanonicalType(vecType), NumElts); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 925 | |
| 926 | // Get the new insert position for the node we care about. |
| 927 | VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 928 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 929 | } |
| 930 | VectorType *New = new VectorType(vecType, NumElts, Canonical); |
| 931 | VectorTypes.InsertNode(New, InsertPos); |
| 932 | Types.push_back(New); |
| 933 | return QualType(New, 0); |
| 934 | } |
| 935 | |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 936 | /// getExtVectorType - Return the unique reference to an extended vector type of |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 937 | /// the specified element type and size. VectorType must be a built-in type. |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 938 | QualType ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 939 | BuiltinType *baseType; |
| 940 | |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 941 | baseType = dyn_cast<BuiltinType>(getCanonicalType(vecType).getTypePtr()); |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 942 | assert(baseType != 0 && "getExtVectorType(): Expecting a built-in type"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 943 | |
| 944 | // Check if we've already instantiated a vector of this type. |
| 945 | llvm::FoldingSetNodeID ID; |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 946 | VectorType::Profile(ID, vecType, NumElts, Type::ExtVector); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 947 | void *InsertPos = 0; |
| 948 | if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 949 | return QualType(VTP, 0); |
| 950 | |
| 951 | // If the element type isn't canonical, this won't be a canonical type either, |
| 952 | // so fill in the canonical type field. |
| 953 | QualType Canonical; |
| 954 | if (!vecType->isCanonical()) { |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 955 | Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 956 | |
| 957 | // Get the new insert position for the node we care about. |
| 958 | VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 959 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 960 | } |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 961 | ExtVectorType *New = new ExtVectorType(vecType, NumElts, Canonical); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 962 | VectorTypes.InsertNode(New, InsertPos); |
| 963 | Types.push_back(New); |
| 964 | return QualType(New, 0); |
| 965 | } |
| 966 | |
| 967 | /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'. |
| 968 | /// |
| 969 | QualType ASTContext::getFunctionTypeNoProto(QualType ResultTy) { |
| 970 | // Unique functions, to guarantee there is only one function of a particular |
| 971 | // structure. |
| 972 | llvm::FoldingSetNodeID ID; |
| 973 | FunctionTypeNoProto::Profile(ID, ResultTy); |
| 974 | |
| 975 | void *InsertPos = 0; |
| 976 | if (FunctionTypeNoProto *FT = |
| 977 | FunctionTypeNoProtos.FindNodeOrInsertPos(ID, InsertPos)) |
| 978 | return QualType(FT, 0); |
| 979 | |
| 980 | QualType Canonical; |
| 981 | if (!ResultTy->isCanonical()) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 982 | Canonical = getFunctionTypeNoProto(getCanonicalType(ResultTy)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 983 | |
| 984 | // Get the new insert position for the node we care about. |
| 985 | FunctionTypeNoProto *NewIP = |
| 986 | FunctionTypeNoProtos.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 987 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | FunctionTypeNoProto *New = new FunctionTypeNoProto(ResultTy, Canonical); |
| 991 | Types.push_back(New); |
Eli Friedman | aa0fdfd | 2008-02-25 22:11:40 +0000 | [diff] [blame] | 992 | FunctionTypeNoProtos.InsertNode(New, InsertPos); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 993 | return QualType(New, 0); |
| 994 | } |
| 995 | |
| 996 | /// getFunctionType - Return a normal function type with a typed argument |
| 997 | /// list. isVariadic indicates whether the argument list includes '...'. |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 998 | QualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray, |
Argiris Kirtzidis | 4b269b4 | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 999 | unsigned NumArgs, bool isVariadic, |
| 1000 | unsigned TypeQuals) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1001 | // Unique functions, to guarantee there is only one function of a particular |
| 1002 | // structure. |
| 1003 | llvm::FoldingSetNodeID ID; |
Argiris Kirtzidis | 4b269b4 | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 1004 | FunctionTypeProto::Profile(ID, ResultTy, ArgArray, NumArgs, isVariadic, |
| 1005 | TypeQuals); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1006 | |
| 1007 | void *InsertPos = 0; |
| 1008 | if (FunctionTypeProto *FTP = |
| 1009 | FunctionTypeProtos.FindNodeOrInsertPos(ID, InsertPos)) |
| 1010 | return QualType(FTP, 0); |
| 1011 | |
| 1012 | // Determine whether the type being created is already canonical or not. |
| 1013 | bool isCanonical = ResultTy->isCanonical(); |
| 1014 | for (unsigned i = 0; i != NumArgs && isCanonical; ++i) |
| 1015 | if (!ArgArray[i]->isCanonical()) |
| 1016 | isCanonical = false; |
| 1017 | |
| 1018 | // If this type isn't canonical, get the canonical version of it. |
| 1019 | QualType Canonical; |
| 1020 | if (!isCanonical) { |
| 1021 | llvm::SmallVector<QualType, 16> CanonicalArgs; |
| 1022 | CanonicalArgs.reserve(NumArgs); |
| 1023 | for (unsigned i = 0; i != NumArgs; ++i) |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1024 | CanonicalArgs.push_back(getCanonicalType(ArgArray[i])); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1025 | |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1026 | Canonical = getFunctionType(getCanonicalType(ResultTy), |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1027 | &CanonicalArgs[0], NumArgs, |
Argiris Kirtzidis | 65b9964 | 2008-10-26 16:43:14 +0000 | [diff] [blame] | 1028 | isVariadic, TypeQuals); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1029 | |
| 1030 | // Get the new insert position for the node we care about. |
| 1031 | FunctionTypeProto *NewIP = |
| 1032 | FunctionTypeProtos.FindNodeOrInsertPos(ID, InsertPos); |
Chris Lattner | 578a37e | 2008-10-12 00:26:57 +0000 | [diff] [blame] | 1033 | assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | // FunctionTypeProto objects are not allocated with new because they have a |
| 1037 | // variable size array (for parameter types) at the end of them. |
| 1038 | FunctionTypeProto *FTP = |
| 1039 | (FunctionTypeProto*)malloc(sizeof(FunctionTypeProto) + |
| 1040 | NumArgs*sizeof(QualType)); |
| 1041 | new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic, |
Argiris Kirtzidis | 4b269b4 | 2008-10-24 21:46:40 +0000 | [diff] [blame] | 1042 | TypeQuals, Canonical); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1043 | Types.push_back(FTP); |
| 1044 | FunctionTypeProtos.InsertNode(FTP, InsertPos); |
| 1045 | return QualType(FTP, 0); |
| 1046 | } |
| 1047 | |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1048 | /// getTypeDeclType - Return the unique reference to the type for the |
| 1049 | /// specified type declaration. |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1050 | QualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) { |
Argiris Kirtzidis | eeec548 | 2008-10-16 16:50:47 +0000 | [diff] [blame] | 1051 | assert(Decl && "Passed null for Decl param"); |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1052 | if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); |
| 1053 | |
Argiris Kirtzidis | eeec548 | 2008-10-16 16:50:47 +0000 | [diff] [blame] | 1054 | if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(Decl)) |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1055 | return getTypedefType(Typedef); |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1056 | else if (TemplateTypeParmDecl *TP = dyn_cast<TemplateTypeParmDecl>(Decl)) |
| 1057 | return getTemplateTypeParmType(TP); |
Argiris Kirtzidis | eeec548 | 2008-10-16 16:50:47 +0000 | [diff] [blame] | 1058 | else if (ObjCInterfaceDecl *ObjCInterface = dyn_cast<ObjCInterfaceDecl>(Decl)) |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1059 | return getObjCInterfaceType(ObjCInterface); |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 1060 | |
Argiris Kirtzidis | eeec548 | 2008-10-16 16:50:47 +0000 | [diff] [blame] | 1061 | if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Decl)) { |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1062 | Decl->TypeForDecl = PrevDecl ? PrevDecl->TypeForDecl |
| 1063 | : new CXXRecordType(CXXRecord); |
| 1064 | } |
Argiris Kirtzidis | eeec548 | 2008-10-16 16:50:47 +0000 | [diff] [blame] | 1065 | else if (RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) { |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1066 | Decl->TypeForDecl = PrevDecl ? PrevDecl->TypeForDecl |
| 1067 | : new RecordType(Record); |
| 1068 | } |
Argiris Kirtzidis | eeec548 | 2008-10-16 16:50:47 +0000 | [diff] [blame] | 1069 | else if (EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) |
Douglas Gregor | ae64489 | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 1070 | Decl->TypeForDecl = PrevDecl ? PrevDecl->TypeForDecl |
| 1071 | : new EnumType(Enum); |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 1072 | else |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1073 | assert(false && "TypeDecl without a type?"); |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 1074 | |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1075 | if (!PrevDecl) Types.push_back(Decl->TypeForDecl); |
Argiris Kirtzidis | ea29d1e | 2008-08-07 20:55:28 +0000 | [diff] [blame] | 1076 | return QualType(Decl->TypeForDecl, 0); |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1079 | void ASTContext::setTagDefinition(TagDecl* D) { |
| 1080 | assert (D->isDefinition()); |
Douglas Gregor | ae64489 | 2008-12-15 16:32:14 +0000 | [diff] [blame] | 1081 | cast<TagType>(D->TypeForDecl)->decl = D; |
Ted Kremenek | 46a837c | 2008-09-05 17:16:31 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1084 | /// getTypedefType - Return the unique reference to the type for the |
| 1085 | /// specified typename decl. |
| 1086 | QualType ASTContext::getTypedefType(TypedefDecl *Decl) { |
| 1087 | if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); |
| 1088 | |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1089 | QualType Canonical = getCanonicalType(Decl->getUnderlyingType()); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1090 | Decl->TypeForDecl = new TypedefType(Type::TypeName, Decl, Canonical); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1091 | Types.push_back(Decl->TypeForDecl); |
| 1092 | return QualType(Decl->TypeForDecl, 0); |
| 1093 | } |
| 1094 | |
Douglas Gregor | dd86106 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1095 | /// getTemplateTypeParmType - Return the unique reference to the type |
| 1096 | /// for the specified template type parameter declaration. |
| 1097 | QualType ASTContext::getTemplateTypeParmType(TemplateTypeParmDecl *Decl) { |
| 1098 | if (!Decl->TypeForDecl) { |
| 1099 | Decl->TypeForDecl = new TemplateTypeParmType(Decl); |
| 1100 | Types.push_back(Decl->TypeForDecl); |
| 1101 | } |
| 1102 | return QualType(Decl->TypeForDecl, 0); |
| 1103 | } |
| 1104 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1105 | /// getObjCInterfaceType - Return the unique reference to the type for the |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1106 | /// specified ObjC interface decl. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1107 | QualType ASTContext::getObjCInterfaceType(ObjCInterfaceDecl *Decl) { |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1108 | if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); |
| 1109 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1110 | Decl->TypeForDecl = new ObjCInterfaceType(Type::ObjCInterface, Decl); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1111 | Types.push_back(Decl->TypeForDecl); |
| 1112 | return QualType(Decl->TypeForDecl, 0); |
| 1113 | } |
| 1114 | |
Chris Lattner | e135230 | 2008-04-07 04:56:42 +0000 | [diff] [blame] | 1115 | /// CmpProtocolNames - Comparison predicate for sorting protocols |
| 1116 | /// alphabetically. |
| 1117 | static bool CmpProtocolNames(const ObjCProtocolDecl *LHS, |
| 1118 | const ObjCProtocolDecl *RHS) { |
Douglas Gregor | 24afd4a | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 1119 | return LHS->getDeclName() < RHS->getDeclName(); |
Chris Lattner | e135230 | 2008-04-07 04:56:42 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | static void SortAndUniqueProtocols(ObjCProtocolDecl **&Protocols, |
| 1123 | unsigned &NumProtocols) { |
| 1124 | ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; |
| 1125 | |
| 1126 | // Sort protocols, keyed by name. |
| 1127 | std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames); |
| 1128 | |
| 1129 | // Remove duplicates. |
| 1130 | ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); |
| 1131 | NumProtocols = ProtocolsEnd-Protocols; |
| 1132 | } |
| 1133 | |
| 1134 | |
Chris Lattner | b0c6a1f | 2008-04-07 04:44:08 +0000 | [diff] [blame] | 1135 | /// getObjCQualifiedInterfaceType - Return a ObjCQualifiedInterfaceType type for |
| 1136 | /// the given interface decl and the conforming protocol list. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1137 | QualType ASTContext::getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl, |
| 1138 | ObjCProtocolDecl **Protocols, unsigned NumProtocols) { |
Chris Lattner | e135230 | 2008-04-07 04:56:42 +0000 | [diff] [blame] | 1139 | // Sort the protocol list alphabetically to canonicalize it. |
| 1140 | SortAndUniqueProtocols(Protocols, NumProtocols); |
| 1141 | |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1142 | llvm::FoldingSetNodeID ID; |
Chris Lattner | 7cdcb25 | 2008-04-07 06:38:24 +0000 | [diff] [blame] | 1143 | ObjCQualifiedInterfaceType::Profile(ID, Decl, Protocols, NumProtocols); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1144 | |
| 1145 | void *InsertPos = 0; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1146 | if (ObjCQualifiedInterfaceType *QT = |
| 1147 | ObjCQualifiedInterfaceTypes.FindNodeOrInsertPos(ID, InsertPos)) |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1148 | return QualType(QT, 0); |
| 1149 | |
| 1150 | // No Match; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1151 | ObjCQualifiedInterfaceType *QType = |
| 1152 | new ObjCQualifiedInterfaceType(Decl, Protocols, NumProtocols); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1153 | Types.push_back(QType); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1154 | ObjCQualifiedInterfaceTypes.InsertNode(QType, InsertPos); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1155 | return QualType(QType, 0); |
| 1156 | } |
| 1157 | |
Chris Lattner | e135230 | 2008-04-07 04:56:42 +0000 | [diff] [blame] | 1158 | /// getObjCQualifiedIdType - Return an ObjCQualifiedIdType for the 'id' decl |
| 1159 | /// and the conforming protocol list. |
Chris Lattner | 4a68fe0 | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 1160 | QualType ASTContext::getObjCQualifiedIdType(ObjCProtocolDecl **Protocols, |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1161 | unsigned NumProtocols) { |
Chris Lattner | e135230 | 2008-04-07 04:56:42 +0000 | [diff] [blame] | 1162 | // Sort the protocol list alphabetically to canonicalize it. |
| 1163 | SortAndUniqueProtocols(Protocols, NumProtocols); |
| 1164 | |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1165 | llvm::FoldingSetNodeID ID; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1166 | ObjCQualifiedIdType::Profile(ID, Protocols, NumProtocols); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1167 | |
| 1168 | void *InsertPos = 0; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1169 | if (ObjCQualifiedIdType *QT = |
Chris Lattner | 4a68fe0 | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 1170 | ObjCQualifiedIdTypes.FindNodeOrInsertPos(ID, InsertPos)) |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1171 | return QualType(QT, 0); |
| 1172 | |
| 1173 | // No Match; |
Chris Lattner | 4a68fe0 | 2008-07-26 00:46:50 +0000 | [diff] [blame] | 1174 | ObjCQualifiedIdType *QType = new ObjCQualifiedIdType(Protocols, NumProtocols); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1175 | Types.push_back(QType); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1176 | ObjCQualifiedIdTypes.InsertNode(QType, InsertPos); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1177 | return QualType(QType, 0); |
| 1178 | } |
| 1179 | |
Steve Naroff | 0604dd9 | 2007-08-01 18:02:17 +0000 | [diff] [blame] | 1180 | /// getTypeOfExpr - Unlike many "get<Type>" functions, we can't unique |
| 1181 | /// TypeOfExpr AST's (since expression's are never shared). For example, |
| 1182 | /// multiple declarations that refer to "typeof(x)" all contain different |
| 1183 | /// DeclRefExpr's. This doesn't effect the type checker, since it operates |
| 1184 | /// on canonical type's (which are always unique). |
Steve Naroff | 11b649c | 2007-08-01 17:20:42 +0000 | [diff] [blame] | 1185 | QualType ASTContext::getTypeOfExpr(Expr *tofExpr) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1186 | QualType Canonical = getCanonicalType(tofExpr->getType()); |
Steve Naroff | 0604dd9 | 2007-08-01 18:02:17 +0000 | [diff] [blame] | 1187 | TypeOfExpr *toe = new TypeOfExpr(tofExpr, Canonical); |
| 1188 | Types.push_back(toe); |
| 1189 | return QualType(toe, 0); |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Steve Naroff | 0604dd9 | 2007-08-01 18:02:17 +0000 | [diff] [blame] | 1192 | /// getTypeOfType - Unlike many "get<Type>" functions, we don't unique |
| 1193 | /// TypeOfType AST's. The only motivation to unique these nodes would be |
| 1194 | /// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be |
| 1195 | /// an issue. This doesn't effect the type checker, since it operates |
| 1196 | /// on canonical type's (which are always unique). |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1197 | QualType ASTContext::getTypeOfType(QualType tofType) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1198 | QualType Canonical = getCanonicalType(tofType); |
Steve Naroff | 0604dd9 | 2007-08-01 18:02:17 +0000 | [diff] [blame] | 1199 | TypeOfType *tot = new TypeOfType(tofType, Canonical); |
| 1200 | Types.push_back(tot); |
| 1201 | return QualType(tot, 0); |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1204 | /// getTagDeclType - Return the unique reference to the type for the |
| 1205 | /// specified TagDecl (struct/union/class/enum) decl. |
| 1206 | QualType ASTContext::getTagDeclType(TagDecl *Decl) { |
Ted Kremenek | ae8fa03 | 2007-11-26 21:16:01 +0000 | [diff] [blame] | 1207 | assert (Decl); |
Douglas Gregor | 1d66155 | 2008-04-13 21:07:44 +0000 | [diff] [blame] | 1208 | return getTypeDeclType(Decl); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /// getSizeType - Return the unique type for "size_t" (C99 7.17), the result |
| 1212 | /// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and |
| 1213 | /// needs to agree with the definition in <stddef.h>. |
| 1214 | QualType ASTContext::getSizeType() const { |
Douglas Gregor | c6507e4 | 2008-11-03 14:12:49 +0000 | [diff] [blame] | 1215 | return getFromTargetType(Target.getSizeType()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Argiris Kirtzidis | 2a4e116 | 2008-08-09 17:20:01 +0000 | [diff] [blame] | 1218 | /// getWCharType - Return the unique type for "wchar_t" (C99 7.17), the |
Eli Friedman | fdd35d7 | 2008-02-12 08:29:21 +0000 | [diff] [blame] | 1219 | /// width of characters in wide strings, The value is target dependent and |
| 1220 | /// needs to agree with the definition in <stddef.h>. |
Argiris Kirtzidis | 2a4e116 | 2008-08-09 17:20:01 +0000 | [diff] [blame] | 1221 | QualType ASTContext::getWCharType() const { |
Argiris Kirtzidis | 1ed03e7 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 1222 | if (LangOpts.CPlusPlus) |
| 1223 | return WCharTy; |
| 1224 | |
Douglas Gregor | c6507e4 | 2008-11-03 14:12:49 +0000 | [diff] [blame] | 1225 | // FIXME: In C, shouldn't WCharTy just be a typedef of the target's |
| 1226 | // wide-character type? |
| 1227 | return getFromTargetType(Target.getWCharType()); |
Eli Friedman | fdd35d7 | 2008-02-12 08:29:21 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Argiris Kirtzidis | 1ed03e7 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 1230 | /// getSignedWCharType - Return the type of "signed wchar_t". |
| 1231 | /// Used when in C++, as a GCC extension. |
| 1232 | QualType ASTContext::getSignedWCharType() const { |
| 1233 | // FIXME: derive from "Target" ? |
| 1234 | return WCharTy; |
| 1235 | } |
| 1236 | |
| 1237 | /// getUnsignedWCharType - Return the type of "unsigned wchar_t". |
| 1238 | /// Used when in C++, as a GCC extension. |
| 1239 | QualType ASTContext::getUnsignedWCharType() const { |
| 1240 | // FIXME: derive from "Target" ? |
| 1241 | return UnsignedIntTy; |
| 1242 | } |
| 1243 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1244 | /// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) |
| 1245 | /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). |
| 1246 | QualType ASTContext::getPointerDiffType() const { |
Douglas Gregor | c6507e4 | 2008-11-03 14:12:49 +0000 | [diff] [blame] | 1247 | return getFromTargetType(Target.getPtrDiffType(0)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Chris Lattner | 19eb97e | 2008-04-02 05:18:44 +0000 | [diff] [blame] | 1250 | //===----------------------------------------------------------------------===// |
| 1251 | // Type Operators |
| 1252 | //===----------------------------------------------------------------------===// |
| 1253 | |
Chris Lattner | 3dae6f4 | 2008-04-06 22:41:35 +0000 | [diff] [blame] | 1254 | /// getCanonicalType - Return the canonical (structural) type corresponding to |
| 1255 | /// the specified potentially non-canonical type. The non-canonical version |
| 1256 | /// of a type may have many "decorated" versions of types. Decorators can |
| 1257 | /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed |
| 1258 | /// to be free of any of these, allowing two canonical types to be compared |
| 1259 | /// for exact equality with a simple pointer comparison. |
| 1260 | QualType ASTContext::getCanonicalType(QualType T) { |
| 1261 | QualType CanType = T.getTypePtr()->getCanonicalTypeInternal(); |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1262 | |
| 1263 | // If the result has type qualifiers, make sure to canonicalize them as well. |
| 1264 | unsigned TypeQuals = T.getCVRQualifiers() | CanType.getCVRQualifiers(); |
| 1265 | if (TypeQuals == 0) return CanType; |
| 1266 | |
| 1267 | // If the type qualifiers are on an array type, get the canonical type of the |
| 1268 | // array with the qualifiers applied to the element type. |
| 1269 | ArrayType *AT = dyn_cast<ArrayType>(CanType); |
| 1270 | if (!AT) |
| 1271 | return CanType.getQualifiedType(TypeQuals); |
| 1272 | |
| 1273 | // Get the canonical version of the element with the extra qualifiers on it. |
| 1274 | // This can recursively sink qualifiers through multiple levels of arrays. |
| 1275 | QualType NewEltTy=AT->getElementType().getWithAdditionalQualifiers(TypeQuals); |
| 1276 | NewEltTy = getCanonicalType(NewEltTy); |
| 1277 | |
| 1278 | if (ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) |
| 1279 | return getConstantArrayType(NewEltTy, CAT->getSize(),CAT->getSizeModifier(), |
| 1280 | CAT->getIndexTypeQualifier()); |
| 1281 | if (IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) |
| 1282 | return getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(), |
| 1283 | IAT->getIndexTypeQualifier()); |
| 1284 | |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1285 | if (DependentSizedArrayType *DSAT = dyn_cast<DependentSizedArrayType>(AT)) |
| 1286 | return getDependentSizedArrayType(NewEltTy, DSAT->getSizeExpr(), |
| 1287 | DSAT->getSizeModifier(), |
| 1288 | DSAT->getIndexTypeQualifier()); |
| 1289 | |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1290 | VariableArrayType *VAT = cast<VariableArrayType>(AT); |
| 1291 | return getVariableArrayType(NewEltTy, VAT->getSizeExpr(), |
| 1292 | VAT->getSizeModifier(), |
| 1293 | VAT->getIndexTypeQualifier()); |
| 1294 | } |
| 1295 | |
| 1296 | |
| 1297 | const ArrayType *ASTContext::getAsArrayType(QualType T) { |
| 1298 | // Handle the non-qualified case efficiently. |
| 1299 | if (T.getCVRQualifiers() == 0) { |
| 1300 | // Handle the common positive case fast. |
| 1301 | if (const ArrayType *AT = dyn_cast<ArrayType>(T)) |
| 1302 | return AT; |
| 1303 | } |
| 1304 | |
| 1305 | // Handle the common negative case fast, ignoring CVR qualifiers. |
| 1306 | QualType CType = T->getCanonicalTypeInternal(); |
| 1307 | |
| 1308 | // Make sure to look through type qualifiers (like ASQuals) for the negative |
| 1309 | // test. |
| 1310 | if (!isa<ArrayType>(CType) && |
| 1311 | !isa<ArrayType>(CType.getUnqualifiedType())) |
| 1312 | return 0; |
| 1313 | |
| 1314 | // Apply any CVR qualifiers from the array type to the element type. This |
| 1315 | // implements C99 6.7.3p8: "If the specification of an array type includes |
| 1316 | // any type qualifiers, the element type is so qualified, not the array type." |
| 1317 | |
| 1318 | // If we get here, we either have type qualifiers on the type, or we have |
| 1319 | // sugar such as a typedef in the way. If we have type qualifiers on the type |
| 1320 | // we must propagate them down into the elemeng type. |
| 1321 | unsigned CVRQuals = T.getCVRQualifiers(); |
| 1322 | unsigned AddrSpace = 0; |
| 1323 | Type *Ty = T.getTypePtr(); |
| 1324 | |
| 1325 | // Rip through ASQualType's and typedefs to get to a concrete type. |
| 1326 | while (1) { |
| 1327 | if (const ASQualType *ASQT = dyn_cast<ASQualType>(Ty)) { |
| 1328 | AddrSpace = ASQT->getAddressSpace(); |
| 1329 | Ty = ASQT->getBaseType(); |
| 1330 | } else { |
| 1331 | T = Ty->getDesugaredType(); |
| 1332 | if (T.getTypePtr() == Ty && T.getCVRQualifiers() == 0) |
| 1333 | break; |
| 1334 | CVRQuals |= T.getCVRQualifiers(); |
| 1335 | Ty = T.getTypePtr(); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | // If we have a simple case, just return now. |
| 1340 | const ArrayType *ATy = dyn_cast<ArrayType>(Ty); |
| 1341 | if (ATy == 0 || (AddrSpace == 0 && CVRQuals == 0)) |
| 1342 | return ATy; |
| 1343 | |
| 1344 | // Otherwise, we have an array and we have qualifiers on it. Push the |
| 1345 | // qualifiers into the array element type and return a new array type. |
| 1346 | // Get the canonical version of the element with the extra qualifiers on it. |
| 1347 | // This can recursively sink qualifiers through multiple levels of arrays. |
| 1348 | QualType NewEltTy = ATy->getElementType(); |
| 1349 | if (AddrSpace) |
| 1350 | NewEltTy = getASQualType(NewEltTy, AddrSpace); |
| 1351 | NewEltTy = NewEltTy.getWithAdditionalQualifiers(CVRQuals); |
| 1352 | |
| 1353 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(ATy)) |
| 1354 | return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), |
| 1355 | CAT->getSizeModifier(), |
| 1356 | CAT->getIndexTypeQualifier())); |
| 1357 | if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy)) |
| 1358 | return cast<ArrayType>(getIncompleteArrayType(NewEltTy, |
| 1359 | IAT->getSizeModifier(), |
| 1360 | IAT->getIndexTypeQualifier())); |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1361 | |
Douglas Gregor | 1b21c7f | 2008-12-05 23:32:09 +0000 | [diff] [blame] | 1362 | if (const DependentSizedArrayType *DSAT |
| 1363 | = dyn_cast<DependentSizedArrayType>(ATy)) |
| 1364 | return cast<ArrayType>( |
| 1365 | getDependentSizedArrayType(NewEltTy, |
| 1366 | DSAT->getSizeExpr(), |
| 1367 | DSAT->getSizeModifier(), |
| 1368 | DSAT->getIndexTypeQualifier())); |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1369 | |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1370 | const VariableArrayType *VAT = cast<VariableArrayType>(ATy); |
| 1371 | return cast<ArrayType>(getVariableArrayType(NewEltTy, VAT->getSizeExpr(), |
| 1372 | VAT->getSizeModifier(), |
| 1373 | VAT->getIndexTypeQualifier())); |
Chris Lattner | 3dae6f4 | 2008-04-06 22:41:35 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | |
Chris Lattner | 19eb97e | 2008-04-02 05:18:44 +0000 | [diff] [blame] | 1377 | /// getArrayDecayedType - Return the properly qualified result of decaying the |
| 1378 | /// specified array type to a pointer. This operation is non-trivial when |
| 1379 | /// handling typedefs etc. The canonical type of "T" must be an array type, |
| 1380 | /// this returns a pointer to a properly qualified element of the array. |
| 1381 | /// |
| 1382 | /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. |
| 1383 | QualType ASTContext::getArrayDecayedType(QualType Ty) { |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1384 | // Get the element type with 'getAsArrayType' so that we don't lose any |
| 1385 | // typedefs in the element type of the array. This also handles propagation |
| 1386 | // of type qualifiers from the array type into the element type if present |
| 1387 | // (C99 6.7.3p8). |
| 1388 | const ArrayType *PrettyArrayType = getAsArrayType(Ty); |
| 1389 | assert(PrettyArrayType && "Not an array type!"); |
Chris Lattner | 19eb97e | 2008-04-02 05:18:44 +0000 | [diff] [blame] | 1390 | |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1391 | QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); |
Chris Lattner | 19eb97e | 2008-04-02 05:18:44 +0000 | [diff] [blame] | 1392 | |
| 1393 | // int x[restrict 4] -> int *restrict |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1394 | return PtrTy.getQualifiedType(PrettyArrayType->getIndexTypeQualifier()); |
Chris Lattner | 19eb97e | 2008-04-02 05:18:44 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Daniel Dunbar | 4a0b75c | 2009-01-05 22:14:37 +0000 | [diff] [blame] | 1397 | QualType ASTContext::getBaseElementType(const VariableArrayType *VAT) { |
Anders Carlsson | 76d19c8 | 2008-12-21 03:44:36 +0000 | [diff] [blame] | 1398 | QualType ElemTy = VAT->getElementType(); |
| 1399 | |
| 1400 | if (const VariableArrayType *VAT = getAsVariableArrayType(ElemTy)) |
| 1401 | return getBaseElementType(VAT); |
| 1402 | |
| 1403 | return ElemTy; |
| 1404 | } |
| 1405 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1406 | /// getFloatingRank - Return a relative rank for floating point types. |
| 1407 | /// This routine will assert if passed a built-in type that isn't a float. |
Chris Lattner | d7135b4 | 2008-04-06 23:38:49 +0000 | [diff] [blame] | 1408 | static FloatingRank getFloatingRank(QualType T) { |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 1409 | if (const ComplexType *CT = T->getAsComplexType()) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1410 | return getFloatingRank(CT->getElementType()); |
Chris Lattner | d7135b4 | 2008-04-06 23:38:49 +0000 | [diff] [blame] | 1411 | |
Daniel Dunbar | 4a0b75c | 2009-01-05 22:14:37 +0000 | [diff] [blame] | 1412 | assert(T->getAsBuiltinType() && "getFloatingRank(): not a floating type"); |
Christopher Lamb | 2a72bb3 | 2008-02-04 02:31:56 +0000 | [diff] [blame] | 1413 | switch (T->getAsBuiltinType()->getKind()) { |
Chris Lattner | d7135b4 | 2008-04-06 23:38:49 +0000 | [diff] [blame] | 1414 | default: assert(0 && "getFloatingRank(): not a floating type"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1415 | case BuiltinType::Float: return FloatRank; |
| 1416 | case BuiltinType::Double: return DoubleRank; |
| 1417 | case BuiltinType::LongDouble: return LongDoubleRank; |
| 1418 | } |
| 1419 | } |
| 1420 | |
Steve Naroff | fa0c453 | 2007-08-27 01:41:48 +0000 | [diff] [blame] | 1421 | /// getFloatingTypeOfSizeWithinDomain - Returns a real floating |
| 1422 | /// point or a complex type (based on typeDomain/typeSize). |
| 1423 | /// 'typeDomain' is a real floating point or complex type. |
| 1424 | /// 'typeSize' is a real floating point or complex type. |
Chris Lattner | 7794ae2 | 2008-04-06 23:58:54 +0000 | [diff] [blame] | 1425 | QualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, |
| 1426 | QualType Domain) const { |
| 1427 | FloatingRank EltRank = getFloatingRank(Size); |
| 1428 | if (Domain->isComplexType()) { |
| 1429 | switch (EltRank) { |
Steve Naroff | fa0c453 | 2007-08-27 01:41:48 +0000 | [diff] [blame] | 1430 | default: assert(0 && "getFloatingRank(): illegal value for rank"); |
Steve Naroff | 3cf497f | 2007-08-27 01:27:54 +0000 | [diff] [blame] | 1431 | case FloatRank: return FloatComplexTy; |
| 1432 | case DoubleRank: return DoubleComplexTy; |
| 1433 | case LongDoubleRank: return LongDoubleComplexTy; |
| 1434 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1435 | } |
Chris Lattner | 7794ae2 | 2008-04-06 23:58:54 +0000 | [diff] [blame] | 1436 | |
| 1437 | assert(Domain->isRealFloatingType() && "Unknown domain!"); |
| 1438 | switch (EltRank) { |
| 1439 | default: assert(0 && "getFloatingRank(): illegal value for rank"); |
| 1440 | case FloatRank: return FloatTy; |
| 1441 | case DoubleRank: return DoubleTy; |
| 1442 | case LongDoubleRank: return LongDoubleTy; |
Steve Naroff | 3cf497f | 2007-08-27 01:27:54 +0000 | [diff] [blame] | 1443 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1446 | /// getFloatingTypeOrder - Compare the rank of the two specified floating |
| 1447 | /// point types, ignoring the domain of the type (i.e. 'double' == |
| 1448 | /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If |
| 1449 | /// LHS < RHS, return -1. |
Chris Lattner | d7135b4 | 2008-04-06 23:38:49 +0000 | [diff] [blame] | 1450 | int ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) { |
| 1451 | FloatingRank LHSR = getFloatingRank(LHS); |
| 1452 | FloatingRank RHSR = getFloatingRank(RHS); |
| 1453 | |
| 1454 | if (LHSR == RHSR) |
Steve Naroff | 45fc982 | 2007-08-27 15:30:22 +0000 | [diff] [blame] | 1455 | return 0; |
Chris Lattner | d7135b4 | 2008-04-06 23:38:49 +0000 | [diff] [blame] | 1456 | if (LHSR > RHSR) |
Steve Naroff | 45fc982 | 2007-08-27 15:30:22 +0000 | [diff] [blame] | 1457 | return 1; |
| 1458 | return -1; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1461 | /// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This |
| 1462 | /// routine will assert if passed a built-in type that isn't an integer or enum, |
| 1463 | /// or if it is not canonicalized. |
| 1464 | static unsigned getIntegerRank(Type *T) { |
| 1465 | assert(T->isCanonical() && "T should be canonicalized"); |
| 1466 | if (isa<EnumType>(T)) |
| 1467 | return 4; |
| 1468 | |
| 1469 | switch (cast<BuiltinType>(T)->getKind()) { |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1470 | default: assert(0 && "getIntegerRank(): not a built-in integer"); |
| 1471 | case BuiltinType::Bool: |
| 1472 | return 1; |
| 1473 | case BuiltinType::Char_S: |
| 1474 | case BuiltinType::Char_U: |
| 1475 | case BuiltinType::SChar: |
| 1476 | case BuiltinType::UChar: |
| 1477 | return 2; |
| 1478 | case BuiltinType::Short: |
| 1479 | case BuiltinType::UShort: |
| 1480 | return 3; |
| 1481 | case BuiltinType::Int: |
| 1482 | case BuiltinType::UInt: |
| 1483 | return 4; |
| 1484 | case BuiltinType::Long: |
| 1485 | case BuiltinType::ULong: |
| 1486 | return 5; |
| 1487 | case BuiltinType::LongLong: |
| 1488 | case BuiltinType::ULongLong: |
| 1489 | return 6; |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1490 | } |
| 1491 | } |
| 1492 | |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1493 | /// getIntegerTypeOrder - Returns the highest ranked integer type: |
| 1494 | /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If |
| 1495 | /// LHS < RHS, return -1. |
| 1496 | int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) { |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1497 | Type *LHSC = getCanonicalType(LHS).getTypePtr(); |
| 1498 | Type *RHSC = getCanonicalType(RHS).getTypePtr(); |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1499 | if (LHSC == RHSC) return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1500 | |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1501 | bool LHSUnsigned = LHSC->isUnsignedIntegerType(); |
| 1502 | bool RHSUnsigned = RHSC->isUnsignedIntegerType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1503 | |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1504 | unsigned LHSRank = getIntegerRank(LHSC); |
| 1505 | unsigned RHSRank = getIntegerRank(RHSC); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1506 | |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1507 | if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. |
| 1508 | if (LHSRank == RHSRank) return 0; |
| 1509 | return LHSRank > RHSRank ? 1 : -1; |
| 1510 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1511 | |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1512 | // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. |
| 1513 | if (LHSUnsigned) { |
| 1514 | // If the unsigned [LHS] type is larger, return it. |
| 1515 | if (LHSRank >= RHSRank) |
| 1516 | return 1; |
| 1517 | |
| 1518 | // If the signed type can represent all values of the unsigned type, it |
| 1519 | // wins. Because we are dealing with 2's complement and types that are |
| 1520 | // powers of two larger than each other, this is always safe. |
| 1521 | return -1; |
| 1522 | } |
Chris Lattner | c1b68db | 2008-04-06 22:59:24 +0000 | [diff] [blame] | 1523 | |
Chris Lattner | 51285d8 | 2008-04-06 23:55:33 +0000 | [diff] [blame] | 1524 | // If the unsigned [RHS] type is larger, return it. |
| 1525 | if (RHSRank >= LHSRank) |
| 1526 | return -1; |
| 1527 | |
| 1528 | // If the signed type can represent all values of the unsigned type, it |
| 1529 | // wins. Because we are dealing with 2's complement and types that are |
| 1530 | // powers of two larger than each other, this is always safe. |
| 1531 | return 1; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1532 | } |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 1533 | |
| 1534 | // getCFConstantStringType - Return the type used for constant CFStrings. |
| 1535 | QualType ASTContext::getCFConstantStringType() { |
| 1536 | if (!CFConstantStringTypeDecl) { |
Chris Lattner | e465048 | 2008-03-15 06:12:44 +0000 | [diff] [blame] | 1537 | CFConstantStringTypeDecl = |
Argiris Kirtzidis | c6cc7d5 | 2008-06-09 23:19:58 +0000 | [diff] [blame] | 1538 | RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), |
Ted Kremenek | 2c98404 | 2008-09-05 01:34:33 +0000 | [diff] [blame] | 1539 | &Idents.get("NSConstantString")); |
Anders Carlsson | bb2cf51 | 2007-11-19 00:25:30 +0000 | [diff] [blame] | 1540 | QualType FieldTypes[4]; |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 1541 | |
| 1542 | // const int *isa; |
| 1543 | FieldTypes[0] = getPointerType(IntTy.getQualifiedType(QualType::Const)); |
Anders Carlsson | bb2cf51 | 2007-11-19 00:25:30 +0000 | [diff] [blame] | 1544 | // int flags; |
| 1545 | FieldTypes[1] = IntTy; |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 1546 | // const char *str; |
Anders Carlsson | bb2cf51 | 2007-11-19 00:25:30 +0000 | [diff] [blame] | 1547 | FieldTypes[2] = getPointerType(CharTy.getQualifiedType(QualType::Const)); |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 1548 | // long length; |
Anders Carlsson | bb2cf51 | 2007-11-19 00:25:30 +0000 | [diff] [blame] | 1549 | FieldTypes[3] = LongTy; |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1550 | |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 1551 | // Create fields |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1552 | for (unsigned i = 0; i < 4; ++i) { |
| 1553 | FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, |
| 1554 | SourceLocation(), 0, |
| 1555 | FieldTypes[i], /*BitWidth=*/0, |
| 1556 | /*Mutable=*/false, /*PrevDecl=*/0); |
Douglas Gregor | 03b2ad2 | 2009-01-12 23:27:07 +0000 | [diff] [blame] | 1557 | CFConstantStringTypeDecl->addDecl(Field); |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | CFConstantStringTypeDecl->completeDefinition(*this); |
Anders Carlsson | e7e7aa2 | 2007-08-17 05:31:46 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | return getTagDeclType(CFConstantStringTypeDecl); |
Gabor Greif | 61ce98c | 2007-09-11 15:32:40 +0000 | [diff] [blame] | 1564 | } |
Anders Carlsson | fb5b1e8 | 2007-10-11 01:00:40 +0000 | [diff] [blame] | 1565 | |
Anders Carlsson | f58cac7 | 2008-08-30 19:34:46 +0000 | [diff] [blame] | 1566 | QualType ASTContext::getObjCFastEnumerationStateType() |
| 1567 | { |
| 1568 | if (!ObjCFastEnumerationStateTypeDecl) { |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1569 | ObjCFastEnumerationStateTypeDecl = |
| 1570 | RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), |
| 1571 | &Idents.get("__objcFastEnumerationState")); |
| 1572 | |
Anders Carlsson | f58cac7 | 2008-08-30 19:34:46 +0000 | [diff] [blame] | 1573 | QualType FieldTypes[] = { |
| 1574 | UnsignedLongTy, |
| 1575 | getPointerType(ObjCIdType), |
| 1576 | getPointerType(UnsignedLongTy), |
| 1577 | getConstantArrayType(UnsignedLongTy, |
| 1578 | llvm::APInt(32, 5), ArrayType::Normal, 0) |
| 1579 | }; |
| 1580 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1581 | for (size_t i = 0; i < 4; ++i) { |
| 1582 | FieldDecl *Field = FieldDecl::Create(*this, |
| 1583 | ObjCFastEnumerationStateTypeDecl, |
| 1584 | SourceLocation(), 0, |
| 1585 | FieldTypes[i], /*BitWidth=*/0, |
| 1586 | /*Mutable=*/false, /*PrevDecl=*/0); |
Douglas Gregor | 03b2ad2 | 2009-01-12 23:27:07 +0000 | [diff] [blame] | 1587 | ObjCFastEnumerationStateTypeDecl->addDecl(Field); |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1588 | } |
Anders Carlsson | f58cac7 | 2008-08-30 19:34:46 +0000 | [diff] [blame] | 1589 | |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1590 | ObjCFastEnumerationStateTypeDecl->completeDefinition(*this); |
Anders Carlsson | f58cac7 | 2008-08-30 19:34:46 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | return getTagDeclType(ObjCFastEnumerationStateTypeDecl); |
| 1594 | } |
| 1595 | |
Anders Carlsson | e3f0257 | 2007-10-29 06:33:42 +0000 | [diff] [blame] | 1596 | // This returns true if a type has been typedefed to BOOL: |
| 1597 | // typedef <type> BOOL; |
Chris Lattner | cb034cb | 2007-10-30 20:27:44 +0000 | [diff] [blame] | 1598 | static bool isTypeTypedefedAsBOOL(QualType T) { |
Anders Carlsson | e3f0257 | 2007-10-29 06:33:42 +0000 | [diff] [blame] | 1599 | if (const TypedefType *TT = dyn_cast<TypedefType>(T)) |
Chris Lattner | 85fb384 | 2008-11-24 03:52:59 +0000 | [diff] [blame] | 1600 | if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) |
| 1601 | return II->isStr("BOOL"); |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1602 | |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1606 | /// getObjCEncodingTypeSize returns size of type for objective-c encoding |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1607 | /// purpose. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1608 | int ASTContext::getObjCEncodingTypeSize(QualType type) { |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 1609 | uint64_t sz = getTypeSize(type); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1610 | |
| 1611 | // Make all integer and enum types at least as large as an int |
| 1612 | if (sz > 0 && type->isIntegralType()) |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 1613 | sz = std::max(sz, getTypeSize(IntTy)); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1614 | // Treat arrays as pointers, since that's how they're passed in. |
| 1615 | else if (type->isArrayType()) |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 1616 | sz = getTypeSize(VoidPtrTy); |
| 1617 | return sz / getTypeSize(CharTy); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1618 | } |
| 1619 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1620 | /// getObjCEncodingForMethodDecl - Return the encoded type for this method |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1621 | /// declaration. |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1622 | void ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, |
Chris Lattner | ae43029 | 2008-11-19 07:24:05 +0000 | [diff] [blame] | 1623 | std::string& S) { |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1624 | // FIXME: This is not very efficient. |
Fariborz Jahanian | 65e7eb5 | 2007-11-01 17:18:37 +0000 | [diff] [blame] | 1625 | // Encode type qualifer, 'in', 'inout', etc. for the return type. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1626 | getObjCEncodingForTypeQualifier(Decl->getObjCDeclQualifier(), S); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1627 | // Encode result type. |
Daniel Dunbar | c9197cd | 2008-10-17 20:21:44 +0000 | [diff] [blame] | 1628 | getObjCEncodingForType(Decl->getResultType(), S); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1629 | // Compute size of all parameters. |
| 1630 | // Start with computing size of a pointer in number of bytes. |
| 1631 | // FIXME: There might(should) be a better way of doing this computation! |
| 1632 | SourceLocation Loc; |
Chris Lattner | 8cd0e93 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 1633 | int PtrSize = getTypeSize(VoidPtrTy) / getTypeSize(CharTy); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1634 | // The first two arguments (self and _cmd) are pointers; account for |
| 1635 | // their size. |
| 1636 | int ParmOffset = 2 * PtrSize; |
| 1637 | int NumOfParams = Decl->getNumParams(); |
| 1638 | for (int i = 0; i < NumOfParams; i++) { |
| 1639 | QualType PType = Decl->getParamDecl(i)->getType(); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1640 | int sz = getObjCEncodingTypeSize (PType); |
| 1641 | assert (sz > 0 && "getObjCEncodingForMethodDecl - Incomplete param type"); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1642 | ParmOffset += sz; |
| 1643 | } |
| 1644 | S += llvm::utostr(ParmOffset); |
| 1645 | S += "@0:"; |
| 1646 | S += llvm::utostr(PtrSize); |
| 1647 | |
| 1648 | // Argument types. |
| 1649 | ParmOffset = 2 * PtrSize; |
| 1650 | for (int i = 0; i < NumOfParams; i++) { |
Fariborz Jahanian | e26cb43 | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 1651 | ParmVarDecl *PVDecl = Decl->getParamDecl(i); |
| 1652 | QualType PType = PVDecl->getOriginalType(); |
| 1653 | if (const ArrayType *AT = |
| 1654 | dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) |
| 1655 | // Use array's original type only if it has known number of |
| 1656 | // elements. |
| 1657 | if (!dyn_cast<ConstantArrayType>(AT)) |
| 1658 | PType = PVDecl->getType(); |
Fariborz Jahanian | 65e7eb5 | 2007-11-01 17:18:37 +0000 | [diff] [blame] | 1659 | // Process argument qualifiers for user supplied arguments; such as, |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1660 | // 'in', 'inout', etc. |
Fariborz Jahanian | e26cb43 | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 1661 | getObjCEncodingForTypeQualifier(PVDecl->getObjCDeclQualifier(), S); |
Daniel Dunbar | c9197cd | 2008-10-17 20:21:44 +0000 | [diff] [blame] | 1662 | getObjCEncodingForType(PType, S); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1663 | S += llvm::utostr(ParmOffset); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1664 | ParmOffset += getObjCEncodingTypeSize(PType); |
Fariborz Jahanian | c81f316 | 2007-10-29 22:57:28 +0000 | [diff] [blame] | 1665 | } |
| 1666 | } |
| 1667 | |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1668 | /// getObjCEncodingForPropertyDecl - Return the encoded type for this |
| 1669 | /// method declaration. If non-NULL, Container must be either an |
| 1670 | /// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be |
| 1671 | /// NULL when getting encodings for protocol properties. |
| 1672 | void ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, |
| 1673 | const Decl *Container, |
Chris Lattner | ae43029 | 2008-11-19 07:24:05 +0000 | [diff] [blame] | 1674 | std::string& S) { |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1675 | // Collect information from the property implementation decl(s). |
| 1676 | bool Dynamic = false; |
| 1677 | ObjCPropertyImplDecl *SynthesizePID = 0; |
| 1678 | |
| 1679 | // FIXME: Duplicated code due to poor abstraction. |
| 1680 | if (Container) { |
| 1681 | if (const ObjCCategoryImplDecl *CID = |
| 1682 | dyn_cast<ObjCCategoryImplDecl>(Container)) { |
| 1683 | for (ObjCCategoryImplDecl::propimpl_iterator |
| 1684 | i = CID->propimpl_begin(), e = CID->propimpl_end(); i != e; ++i) { |
| 1685 | ObjCPropertyImplDecl *PID = *i; |
| 1686 | if (PID->getPropertyDecl() == PD) { |
| 1687 | if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { |
| 1688 | Dynamic = true; |
| 1689 | } else { |
| 1690 | SynthesizePID = PID; |
| 1691 | } |
| 1692 | } |
| 1693 | } |
| 1694 | } else { |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 1695 | const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1696 | for (ObjCCategoryImplDecl::propimpl_iterator |
| 1697 | i = OID->propimpl_begin(), e = OID->propimpl_end(); i != e; ++i) { |
| 1698 | ObjCPropertyImplDecl *PID = *i; |
| 1699 | if (PID->getPropertyDecl() == PD) { |
| 1700 | if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { |
| 1701 | Dynamic = true; |
| 1702 | } else { |
| 1703 | SynthesizePID = PID; |
| 1704 | } |
| 1705 | } |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | // FIXME: This is not very efficient. |
| 1711 | S = "T"; |
| 1712 | |
| 1713 | // Encode result type. |
| 1714 | // FIXME: GCC uses a generating_property_type_encoding mode during |
| 1715 | // this part. Investigate. |
Daniel Dunbar | c9197cd | 2008-10-17 20:21:44 +0000 | [diff] [blame] | 1716 | getObjCEncodingForType(PD->getType(), S); |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1717 | |
| 1718 | if (PD->isReadOnly()) { |
| 1719 | S += ",R"; |
| 1720 | } else { |
| 1721 | switch (PD->getSetterKind()) { |
| 1722 | case ObjCPropertyDecl::Assign: break; |
| 1723 | case ObjCPropertyDecl::Copy: S += ",C"; break; |
| 1724 | case ObjCPropertyDecl::Retain: S += ",&"; break; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | // It really isn't clear at all what this means, since properties |
| 1729 | // are "dynamic by default". |
| 1730 | if (Dynamic) |
| 1731 | S += ",D"; |
| 1732 | |
| 1733 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { |
| 1734 | S += ",G"; |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1735 | S += PD->getGetterName().getAsString(); |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { |
| 1739 | S += ",S"; |
Chris Lattner | 3a8f294 | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1740 | S += PD->getSetterName().getAsString(); |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | if (SynthesizePID) { |
| 1744 | const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); |
| 1745 | S += ",V"; |
Chris Lattner | 6c5ec62 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1746 | S += OID->getNameAsString(); |
Daniel Dunbar | 698d6f3 | 2008-08-28 04:38:10 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | // FIXME: OBJCGC: weak & strong |
| 1750 | } |
| 1751 | |
Fariborz Jahanian | e07d9ec | 2008-12-23 19:56:47 +0000 | [diff] [blame] | 1752 | /// getLegacyIntegralTypeEncoding - |
| 1753 | /// Another legacy compatibility encoding: 32-bit longs are encoded as |
| 1754 | /// 'l' or 'L', but not always. For typedefs, we need to use |
| 1755 | /// 'i' or 'I' instead if encoding a struct field, or a pointer! |
| 1756 | /// |
| 1757 | void ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { |
| 1758 | if (dyn_cast<TypedefType>(PointeeTy.getTypePtr())) { |
| 1759 | if (const BuiltinType *BT = PointeeTy->getAsBuiltinType()) { |
| 1760 | if (BT->getKind() == BuiltinType::ULong) |
| 1761 | PointeeTy = UnsignedIntTy; |
| 1762 | else if (BT->getKind() == BuiltinType::Long) |
| 1763 | PointeeTy = IntTy; |
| 1764 | } |
| 1765 | } |
| 1766 | } |
| 1767 | |
Fariborz Jahanian | 248db26 | 2008-01-22 22:44:46 +0000 | [diff] [blame] | 1768 | void ASTContext::getObjCEncodingForType(QualType T, std::string& S, |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1769 | FieldDecl *Field) const { |
Daniel Dunbar | f8cfe56 | 2008-10-17 07:30:50 +0000 | [diff] [blame] | 1770 | // We follow the behavior of gcc, expanding structures which are |
| 1771 | // directly pointed to, and expanding embedded structures. Note that |
| 1772 | // these rules are sufficient to prevent recursive encoding of the |
| 1773 | // same type. |
Fariborz Jahanian | 89ed86b | 2008-12-22 23:22:27 +0000 | [diff] [blame] | 1774 | getObjCEncodingForTypeImpl(T, S, true, true, Field, |
| 1775 | true /* outermost type */); |
Daniel Dunbar | f8cfe56 | 2008-10-17 07:30:50 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
Fariborz Jahanian | d136195 | 2009-01-13 01:18:13 +0000 | [diff] [blame] | 1778 | static void EncodeBitField(const ASTContext *Context, std::string& S, |
| 1779 | FieldDecl *FD) { |
| 1780 | const Expr *E = FD->getBitWidth(); |
| 1781 | assert(E && "bitfield width not there - getObjCEncodingForTypeImpl"); |
| 1782 | ASTContext *Ctx = const_cast<ASTContext*>(Context); |
| 1783 | unsigned N = E->getIntegerConstantExprValue(*Ctx).getZExtValue(); |
| 1784 | S += 'b'; |
| 1785 | S += llvm::utostr(N); |
| 1786 | } |
| 1787 | |
Daniel Dunbar | f8cfe56 | 2008-10-17 07:30:50 +0000 | [diff] [blame] | 1788 | void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, |
| 1789 | bool ExpandPointedToStructures, |
| 1790 | bool ExpandStructures, |
Fariborz Jahanian | 89ed86b | 2008-12-22 23:22:27 +0000 | [diff] [blame] | 1791 | FieldDecl *FD, |
| 1792 | bool OutermostType) const { |
Anders Carlsson | e3f0257 | 2007-10-29 06:33:42 +0000 | [diff] [blame] | 1793 | if (const BuiltinType *BT = T->getAsBuiltinType()) { |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1794 | if (FD && FD->isBitField()) { |
Fariborz Jahanian | d136195 | 2009-01-13 01:18:13 +0000 | [diff] [blame] | 1795 | EncodeBitField(this, S, FD); |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1796 | } |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1797 | else { |
| 1798 | char encoding; |
| 1799 | switch (BT->getKind()) { |
| 1800 | default: assert(0 && "Unhandled builtin type kind"); |
| 1801 | case BuiltinType::Void: encoding = 'v'; break; |
| 1802 | case BuiltinType::Bool: encoding = 'B'; break; |
| 1803 | case BuiltinType::Char_U: |
| 1804 | case BuiltinType::UChar: encoding = 'C'; break; |
| 1805 | case BuiltinType::UShort: encoding = 'S'; break; |
| 1806 | case BuiltinType::UInt: encoding = 'I'; break; |
| 1807 | case BuiltinType::ULong: encoding = 'L'; break; |
| 1808 | case BuiltinType::ULongLong: encoding = 'Q'; break; |
| 1809 | case BuiltinType::Char_S: |
| 1810 | case BuiltinType::SChar: encoding = 'c'; break; |
| 1811 | case BuiltinType::Short: encoding = 's'; break; |
| 1812 | case BuiltinType::Int: encoding = 'i'; break; |
| 1813 | case BuiltinType::Long: encoding = 'l'; break; |
| 1814 | case BuiltinType::LongLong: encoding = 'q'; break; |
| 1815 | case BuiltinType::Float: encoding = 'f'; break; |
| 1816 | case BuiltinType::Double: encoding = 'd'; break; |
| 1817 | case BuiltinType::LongDouble: encoding = 'd'; break; |
| 1818 | } |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1819 | |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1820 | S += encoding; |
| 1821 | } |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1822 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1823 | else if (T->isObjCQualifiedIdType()) { |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1824 | // Treat id<P...> same as 'id' for encoding purposes. |
Daniel Dunbar | f8cfe56 | 2008-10-17 07:30:50 +0000 | [diff] [blame] | 1825 | return getObjCEncodingForTypeImpl(getObjCIdType(), S, |
| 1826 | ExpandPointedToStructures, |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1827 | ExpandStructures, FD); |
Fariborz Jahanian | e76e841 | 2007-12-17 21:03:50 +0000 | [diff] [blame] | 1828 | } |
| 1829 | else if (const PointerType *PT = T->getAsPointerType()) { |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1830 | QualType PointeeTy = PT->getPointeeType(); |
Fariborz Jahanian | e07d9ec | 2008-12-23 19:56:47 +0000 | [diff] [blame] | 1831 | bool isReadOnly = false; |
| 1832 | // For historical/compatibility reasons, the read-only qualifier of the |
| 1833 | // pointee gets emitted _before_ the '^'. The read-only qualifier of |
| 1834 | // the pointer itself gets ignored, _unless_ we are looking at a typedef! |
| 1835 | // Also, do not emit the 'r' for anything but the outermost type! |
| 1836 | if (dyn_cast<TypedefType>(T.getTypePtr())) { |
| 1837 | if (OutermostType && T.isConstQualified()) { |
| 1838 | isReadOnly = true; |
| 1839 | S += 'r'; |
| 1840 | } |
| 1841 | } |
| 1842 | else if (OutermostType) { |
| 1843 | QualType P = PointeeTy; |
| 1844 | while (P->getAsPointerType()) |
| 1845 | P = P->getAsPointerType()->getPointeeType(); |
| 1846 | if (P.isConstQualified()) { |
| 1847 | isReadOnly = true; |
| 1848 | S += 'r'; |
| 1849 | } |
| 1850 | } |
| 1851 | if (isReadOnly) { |
| 1852 | // Another legacy compatibility encoding. Some ObjC qualifier and type |
| 1853 | // combinations need to be rearranged. |
| 1854 | // Rewrite "in const" from "nr" to "rn" |
| 1855 | const char * s = S.c_str(); |
| 1856 | int len = S.length(); |
| 1857 | if (len >= 2 && s[len-2] == 'n' && s[len-1] == 'r') { |
| 1858 | std::string replace = "rn"; |
| 1859 | S.replace(S.end()-2, S.end(), replace); |
| 1860 | } |
| 1861 | } |
Fariborz Jahanian | c867947 | 2008-12-19 00:14:49 +0000 | [diff] [blame] | 1862 | if (isObjCIdType(PointeeTy)) { |
Fariborz Jahanian | 80faffa | 2007-10-30 17:06:23 +0000 | [diff] [blame] | 1863 | S += '@'; |
| 1864 | return; |
Fariborz Jahanian | c867947 | 2008-12-19 00:14:49 +0000 | [diff] [blame] | 1865 | } |
| 1866 | else if (PointeeTy->isObjCInterfaceType()) { |
Fariborz Jahanian | d3498aa | 2008-12-23 21:30:15 +0000 | [diff] [blame] | 1867 | if (dyn_cast<TypedefType>(PointeeTy.getTypePtr())) { |
| 1868 | // Another historical/compatibility reason. |
| 1869 | // We encode the underlying type which comes out as |
| 1870 | // {...}; |
| 1871 | S += '^'; |
| 1872 | getObjCEncodingForTypeImpl(PointeeTy, S, |
| 1873 | false, ExpandPointedToStructures, |
| 1874 | NULL); |
| 1875 | return; |
| 1876 | } |
Fariborz Jahanian | c867947 | 2008-12-19 00:14:49 +0000 | [diff] [blame] | 1877 | S += '@'; |
Fariborz Jahanian | 320ac42 | 2008-12-20 19:17:01 +0000 | [diff] [blame] | 1878 | if (FD) { |
| 1879 | ObjCInterfaceDecl *OI = PointeeTy->getAsObjCInterfaceType()->getDecl(); |
| 1880 | S += '"'; |
| 1881 | S += OI->getNameAsCString(); |
| 1882 | S += '"'; |
| 1883 | } |
Fariborz Jahanian | c867947 | 2008-12-19 00:14:49 +0000 | [diff] [blame] | 1884 | return; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1885 | } else if (isObjCClassType(PointeeTy)) { |
Anders Carlsson | 7f23e3d | 2007-10-31 02:53:19 +0000 | [diff] [blame] | 1886 | S += '#'; |
| 1887 | return; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1888 | } else if (isObjCSelType(PointeeTy)) { |
Anders Carlsson | 7f23e3d | 2007-10-31 02:53:19 +0000 | [diff] [blame] | 1889 | S += ':'; |
| 1890 | return; |
Fariborz Jahanian | 80faffa | 2007-10-30 17:06:23 +0000 | [diff] [blame] | 1891 | } |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1892 | |
| 1893 | if (PointeeTy->isCharType()) { |
| 1894 | // char pointer types should be encoded as '*' unless it is a |
| 1895 | // type that has been typedef'd to 'BOOL'. |
Anders Carlsson | e3f0257 | 2007-10-29 06:33:42 +0000 | [diff] [blame] | 1896 | if (!isTypeTypedefedAsBOOL(PointeeTy)) { |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1897 | S += '*'; |
| 1898 | return; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | S += '^'; |
Fariborz Jahanian | e07d9ec | 2008-12-23 19:56:47 +0000 | [diff] [blame] | 1903 | getLegacyIntegralTypeEncoding(PointeeTy); |
| 1904 | |
| 1905 | getObjCEncodingForTypeImpl(PointeeTy, S, |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1906 | false, ExpandPointedToStructures, |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1907 | NULL); |
Chris Lattner | a1923f6 | 2008-08-04 07:31:14 +0000 | [diff] [blame] | 1908 | } else if (const ArrayType *AT = |
| 1909 | // Ignore type qualifiers etc. |
| 1910 | dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1911 | S += '['; |
| 1912 | |
| 1913 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) |
| 1914 | S += llvm::utostr(CAT->getSize().getZExtValue()); |
| 1915 | else |
| 1916 | assert(0 && "Unhandled array type!"); |
| 1917 | |
Daniel Dunbar | f8cfe56 | 2008-10-17 07:30:50 +0000 | [diff] [blame] | 1918 | getObjCEncodingForTypeImpl(AT->getElementType(), S, |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1919 | false, ExpandStructures, FD); |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1920 | S += ']'; |
Anders Carlsson | 5695bb7 | 2007-10-30 00:06:20 +0000 | [diff] [blame] | 1921 | } else if (T->getAsFunctionType()) { |
| 1922 | S += '?'; |
Fariborz Jahanian | c8ba2bd | 2007-11-13 23:21:38 +0000 | [diff] [blame] | 1923 | } else if (const RecordType *RTy = T->getAsRecordType()) { |
Daniel Dunbar | f8cfe56 | 2008-10-17 07:30:50 +0000 | [diff] [blame] | 1924 | RecordDecl *RDecl = RTy->getDecl(); |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1925 | S += RDecl->isUnion() ? '(' : '{'; |
Daniel Dunbar | 146b2d0 | 2008-10-17 06:22:57 +0000 | [diff] [blame] | 1926 | // Anonymous structures print as '?' |
| 1927 | if (const IdentifierInfo *II = RDecl->getIdentifier()) { |
| 1928 | S += II->getName(); |
| 1929 | } else { |
| 1930 | S += '?'; |
| 1931 | } |
Daniel Dunbar | c9197cd | 2008-10-17 20:21:44 +0000 | [diff] [blame] | 1932 | if (ExpandStructures) { |
Fariborz Jahanian | 248db26 | 2008-01-22 22:44:46 +0000 | [diff] [blame] | 1933 | S += '='; |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1934 | for (RecordDecl::field_iterator Field = RDecl->field_begin(), |
| 1935 | FieldEnd = RDecl->field_end(); |
| 1936 | Field != FieldEnd; ++Field) { |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1937 | if (FD) { |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1938 | S += '"'; |
Douglas Gregor | 8acb727 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1939 | S += Field->getNameAsString(); |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1940 | S += '"'; |
| 1941 | } |
| 1942 | |
| 1943 | // Special case bit-fields. |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1944 | if (Field->isBitField()) { |
| 1945 | getObjCEncodingForTypeImpl(Field->getType(), S, false, true, |
| 1946 | (*Field)); |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1947 | } else { |
Fariborz Jahanian | e07d9ec | 2008-12-23 19:56:47 +0000 | [diff] [blame] | 1948 | QualType qt = Field->getType(); |
| 1949 | getLegacyIntegralTypeEncoding(qt); |
| 1950 | getObjCEncodingForTypeImpl(qt, S, false, true, |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1951 | FD); |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1952 | } |
Fariborz Jahanian | 248db26 | 2008-01-22 22:44:46 +0000 | [diff] [blame] | 1953 | } |
Fariborz Jahanian | c8ba2bd | 2007-11-13 23:21:38 +0000 | [diff] [blame] | 1954 | } |
Daniel Dunbar | aa91310 | 2008-10-17 16:17:37 +0000 | [diff] [blame] | 1955 | S += RDecl->isUnion() ? ')' : '}'; |
Steve Naroff | 49af3f3 | 2007-12-12 22:30:11 +0000 | [diff] [blame] | 1956 | } else if (T->isEnumeralType()) { |
Fariborz Jahanian | d136195 | 2009-01-13 01:18:13 +0000 | [diff] [blame] | 1957 | if (FD && FD->isBitField()) |
| 1958 | EncodeBitField(this, S, FD); |
| 1959 | else |
| 1960 | S += 'i'; |
Steve Naroff | 62f09f5 | 2008-09-24 15:05:44 +0000 | [diff] [blame] | 1961 | } else if (T->isBlockPointerType()) { |
| 1962 | S += '^'; // This type string is the same as general pointers. |
Fariborz Jahanian | 0cd547f | 2008-12-19 23:34:38 +0000 | [diff] [blame] | 1963 | } else if (T->isObjCInterfaceType()) { |
| 1964 | // @encode(class_name) |
| 1965 | ObjCInterfaceDecl *OI = T->getAsObjCInterfaceType()->getDecl(); |
| 1966 | S += '{'; |
| 1967 | const IdentifierInfo *II = OI->getIdentifier(); |
| 1968 | S += II->getName(); |
| 1969 | S += '='; |
| 1970 | std::vector<FieldDecl*> RecFields; |
| 1971 | CollectObjCIvars(OI, RecFields); |
| 1972 | for (unsigned int i = 0; i != RecFields.size(); i++) { |
| 1973 | if (RecFields[i]->isBitField()) |
| 1974 | getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true, |
| 1975 | RecFields[i]); |
| 1976 | else |
| 1977 | getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true, |
| 1978 | FD); |
| 1979 | } |
| 1980 | S += '}'; |
| 1981 | } |
| 1982 | else |
Steve Naroff | 53b6f4c | 2008-01-30 19:17:43 +0000 | [diff] [blame] | 1983 | assert(0 && "@encode for type not implemented!"); |
Anders Carlsson | 36f07d8 | 2007-10-29 05:01:08 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1986 | void ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, |
Fariborz Jahanian | 65e7eb5 | 2007-11-01 17:18:37 +0000 | [diff] [blame] | 1987 | std::string& S) const { |
| 1988 | if (QT & Decl::OBJC_TQ_In) |
| 1989 | S += 'n'; |
| 1990 | if (QT & Decl::OBJC_TQ_Inout) |
| 1991 | S += 'N'; |
| 1992 | if (QT & Decl::OBJC_TQ_Out) |
| 1993 | S += 'o'; |
| 1994 | if (QT & Decl::OBJC_TQ_Bycopy) |
| 1995 | S += 'O'; |
| 1996 | if (QT & Decl::OBJC_TQ_Byref) |
| 1997 | S += 'R'; |
| 1998 | if (QT & Decl::OBJC_TQ_Oneway) |
| 1999 | S += 'V'; |
| 2000 | } |
| 2001 | |
Anders Carlsson | fb5b1e8 | 2007-10-11 01:00:40 +0000 | [diff] [blame] | 2002 | void ASTContext::setBuiltinVaListType(QualType T) |
| 2003 | { |
| 2004 | assert(BuiltinVaListType.isNull() && "__builtin_va_list type already set!"); |
| 2005 | |
| 2006 | BuiltinVaListType = T; |
| 2007 | } |
| 2008 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2009 | void ASTContext::setObjCIdType(TypedefDecl *TD) |
Steve Naroff | 9d12c90 | 2007-10-15 14:41:52 +0000 | [diff] [blame] | 2010 | { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2011 | ObjCIdType = getTypedefType(TD); |
Steve Naroff | 9d12c90 | 2007-10-15 14:41:52 +0000 | [diff] [blame] | 2012 | |
| 2013 | // typedef struct objc_object *id; |
| 2014 | const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType(); |
Fariborz Jahanian | de93967 | 2009-01-16 19:58:32 +0000 | [diff] [blame^] | 2015 | // User error - caller will issue diagnostics. |
| 2016 | if (!ptr) |
| 2017 | return; |
Steve Naroff | 9d12c90 | 2007-10-15 14:41:52 +0000 | [diff] [blame] | 2018 | const RecordType *rec = ptr->getPointeeType()->getAsStructureType(); |
Fariborz Jahanian | de93967 | 2009-01-16 19:58:32 +0000 | [diff] [blame^] | 2019 | // User error - caller will issue diagnostics. |
| 2020 | if (!rec) |
| 2021 | return; |
Steve Naroff | 9d12c90 | 2007-10-15 14:41:52 +0000 | [diff] [blame] | 2022 | IdStructType = rec; |
| 2023 | } |
| 2024 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2025 | void ASTContext::setObjCSelType(TypedefDecl *TD) |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2026 | { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2027 | ObjCSelType = getTypedefType(TD); |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2028 | |
| 2029 | // typedef struct objc_selector *SEL; |
| 2030 | const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType(); |
Fariborz Jahanian | de93967 | 2009-01-16 19:58:32 +0000 | [diff] [blame^] | 2031 | if (!ptr) |
| 2032 | return; |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2033 | const RecordType *rec = ptr->getPointeeType()->getAsStructureType(); |
Fariborz Jahanian | de93967 | 2009-01-16 19:58:32 +0000 | [diff] [blame^] | 2034 | if (!rec) |
| 2035 | return; |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2036 | SelStructType = rec; |
| 2037 | } |
| 2038 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2039 | void ASTContext::setObjCProtoType(QualType QT) |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2040 | { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2041 | ObjCProtoType = QT; |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2044 | void ASTContext::setObjCClassType(TypedefDecl *TD) |
Anders Carlsson | 7f23e3d | 2007-10-31 02:53:19 +0000 | [diff] [blame] | 2045 | { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2046 | ObjCClassType = getTypedefType(TD); |
Anders Carlsson | 7f23e3d | 2007-10-31 02:53:19 +0000 | [diff] [blame] | 2047 | |
| 2048 | // typedef struct objc_class *Class; |
| 2049 | const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType(); |
| 2050 | assert(ptr && "'Class' incorrectly typed"); |
| 2051 | const RecordType *rec = ptr->getPointeeType()->getAsStructureType(); |
| 2052 | assert(rec && "'Class' incorrectly typed"); |
| 2053 | ClassStructType = rec; |
| 2054 | } |
| 2055 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2056 | void ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { |
| 2057 | assert(ObjCConstantStringType.isNull() && |
Steve Naroff | f2e3031 | 2007-10-15 23:35:17 +0000 | [diff] [blame] | 2058 | "'NSConstantString' type already set!"); |
| 2059 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2060 | ObjCConstantStringType = getObjCInterfaceType(Decl); |
Steve Naroff | f2e3031 | 2007-10-15 23:35:17 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Douglas Gregor | c6507e4 | 2008-11-03 14:12:49 +0000 | [diff] [blame] | 2063 | /// getFromTargetType - Given one of the integer types provided by |
Douglas Gregor | bb66b41 | 2008-11-03 15:57:00 +0000 | [diff] [blame] | 2064 | /// TargetInfo, produce the corresponding type. The unsigned @p Type |
| 2065 | /// is actually a value of type @c TargetInfo::IntType. |
| 2066 | QualType ASTContext::getFromTargetType(unsigned Type) const { |
Douglas Gregor | c6507e4 | 2008-11-03 14:12:49 +0000 | [diff] [blame] | 2067 | switch (Type) { |
| 2068 | case TargetInfo::NoInt: return QualType(); |
| 2069 | case TargetInfo::SignedShort: return ShortTy; |
| 2070 | case TargetInfo::UnsignedShort: return UnsignedShortTy; |
| 2071 | case TargetInfo::SignedInt: return IntTy; |
| 2072 | case TargetInfo::UnsignedInt: return UnsignedIntTy; |
| 2073 | case TargetInfo::SignedLong: return LongTy; |
| 2074 | case TargetInfo::UnsignedLong: return UnsignedLongTy; |
| 2075 | case TargetInfo::SignedLongLong: return LongLongTy; |
| 2076 | case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; |
| 2077 | } |
| 2078 | |
| 2079 | assert(false && "Unhandled TargetInfo::IntType value"); |
Daniel Dunbar | 7b0dcc2 | 2008-11-11 01:16:00 +0000 | [diff] [blame] | 2080 | return QualType(); |
Douglas Gregor | c6507e4 | 2008-11-03 14:12:49 +0000 | [diff] [blame] | 2081 | } |
Ted Kremenek | 118930e | 2008-07-24 23:58:27 +0000 | [diff] [blame] | 2082 | |
| 2083 | //===----------------------------------------------------------------------===// |
| 2084 | // Type Predicates. |
| 2085 | //===----------------------------------------------------------------------===// |
| 2086 | |
Fariborz Jahanian | 82f5496 | 2009-01-13 23:34:40 +0000 | [diff] [blame] | 2087 | /// isObjCNSObjectType - Return true if this is an NSObject object using |
| 2088 | /// NSObject attribute on a c-style pointer type. |
| 2089 | /// FIXME - Make it work directly on types. |
| 2090 | /// |
| 2091 | bool ASTContext::isObjCNSObjectType(QualType Ty) const { |
| 2092 | if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { |
| 2093 | if (TypedefDecl *TD = TDT->getDecl()) |
| 2094 | if (TD->getAttr<ObjCNSObjectAttr>()) |
| 2095 | return true; |
| 2096 | } |
| 2097 | return false; |
| 2098 | } |
| 2099 | |
Ted Kremenek | 118930e | 2008-07-24 23:58:27 +0000 | [diff] [blame] | 2100 | /// isObjCObjectPointerType - Returns true if type is an Objective-C pointer |
| 2101 | /// to an object type. This includes "id" and "Class" (two 'special' pointers |
| 2102 | /// to struct), Interface* (pointer to ObjCInterfaceType) and id<P> (qualified |
| 2103 | /// ID type). |
| 2104 | bool ASTContext::isObjCObjectPointerType(QualType Ty) const { |
| 2105 | if (Ty->isObjCQualifiedIdType()) |
| 2106 | return true; |
| 2107 | |
Steve Naroff | d9e0080 | 2008-10-21 18:24:04 +0000 | [diff] [blame] | 2108 | // Blocks are objects. |
| 2109 | if (Ty->isBlockPointerType()) |
| 2110 | return true; |
| 2111 | |
| 2112 | // All other object types are pointers. |
Ted Kremenek | 118930e | 2008-07-24 23:58:27 +0000 | [diff] [blame] | 2113 | if (!Ty->isPointerType()) |
| 2114 | return false; |
| 2115 | |
| 2116 | // Check to see if this is 'id' or 'Class', both of which are typedefs for |
| 2117 | // pointer types. This looks for the typedef specifically, not for the |
| 2118 | // underlying type. |
| 2119 | if (Ty == getObjCIdType() || Ty == getObjCClassType()) |
| 2120 | return true; |
| 2121 | |
| 2122 | // If this a pointer to an interface (e.g. NSString*), it is ok. |
Fariborz Jahanian | 82f5496 | 2009-01-13 23:34:40 +0000 | [diff] [blame] | 2123 | if (Ty->getAsPointerType()->getPointeeType()->isObjCInterfaceType()) |
| 2124 | return true; |
| 2125 | |
| 2126 | // If is has NSObject attribute, OK as well. |
| 2127 | return isObjCNSObjectType(Ty); |
Ted Kremenek | 118930e | 2008-07-24 23:58:27 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
Chris Lattner | 6ff358b | 2008-04-07 06:51:04 +0000 | [diff] [blame] | 2130 | //===----------------------------------------------------------------------===// |
| 2131 | // Type Compatibility Testing |
| 2132 | //===----------------------------------------------------------------------===// |
Chris Lattner | 5003e8b | 2007-11-01 05:03:41 +0000 | [diff] [blame] | 2133 | |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2134 | /// typesAreBlockCompatible - This routine is called when comparing two |
Steve Naroff | d6163f3 | 2008-09-05 22:11:13 +0000 | [diff] [blame] | 2135 | /// block types. Types must be strictly compatible here. For example, |
| 2136 | /// C unfortunately doesn't produce an error for the following: |
| 2137 | /// |
| 2138 | /// int (*emptyArgFunc)(); |
| 2139 | /// int (*intArgList)(int) = emptyArgFunc; |
| 2140 | /// |
| 2141 | /// For blocks, we will produce an error for the following (similar to C++): |
| 2142 | /// |
| 2143 | /// int (^emptyArgBlock)(); |
| 2144 | /// int (^intArgBlock)(int) = emptyArgBlock; |
| 2145 | /// |
| 2146 | /// FIXME: When the dust settles on this integration, fold this into mergeTypes. |
| 2147 | /// |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2148 | bool ASTContext::typesAreBlockCompatible(QualType lhs, QualType rhs) { |
Steve Naroff | 09e1b9e | 2008-12-10 17:49:55 +0000 | [diff] [blame] | 2149 | const FunctionType *lbase = lhs->getAsFunctionType(); |
| 2150 | const FunctionType *rbase = rhs->getAsFunctionType(); |
| 2151 | const FunctionTypeProto *lproto = dyn_cast<FunctionTypeProto>(lbase); |
| 2152 | const FunctionTypeProto *rproto = dyn_cast<FunctionTypeProto>(rbase); |
| 2153 | if (lproto && rproto) |
| 2154 | return !mergeTypes(lhs, rhs).isNull(); |
| 2155 | return false; |
Steve Naroff | 3454b6c | 2008-09-04 15:10:53 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
Chris Lattner | 6ff358b | 2008-04-07 06:51:04 +0000 | [diff] [blame] | 2158 | /// areCompatVectorTypes - Return true if the two specified vector types are |
| 2159 | /// compatible. |
| 2160 | static bool areCompatVectorTypes(const VectorType *LHS, |
| 2161 | const VectorType *RHS) { |
| 2162 | assert(LHS->isCanonical() && RHS->isCanonical()); |
| 2163 | return LHS->getElementType() == RHS->getElementType() && |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2164 | LHS->getNumElements() == RHS->getNumElements(); |
Chris Lattner | 6ff358b | 2008-04-07 06:51:04 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2167 | /// canAssignObjCInterfaces - Return true if the two interface types are |
Chris Lattner | 6ff358b | 2008-04-07 06:51:04 +0000 | [diff] [blame] | 2168 | /// compatible for assignment from RHS to LHS. This handles validation of any |
| 2169 | /// protocol qualifiers on the LHS or RHS. |
| 2170 | /// |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2171 | bool ASTContext::canAssignObjCInterfaces(const ObjCInterfaceType *LHS, |
| 2172 | const ObjCInterfaceType *RHS) { |
Chris Lattner | 6ff358b | 2008-04-07 06:51:04 +0000 | [diff] [blame] | 2173 | // Verify that the base decls are compatible: the RHS must be a subclass of |
| 2174 | // the LHS. |
| 2175 | if (!LHS->getDecl()->isSuperClassOf(RHS->getDecl())) |
| 2176 | return false; |
| 2177 | |
| 2178 | // RHS must have a superset of the protocols in the LHS. If the LHS is not |
| 2179 | // protocol qualified at all, then we are good. |
| 2180 | if (!isa<ObjCQualifiedInterfaceType>(LHS)) |
| 2181 | return true; |
| 2182 | |
| 2183 | // Okay, we know the LHS has protocol qualifiers. If the RHS doesn't, then it |
| 2184 | // isn't a superset. |
| 2185 | if (!isa<ObjCQualifiedInterfaceType>(RHS)) |
| 2186 | return true; // FIXME: should return false! |
| 2187 | |
| 2188 | // Finally, we must have two protocol-qualified interfaces. |
| 2189 | const ObjCQualifiedInterfaceType *LHSP =cast<ObjCQualifiedInterfaceType>(LHS); |
| 2190 | const ObjCQualifiedInterfaceType *RHSP =cast<ObjCQualifiedInterfaceType>(RHS); |
| 2191 | ObjCQualifiedInterfaceType::qual_iterator LHSPI = LHSP->qual_begin(); |
| 2192 | ObjCQualifiedInterfaceType::qual_iterator LHSPE = LHSP->qual_end(); |
| 2193 | ObjCQualifiedInterfaceType::qual_iterator RHSPI = RHSP->qual_begin(); |
| 2194 | ObjCQualifiedInterfaceType::qual_iterator RHSPE = RHSP->qual_end(); |
| 2195 | |
| 2196 | // All protocols in LHS must have a presence in RHS. Since the protocol lists |
| 2197 | // are both sorted alphabetically and have no duplicates, we can scan RHS and |
| 2198 | // LHS in a single parallel scan until we run out of elements in LHS. |
| 2199 | assert(LHSPI != LHSPE && "Empty LHS protocol list?"); |
| 2200 | ObjCProtocolDecl *LHSProto = *LHSPI; |
| 2201 | |
| 2202 | while (RHSPI != RHSPE) { |
| 2203 | ObjCProtocolDecl *RHSProto = *RHSPI++; |
| 2204 | // If the RHS has a protocol that the LHS doesn't, ignore it. |
| 2205 | if (RHSProto != LHSProto) |
| 2206 | continue; |
| 2207 | |
| 2208 | // Otherwise, the RHS does have this element. |
| 2209 | ++LHSPI; |
| 2210 | if (LHSPI == LHSPE) |
| 2211 | return true; // All protocols in LHS exist in RHS. |
| 2212 | |
| 2213 | LHSProto = *LHSPI; |
| 2214 | } |
| 2215 | |
| 2216 | // If we got here, we didn't find one of the LHS's protocols in the RHS list. |
| 2217 | return false; |
| 2218 | } |
| 2219 | |
Steve Naroff | 85f0dc5 | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 2220 | /// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, |
| 2221 | /// both shall have the identically qualified version of a compatible type. |
| 2222 | /// C99 6.2.7p1: Two types have compatible types if their types are the |
| 2223 | /// same. See 6.7.[2,3,5] for additional rules. |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2224 | bool ASTContext::typesAreCompatible(QualType LHS, QualType RHS) { |
| 2225 | return !mergeTypes(LHS, RHS).isNull(); |
| 2226 | } |
| 2227 | |
| 2228 | QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs) { |
| 2229 | const FunctionType *lbase = lhs->getAsFunctionType(); |
| 2230 | const FunctionType *rbase = rhs->getAsFunctionType(); |
| 2231 | const FunctionTypeProto *lproto = dyn_cast<FunctionTypeProto>(lbase); |
| 2232 | const FunctionTypeProto *rproto = dyn_cast<FunctionTypeProto>(rbase); |
| 2233 | bool allLTypes = true; |
| 2234 | bool allRTypes = true; |
| 2235 | |
| 2236 | // Check return type |
| 2237 | QualType retType = mergeTypes(lbase->getResultType(), rbase->getResultType()); |
| 2238 | if (retType.isNull()) return QualType(); |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2239 | if (getCanonicalType(retType) != getCanonicalType(lbase->getResultType())) |
| 2240 | allLTypes = false; |
| 2241 | if (getCanonicalType(retType) != getCanonicalType(rbase->getResultType())) |
| 2242 | allRTypes = false; |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2243 | |
| 2244 | if (lproto && rproto) { // two C99 style function prototypes |
| 2245 | unsigned lproto_nargs = lproto->getNumArgs(); |
| 2246 | unsigned rproto_nargs = rproto->getNumArgs(); |
| 2247 | |
| 2248 | // Compatible functions must have the same number of arguments |
| 2249 | if (lproto_nargs != rproto_nargs) |
| 2250 | return QualType(); |
| 2251 | |
| 2252 | // Variadic and non-variadic functions aren't compatible |
| 2253 | if (lproto->isVariadic() != rproto->isVariadic()) |
| 2254 | return QualType(); |
| 2255 | |
Argiris Kirtzidis | 65b9964 | 2008-10-26 16:43:14 +0000 | [diff] [blame] | 2256 | if (lproto->getTypeQuals() != rproto->getTypeQuals()) |
| 2257 | return QualType(); |
| 2258 | |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2259 | // Check argument compatibility |
| 2260 | llvm::SmallVector<QualType, 10> types; |
| 2261 | for (unsigned i = 0; i < lproto_nargs; i++) { |
| 2262 | QualType largtype = lproto->getArgType(i).getUnqualifiedType(); |
| 2263 | QualType rargtype = rproto->getArgType(i).getUnqualifiedType(); |
| 2264 | QualType argtype = mergeTypes(largtype, rargtype); |
| 2265 | if (argtype.isNull()) return QualType(); |
| 2266 | types.push_back(argtype); |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2267 | if (getCanonicalType(argtype) != getCanonicalType(largtype)) |
| 2268 | allLTypes = false; |
| 2269 | if (getCanonicalType(argtype) != getCanonicalType(rargtype)) |
| 2270 | allRTypes = false; |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2271 | } |
| 2272 | if (allLTypes) return lhs; |
| 2273 | if (allRTypes) return rhs; |
| 2274 | return getFunctionType(retType, types.begin(), types.size(), |
Argiris Kirtzidis | 65b9964 | 2008-10-26 16:43:14 +0000 | [diff] [blame] | 2275 | lproto->isVariadic(), lproto->getTypeQuals()); |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | if (lproto) allRTypes = false; |
| 2279 | if (rproto) allLTypes = false; |
| 2280 | |
| 2281 | const FunctionTypeProto *proto = lproto ? lproto : rproto; |
| 2282 | if (proto) { |
| 2283 | if (proto->isVariadic()) return QualType(); |
| 2284 | // Check that the types are compatible with the types that |
| 2285 | // would result from default argument promotions (C99 6.7.5.3p15). |
| 2286 | // The only types actually affected are promotable integer |
| 2287 | // types and floats, which would be passed as a different |
| 2288 | // type depending on whether the prototype is visible. |
| 2289 | unsigned proto_nargs = proto->getNumArgs(); |
| 2290 | for (unsigned i = 0; i < proto_nargs; ++i) { |
| 2291 | QualType argTy = proto->getArgType(i); |
| 2292 | if (argTy->isPromotableIntegerType() || |
| 2293 | getCanonicalType(argTy).getUnqualifiedType() == FloatTy) |
| 2294 | return QualType(); |
| 2295 | } |
| 2296 | |
| 2297 | if (allLTypes) return lhs; |
| 2298 | if (allRTypes) return rhs; |
| 2299 | return getFunctionType(retType, proto->arg_type_begin(), |
Argiris Kirtzidis | 65b9964 | 2008-10-26 16:43:14 +0000 | [diff] [blame] | 2300 | proto->getNumArgs(), lproto->isVariadic(), |
| 2301 | lproto->getTypeQuals()); |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | if (allLTypes) return lhs; |
| 2305 | if (allRTypes) return rhs; |
| 2306 | return getFunctionTypeNoProto(retType); |
| 2307 | } |
| 2308 | |
| 2309 | QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { |
Bill Wendling | 6a9d854 | 2007-12-03 07:33:35 +0000 | [diff] [blame] | 2310 | // C++ [expr]: If an expression initially has the type "reference to T", the |
| 2311 | // type is adjusted to "T" prior to any further analysis, the expression |
| 2312 | // designates the object or function denoted by the reference, and the |
| 2313 | // expression is an lvalue. |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2314 | // FIXME: C++ shouldn't be going through here! The rules are different |
| 2315 | // enough that they should be handled separately. |
| 2316 | if (const ReferenceType *RT = LHS->getAsReferenceType()) |
Chris Lattner | 855fed4 | 2008-04-07 04:07:56 +0000 | [diff] [blame] | 2317 | LHS = RT->getPointeeType(); |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2318 | if (const ReferenceType *RT = RHS->getAsReferenceType()) |
Chris Lattner | 855fed4 | 2008-04-07 04:07:56 +0000 | [diff] [blame] | 2319 | RHS = RT->getPointeeType(); |
Chris Lattner | d47d604 | 2008-04-07 05:37:56 +0000 | [diff] [blame] | 2320 | |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2321 | QualType LHSCan = getCanonicalType(LHS), |
| 2322 | RHSCan = getCanonicalType(RHS); |
| 2323 | |
| 2324 | // If two types are identical, they are compatible. |
| 2325 | if (LHSCan == RHSCan) |
| 2326 | return LHS; |
| 2327 | |
| 2328 | // If the qualifiers are different, the types aren't compatible |
| 2329 | if (LHSCan.getCVRQualifiers() != RHSCan.getCVRQualifiers() || |
| 2330 | LHSCan.getAddressSpace() != RHSCan.getAddressSpace()) |
| 2331 | return QualType(); |
| 2332 | |
| 2333 | Type::TypeClass LHSClass = LHSCan->getTypeClass(); |
| 2334 | Type::TypeClass RHSClass = RHSCan->getTypeClass(); |
| 2335 | |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2336 | // We want to consider the two function types to be the same for these |
| 2337 | // comparisons, just force one to the other. |
| 2338 | if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; |
| 2339 | if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; |
Eli Friedman | 398837e | 2008-02-12 08:23:06 +0000 | [diff] [blame] | 2340 | |
| 2341 | // Same as above for arrays |
Chris Lattner | b5709e2 | 2008-04-07 05:43:21 +0000 | [diff] [blame] | 2342 | if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) |
| 2343 | LHSClass = Type::ConstantArray; |
| 2344 | if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) |
| 2345 | RHSClass = Type::ConstantArray; |
Steve Naroff | 85f0dc5 | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 2346 | |
Nate Begeman | af6ed50 | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2347 | // Canonicalize ExtVector -> Vector. |
| 2348 | if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; |
| 2349 | if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; |
Chris Lattner | b5709e2 | 2008-04-07 05:43:21 +0000 | [diff] [blame] | 2350 | |
Chris Lattner | 7cdcb25 | 2008-04-07 06:38:24 +0000 | [diff] [blame] | 2351 | // Consider qualified interfaces and interfaces the same. |
| 2352 | if (LHSClass == Type::ObjCQualifiedInterface) LHSClass = Type::ObjCInterface; |
| 2353 | if (RHSClass == Type::ObjCQualifiedInterface) RHSClass = Type::ObjCInterface; |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2354 | |
Chris Lattner | b5709e2 | 2008-04-07 05:43:21 +0000 | [diff] [blame] | 2355 | // If the canonical type classes don't match. |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2356 | if (LHSClass != RHSClass) { |
Steve Naroff | 28ceff7 | 2008-12-10 22:14:21 +0000 | [diff] [blame] | 2357 | // ID is compatible with all qualified id types. |
| 2358 | if (LHS->isObjCQualifiedIdType()) { |
| 2359 | if (const PointerType *PT = RHS->getAsPointerType()) { |
| 2360 | QualType pType = PT->getPointeeType(); |
| 2361 | if (isObjCIdType(pType)) |
| 2362 | return LHS; |
| 2363 | // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true). |
| 2364 | // Unfortunately, this API is part of Sema (which we don't have access |
| 2365 | // to. Need to refactor. The following check is insufficient, since we |
| 2366 | // need to make sure the class implements the protocol. |
| 2367 | if (pType->isObjCInterfaceType()) |
| 2368 | return LHS; |
| 2369 | } |
| 2370 | } |
| 2371 | if (RHS->isObjCQualifiedIdType()) { |
| 2372 | if (const PointerType *PT = LHS->getAsPointerType()) { |
| 2373 | QualType pType = PT->getPointeeType(); |
| 2374 | if (isObjCIdType(pType)) |
| 2375 | return RHS; |
| 2376 | // FIXME: need to use ObjCQualifiedIdTypesAreCompatible(LHS, RHS, true). |
| 2377 | // Unfortunately, this API is part of Sema (which we don't have access |
| 2378 | // to. Need to refactor. The following check is insufficient, since we |
| 2379 | // need to make sure the class implements the protocol. |
| 2380 | if (pType->isObjCInterfaceType()) |
| 2381 | return RHS; |
| 2382 | } |
| 2383 | } |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2384 | // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, |
| 2385 | // a signed integer type, or an unsigned integer type. |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2386 | if (const EnumType* ETy = LHS->getAsEnumType()) { |
| 2387 | if (ETy->getDecl()->getIntegerType() == RHSCan.getUnqualifiedType()) |
| 2388 | return RHS; |
Eli Friedman | ad6c06c | 2008-02-12 08:46:17 +0000 | [diff] [blame] | 2389 | } |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2390 | if (const EnumType* ETy = RHS->getAsEnumType()) { |
| 2391 | if (ETy->getDecl()->getIntegerType() == LHSCan.getUnqualifiedType()) |
| 2392 | return LHS; |
Eli Friedman | ad6c06c | 2008-02-12 08:46:17 +0000 | [diff] [blame] | 2393 | } |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2394 | |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2395 | return QualType(); |
Steve Naroff | 85f0dc5 | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 2396 | } |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2397 | |
Steve Naroff | c88babe | 2008-01-09 22:43:08 +0000 | [diff] [blame] | 2398 | // The canonical type classes match. |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2399 | switch (LHSClass) { |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2400 | case Type::Pointer: |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2401 | { |
| 2402 | // Merge two pointer types, while trying to preserve typedef info |
| 2403 | QualType LHSPointee = LHS->getAsPointerType()->getPointeeType(); |
| 2404 | QualType RHSPointee = RHS->getAsPointerType()->getPointeeType(); |
| 2405 | QualType ResultType = mergeTypes(LHSPointee, RHSPointee); |
| 2406 | if (ResultType.isNull()) return QualType(); |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2407 | if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) |
| 2408 | return LHS; |
| 2409 | if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) |
| 2410 | return RHS; |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2411 | return getPointerType(ResultType); |
| 2412 | } |
Steve Naroff | 09e1b9e | 2008-12-10 17:49:55 +0000 | [diff] [blame] | 2413 | case Type::BlockPointer: |
| 2414 | { |
| 2415 | // Merge two block pointer types, while trying to preserve typedef info |
| 2416 | QualType LHSPointee = LHS->getAsBlockPointerType()->getPointeeType(); |
| 2417 | QualType RHSPointee = RHS->getAsBlockPointerType()->getPointeeType(); |
| 2418 | QualType ResultType = mergeTypes(LHSPointee, RHSPointee); |
| 2419 | if (ResultType.isNull()) return QualType(); |
| 2420 | if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) |
| 2421 | return LHS; |
| 2422 | if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) |
| 2423 | return RHS; |
| 2424 | return getBlockPointerType(ResultType); |
| 2425 | } |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2426 | case Type::ConstantArray: |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2427 | { |
| 2428 | const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); |
| 2429 | const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); |
| 2430 | if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) |
| 2431 | return QualType(); |
| 2432 | |
| 2433 | QualType LHSElem = getAsArrayType(LHS)->getElementType(); |
| 2434 | QualType RHSElem = getAsArrayType(RHS)->getElementType(); |
| 2435 | QualType ResultType = mergeTypes(LHSElem, RHSElem); |
| 2436 | if (ResultType.isNull()) return QualType(); |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2437 | if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) |
| 2438 | return LHS; |
| 2439 | if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) |
| 2440 | return RHS; |
Eli Friedman | c91a3f3 | 2008-08-22 01:48:21 +0000 | [diff] [blame] | 2441 | if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), |
| 2442 | ArrayType::ArraySizeModifier(), 0); |
| 2443 | if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), |
| 2444 | ArrayType::ArraySizeModifier(), 0); |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2445 | const VariableArrayType* LVAT = getAsVariableArrayType(LHS); |
| 2446 | const VariableArrayType* RVAT = getAsVariableArrayType(RHS); |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2447 | if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) |
| 2448 | return LHS; |
| 2449 | if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) |
| 2450 | return RHS; |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2451 | if (LVAT) { |
| 2452 | // FIXME: This isn't correct! But tricky to implement because |
| 2453 | // the array's size has to be the size of LHS, but the type |
| 2454 | // has to be different. |
| 2455 | return LHS; |
| 2456 | } |
| 2457 | if (RVAT) { |
| 2458 | // FIXME: This isn't correct! But tricky to implement because |
| 2459 | // the array's size has to be the size of RHS, but the type |
| 2460 | // has to be different. |
| 2461 | return RHS; |
| 2462 | } |
Eli Friedman | c91a3f3 | 2008-08-22 01:48:21 +0000 | [diff] [blame] | 2463 | if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; |
| 2464 | if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2465 | return getIncompleteArrayType(ResultType, ArrayType::ArraySizeModifier(),0); |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2466 | } |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2467 | case Type::FunctionNoProto: |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2468 | return mergeFunctionTypes(LHS, RHS); |
| 2469 | case Type::Tagged: |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2470 | // FIXME: Why are these compatible? |
| 2471 | if (isObjCIdType(LHS) && isObjCClassType(RHS)) return LHS; |
| 2472 | if (isObjCClassType(LHS) && isObjCIdType(RHS)) return LHS; |
| 2473 | return QualType(); |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2474 | case Type::Builtin: |
Chris Lattner | d1240fa | 2008-04-07 05:55:38 +0000 | [diff] [blame] | 2475 | // Only exactly equal builtin types are compatible, which is tested above. |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2476 | return QualType(); |
Chris Lattner | d1240fa | 2008-04-07 05:55:38 +0000 | [diff] [blame] | 2477 | case Type::Vector: |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2478 | if (areCompatVectorTypes(LHS->getAsVectorType(), RHS->getAsVectorType())) |
| 2479 | return LHS; |
Chris Lattner | 2fda0ed | 2008-10-05 17:34:18 +0000 | [diff] [blame] | 2480 | return QualType(); |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2481 | case Type::ObjCInterface: |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2482 | // Distinct ObjC interfaces are not compatible; see canAssignObjCInterfaces |
| 2483 | // for checking assignment/comparison safety |
| 2484 | return QualType(); |
Steve Naroff | 28ceff7 | 2008-12-10 22:14:21 +0000 | [diff] [blame] | 2485 | case Type::ObjCQualifiedId: |
| 2486 | // Distinct qualified id's are not compatible. |
| 2487 | return QualType(); |
Chris Lattner | c38d452 | 2008-01-14 05:45:46 +0000 | [diff] [blame] | 2488 | default: |
| 2489 | assert(0 && "unexpected type"); |
Eli Friedman | 0d9549b | 2008-08-22 00:56:42 +0000 | [diff] [blame] | 2490 | return QualType(); |
Steve Naroff | 85f0dc5 | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 2491 | } |
Steve Naroff | 85f0dc5 | 2007-10-15 20:41:53 +0000 | [diff] [blame] | 2492 | } |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 2493 | |
Chris Lattner | 1d78a86 | 2008-04-07 07:01:58 +0000 | [diff] [blame] | 2494 | //===----------------------------------------------------------------------===// |
Eli Friedman | 0832dbc | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 2495 | // Integer Predicates |
| 2496 | //===----------------------------------------------------------------------===// |
Chris Lattner | 74f6701 | 2009-01-16 07:15:35 +0000 | [diff] [blame] | 2497 | |
Eli Friedman | 0832dbc | 2008-06-28 06:23:08 +0000 | [diff] [blame] | 2498 | unsigned ASTContext::getIntWidth(QualType T) { |
| 2499 | if (T == BoolTy) |
| 2500 | return 1; |
| 2501 | // At the moment, only bool has padding bits |
| 2502 | return (unsigned)getTypeSize(T); |
| 2503 | } |
| 2504 | |
| 2505 | QualType ASTContext::getCorrespondingUnsignedType(QualType T) { |
| 2506 | assert(T->isSignedIntegerType() && "Unexpected type"); |
| 2507 | if (const EnumType* ETy = T->getAsEnumType()) |
| 2508 | T = ETy->getDecl()->getIntegerType(); |
| 2509 | const BuiltinType* BTy = T->getAsBuiltinType(); |
| 2510 | assert (BTy && "Unexpected signed integer type"); |
| 2511 | switch (BTy->getKind()) { |
| 2512 | case BuiltinType::Char_S: |
| 2513 | case BuiltinType::SChar: |
| 2514 | return UnsignedCharTy; |
| 2515 | case BuiltinType::Short: |
| 2516 | return UnsignedShortTy; |
| 2517 | case BuiltinType::Int: |
| 2518 | return UnsignedIntTy; |
| 2519 | case BuiltinType::Long: |
| 2520 | return UnsignedLongTy; |
| 2521 | case BuiltinType::LongLong: |
| 2522 | return UnsignedLongLongTy; |
| 2523 | default: |
| 2524 | assert(0 && "Unexpected signed integer type"); |
| 2525 | return QualType(); |
| 2526 | } |
| 2527 | } |
| 2528 | |
| 2529 | |
| 2530 | //===----------------------------------------------------------------------===// |
Chris Lattner | 1d78a86 | 2008-04-07 07:01:58 +0000 | [diff] [blame] | 2531 | // Serialization Support |
| 2532 | //===----------------------------------------------------------------------===// |
| 2533 | |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 2534 | /// Emit - Serialize an ASTContext object to Bitcode. |
| 2535 | void ASTContext::Emit(llvm::Serializer& S) const { |
Ted Kremenek | 842126e | 2008-06-04 15:55:15 +0000 | [diff] [blame] | 2536 | S.Emit(LangOpts); |
Ted Kremenek | 9af4d5c | 2007-10-31 20:00:03 +0000 | [diff] [blame] | 2537 | S.EmitRef(SourceMgr); |
| 2538 | S.EmitRef(Target); |
| 2539 | S.EmitRef(Idents); |
| 2540 | S.EmitRef(Selectors); |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 2541 | |
Ted Kremenek | 68228a9 | 2007-10-31 22:44:07 +0000 | [diff] [blame] | 2542 | // Emit the size of the type vector so that we can reserve that size |
| 2543 | // when we reconstitute the ASTContext object. |
Ted Kremenek | 0199d9f | 2007-11-06 22:26:16 +0000 | [diff] [blame] | 2544 | S.EmitInt(Types.size()); |
| 2545 | |
Ted Kremenek | 034a78c | 2007-11-13 22:02:55 +0000 | [diff] [blame] | 2546 | for (std::vector<Type*>::const_iterator I=Types.begin(), E=Types.end(); |
| 2547 | I!=E;++I) |
| 2548 | (*I)->Emit(S); |
Ted Kremenek | 0199d9f | 2007-11-06 22:26:16 +0000 | [diff] [blame] | 2549 | |
Argiris Kirtzidis | d358600 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 2550 | S.EmitOwnedPtr(TUDecl); |
| 2551 | |
Ted Kremenek | e1fed7a | 2007-11-01 18:11:32 +0000 | [diff] [blame] | 2552 | // FIXME: S.EmitOwnedPtr(CFConstantStringTypeDecl); |
Ted Kremenek | 738e6c0 | 2007-10-31 17:10:13 +0000 | [diff] [blame] | 2553 | } |
| 2554 | |
Ted Kremenek | acba361 | 2007-11-13 00:25:37 +0000 | [diff] [blame] | 2555 | ASTContext* ASTContext::Create(llvm::Deserializer& D) { |
Ted Kremenek | 842126e | 2008-06-04 15:55:15 +0000 | [diff] [blame] | 2556 | |
| 2557 | // Read the language options. |
| 2558 | LangOptions LOpts; |
| 2559 | LOpts.Read(D); |
| 2560 | |
Ted Kremenek | 68228a9 | 2007-10-31 22:44:07 +0000 | [diff] [blame] | 2561 | SourceManager &SM = D.ReadRef<SourceManager>(); |
| 2562 | TargetInfo &t = D.ReadRef<TargetInfo>(); |
| 2563 | IdentifierTable &idents = D.ReadRef<IdentifierTable>(); |
| 2564 | SelectorTable &sels = D.ReadRef<SelectorTable>(); |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2565 | |
Ted Kremenek | 68228a9 | 2007-10-31 22:44:07 +0000 | [diff] [blame] | 2566 | unsigned size_reserve = D.ReadInt(); |
| 2567 | |
Douglas Gregor | 24afd4a | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 2568 | ASTContext* A = new ASTContext(LOpts, SM, t, idents, sels, |
| 2569 | size_reserve); |
Ted Kremenek | 68228a9 | 2007-10-31 22:44:07 +0000 | [diff] [blame] | 2570 | |
Ted Kremenek | 034a78c | 2007-11-13 22:02:55 +0000 | [diff] [blame] | 2571 | for (unsigned i = 0; i < size_reserve; ++i) |
| 2572 | Type::Create(*A,i,D); |
Chris Lattner | eee57c0 | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2573 | |
Argiris Kirtzidis | d358600 | 2008-04-17 14:40:12 +0000 | [diff] [blame] | 2574 | A->TUDecl = cast<TranslationUnitDecl>(D.ReadOwnedPtr<Decl>(*A)); |
| 2575 | |
Ted Kremenek | e1fed7a | 2007-11-01 18:11:32 +0000 | [diff] [blame] | 2576 | // FIXME: A->CFConstantStringTypeDecl = D.ReadOwnedPtr<RecordDecl>(); |
Ted Kremenek | 68228a9 | 2007-10-31 22:44:07 +0000 | [diff] [blame] | 2577 | |
| 2578 | return A; |
| 2579 | } |