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