Chris Lattner | ddc135e | 2006-11-10 06:34:16 +0000 | [diff] [blame] | 1 | //===--- ASTContext.cpp - Context to hold long-lived AST nodes ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the ASTContext interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/ASTContext.h" |
Chris Lattner | d0342e5 | 2006-11-20 04:02:15 +0000 | [diff] [blame] | 15 | #include "clang/AST/Decl.h" |
Chris Lattner | ddc135e | 2006-11-10 06:34:16 +0000 | [diff] [blame] | 16 | #include "clang/Lex/Preprocessor.h" |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Steve Naroff | 6fbf0dc | 2007-03-16 00:33:25 +0000 | [diff] [blame] | 18 | |
Chris Lattner | ddc135e | 2006-11-10 06:34:16 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | using namespace clang; |
| 21 | |
Chris Lattner | d5973eb | 2006-11-12 00:53:46 +0000 | [diff] [blame] | 22 | ASTContext::~ASTContext() { |
| 23 | // Deallocate all the types. |
| 24 | while (!Types.empty()) { |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 25 | if (FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(Types.back())) { |
| 26 | // Destroy the object, but don't call delete. These are malloc'd. |
| 27 | FT->~FunctionTypeProto(); |
| 28 | free(FT); |
| 29 | } else { |
| 30 | delete Types.back(); |
| 31 | } |
Chris Lattner | d5973eb | 2006-11-12 00:53:46 +0000 | [diff] [blame] | 32 | Types.pop_back(); |
| 33 | } |
| 34 | } |
| 35 | |
Chris Lattner | 4eb445d | 2007-01-26 01:27:23 +0000 | [diff] [blame] | 36 | void ASTContext::PrintStats() const { |
| 37 | fprintf(stderr, "*** AST Context Stats:\n"); |
| 38 | fprintf(stderr, " %d types total.\n", (int)Types.size()); |
| 39 | unsigned NumBuiltin = 0, NumPointer = 0, NumArray = 0, NumFunctionP = 0; |
| 40 | unsigned NumFunctionNP = 0, NumTypeName = 0, NumTagged = 0; |
| 41 | |
| 42 | unsigned NumTagStruct = 0, NumTagUnion = 0, NumTagEnum = 0, NumTagClass = 0; |
| 43 | |
| 44 | for (unsigned i = 0, e = Types.size(); i != e; ++i) { |
| 45 | Type *T = Types[i]; |
| 46 | if (isa<BuiltinType>(T)) |
| 47 | ++NumBuiltin; |
| 48 | else if (isa<PointerType>(T)) |
| 49 | ++NumPointer; |
| 50 | else if (isa<ArrayType>(T)) |
| 51 | ++NumArray; |
| 52 | else if (isa<FunctionTypeNoProto>(T)) |
| 53 | ++NumFunctionNP; |
| 54 | else if (isa<FunctionTypeProto>(T)) |
| 55 | ++NumFunctionP; |
Chris Lattner | 32d920b | 2007-01-26 02:01:53 +0000 | [diff] [blame] | 56 | else if (isa<TypedefType>(T)) |
Chris Lattner | 4eb445d | 2007-01-26 01:27:23 +0000 | [diff] [blame] | 57 | ++NumTypeName; |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 58 | else if (TagType *TT = dyn_cast<TagType>(T)) { |
Chris Lattner | 4eb445d | 2007-01-26 01:27:23 +0000 | [diff] [blame] | 59 | ++NumTagged; |
| 60 | switch (TT->getDecl()->getKind()) { |
| 61 | default: assert(0 && "Unknown tagged type!"); |
| 62 | case Decl::Struct: ++NumTagStruct; break; |
| 63 | case Decl::Union: ++NumTagUnion; break; |
| 64 | case Decl::Class: ++NumTagClass; break; |
| 65 | case Decl::Enum: ++NumTagEnum; break; |
| 66 | } |
| 67 | } else { |
| 68 | assert(0 && "Unknown type!"); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | fprintf(stderr, " %d builtin types\n", NumBuiltin); |
| 73 | fprintf(stderr, " %d pointer types\n", NumPointer); |
| 74 | fprintf(stderr, " %d array types\n", NumArray); |
| 75 | fprintf(stderr, " %d function types with proto\n", NumFunctionP); |
| 76 | fprintf(stderr, " %d function types with no proto\n", NumFunctionNP); |
| 77 | fprintf(stderr, " %d typename (typedef) types\n", NumTypeName); |
| 78 | fprintf(stderr, " %d tagged types\n", NumTagged); |
| 79 | fprintf(stderr, " %d struct types\n", NumTagStruct); |
| 80 | fprintf(stderr, " %d union types\n", NumTagUnion); |
| 81 | fprintf(stderr, " %d class types\n", NumTagClass); |
| 82 | fprintf(stderr, " %d enum types\n", NumTagEnum); |
Chris Lattner | 4eb445d | 2007-01-26 01:27:23 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 86 | void ASTContext::InitBuiltinType(TypeRef &R, BuiltinType::Kind K) { |
| 87 | Types.push_back((R = new BuiltinType(K)).getTypePtr()); |
Chris Lattner | d5973eb | 2006-11-12 00:53:46 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 91 | void ASTContext::InitBuiltinTypes() { |
| 92 | assert(VoidTy.isNull() && "Context reinitialized?"); |
| 93 | |
| 94 | // C99 6.2.5p19. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 95 | InitBuiltinType(VoidTy, BuiltinType::Void); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 96 | |
| 97 | // C99 6.2.5p2. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 98 | InitBuiltinType(BoolTy, BuiltinType::Bool); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 99 | // C99 6.2.5p3. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 100 | InitBuiltinType(CharTy, BuiltinType::Char); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 101 | // C99 6.2.5p4. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 102 | InitBuiltinType(SignedCharTy, BuiltinType::SChar); |
| 103 | InitBuiltinType(ShortTy, BuiltinType::Short); |
| 104 | InitBuiltinType(IntTy, BuiltinType::Int); |
| 105 | InitBuiltinType(LongTy, BuiltinType::Long); |
| 106 | InitBuiltinType(LongLongTy, BuiltinType::LongLong); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 107 | |
| 108 | // C99 6.2.5p6. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 109 | InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); |
| 110 | InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); |
| 111 | InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); |
| 112 | InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); |
| 113 | InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 114 | |
| 115 | // C99 6.2.5p10. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 116 | InitBuiltinType(FloatTy, BuiltinType::Float); |
| 117 | InitBuiltinType(DoubleTy, BuiltinType::Double); |
| 118 | InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 119 | |
| 120 | // C99 6.2.5p11. |
Chris Lattner | 726f97b | 2006-12-03 02:57:32 +0000 | [diff] [blame] | 121 | InitBuiltinType(FloatComplexTy, BuiltinType::FloatComplex); |
| 122 | InitBuiltinType(DoubleComplexTy, BuiltinType::DoubleComplex); |
| 123 | InitBuiltinType(LongDoubleComplexTy, BuiltinType::LongDoubleComplex); |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /// getPointerType - Return the uniqued reference to the type for a pointer to |
| 127 | /// the specified type. |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 128 | TypeRef ASTContext::getPointerType(TypeRef T) { |
Chris Lattner | d5973eb | 2006-11-12 00:53:46 +0000 | [diff] [blame] | 129 | // Unique pointers, to guarantee there is only one pointer of a particular |
| 130 | // structure. |
Chris Lattner | 67521df | 2007-01-27 01:29:36 +0000 | [diff] [blame] | 131 | FoldingSetNodeID ID; |
| 132 | PointerType::Profile(ID, T); |
| 133 | |
| 134 | void *InsertPos = 0; |
| 135 | if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 136 | return PT; |
Chris Lattner | 970e54e | 2006-11-12 00:37:36 +0000 | [diff] [blame] | 137 | |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 138 | // If the pointee type isn't canonical, this won't be a canonical type either, |
| 139 | // so fill in the canonical type field. |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 140 | TypeRef Canonical = 0; |
Chris Lattner | 67521df | 2007-01-27 01:29:36 +0000 | [diff] [blame] | 141 | if (!T->isCanonical()) { |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 142 | Canonical = getPointerType(T.getCanonicalType()); |
Chris Lattner | 67521df | 2007-01-27 01:29:36 +0000 | [diff] [blame] | 143 | |
| 144 | // Get the new insert position for the node we care about. |
| 145 | PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); |
| 146 | assert(NewIP == 0 && "Shouldn't be in the map!"); |
| 147 | } |
Chris Lattner | 67521df | 2007-01-27 01:29:36 +0000 | [diff] [blame] | 148 | PointerType *New = new PointerType(T, Canonical); |
| 149 | Types.push_back(New); |
| 150 | PointerTypes.InsertNode(New, InsertPos); |
| 151 | return New; |
Chris Lattner | ddc135e | 2006-11-10 06:34:16 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 154 | /// getArrayType - Return the unique reference to the type for an array of the |
| 155 | /// specified element type. |
| 156 | TypeRef ASTContext::getArrayType(TypeRef EltTy,ArrayType::ArraySizeModifier ASM, |
Steve Naroff | 408451b | 2007-02-26 22:17:12 +0000 | [diff] [blame] | 157 | unsigned EltTypeQuals, Expr *NumElts) { |
Chris Lattner | 36f8e65 | 2007-01-27 08:31:04 +0000 | [diff] [blame] | 158 | // Unique array types, to guarantee there is only one array of a particular |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 159 | // structure. |
Chris Lattner | 36f8e65 | 2007-01-27 08:31:04 +0000 | [diff] [blame] | 160 | FoldingSetNodeID ID; |
Steve Naroff | b7d4924 | 2007-03-14 19:55:17 +0000 | [diff] [blame] | 161 | ArrayType::Profile(ID, ASM, EltTypeQuals, EltTy, NumElts); |
Steve Naroff | 408451b | 2007-02-26 22:17:12 +0000 | [diff] [blame] | 162 | |
Chris Lattner | 36f8e65 | 2007-01-27 08:31:04 +0000 | [diff] [blame] | 163 | void *InsertPos = 0; |
| 164 | if (ArrayType *ATP = ArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) |
| 165 | return ATP; |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 166 | |
| 167 | // If the element type isn't canonical, this won't be a canonical type either, |
| 168 | // so fill in the canonical type field. |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 169 | TypeRef Canonical = 0; |
Chris Lattner | 36f8e65 | 2007-01-27 08:31:04 +0000 | [diff] [blame] | 170 | if (!EltTy->isCanonical()) { |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 171 | Canonical = getArrayType(EltTy.getCanonicalType(), ASM, EltTypeQuals, |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 172 | NumElts); |
Chris Lattner | 36f8e65 | 2007-01-27 08:31:04 +0000 | [diff] [blame] | 173 | |
| 174 | // Get the new insert position for the node we care about. |
| 175 | ArrayType *NewIP = ArrayTypes.FindNodeOrInsertPos(ID, InsertPos); |
| 176 | assert(NewIP == 0 && "Shouldn't be in the map!"); |
| 177 | } |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 178 | |
Steve Naroff | b7d4924 | 2007-03-14 19:55:17 +0000 | [diff] [blame] | 179 | ArrayType *New = new ArrayType(EltTy, ASM, EltTypeQuals, Canonical, NumElts); |
Chris Lattner | 36f8e65 | 2007-01-27 08:31:04 +0000 | [diff] [blame] | 180 | ArrayTypes.InsertNode(New, InsertPos); |
| 181 | Types.push_back(New); |
| 182 | return New; |
Chris Lattner | 7ccecb9 | 2006-11-12 08:50:50 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 185 | /// getFunctionTypeNoProto - Return a K&R style C function type like 'int()'. |
| 186 | /// |
| 187 | TypeRef ASTContext::getFunctionTypeNoProto(TypeRef ResultTy) { |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 188 | // Unique functions, to guarantee there is only one function of a particular |
| 189 | // structure. |
Chris Lattner | 47955de | 2007-01-27 08:37:20 +0000 | [diff] [blame] | 190 | FoldingSetNodeID ID; |
| 191 | FunctionTypeNoProto::Profile(ID, ResultTy); |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 192 | |
Chris Lattner | 47955de | 2007-01-27 08:37:20 +0000 | [diff] [blame] | 193 | void *InsertPos = 0; |
| 194 | if (FunctionTypeNoProto *FT = |
| 195 | FunctionTypeNoProtos.FindNodeOrInsertPos(ID, InsertPos)) |
| 196 | return FT; |
| 197 | |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 198 | TypeRef Canonical = 0; |
Chris Lattner | 47955de | 2007-01-27 08:37:20 +0000 | [diff] [blame] | 199 | if (!ResultTy->isCanonical()) { |
| 200 | Canonical =getFunctionTypeNoProto(ResultTy.getCanonicalType()).getTypePtr(); |
| 201 | |
| 202 | // Get the new insert position for the node we care about. |
| 203 | FunctionTypeNoProto *NewIP = |
| 204 | FunctionTypeNoProtos.FindNodeOrInsertPos(ID, InsertPos); |
| 205 | assert(NewIP == 0 && "Shouldn't be in the map!"); |
| 206 | } |
| 207 | |
| 208 | FunctionTypeNoProto *New = new FunctionTypeNoProto(ResultTy, Canonical); |
| 209 | Types.push_back(New); |
| 210 | FunctionTypeProtos.InsertNode(New, InsertPos); |
| 211 | return New; |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /// getFunctionType - Return a normal function type with a typed argument |
| 215 | /// list. isVariadic indicates whether the argument list includes '...'. |
| 216 | TypeRef ASTContext::getFunctionType(TypeRef ResultTy, TypeRef *ArgArray, |
| 217 | unsigned NumArgs, bool isVariadic) { |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 218 | // Unique functions, to guarantee there is only one function of a particular |
| 219 | // structure. |
Chris Lattner | fd4de79 | 2007-01-27 01:15:32 +0000 | [diff] [blame] | 220 | FoldingSetNodeID ID; |
| 221 | FunctionTypeProto::Profile(ID, ResultTy, ArgArray, NumArgs, isVariadic); |
| 222 | |
| 223 | void *InsertPos = 0; |
| 224 | if (FunctionTypeProto *FTP = |
| 225 | FunctionTypeProtos.FindNodeOrInsertPos(ID, InsertPos)) |
| 226 | return FTP; |
| 227 | |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 228 | // Determine whether the type being created is already canonical or not. |
| 229 | bool isCanonical = ResultTy->isCanonical(); |
| 230 | for (unsigned i = 0; i != NumArgs && isCanonical; ++i) |
| 231 | if (!ArgArray[i]->isCanonical()) |
| 232 | isCanonical = false; |
| 233 | |
| 234 | // If this type isn't canonical, get the canonical version of it. |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 235 | TypeRef Canonical = 0; |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 236 | if (!isCanonical) { |
| 237 | SmallVector<TypeRef, 16> CanonicalArgs; |
| 238 | CanonicalArgs.reserve(NumArgs); |
| 239 | for (unsigned i = 0; i != NumArgs; ++i) |
| 240 | CanonicalArgs.push_back(ArgArray[i].getCanonicalType()); |
| 241 | |
| 242 | Canonical = getFunctionType(ResultTy.getCanonicalType(), |
| 243 | &CanonicalArgs[0], NumArgs, |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 244 | isVariadic); |
Chris Lattner | fd4de79 | 2007-01-27 01:15:32 +0000 | [diff] [blame] | 245 | |
| 246 | // Get the new insert position for the node we care about. |
| 247 | FunctionTypeProto *NewIP = |
| 248 | FunctionTypeProtos.FindNodeOrInsertPos(ID, InsertPos); |
| 249 | assert(NewIP == 0 && "Shouldn't be in the map!"); |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // FunctionTypeProto objects are not allocated with new because they have a |
| 253 | // variable size array (for parameter types) at the end of them. |
| 254 | FunctionTypeProto *FTP = |
| 255 | (FunctionTypeProto*)malloc(sizeof(FunctionTypeProto) + |
| 256 | (NumArgs-1)*sizeof(TypeRef)); |
| 257 | new (FTP) FunctionTypeProto(ResultTy, ArgArray, NumArgs, isVariadic, |
| 258 | Canonical); |
| 259 | |
| 260 | Types.push_back(FTP); |
Chris Lattner | fd4de79 | 2007-01-27 01:15:32 +0000 | [diff] [blame] | 261 | FunctionTypeProtos.InsertNode(FTP, InsertPos); |
Chris Lattner | c6ad813 | 2006-12-02 07:52:18 +0000 | [diff] [blame] | 262 | return FTP; |
| 263 | } |
Chris Lattner | ef51c20 | 2006-11-10 07:17:23 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 32d920b | 2007-01-26 02:01:53 +0000 | [diff] [blame] | 265 | /// getTypedefType - Return the unique reference to the type for the |
Chris Lattner | d0342e5 | 2006-11-20 04:02:15 +0000 | [diff] [blame] | 266 | /// specified typename decl. |
Chris Lattner | 32d920b | 2007-01-26 02:01:53 +0000 | [diff] [blame] | 267 | TypeRef ASTContext::getTypedefType(TypedefDecl *Decl) { |
Chris Lattner | 6668fc6 | 2007-01-26 02:07:07 +0000 | [diff] [blame] | 268 | if (Decl->TypeForDecl) return Decl->TypeForDecl; |
Chris Lattner | d0342e5 | 2006-11-20 04:02:15 +0000 | [diff] [blame] | 269 | |
Steve Naroff | d50c88e | 2007-04-05 21:15:20 +0000 | [diff] [blame^] | 270 | TypeRef Canonical = Decl->getUnderlyingType().getCanonicalType(); |
Chris Lattner | cceab1a | 2007-03-26 20:16:44 +0000 | [diff] [blame] | 271 | Decl->TypeForDecl = new TypedefType(Decl, Canonical); |
| 272 | Types.push_back(Decl->TypeForDecl); |
| 273 | return Decl->TypeForDecl; |
Chris Lattner | d0342e5 | 2006-11-20 04:02:15 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Chris Lattner | fb07246 | 2007-01-23 05:45:31 +0000 | [diff] [blame] | 276 | /// getTagDeclType - Return the unique reference to the type for the |
| 277 | /// specified TagDecl (struct/union/class/enum) decl. |
| 278 | TypeRef ASTContext::getTagDeclType(TagDecl *Decl) { |
Chris Lattner | 733067d | 2007-01-26 01:42:24 +0000 | [diff] [blame] | 279 | // The decl stores the type cache. |
| 280 | if (Decl->TypeForDecl) return Decl->TypeForDecl; |
Chris Lattner | fb07246 | 2007-01-23 05:45:31 +0000 | [diff] [blame] | 281 | |
Chris Lattner | cceab1a | 2007-03-26 20:16:44 +0000 | [diff] [blame] | 282 | Decl->TypeForDecl = new TagType(Decl, 0); |
| 283 | Types.push_back(Decl->TypeForDecl); |
| 284 | return Decl->TypeForDecl; |
Chris Lattner | fb07246 | 2007-01-23 05:45:31 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Steve Naroff | 92e30f8 | 2007-04-02 22:35:25 +0000 | [diff] [blame] | 287 | /// getSizeType - Return the unique type for "size_t" (C99 7.17), the result |
Steve Naroff | 0f6256d | 2007-04-02 23:01:44 +0000 | [diff] [blame] | 288 | /// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and |
Steve Naroff | 92e30f8 | 2007-04-02 22:35:25 +0000 | [diff] [blame] | 289 | /// needs to agree with the definition in <stddef.h>. |
Steve Naroff | 0f6256d | 2007-04-02 23:01:44 +0000 | [diff] [blame] | 290 | TypeRef ASTContext::getSizeType() const { |
Steve Naroff | 92e30f8 | 2007-04-02 22:35:25 +0000 | [diff] [blame] | 291 | // On Darwin, size_t is defined as a "long unsigned int". |
| 292 | // FIXME: should derive from "Target". |
| 293 | return UnsignedLongTy; |
| 294 | } |
Chris Lattner | fb07246 | 2007-01-23 05:45:31 +0000 | [diff] [blame] | 295 | |