ASTContext.cpp revision 04e8357f6801e9ff52673e7e899a67bbabf9de93
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- ASTContext.cpp - Context to hold long-lived AST nodes ------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the ASTContext interface. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/ASTContext.h" 1549aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h" 16980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 17aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 18b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#include "clang/AST/TypeLoc.h" 19e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/Expr.h" 202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/ExternalASTSource.h" 2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 221b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 23a9376d470ccb0eac74fe09a6b2a18a890f1d17c4Chris Lattner#include "clang/Basic/SourceManager.h" 245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/TargetInfo.h" 2585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson#include "llvm/ADT/StringExtras.h" 266fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman#include "llvm/Support/MathExtras.h" 27557c5b1717bc8919b1b40cf2064b51491ec53a44Chris Lattner#include "llvm/Support/MemoryBuffer.h" 2829445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson#include "RecordLayoutBuilder.h" 2929445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerenum FloatingRank { 335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FloatRank, DoubleRank, LongDoubleRank 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3661710854be2b098428aff5316e64bd34b30fbcb7Chris LattnerASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, 3761710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner TargetInfo &t, 38e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar IdentifierTable &idents, SelectorTable &sels, 391b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner Builtin::Context &builtins, 401b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner bool FreeMem, unsigned size_reserve) : 41ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), 42782fa308a765aeac2acb39c4e697c937ec21185bMike Stump ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0), 43782fa308a765aeac2acb39c4e697c937ec21185bMike Stump sigjmp_bufDecl(0), SourceMgr(SM), LangOpts(LOpts), 442e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LoadedExternalComments(false), FreeMemory(FreeMem), Target(t), 452e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Idents(idents), Selectors(sels), 46e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts) { 470f436560640a1cff5b6d96f80f540770f139453fDavid Chisnall ObjCIdRedefinitionType = QualType(); 480f436560640a1cff5b6d96f80f540770f139453fDavid Chisnall ObjCClassRedefinitionType = QualType(); 49e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar if (size_reserve > 0) Types.reserve(size_reserve); 50e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar TUDecl = TranslationUnitDecl::Create(*this); 5114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff InitBuiltinTypes(); 52e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar} 53e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar 545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerASTContext::~ASTContext() { 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Deallocate all the types. 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer while (!Types.empty()) { 574b05b1dee6cc65ae61d93dab7edff72710f24589Ted Kremenek Types.back()->Destroy(*this); 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.pop_back(); 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 60b26153c2b06934b6d39886cae2a379988d9c3e2bEli Friedman 61b74668edbc119880eb0a7e563432314432cb775dNuno Lopes { 62b74668edbc119880eb0a7e563432314432cb775dNuno Lopes llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator 63b74668edbc119880eb0a7e563432314432cb775dNuno Lopes I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); 64b74668edbc119880eb0a7e563432314432cb775dNuno Lopes while (I != E) { 65b74668edbc119880eb0a7e563432314432cb775dNuno Lopes ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second); 66b74668edbc119880eb0a7e563432314432cb775dNuno Lopes delete R; 67b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 68b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 69b74668edbc119880eb0a7e563432314432cb775dNuno Lopes 70b74668edbc119880eb0a7e563432314432cb775dNuno Lopes { 71b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>::iterator 72b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar I = ObjCLayouts.begin(), E = ObjCLayouts.end(); 73b74668edbc119880eb0a7e563432314432cb775dNuno Lopes while (I != E) { 74b74668edbc119880eb0a7e563432314432cb775dNuno Lopes ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second); 75b74668edbc119880eb0a7e563432314432cb775dNuno Lopes delete R; 76b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 77b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 78b74668edbc119880eb0a7e563432314432cb775dNuno Lopes 79ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor // Destroy nested-name-specifiers. 801ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor for (llvm::FoldingSet<NestedNameSpecifier>::iterator 811ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor NNS = NestedNameSpecifiers.begin(), 821ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor NNSEnd = NestedNameSpecifiers.end(); 83e7dcd782df0e1cc3a63e429a866098e69db39153Douglas Gregor NNS != NNSEnd; 841ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor /* Increment in loop */) 851ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor (*NNS++).Destroy(*this); 86ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 87ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor if (GlobalNestedNameSpecifier) 88ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor GlobalNestedNameSpecifier->Destroy(*this); 89ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 90b26153c2b06934b6d39886cae2a379988d9c3e2bEli Friedman TUDecl->Destroy(*this); 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 932cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid 942cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorASTContext::setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source) { 952cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource.reset(Source.take()); 962cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::PrintStats() const { 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer fprintf(stderr, "*** AST Context Stats:\n"); 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer fprintf(stderr, " %d types total.\n", (int)Types.size()); 1017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 102dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned counts[] = { 103dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define TYPE(Name, Parent) 0, 104dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 105dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 106dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor 0 // Extra 107dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor }; 108c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0, e = Types.size(); i != e; ++i) { 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *T = Types[i]; 111dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor counts[(unsigned)T->getTypeClass()]++; 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 114dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned Idx = 0; 115dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned TotalBytes = 0; 116dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define TYPE(Name, Parent) \ 117dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor if (counts[Idx]) \ 118dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor fprintf(stderr, " %d %s types\n", (int)counts[Idx], #Name); \ 119dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor TotalBytes += counts[Idx] * sizeof(Name##Type); \ 120dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor ++Idx; 121dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 122dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 123dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor 124dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor fprintf(stderr, "Total bytes = %d\n", int(TotalBytes)); 1252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (ExternalSource.get()) { 1272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor fprintf(stderr, "\n"); 1282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource->PrintStats(); 1292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::InitBuiltinType(QualType &R, BuiltinType::Kind K) { 134f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff Types.push_back((R = QualType(new (*this,8) BuiltinType(K),0)).getTypePtr()); 1355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::InitBuiltinTypes() { 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(VoidTy.isNull() && "Context reinitialized?"); 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p19. 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(VoidTy, BuiltinType::Void); 1425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p2. 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(BoolTy, BuiltinType::Bool); 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p3. 14615b91764d08e886391c865c4a444d7b51141c284Eli Friedman if (LangOpts.CharIsSigned) 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_S); 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_U); 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p4. 1515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(SignedCharTy, BuiltinType::SChar); 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(ShortTy, BuiltinType::Short); 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(IntTy, BuiltinType::Int); 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongTy, BuiltinType::Long); 1555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongLongTy, BuiltinType::LongLong); 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p6. 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p10. 1655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(FloatTy, BuiltinType::Float); 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(DoubleTy, BuiltinType::Double); 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); 16864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 1692df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner // GNU extension, 128-bit integers. 1702df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(Int128Ty, BuiltinType::Int128); 1712df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); 1722df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner 1733a2503227c3db04a3619735127483263c1075ef7Chris Lattner if (LangOpts.CPlusPlus) // C++ 3.9.1p5 1743a2503227c3db04a3619735127483263c1075ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar); 1753a2503227c3db04a3619735127483263c1075ef7Chris Lattner else // C99 1763a2503227c3db04a3619735127483263c1075ef7Chris Lattner WCharTy = getFromTargetType(Target.getWCharType()); 17764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 178f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 179f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char16Ty, BuiltinType::Char16); 180f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 181f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16Ty = getFromTargetType(Target.getChar16Type()); 182f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 183f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 184f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char32Ty, BuiltinType::Char32); 185f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 186f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32Ty = getFromTargetType(Target.getChar32Type()); 187f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 1888e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // Placeholder type for functions. 189898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(OverloadTy, BuiltinType::Overload); 190898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 191898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Placeholder type for type-dependent expressions whose type is 192898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // completely unknown. No code should ever check a type against 193898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // DependentTy and users should never see it; however, it is here to 194898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // help diagnose failures to properly check for type-dependent 195898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // expressions. 196898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(DependentTy, BuiltinType::Dependent); 1978e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 198e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // Placeholder type for C++0x auto declarations whose real type has 199e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // not yet been deduced. 200e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson InitBuiltinType(UndeducedAutoTy, BuiltinType::UndeducedAuto); 201e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson 2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p11. 2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FloatComplexTy = getComplexType(FloatTy); 2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DoubleComplexTy = getComplexType(DoubleTy); 2055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongDoubleComplexTy = getComplexType(LongDoubleTy); 2068e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 2077e219e47de26346885d667131977bd9ca2d7662aSteve Naroff BuiltinVaListType = QualType(); 20814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 209de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // "Builtin" typedefs set by Sema::ActOnTranslationUnitScope(). 210de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCIdTypedefType = QualType(); 211de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClassTypedefType = QualType(); 212de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff 213de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // Builtin types for 'id' and 'Class'. 214de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); 215de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); 21614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 217a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = QualType(); 21833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 21933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // void * type 22033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian VoidPtrTy = getPointerType(VoidTy); 2216e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2226e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // nullptr type (C++0x 2.14.7) 2236e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 2245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2267caa6825f42a0f7e97d6fc06233133c42b218e46Douglas GregorVarDecl *ASTContext::getInstantiatedFromStaticDataMember(VarDecl *Var) { 2277caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Var->isStaticDataMember() && "Not a static data member"); 2287caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor llvm::DenseMap<VarDecl *, VarDecl *>::iterator Pos 2297caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor = InstantiatedFromStaticDataMember.find(Var); 2307caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor if (Pos == InstantiatedFromStaticDataMember.end()) 2317caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return 0; 2327caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 2337caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return Pos->second; 2347caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 2357caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 2367caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregorvoid 2377caa6825f42a0f7e97d6fc06233133c42b218e46Douglas GregorASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl) { 2387caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Inst->isStaticDataMember() && "Not a static data member"); 2397caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Tmpl->isStaticDataMember() && "Not a static data member"); 2407caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(!InstantiatedFromStaticDataMember[Inst] && 2417caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor "Already noted what static data member was instantiated from"); 2427caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor InstantiatedFromStaticDataMember[Inst] = Tmpl; 2437caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 2447caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 2452e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregornamespace { 2462e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor class BeforeInTranslationUnit 2472e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor : std::binary_function<SourceRange, SourceRange, bool> { 2482e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceManager *SourceMgr; 2492e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2502e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor public: 2512e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor explicit BeforeInTranslationUnit(SourceManager *SM) : SourceMgr(SM) { } 2522e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2532e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor bool operator()(SourceRange X, SourceRange Y) { 2542e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return SourceMgr->isBeforeInTranslationUnit(X.getBegin(), Y.getBegin()); 2552e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 2562e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor }; 2572e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor} 2582e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2592e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \brief Determine whether the given comment is a Doxygen-style comment. 2602e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// 2612e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \param Start the start of the comment text. 2622e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// 2632e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \param End the end of the comment text. 2642e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// 2652e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \param Member whether we want to check whether this is a member comment 2662e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// (which requires a < after the Doxygen-comment delimiter). Otherwise, 2672e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// we only return true when we find a non-member comment. 2682e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregorstatic bool 2692e22253e03e175144aeb9d13350a12fd83f858beDouglas GregorisDoxygenComment(SourceManager &SourceMgr, SourceRange Comment, 2702e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor bool Member = false) { 2712e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor const char *BufferStart 2722e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin())).first; 2732e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor const char *Start = BufferStart + SourceMgr.getFileOffset(Comment.getBegin()); 2742e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor const char* End = BufferStart + SourceMgr.getFileOffset(Comment.getEnd()); 2752e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2762e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (End - Start < 4) 2772e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return false; 2782e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2792e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor assert(Start[0] == '/' && "Not a comment?"); 2802e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Start[1] == '*' && !(Start[2] == '!' || Start[2] == '*')) 2812e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return false; 2822e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Start[1] == '/' && !(Start[2] == '!' || Start[2] == '/')) 2832e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return false; 2842e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2852e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return (Start[3] == '<') == Member; 2862e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor} 2872e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2882e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \brief Retrieve the comment associated with the given declaration, if 2892e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// it has one. 2902e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregorconst char *ASTContext::getCommentForDecl(const Decl *D) { 2912e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!D) 2922e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 2932e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 2942e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Check whether we have cached a comment string for this declaration 2952e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // already. 2962e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor llvm::DenseMap<const Decl *, std::string>::iterator Pos 2972e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = DeclComments.find(D); 2982e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Pos != DeclComments.end()) 2992e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return Pos->second.c_str(); 3002e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3012e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If we have an external AST source and have not yet loaded comments from 3022e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // that source, do so now. 3032e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (ExternalSource && !LoadedExternalComments) { 3042e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::vector<SourceRange> LoadedComments; 3052e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ExternalSource->ReadComments(LoadedComments); 3062e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3072e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!LoadedComments.empty()) 3082e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Comments.insert(Comments.begin(), LoadedComments.begin(), 3092e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LoadedComments.end()); 3102e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3112e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LoadedExternalComments = true; 3122e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 3132e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3142e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If there are no comments anywhere, we won't find anything. 3152e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Comments.empty()) 3162e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3172e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3182e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the declaration doesn't map directly to a location in a file, we 3192e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // can't find the comment. 3202e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceLocation DeclStartLoc = D->getLocStart(); 3212e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (DeclStartLoc.isInvalid() || !DeclStartLoc.isFileID()) 3222e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3232e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3242e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Find the comment that occurs just before this declaration. 3252e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::vector<SourceRange>::iterator LastComment 3262e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = std::lower_bound(Comments.begin(), Comments.end(), 3272e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceRange(DeclStartLoc), 3282e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor BeforeInTranslationUnit(&SourceMgr)); 3292e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3302e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Decompose the location for the start of the declaration and find the 3312e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // beginning of the file buffer. 3322e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> DeclStartDecomp 3332e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(DeclStartLoc); 3342e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor const char *FileBufferStart 3352e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getBufferData(DeclStartDecomp.first).first; 3362e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3372e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // First check whether we have a comment for a member. 3382e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (LastComment != Comments.end() && 3392e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor !isa<TagDecl>(D) && !isa<NamespaceDecl>(D) && 3402e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor isDoxygenComment(SourceMgr, *LastComment, true)) { 3412e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> LastCommentEndDecomp 3422e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(LastComment->getEnd()); 3432e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (DeclStartDecomp.first == LastCommentEndDecomp.first && 3442e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second) 3452e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor == SourceMgr.getLineNumber(LastCommentEndDecomp.first, 3462e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LastCommentEndDecomp.second)) { 3472e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // The Doxygen member comment comes after the declaration starts and 3482e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // is on the same line and in the same file as the declaration. This 3492e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // is the comment we want. 3502e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::string &Result = DeclComments[D]; 3512e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Result.append(FileBufferStart + 3522e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceMgr.getFileOffset(LastComment->getBegin()), 3532e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor FileBufferStart + LastCommentEndDecomp.second + 1); 3542e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return Result.c_str(); 3552e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 3562e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 3572e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3582e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (LastComment == Comments.begin()) 3592e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3602e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor --LastComment; 3612e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3622e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Decompose the end of the comment. 3632e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> LastCommentEndDecomp 3642e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(LastComment->getEnd()); 3652e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3662e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the comment and the declaration aren't in the same file, then they 3672e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // aren't related. 3682e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (DeclStartDecomp.first != LastCommentEndDecomp.first) 3692e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3702e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3712e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Check that we actually have a Doxygen comment. 3722e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!isDoxygenComment(SourceMgr, *LastComment)) 3732e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3742e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3752e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Compute the starting line for the declaration and for the end of the 3762e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // comment (this is expensive). 3772e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor unsigned DeclStartLine 3782e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second); 3792e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor unsigned CommentEndLine 3802e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getLineNumber(LastCommentEndDecomp.first, 3812e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LastCommentEndDecomp.second); 3822e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3832e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the comment does not end on the line prior to the declaration, then 3842e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // the comment is not associated with the declaration at all. 3852e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (CommentEndLine + 1 != DeclStartLine) 3862e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3872e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3882e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // We have a comment, but there may be more comments on the previous lines. 3892e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Keep looking so long as the comments are still Doxygen comments and are 3902e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // still adjacent. 3912e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor unsigned ExpectedLine 3922e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getSpellingLineNumber(LastComment->getBegin()) - 1; 3932e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::vector<SourceRange>::iterator FirstComment = LastComment; 3942e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor while (FirstComment != Comments.begin()) { 3952e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Look at the previous comment 3962e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor --FirstComment; 3972e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> Decomp 3982e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); 3992e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4002e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If this previous comment is in a different file, we're done. 4012e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Decomp.first != DeclStartDecomp.first) { 4022e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4032e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor break; 4042e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4052e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4062e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If this comment is not a Doxygen comment, we're done. 4072e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!isDoxygenComment(SourceMgr, *FirstComment)) { 4082e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4092e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor break; 4102e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4112e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4122e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the line number is not what we expected, we're done. 4132e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor unsigned Line = SourceMgr.getLineNumber(Decomp.first, Decomp.second); 4142e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Line != ExpectedLine) { 4152e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4162e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor break; 4172e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4182e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4192e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Set the next expected line number. 4202e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ExpectedLine 4212e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getSpellingLineNumber(FirstComment->getBegin()) - 1; 4222e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4232e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4242e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // The iterator range [FirstComment, LastComment] contains all of the 4252e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // BCPL comments that, together, are associated with this declaration. 4262e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Form a single comment block string for this declaration that concatenates 4272e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // all of these comments. 4282e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::string &Result = DeclComments[D]; 4292e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor while (FirstComment != LastComment) { 4302e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> DecompStart 4312e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(FirstComment->getBegin()); 4322e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> DecompEnd 4332e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); 4342e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Result.append(FileBufferStart + DecompStart.second, 4352e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor FileBufferStart + DecompEnd.second + 1); 4362e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4372e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4382e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4392e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Append the last comment line. 4402e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Result.append(FileBufferStart + 4412e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceMgr.getFileOffset(LastComment->getBegin()), 4422e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor FileBufferStart + LastCommentEndDecomp.second + 1); 4432e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return Result.c_str(); 4442e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor} 4452e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 446464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 447464175bba1318bef7905122e9fda20cff926df78Chris Lattner// Type Sizing and Analysis 448464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 449a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 450b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 451b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// scalar floating point type. 452b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattnerconst llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 453b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner const BuiltinType *BT = T->getAsBuiltinType(); 454b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(BT && "Not a floating point type!"); 455b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner switch (BT->getKind()) { 456b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner default: assert(0 && "Not a floating point type!"); 457b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case BuiltinType::Float: return Target.getFloatFormat(); 458b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case BuiltinType::Double: return Target.getDoubleFormat(); 459b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case BuiltinType::LongDouble: return Target.getLongDoubleFormat(); 460b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 461b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 462b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 463af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// getDeclAlign - Return a conservative estimate of the alignment of the 464af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// specified decl. Note that bitfields do not have a valid alignment, so 465af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// this method will assert on them. 466b7d0844c887a72064b624dc6df12cbe1441f69d0Daniel Dunbarunsigned ASTContext::getDeclAlignInBytes(const Decl *D) { 467dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman unsigned Align = Target.getCharWidth(); 468dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 46940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (const AlignedAttr* AA = D->getAttr<AlignedAttr>()) 470dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman Align = std::max(Align, AA->getAlignment()); 471dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 472af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 473af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner QualType T = VD->getType(); 4746217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType* RT = T->getAs<ReferenceType>()) { 4754cc2cfd48d7c2d11141871cad590db7b52ce00a0Anders Carlsson unsigned AS = RT->getPointeeType().getAddressSpace(); 476f0930235ce58a91aa3b840bece9052f44d630536Anders Carlsson Align = Target.getPointerAlign(AS); 4774cc2cfd48d7c2d11141871cad590db7b52ce00a0Anders Carlsson } else if (!T->isIncompleteType() && !T->isFunctionType()) { 4784cc2cfd48d7c2d11141871cad590db7b52ce00a0Anders Carlsson // Incomplete or function types default to 1. 479dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman while (isa<VariableArrayType>(T) || isa<IncompleteArrayType>(T)) 480dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman T = cast<ArrayType>(T)->getElementType(); 481dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 482dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); 483dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman } 484af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner } 485dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 486dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman return Align / Target.getCharWidth(); 487af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner} 488b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 489a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner/// getTypeSize - Return the size of the specified type, in bits. This method 490a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner/// does not work on incomplete types. 491d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattnerstd::pair<uint64_t, unsigned> 4921d75118af76cae2bfc06389cde410e14bd0a19fcDaniel DunbarASTContext::getTypeInfo(const Type *T) { 4935e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump uint64_t Width=0; 4945e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump unsigned Align=8; 495a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (T->getTypeClass()) { 49672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 49772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 49818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor#define NON_CANONICAL_TYPE(Class, Base) 49972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 50072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 50118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor assert(false && "Should not see dependent types"); 50272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor break; 50372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 5045d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionNoProto: 5055d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionProto: 50618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(function) = 32 bits 50718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 50818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 32; 50918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 51018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 51172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 512fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::VariableArray: 51318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 51418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = getTypeAlign(cast<ArrayType>(T)->getElementType()); 51518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 51618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 5177e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor case Type::ConstantArrayWithExpr: 5187e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor case Type::ConstantArrayWithoutExpr: 519fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::ConstantArray: { 5201d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ConstantArrayType *CAT = cast<ConstantArrayType>(T); 521030d8846c7e520330007087e949f621989876e3aChris Lattner 52298be4943e8dc4f3905629a7102668960873cf863Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType()); 5239e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*CAT->getSize().getZExtValue(); 524030d8846c7e520330007087e949f621989876e3aChris Lattner Align = EltInfo.second; 525030d8846c7e520330007087e949f621989876e3aChris Lattner break; 5265c09a02a5db85e08a432b6eeced9aa656349710dChristopher Lamb } 527213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case Type::ExtVector: 528030d8846c7e520330007087e949f621989876e3aChris Lattner case Type::Vector: { 529030d8846c7e520330007087e949f621989876e3aChris Lattner std::pair<uint64_t, unsigned> EltInfo = 53098be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<VectorType>(T)->getElementType()); 5319e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*cast<VectorType>(T)->getNumElements(); 5324bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman Align = Width; 5336fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // If the alignment is not a power of 2, round up to the next power of 2. 5346fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // This happens for non-power-of-2 length vectors. 5356fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // FIXME: this should probably be a target property. 5366fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman Align = 1 << llvm::Log2_32_Ceil(Align); 537030d8846c7e520330007087e949f621989876e3aChris Lattner break; 538030d8846c7e520330007087e949f621989876e3aChris Lattner } 5395d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner 5409e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner case Type::Builtin: 541a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 542692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner default: assert(0 && "Unknown builtin type!"); 543d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner case BuiltinType::Void: 54418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(void) = 8 bits. 54518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 54618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 8; 54718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 54818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 5496f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Bool: 5509e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getBoolWidth(); 5519e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getBoolAlign(); 5526f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 553692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_S: 554692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_U: 555692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UChar: 5566f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::SChar: 5579e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getCharWidth(); 5589e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getCharAlign(); 5596f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 56064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis case BuiltinType::WChar: 56164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Width = Target.getWCharWidth(); 56264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Align = Target.getWCharAlign(); 56364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis break; 564f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char16: 565f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Width = Target.getChar16Width(); 566f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Align = Target.getChar16Align(); 567f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 568f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char32: 569f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Width = Target.getChar32Width(); 570f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Align = Target.getChar32Align(); 571f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 572692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UShort: 5736f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Short: 5749e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getShortWidth(); 5759e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getShortAlign(); 5766f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 577692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UInt: 5786f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Int: 5799e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getIntWidth(); 5809e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getIntAlign(); 5816f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 582692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULong: 5836f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Long: 5849e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getLongWidth(); 5859e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getLongAlign(); 5866f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 587692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULongLong: 5886f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongLong: 5899e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getLongLongWidth(); 5909e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getLongLongAlign(); 5916f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 592ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::Int128: 593ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::UInt128: 594ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Width = 128; 595ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Align = 128; // int128_t is 128-bit aligned on all targets. 596ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner break; 5976f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Float: 5989e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getFloatWidth(); 5999e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getFloatAlign(); 6006f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 6016f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Double: 6025426bf6456a5aeac416a9150de157904d101c819Chris Lattner Width = Target.getDoubleWidth(); 6035426bf6456a5aeac416a9150de157904d101c819Chris Lattner Align = Target.getDoubleAlign(); 6046f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 6056f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongDouble: 6069e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getLongDoubleWidth(); 6079e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getLongDoubleAlign(); 6086f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 6096e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case BuiltinType::NullPtr: 6106e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl Width = Target.getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) 6116e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl Align = Target.getPointerAlign(0); // == sizeof(void*) 6121590d9c0fec4c710c2962e4bb71f76979b5163d3Sebastian Redl break; 613a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 614bfef6d7c67831a135d6ab79931f010f750a730adChris Lattner break; 615f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman case Type::FixedWidthInt: 616f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // FIXME: This isn't precisely correct; the width/alignment should depend 617f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // on the available types for the target 618f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width = cast<FixedWidthIntType>(T)->getWidth(); 619736166b38235cf6d0ffb67638960d95fb2afcbd6Chris Lattner Width = std::max(llvm::NextPowerOf2(Width - 1), (uint64_t)8); 620f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Align = Width; 621f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman break; 622f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian case Type::ExtQual: 62398be4943e8dc4f3905629a7102668960873cf863Chris Lattner // FIXME: Pointers into different addr spaces could have different sizes and 62498be4943e8dc4f3905629a7102668960873cf863Chris Lattner // alignment requirements: getPointerInfo should take an AddrSpace. 625f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian return getTypeInfo(QualType(cast<ExtQualType>(T)->getBaseType(), 0)); 626d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case Type::ObjCObjectPointer: 6275426bf6456a5aeac416a9150de157904d101c819Chris Lattner Width = Target.getPointerWidth(0); 628f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner Align = Target.getPointerAlign(0); 6296f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 630485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff case Type::BlockPointer: { 631485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff unsigned AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace(); 632485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff Width = Target.getPointerWidth(AS); 633485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff Align = Target.getPointerAlign(AS); 634485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff break; 635485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff } 636f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner case Type::Pointer: { 637f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner unsigned AS = cast<PointerType>(T)->getPointeeType().getAddressSpace(); 6385426bf6456a5aeac416a9150de157904d101c819Chris Lattner Width = Target.getPointerWidth(AS); 639f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner Align = Target.getPointerAlign(AS); 640f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner break; 641f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner } 6427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 6437c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 6447ab2ed8e881ffdc84e890f5265c41b930df17ceeChris Lattner // "When applied to a reference or a reference type, the result is the size 6455d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // of the referenced type." C++98 5.3.3p2: expr.sizeof. 6466f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner // FIXME: This is wrong for struct layout: a reference in a struct has 6476f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner // pointer size. 648bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return getTypeInfo(cast<ReferenceType>(T)->getPointeeType()); 649f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case Type::MemberPointer: { 6501cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson // FIXME: This is ABI dependent. We use the Itanium C++ ABI. 6511cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson // http://www.codesourcery.com/public/cxx-abi/abi.html#member-pointers 6521cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson // If we ever want to support other ABIs this needs to be abstracted. 6531cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson 654f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Pointee = cast<MemberPointerType>(T)->getPointeeType(); 6551cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson std::pair<uint64_t, unsigned> PtrDiffInfo = 6561cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson getTypeInfo(getPointerDiffType()); 6571cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Width = PtrDiffInfo.first; 658f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (Pointee->isFunctionType()) 659f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Width *= 2; 6601cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Align = PtrDiffInfo.second; 6611cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson break; 662f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 6635d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::Complex: { 6645d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // Complex types have the same alignment as their elements, but twice the 6655d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // size. 6665d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner std::pair<uint64_t, unsigned> EltInfo = 66798be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<ComplexType>(T)->getElementType()); 6689e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*2; 6695d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner Align = EltInfo.second; 6705d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner break; 6715d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner } 67244a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel case Type::ObjCInterface: { 6731d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); 67444a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); 67544a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel Width = Layout.getSize(); 67644a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel Align = Layout.getAlignment(); 67744a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel break; 67844a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel } 67972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 68072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: { 6811d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const TagType *TT = cast<TagType>(T); 6821d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar 6831d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (TT->getDecl()->isInvalidDecl()) { 6848389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner Width = 1; 6858389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner Align = 1; 6868389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner break; 6878389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner } 6888389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner 6891d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (const EnumType *ET = dyn_cast<EnumType>(TT)) 6907176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner return getTypeInfo(ET->getDecl()->getIntegerType()); 6917176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner 6921d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const RecordType *RT = cast<RecordType>(TT); 6937176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 6947176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner Width = Layout.getSize(); 6957176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner Align = Layout.getAlignment(); 696dc0d73e6495404418acf8548875aeaff07791a74Chris Lattner break; 697a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 6987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 69918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::Typedef: { 70018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); 70140b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>()) { 70218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = Aligned->getAlignment(); 70318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr()); 70418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } else 70518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 7067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 7077176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner } 70818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 70918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOfExpr: 71018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType() 71118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor .getTypePtr()); 71218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 71318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOf: 71418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfType>(T)->getUnderlyingType().getTypePtr()); 71518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 716395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson case Type::Decltype: 717395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return getTypeInfo(cast<DecltypeType>(T)->getUnderlyingExpr()->getType() 718395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson .getTypePtr()); 719395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 72018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::QualifiedName: 72118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<QualifiedNameType>(T)->getNamedType().getTypePtr()); 72218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 72318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TemplateSpecialization: 72418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor assert(getCanonicalType(T) != T && 72518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor "Cannot request the size of a dependent type"); 72618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // FIXME: this is likely to be wrong once we support template 72718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // aliases, since a template alias could refer to a typedef that 72818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // has an __aligned__ attribute on it. 72918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(getCanonicalType(T)); 73018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } 731d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner 732464175bba1318bef7905122e9fda20cff926df78Chris Lattner assert(Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2"); 7339e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner return std::make_pair(Width, Align); 734a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner} 735a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 73634ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// getPreferredTypeAlign - Return the "preferred" alignment of the specified 73734ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// type for the current target in bits. This can be different than the ABI 73834ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// alignment in cases where it is beneficial for performance to overalign 73934ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// a data type. 74034ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattnerunsigned ASTContext::getPreferredTypeAlign(const Type *T) { 74134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner unsigned ABIAlign = getTypeAlign(T); 7421eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 7431eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman // Double and long long should be naturally aligned if possible. 7441eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman if (const ComplexType* CT = T->getAsComplexType()) 7451eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T = CT->getElementType().getTypePtr(); 7461eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::Double) || 7471eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T->isSpecificBuiltinType(BuiltinType::LongLong)) 7481eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman return std::max(ABIAlign, (unsigned)getTypeSize(T)); 7491eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 75034ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner return ABIAlign; 75134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner} 75234ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner 753a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbarstatic void CollectLocalObjCIvars(ASTContext *Ctx, 754a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar const ObjCInterfaceDecl *OI, 755a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar llvm::SmallVectorImpl<FieldDecl*> &Fields) { 756a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 757a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian E = OI->ivar_end(); I != E; ++I) { 758f1690858344968358131f8d5690d9ee458883000Chris Lattner ObjCIvarDecl *IVDecl = *I; 759a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian if (!IVDecl->isInvalidDecl()) 760a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian Fields.push_back(cast<FieldDecl>(IVDecl)); 761a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian } 762a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian} 763a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian 764a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbarvoid ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI, 765a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar llvm::SmallVectorImpl<FieldDecl*> &Fields) { 766a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) 767a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar CollectObjCIvars(SuperClass, Fields); 768a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar CollectLocalObjCIvars(this, OI, Fields); 769a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar} 770a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar 7718e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian/// ShallowCollectObjCIvars - 7728e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian/// Collect all ivars, including those synthesized, in the current class. 7738e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian/// 7748e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanianvoid ASTContext::ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI, 7758e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars, 7768e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian bool CollectSynthesized) { 7778e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 7788e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian E = OI->ivar_end(); I != E; ++I) { 7798e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian Ivars.push_back(*I); 7808e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian } 7818e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if (CollectSynthesized) 7828e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian CollectSynthesizedIvars(OI, Ivars); 7838e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 7848e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 7859820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanianvoid ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD, 7869820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { 78717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(), 78817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = PD->prop_end(); I != E; ++I) 7899820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 7909820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian Ivars.push_back(Ivar); 7919820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 7929820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian // Also look into nested protocols. 7939820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 7949820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian E = PD->protocol_end(); P != E; ++P) 7959820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian CollectProtocolSynthesizedIvars(*P, Ivars); 7969820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 7979820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 7989820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// CollectSynthesizedIvars - 7999820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// This routine collect synthesized ivars for the designated class. 8009820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// 8019820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanianvoid ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI, 8029820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { 80317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(), 80417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = OI->prop_end(); I != E; ++I) { 8059820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 8069820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian Ivars.push_back(Ivar); 8079820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian } 8089820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian // Also look into interface's protocol list for properties declared 8099820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian // in the protocol and whose ivars are synthesized. 8109820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 8119820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian PE = OI->protocol_end(); P != PE; ++P) { 8129820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian ObjCProtocolDecl *PD = (*P); 8139820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian CollectProtocolSynthesizedIvars(PD, Ivars); 8149820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian } 8159820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 8169820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 8178e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanianunsigned ASTContext::CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD) { 8188e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian unsigned count = 0; 81917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(), 82017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = PD->prop_end(); I != E; ++I) 8218e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if ((*I)->getPropertyIvarDecl()) 8228e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian ++count; 8238e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8248e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian // Also look into nested protocols. 8258e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 8268e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian E = PD->protocol_end(); P != E; ++P) 8278e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian count += CountProtocolSynthesizedIvars(*P); 8288e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 8298e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 8308e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8318e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanianunsigned ASTContext::CountSynthesizedIvars(const ObjCInterfaceDecl *OI) 8328e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian{ 8338e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian unsigned count = 0; 83417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(), 83517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = OI->prop_end(); I != E; ++I) { 8368e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if ((*I)->getPropertyIvarDecl()) 8378e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian ++count; 8388e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian } 8398e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian // Also look into interface's protocol list for properties declared 8408e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian // in the protocol and whose ivars are synthesized. 8418e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 8428e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian PE = OI->protocol_end(); P != PE; ++P) { 8438e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian ObjCProtocolDecl *PD = (*P); 8448e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian count += CountProtocolSynthesizedIvars(PD); 8458e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian } 8468e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 8478e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 8488e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8498a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 8508a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCImplementationDecl *ASTContext::getObjCImplementation(ObjCInterfaceDecl *D) { 8518a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 8528a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 8538a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 8548a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCImplementationDecl>(I->second); 8558a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 8568a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 8578a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 8588a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCCategoryImplDecl *ASTContext::getObjCImplementation(ObjCCategoryDecl *D) { 8598a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 8608a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 8618a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 8628a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCCategoryImplDecl>(I->second); 8638a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 8648a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 8658a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 8668a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCInterfaceDecl. 8678a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCInterfaceDecl *IFaceD, 8688a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *ImplD) { 8698a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(IFaceD && ImplD && "Passed null params"); 8708a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[IFaceD] = ImplD; 8718a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 8728a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCCategoryDecl. 8738a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCCategoryDecl *CatD, 8748a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *ImplD) { 8758a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(CatD && ImplD && "Passed null params"); 8768a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[CatD] = ImplD; 8778a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 8788a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 879b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Allocate an uninitialized DeclaratorInfo. 880b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 881b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// The caller should initialize the memory held by DeclaratorInfo using 882b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// the TypeLoc wrappers. 883b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 884b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \param T the type that will be the basis for type source info. This type 885b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// should refer to how the declarator was written in source code, not to 886b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// what type semantic analysis resolved the declarator to. 887b17166c8077cd900cca83a895c43b30ea6660598Argyrios KyrtzidisDeclaratorInfo *ASTContext::CreateDeclaratorInfo(QualType T) { 888b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis unsigned DataSize = TypeLoc::getFullDataSizeForType(T); 889b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis DeclaratorInfo *DInfo = 890b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis (DeclaratorInfo*)BumpAlloc.Allocate(sizeof(DeclaratorInfo) + DataSize, 8); 891b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis new (DInfo) DeclaratorInfo(T); 892b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return DInfo; 893b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 894b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 895b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// getInterfaceLayoutImpl - Get or compute information about the 896b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// layout of the given interface. 897b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// 898b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// \param Impl - If given, also include the layout of the interface's 899b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// implementation. This may differ by including synthesized ivars. 90044a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patelconst ASTRecordLayout & 901b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel DunbarASTContext::getObjCLayout(const ObjCInterfaceDecl *D, 902b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar const ObjCImplementationDecl *Impl) { 903532d4daa038d972240138e2fd6e1122517340833Daniel Dunbar assert(!D->isForwardDecl() && "Invalid interface decl!"); 904532d4daa038d972240138e2fd6e1122517340833Daniel Dunbar 90544a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel // Look up this layout, if already laid out, return what we have. 906d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar ObjCContainerDecl *Key = 907d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar Impl ? (ObjCContainerDecl*) Impl : (ObjCContainerDecl*) D; 908d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar if (const ASTRecordLayout *Entry = ObjCLayouts[Key]) 909d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar return *Entry; 91044a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel 911453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // Add in synthesized ivar count if laying out an implementation. 912453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar if (Impl) { 91329445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson unsigned FieldCount = D->ivar_size(); 9148e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian unsigned SynthCount = CountSynthesizedIvars(D); 9158e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian FieldCount += SynthCount; 916d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar // If there aren't any sythesized ivars then reuse the interface 917453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // entry. Note we can't cache this because we simply free all 918453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // entries later; however we shouldn't look up implementations 919453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // frequently. 9208e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if (SynthCount == 0) 921453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar return getObjCLayout(D, 0); 922453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar } 923453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar 92429445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson const ASTRecordLayout *NewEntry = 92529445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson ASTRecordLayoutBuilder::ComputeLayout(*this, D, Impl); 92629445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson ObjCLayouts[Key] = NewEntry; 92729445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson 92844a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel return *NewEntry; 92944a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel} 93044a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel 931b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 932b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel DunbarASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) { 933b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D, 0); 934b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 935b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 936b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 937b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel DunbarASTContext::getASTObjCImplementationLayout(const ObjCImplementationDecl *D) { 938b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D->getClassInterface(), D); 939b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 940b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 94188a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel/// getASTRecordLayout - Get or compute information about the layout of the 942464175bba1318bef7905122e9fda20cff926df78Chris Lattner/// specified record (struct/union/class), which indicates its size and field 943464175bba1318bef7905122e9fda20cff926df78Chris Lattner/// position information. 94498be4943e8dc4f3905629a7102668960873cf863Chris Lattnerconst ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) { 9454b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek D = D->getDefinition(*this); 9464b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek assert(D && "Cannot get layout of forward declarations!"); 9474bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman 948464175bba1318bef7905122e9fda20cff926df78Chris Lattner // Look up this layout, if already laid out, return what we have. 949ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman // Note that we can't save a reference to the entry because this function 950ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman // is recursive. 951ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman const ASTRecordLayout *Entry = ASTRecordLayouts[D]; 952464175bba1318bef7905122e9fda20cff926df78Chris Lattner if (Entry) return *Entry; 9534bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman 95429445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson const ASTRecordLayout *NewEntry = 95529445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson ASTRecordLayoutBuilder::ComputeLayout(*this, D); 956ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman ASTRecordLayouts[D] = NewEntry; 95729445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson 9585d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner return *NewEntry; 959464175bba1318bef7905122e9fda20cff926df78Chris Lattner} 960464175bba1318bef7905122e9fda20cff926df78Chris Lattner 961a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 962a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner// Type creation/memoization methods 963a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 964a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 965f11284ac87daa613bc7b30db9f54bd716d123222Fariborz JahanianQualType ASTContext::getAddrSpaceQualType(QualType T, unsigned AddressSpace) { 966f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType CanT = getCanonicalType(T); 967f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner if (CanT.getAddressSpace() == AddressSpace) 968f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return T; 969b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 970b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // If we are composing extended qualifiers together, merge together into one 971b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // ExtQualType node. 972b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner unsigned CVRQuals = T.getCVRQualifiers(); 973b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner QualType::GCAttrTypes GCAttr = QualType::GCNone; 974b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type *TypeNode = T.getTypePtr(); 975b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 976b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (ExtQualType *EQT = dyn_cast<ExtQualType>(TypeNode)) { 977b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // If this type already has an address space specified, it cannot get 978b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // another one. 979b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(EQT->getAddressSpace() == 0 && 980b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner "Type cannot be in multiple addr spaces!"); 981b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner GCAttr = EQT->getObjCGCAttr(); 982b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner TypeNode = EQT->getBaseType(); 983b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 984f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner 985b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // Check if we've already instantiated this type. 986ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb llvm::FoldingSetNodeID ID; 9872455636163fdd18581d7fdae816433f886d88213Mike Stump ExtQualType::Profile(ID, TypeNode, AddressSpace, GCAttr); 988ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb void *InsertPos = 0; 989f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (ExtQualType *EXTQy = ExtQualTypes.FindNodeOrInsertPos(ID, InsertPos)) 990b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return QualType(EXTQy, CVRQuals); 991b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 992ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // If the base type isn't canonical, this won't be a canonical type either, 993ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb // so fill in the canonical type field. 994ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb QualType Canonical; 995b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (!TypeNode->isCanonical()) { 996f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian Canonical = getAddrSpaceQualType(CanT, AddressSpace); 997ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 998b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // Update InsertPos, the previous call could have invalidated it. 999f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian ExtQualType *NewIP = ExtQualTypes.FindNodeOrInsertPos(ID, InsertPos); 1000f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 1001ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb } 1002b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner ExtQualType *New = 1003b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner new (*this, 8) ExtQualType(TypeNode, Canonical, AddressSpace, GCAttr); 1004f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian ExtQualTypes.InsertNode(New, InsertPos); 1005ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb Types.push_back(New); 1006b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return QualType(New, CVRQuals); 1007ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1008ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1009b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris LattnerQualType ASTContext::getObjCGCQualType(QualType T, 1010b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner QualType::GCAttrTypes GCAttr) { 1011d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CanT = getCanonicalType(T); 1012b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (CanT.getObjCGCAttr() == GCAttr) 1013d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return T; 1014d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 10154027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian if (T->isPointerType()) { 10166217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType Pointee = T->getAs<PointerType>()->getPointeeType(); 101758f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff if (Pointee->isAnyPointerType()) { 10184027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian QualType ResultType = getObjCGCQualType(Pointee, GCAttr); 10194027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian return getPointerType(ResultType); 10204027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 10214027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 1022b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // If we are composing extended qualifiers together, merge together into one 1023b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // ExtQualType node. 1024b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner unsigned CVRQuals = T.getCVRQualifiers(); 1025b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Type *TypeNode = T.getTypePtr(); 1026b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner unsigned AddressSpace = 0; 1027b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 1028b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (ExtQualType *EQT = dyn_cast<ExtQualType>(TypeNode)) { 10292455636163fdd18581d7fdae816433f886d88213Mike Stump // If this type already has an ObjCGC specified, it cannot get 1030b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // another one. 1031b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner assert(EQT->getObjCGCAttr() == QualType::GCNone && 10322455636163fdd18581d7fdae816433f886d88213Mike Stump "Type cannot have multiple ObjCGCs!"); 1033b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner AddressSpace = EQT->getAddressSpace(); 1034b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner TypeNode = EQT->getBaseType(); 1035b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner } 1036d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1037d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian // Check if we've already instantiated an gc qual'd type of this type. 1038d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian llvm::FoldingSetNodeID ID; 10392455636163fdd18581d7fdae816433f886d88213Mike Stump ExtQualType::Profile(ID, TypeNode, AddressSpace, GCAttr); 1040d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian void *InsertPos = 0; 1041d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (ExtQualType *EXTQy = ExtQualTypes.FindNodeOrInsertPos(ID, InsertPos)) 1042b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return QualType(EXTQy, CVRQuals); 1043d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1044d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian // If the base type isn't canonical, this won't be a canonical type either, 1045d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian // so fill in the canonical type field. 10465a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: Isn't this also not canonical if the base type is a array 10475a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // or pointer type? I can't find any documentation for objc_gc, though... 1048d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType Canonical; 1049d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian if (!T->isCanonical()) { 1050b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner Canonical = getObjCGCQualType(CanT, GCAttr); 1051d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian 1052b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner // Update InsertPos, the previous call could have invalidated it. 1053d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian ExtQualType *NewIP = ExtQualTypes.FindNodeOrInsertPos(ID, InsertPos); 1054d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 1055d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian } 1056b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner ExtQualType *New = 1057b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner new (*this, 8) ExtQualType(TypeNode, Canonical, AddressSpace, GCAttr); 1058d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian ExtQualTypes.InsertNode(New, InsertPos); 1059d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian Types.push_back(New); 1060b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return QualType(New, CVRQuals); 1061d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1062a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 10632455636163fdd18581d7fdae816433f886d88213Mike StumpQualType ASTContext::getNoReturnType(QualType T) { 10646dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump QualifierSet qs; 10656dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump qs.strip(T); 10662455636163fdd18581d7fdae816433f886d88213Mike Stump if (T->isPointerType()) { 10676217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType Pointee = T->getAs<PointerType>()->getPointeeType(); 10682455636163fdd18581d7fdae816433f886d88213Mike Stump QualType ResultType = getNoReturnType(Pointee); 10696dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump ResultType = getPointerType(ResultType); 10706dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump ResultType.setCVRQualifiers(T.getCVRQualifiers()); 10716dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump return qs.apply(ResultType, *this); 10722455636163fdd18581d7fdae816433f886d88213Mike Stump } 10732455636163fdd18581d7fdae816433f886d88213Mike Stump if (T->isBlockPointerType()) { 10746217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType Pointee = T->getAs<BlockPointerType>()->getPointeeType(); 10752455636163fdd18581d7fdae816433f886d88213Mike Stump QualType ResultType = getNoReturnType(Pointee); 10766dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump ResultType = getBlockPointerType(ResultType); 10776dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump ResultType.setCVRQualifiers(T.getCVRQualifiers()); 10786dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump return qs.apply(ResultType, *this); 10792455636163fdd18581d7fdae816433f886d88213Mike Stump } 10802455636163fdd18581d7fdae816433f886d88213Mike Stump if (!T->isFunctionType()) 10812455636163fdd18581d7fdae816433f886d88213Mike Stump assert(0 && "can't noreturn qualify non-pointer to function or block type"); 10822455636163fdd18581d7fdae816433f886d88213Mike Stump 1083e24aea225ec87b935ede6c21c964dd47a4afb810Mike Stump if (const FunctionNoProtoType *F = T->getAsFunctionNoProtoType()) { 10842455636163fdd18581d7fdae816433f886d88213Mike Stump return getFunctionNoProtoType(F->getResultType(), true); 10852455636163fdd18581d7fdae816433f886d88213Mike Stump } 1086e24aea225ec87b935ede6c21c964dd47a4afb810Mike Stump const FunctionProtoType *F = T->getAsFunctionProtoType(); 10872455636163fdd18581d7fdae816433f886d88213Mike Stump return getFunctionType(F->getResultType(), F->arg_type_begin(), 10882455636163fdd18581d7fdae816433f886d88213Mike Stump F->getNumArgs(), F->isVariadic(), F->getTypeQuals(), 10892455636163fdd18581d7fdae816433f886d88213Mike Stump F->hasExceptionSpec(), F->hasAnyExceptionSpec(), 10902455636163fdd18581d7fdae816433f886d88213Mike Stump F->getNumExceptions(), F->exception_begin(), true); 10912455636163fdd18581d7fdae816433f886d88213Mike Stump} 10922455636163fdd18581d7fdae816433f886d88213Mike Stump 10935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getComplexType - Return the uniqued reference to the type for a complex 10945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// number with the specified element type. 10955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getComplexType(QualType T) { 10965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 10975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 10985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 10995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType::Profile(ID, T); 11005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 11025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) 11035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(CT, 0); 11045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 11065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 11075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!T->isCanonical()) { 1109f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getComplexType(getCanonicalType(T)); 11105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 11125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); 1113f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 11145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1115f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff ComplexType *New = new (*this,8) ComplexType(T, Canonical); 11165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexTypes.InsertNode(New, InsertPos); 11185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 11195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1121f98aba35e6c3da5aae61843fc01334939e4e12ecEli FriedmanQualType ASTContext::getFixedWidthIntType(unsigned Width, bool Signed) { 1122f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman llvm::DenseMap<unsigned, FixedWidthIntType*> &Map = Signed ? 1123f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman SignedFixedWidthIntTypes : UnsignedFixedWidthIntTypes; 1124f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType *&Entry = Map[Width]; 1125f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (!Entry) 1126f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Entry = new FixedWidthIntType(Width, Signed); 1127f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return QualType(Entry, 0); 1128f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman} 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getPointerType - Return the uniqued reference to the type for a pointer to 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the specified type. 11325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getPointerType(QualType T) { 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType::Profile(ID, T); 11375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(PT, 0); 11415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 11435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!T->isCanonical()) { 1146f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getPointerType(getCanonicalType(T)); 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 11495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1150f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 11515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1152f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff PointerType *New = new (*this,8) PointerType(T, Canonical); 11535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerTypes.InsertNode(New, InsertPos); 11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11585618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// getBlockPointerType - Return the uniqued reference to the type for 11595618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// a pointer to the specified block. 11605618bd4a52c45fbbb605e3ba885663b2164db8a3Steve NaroffQualType ASTContext::getBlockPointerType(QualType T) { 1161296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff assert(T->isFunctionType() && "block of function types only"); 1162296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // Unique pointers, to guarantee there is only one block of a particular 11635618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // structure. 11645618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff llvm::FoldingSetNodeID ID; 11655618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType::Profile(ID, T); 11665618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 11675618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void *InsertPos = 0; 11685618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (BlockPointerType *PT = 11695618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 11705618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(PT, 0); 11715618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 1172296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // If the block pointee type isn't canonical, this won't be a canonical 11735618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // type either so fill in the canonical type field. 11745618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType Canonical; 11755618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (!T->isCanonical()) { 11765618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Canonical = getBlockPointerType(getCanonicalType(T)); 11775618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 11785618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the new insert position for the node we care about. 11795618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType *NewIP = 11805618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1181f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 11825618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 1183f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff BlockPointerType *New = new (*this,8) BlockPointerType(T, Canonical); 11845618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Types.push_back(New); 11855618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.InsertNode(New, InsertPos); 11865618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(New, 0); 11875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 11885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 11897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getLValueReferenceType - Return the uniqued reference to the type for an 11907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// lvalue reference to the specified type. 11917c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian RedlQualType ASTContext::getLValueReferenceType(QualType T) { 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ReferenceType::Profile(ID, T); 11965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 11987c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (LValueReferenceType *RT = 11997c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 12005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(RT, 0); 12017c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the referencee type isn't canonical, this won't be a canonical type 12035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // either, so fill in the canonical type field. 12045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 12055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!T->isCanonical()) { 12067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Canonical = getLValueReferenceType(getCanonicalType(T)); 12077c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Get the new insert position for the node we care about. 12097c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType *NewIP = 12107c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 12117c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 12127c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 12137c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12147c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType *New = new (*this,8) LValueReferenceType(T, Canonical); 12157c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Types.push_back(New); 12167c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.InsertNode(New, InsertPos); 12177c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(New, 0); 12187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 12197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getRValueReferenceType - Return the uniqued reference to the type for an 12217c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// rvalue reference to the specified type. 12227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian RedlQualType ASTContext::getRValueReferenceType(QualType T) { 12237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 12247c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // structure. 12257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl llvm::FoldingSetNodeID ID; 12267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType::Profile(ID, T); 12277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl void *InsertPos = 0; 12297c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (RValueReferenceType *RT = 12307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 12317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(RT, 0); 12327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12337c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // If the referencee type isn't canonical, this won't be a canonical type 12347c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // either, so fill in the canonical type field. 12357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl QualType Canonical; 12367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (!T->isCanonical()) { 12377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Canonical = getRValueReferenceType(getCanonicalType(T)); 12387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 12407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType *NewIP = 12417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 1242f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 12435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType *New = new (*this,8) RValueReferenceType(T, Canonical); 12465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 12477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.InsertNode(New, InsertPos); 12485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1251f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// getMemberPointerType - Return the uniqued reference to the type for a 1252f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// member pointer to the specified type, in the specified class. 1253f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian RedlQualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) 1254f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl{ 1255f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 1256f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // structure. 1257f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl llvm::FoldingSetNodeID ID; 1258f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType::Profile(ID, T, Cls); 1259f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1260f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *InsertPos = 0; 1261f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (MemberPointerType *PT = 1262f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 1263f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(PT, 0); 1264f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1265f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // If the pointee or class type isn't canonical, this won't be a canonical 1266f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type either, so fill in the canonical type field. 1267f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Canonical; 1268f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (!T->isCanonical()) { 1269f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls)); 1270f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1271f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Get the new insert position for the node we care about. 1272f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType *NewIP = 1273f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1274f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 1275f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 1276f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff MemberPointerType *New = new (*this,8) MemberPointerType(T, Cls, Canonical); 1277f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Types.push_back(New); 1278f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.InsertNode(New, InsertPos); 1279f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(New, 0); 1280f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1281f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1282fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff/// getConstantArrayType - Return the unique reference to the type for an 1283fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff/// array of the specified element type. 1284fb22d96692c5240fb8d611290dbf7eeed3759c73Steve NaroffQualType ASTContext::getConstantArrayType(QualType EltTy, 128538aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner const llvm::APInt &ArySizeIn, 1286c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 1287c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned EltTypeQuals) { 1288587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman assert((EltTy->isDependentType() || EltTy->isConstantSizeType()) && 1289587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman "Constant array of VLAs is illegal!"); 1290587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman 129138aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // Convert the array size into a canonical width matching the pointer size for 129238aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // the target. 129338aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner llvm::APInt ArySize(ArySizeIn); 129438aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); 129538aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 12970be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, EltTypeQuals); 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 13007192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek if (ConstantArrayType *ATP = 13017192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 13025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(ATP, 0); 13035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 13055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 13065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 13075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!EltTy->isCanonical()) { 1308f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getConstantArrayType(getCanonicalType(EltTy), ArySize, 1309c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ASM, EltTypeQuals); 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 13117192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayType *NewIP = 13127192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 1313f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 13145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1316566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek ConstantArrayType *New = 1317f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff new(*this,8)ConstantArrayType(EltTy, Canonical, ArySize, ASM, EltTypeQuals); 13187192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.InsertNode(New, InsertPos); 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 13215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// getConstantArrayWithExprType - Return a reference to the type for 13247e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// an array of the specified element type. 13257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType 13267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorASTContext::getConstantArrayWithExprType(QualType EltTy, 13277e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &ArySizeIn, 13287e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *ArySizeExpr, 13297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier ASM, 13307e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals, 13317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets) { 13327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Convert the array size into a canonical width matching the pointer 13337e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // size for the target. 13347e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor llvm::APInt ArySize(ArySizeIn); 13357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); 13367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13377e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Compute the canonical ConstantArrayType. 13387e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor QualType Canonical = getConstantArrayType(getCanonicalType(EltTy), 13397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize, ASM, EltTypeQuals); 13407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Since we don't unique expressions, it isn't possible to unique VLA's 13417e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // that have an expression provided for their size. 13427e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithExprType *New = 13437e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor new(*this,8)ConstantArrayWithExprType(EltTy, Canonical, 13447e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize, ArySizeExpr, 13457e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ASM, EltTypeQuals, Brackets); 13467e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Types.push_back(New); 13477e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return QualType(New, 0); 13487e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor} 13497e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13507e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// getConstantArrayWithoutExprType - Return a reference to the type for 13517e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// an array of the specified element type. 13527e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType 13537e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorASTContext::getConstantArrayWithoutExprType(QualType EltTy, 13547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &ArySizeIn, 13557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier ASM, 13567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals) { 13577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Convert the array size into a canonical width matching the pointer 13587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // size for the target. 13597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor llvm::APInt ArySize(ArySizeIn); 13607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); 13617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Compute the canonical ConstantArrayType. 13637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor QualType Canonical = getConstantArrayType(getCanonicalType(EltTy), 13647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize, ASM, EltTypeQuals); 13657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ConstantArrayWithoutExprType *New = 13667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor new(*this,8)ConstantArrayWithoutExprType(EltTy, Canonical, 13677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize, ASM, EltTypeQuals); 13687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Types.push_back(New); 13697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return QualType(New, 0); 13707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor} 13717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1372bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// getVariableArrayType - Returns a non-unique reference to the type for a 1373bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// variable array of the specified element type. 13747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getVariableArrayType(QualType EltTy, 13757e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 1376c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 13777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals, 13787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets) { 1379c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Since we don't unique expressions, it isn't possible to unique VLA's 1380c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // that have an expression provided for their size. 1381c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1382566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek VariableArrayType *New = 13837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor new(*this,8)VariableArrayType(EltTy, QualType(), 13847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor NumElts, ASM, EltTypeQuals, Brackets); 1385c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1386c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman VariableArrayTypes.push_back(New); 1387c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 1388c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 1389c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman} 1390c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1391898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// getDependentSizedArrayType - Returns a non-unique reference to 1392898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// the type for a dependently-sized array of the specified element 139304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor/// type. 13947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getDependentSizedArrayType(QualType EltTy, 13957e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 1396898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArrayType::ArraySizeModifier ASM, 13977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals, 13987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets) { 1399898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor assert((NumElts->isTypeDependent() || NumElts->isValueDependent()) && 1400898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor "Size must be type- or value-dependent!"); 1401898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 140204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor llvm::FoldingSetNodeID ID; 140304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayType::Profile(ID, *this, getCanonicalType(EltTy), ASM, 140404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor EltTypeQuals, NumElts); 1405898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 140604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor void *InsertPos = 0; 140704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayType *Canon 140804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor = DependentSizedArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 140904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayType *New; 141004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor if (Canon) { 141104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor // We already have a canonical version of this array type; use it as 141204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor // the canonical type for a newly-built type. 141304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor New = new (*this,8) DependentSizedArrayType(*this, EltTy, 141404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType(Canon, 0), 141504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor NumElts, ASM, EltTypeQuals, 141604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Brackets); 141704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } else { 141804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType CanonEltTy = getCanonicalType(EltTy); 141904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor if (CanonEltTy == EltTy) { 142004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor New = new (*this,8) DependentSizedArrayType(*this, EltTy, QualType(), 142104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor NumElts, ASM, EltTypeQuals, 142204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Brackets); 142304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayTypes.InsertNode(New, InsertPos); 142404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } else { 142504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType Canon = getDependentSizedArrayType(CanonEltTy, NumElts, 142604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASM, EltTypeQuals, 142704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor SourceRange()); 142804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor New = new (*this,8) DependentSizedArrayType(*this, EltTy, Canon, 142904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor NumElts, ASM, EltTypeQuals, 143004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor Brackets); 143104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } 143204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } 143304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor 1434898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Types.push_back(New); 1435898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return QualType(New, 0); 1436898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1437898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1438c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli FriedmanQualType ASTContext::getIncompleteArrayType(QualType EltTy, 1439c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArrayType::ArraySizeModifier ASM, 1440c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman unsigned EltTypeQuals) { 1441c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman llvm::FoldingSetNodeID ID; 14420be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner IncompleteArrayType::Profile(ID, EltTy, ASM, EltTypeQuals); 1443c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1444c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void *InsertPos = 0; 1445c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman if (IncompleteArrayType *ATP = 1446c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 1447c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(ATP, 0); 1448c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1449c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // If the element type isn't canonical, this won't be a canonical type 1450c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // either, so fill in the canonical type field. 1451c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman QualType Canonical; 1452c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1453c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman if (!EltTy->isCanonical()) { 1454f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getIncompleteArrayType(getCanonicalType(EltTy), 14552bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek ASM, EltTypeQuals); 1456c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1457c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Get the new insert position for the node we care about. 1458c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType *NewIP = 1459c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 1460f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 14612bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 1462c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 14637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor IncompleteArrayType *New 14647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor = new (*this,8) IncompleteArrayType(EltTy, Canonical, 14657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ASM, EltTypeQuals); 1466c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1467c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayTypes.InsertNode(New, InsertPos); 1468c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 1469c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 1470fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff} 1471fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 147273322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// getVectorType - Return the unique reference to a vector type of 147373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 147473322924127c873c13101b705dd823f5539ffa5fSteve NaroffQualType ASTContext::getVectorType(QualType vecType, unsigned NumElts) { 14755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BuiltinType *baseType; 14765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1477f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner baseType = dyn_cast<BuiltinType>(getCanonicalType(vecType).getTypePtr()); 147873322924127c873c13101b705dd823f5539ffa5fSteve Naroff assert(baseType != 0 && "getVectorType(): Expecting a built-in type"); 14795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Check if we've already instantiated a vector of this type. 14815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 148273322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType::Profile(ID, vecType, NumElts, Type::Vector); 14835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 14845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 14855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(VTP, 0); 14865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 14885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 14895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 14905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!vecType->isCanonical()) { 1491f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getVectorType(getCanonicalType(vecType), NumElts); 14925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 14945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 1495f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 14965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1497f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff VectorType *New = new (*this,8) VectorType(vecType, NumElts, Canonical); 14985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorTypes.InsertNode(New, InsertPos); 14995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 15005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1503213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// getExtVectorType - Return the unique reference to an extended vector type of 150473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 1505213541a68a3e137d11d2cefb612c6cdb410d7e8eNate BegemanQualType ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) { 150673322924127c873c13101b705dd823f5539ffa5fSteve Naroff BuiltinType *baseType; 150773322924127c873c13101b705dd823f5539ffa5fSteve Naroff 1508f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner baseType = dyn_cast<BuiltinType>(getCanonicalType(vecType).getTypePtr()); 1509213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman assert(baseType != 0 && "getExtVectorType(): Expecting a built-in type"); 151073322924127c873c13101b705dd823f5539ffa5fSteve Naroff 151173322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Check if we've already instantiated a vector of this type. 151273322924127c873c13101b705dd823f5539ffa5fSteve Naroff llvm::FoldingSetNodeID ID; 1513213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman VectorType::Profile(ID, vecType, NumElts, Type::ExtVector); 151473322924127c873c13101b705dd823f5539ffa5fSteve Naroff void *InsertPos = 0; 151573322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 151673322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(VTP, 0); 151773322924127c873c13101b705dd823f5539ffa5fSteve Naroff 151873322924127c873c13101b705dd823f5539ffa5fSteve Naroff // If the element type isn't canonical, this won't be a canonical type either, 151973322924127c873c13101b705dd823f5539ffa5fSteve Naroff // so fill in the canonical type field. 152073322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType Canonical; 152173322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (!vecType->isCanonical()) { 1522213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); 152373322924127c873c13101b705dd823f5539ffa5fSteve Naroff 152473322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Get the new insert position for the node we care about. 152573322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 1526f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 152773322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 1528f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff ExtVectorType *New = new (*this,8) ExtVectorType(vecType, NumElts, Canonical); 152973322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorTypes.InsertNode(New, InsertPos); 153073322924127c873c13101b705dd823f5539ffa5fSteve Naroff Types.push_back(New); 153173322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(New, 0); 153273322924127c873c13101b705dd823f5539ffa5fSteve Naroff} 153373322924127c873c13101b705dd823f5539ffa5fSteve Naroff 15349cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas GregorQualType ASTContext::getDependentSizedExtVectorType(QualType vecType, 15359cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr, 15369cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation AttrLoc) { 15372ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor llvm::FoldingSetNodeID ID; 15382ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), 15392ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr); 15402ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 15412ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void *InsertPos = 0; 15422ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *Canon 15432ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 15442ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *New; 15452ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (Canon) { 15462ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // We already have a canonical version of this array type; use it as 15472ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // the canonical type for a newly-built type. 15482ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor New = new (*this,8) DependentSizedExtVectorType(*this, vecType, 15492ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType(Canon, 0), 15502ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr, AttrLoc); 15512ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 15522ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType CanonVecTy = getCanonicalType(vecType); 15532ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (CanonVecTy == vecType) { 15542ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor New = new (*this,8) DependentSizedExtVectorType(*this, vecType, 15552ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType(), SizeExpr, 15562ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor AttrLoc); 15572ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorTypes.InsertNode(New, InsertPos); 15582ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 15592ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, 15602ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SourceLocation()); 15612ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor New = new (*this,8) DependentSizedExtVectorType(*this, vecType, Canon, 15622ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr, AttrLoc); 15632ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 15642ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 15652ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor 15669cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Types.push_back(New); 15679cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(New, 0); 15689cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 15699cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 157072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 15715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 15722455636163fdd18581d7fdae816433f886d88213Mike StumpQualType ASTContext::getFunctionNoProtoType(QualType ResultTy, bool NoReturn) { 15735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 15745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 15755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 15762455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType::Profile(ID, ResultTy, NoReturn); 15775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 157972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor if (FunctionNoProtoType *FT = 158072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 15815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FT, 0); 15825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 15845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!ResultTy->isCanonical()) { 15852455636163fdd18581d7fdae816433f886d88213Mike Stump Canonical = getFunctionNoProtoType(getCanonicalType(ResultTy), NoReturn); 15865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 158872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType *NewIP = 158972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 1590f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 15915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15932455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType *New 15942455636163fdd18581d7fdae816433f886d88213Mike Stump = new (*this,8) FunctionNoProtoType(ResultTy, Canonical, NoReturn); 15955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 159672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.InsertNode(New, InsertPos); 15975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 15985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFunctionType - Return a normal function type with a typed argument 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// list. isVariadic indicates whether the argument list includes '...'. 160261710854be2b098428aff5316e64bd34b30fbcb7Chris LattnerQualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray, 1603971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned NumArgs, bool isVariadic, 1604465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned TypeQuals, bool hasExceptionSpec, 1605465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec, unsigned NumExs, 16062455636163fdd18581d7fdae816433f886d88213Mike Stump const QualType *ExArray, bool NoReturn) { 16075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 16085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 16095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 161072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, isVariadic, 1611465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl TypeQuals, hasExceptionSpec, hasAnyExceptionSpec, 16122455636163fdd18581d7fdae816433f886d88213Mike Stump NumExs, ExArray, NoReturn); 16135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 161572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor if (FunctionProtoType *FTP = 161672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 16175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 1618465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1619465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Determine whether the type being created is already canonical or not. 16205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical = ResultTy->isCanonical(); 1621465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl if (hasExceptionSpec) 1622465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl isCanonical = false; 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs && isCanonical; ++i) 16245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!ArgArray[i]->isCanonical()) 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer isCanonical = false; 16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this type isn't canonical, get the canonical version of it. 1628465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // The exception spec is not part of the canonical type. 16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 16305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!isCanonical) { 16315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<QualType, 16> CanonicalArgs; 16325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CanonicalArgs.reserve(NumArgs); 16335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 1634f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner CanonicalArgs.push_back(getCanonicalType(ArgArray[i])); 1635465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1636f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getFunctionType(getCanonicalType(ResultTy), 1637beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad CanonicalArgs.data(), NumArgs, 163847259d9ca7840dd66f06f5f11da7768b23d1e0fdDouglas Gregor isVariadic, TypeQuals, false, 163947259d9ca7840dd66f06f5f11da7768b23d1e0fdDouglas Gregor false, 0, 0, NoReturn); 1640465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 16415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 164272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType *NewIP = 164372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 1644f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 16455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1646465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 164772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // FunctionProtoType objects are allocated with extra bytes after them 1648465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // for two variable size arrays (for parameter and exception types) at the 1649465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // end of them. 165072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType *FTP = 1651465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl (FunctionProtoType*)Allocate(sizeof(FunctionProtoType) + 1652465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs*sizeof(QualType) + 1653465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumExs*sizeof(QualType), 8); 165472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, isVariadic, 1655465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl TypeQuals, hasExceptionSpec, hasAnyExceptionSpec, 16562455636163fdd18581d7fdae816433f886d88213Mike Stump ExArray, NumExs, Canonical, NoReturn); 16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(FTP); 165872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.InsertNode(FTP, InsertPos); 16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16622ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// getTypeDeclType - Return the unique reference to the type for the 16632ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// specified type declaration. 16644b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed KremenekQualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) { 16651e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis assert(Decl && "Passed null for Decl param"); 16662ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 16672ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 16681e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(Decl)) 16692ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getTypedefType(Typedef); 1670fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor else if (isa<TemplateTypeParmDecl>(Decl)) { 1671fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor assert(false && "Template type parameter types are always available."); 16729fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (ObjCInterfaceDecl *ObjCInterface 16739fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump = dyn_cast<ObjCInterfaceDecl>(Decl)) 16742ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getObjCInterfaceType(ObjCInterface); 167549aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 1676c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) { 1677566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek if (PrevDecl) 1678566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek Decl->TypeForDecl = PrevDecl->TypeForDecl; 1679f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff else 1680f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff Decl->TypeForDecl = new (*this,8) RecordType(Record); 16819fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) { 1682566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek if (PrevDecl) 1683566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek Decl->TypeForDecl = PrevDecl->TypeForDecl; 1684f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff else 1685f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff Decl->TypeForDecl = new (*this,8) EnumType(Enum); 16869fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else 16872ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor assert(false && "TypeDecl without a type?"); 168849aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 16894b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek if (!PrevDecl) Types.push_back(Decl->TypeForDecl); 169049aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis return QualType(Decl->TypeForDecl, 0); 16912ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor} 16922ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTypedefType - Return the unique reference to the type for the 16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified typename decl. 16955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getTypedefType(TypedefDecl *Decl) { 16965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 16975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1698f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(Decl->getUnderlyingType()); 169972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor Decl->TypeForDecl = new(*this,8) TypedefType(Type::Typedef, Decl, Canonical); 17005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(Decl->TypeForDecl); 17015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(Decl->TypeForDecl, 0); 17025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1704fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor/// \brief Retrieve the template type parameter type for a template 170576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson/// parameter or parameter pack with the given depth, index, and (optionally) 170676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson/// name. 1707fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas GregorQualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, 170876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool ParameterPack, 1709fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name) { 1710fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor llvm::FoldingSetNodeID ID; 171176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, Name); 1712fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void *InsertPos = 0; 1713fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmType *TypeParm 1714fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 1715fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1716fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor if (TypeParm) 1717fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 1718fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 171976e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson if (Name) { 172076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); 172176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TypeParm = new (*this, 8) TemplateTypeParmType(Depth, Index, ParameterPack, 172276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson Name, Canon); 172376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson } else 172476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TypeParm = new (*this, 8) TemplateTypeParmType(Depth, Index, ParameterPack); 1725fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1726fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Types.push_back(TypeParm); 1727fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); 1728fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1729fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 1730fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor} 1731fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 173255f6b14230c94272efbbcdd89a92224c8db9f225Douglas GregorQualType 17337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorASTContext::getTemplateSpecializationType(TemplateName Template, 17347532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 17357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, 17367532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualType Canon) { 1737b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor if (!Canon.isNull()) 1738b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor Canon = getCanonicalType(Canon); 1739b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor else { 1740b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor // Build the canonical template specialization type. 17411275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateName CanonTemplate = getCanonicalTemplateName(Template); 17421275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor llvm::SmallVector<TemplateArgument, 4> CanonArgs; 17431275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs.reserve(NumArgs); 17441275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) 17451275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); 17461275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 17471275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Determine whether this canonical template specialization type already 17481275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // exists. 17491275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor llvm::FoldingSetNodeID ID; 17501275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateSpecializationType::Profile(ID, CanonTemplate, 1751828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor CanonArgs.data(), NumArgs, *this); 17521275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 17531275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor void *InsertPos = 0; 17541275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateSpecializationType *Spec 17551275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 17561275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 17571275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor if (!Spec) { 17581275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate a new canonical template specialization type. 17591275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor void *Mem = Allocate((sizeof(TemplateSpecializationType) + 17601275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor sizeof(TemplateArgument) * NumArgs), 17611275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 8); 1762828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Spec = new (Mem) TemplateSpecializationType(*this, CanonTemplate, 17631275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs.data(), NumArgs, 1764b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor Canon); 17651275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor Types.push_back(Spec); 17661275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateSpecializationTypes.InsertNode(Spec, InsertPos); 17671275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 17681275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 1769b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor if (Canon.isNull()) 1770b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor Canon = QualType(Spec, 0); 17711275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor assert(Canon->isDependentType() && 17721275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor "Non-dependent template-id type must have a canonical type"); 1773b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor } 1774fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 17751275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate the (non-canonical) template specialization type, but don't 17761275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // try to unique it: these types typically have location information that 17771275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // we don't unique and don't want to lose. 17787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *Mem = Allocate((sizeof(TemplateSpecializationType) + 177940808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor sizeof(TemplateArgument) * NumArgs), 178040808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor 8); 17811275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateSpecializationType *Spec 1782828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor = new (Mem) TemplateSpecializationType(*this, Template, Args, NumArgs, 1783828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Canon); 17841275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 178555f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor Types.push_back(Spec); 178655f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor return QualType(Spec, 0); 178755f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 178855f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 1789e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas GregorQualType 1790ab452ba8323d1985e08bade2bced588cddf2cc28Douglas GregorASTContext::getQualifiedNameType(NestedNameSpecifier *NNS, 1791e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType) { 1792e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor llvm::FoldingSetNodeID ID; 1793ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType::Profile(ID, NNS, NamedType); 1794e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1795e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void *InsertPos = 0; 1796e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualifiedNameType *T 1797e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor = QualifiedNameTypes.FindNodeOrInsertPos(ID, InsertPos); 1798e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor if (T) 1799e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 1800e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1801ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor T = new (*this) QualifiedNameType(NNS, NamedType, 1802ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor getCanonicalType(NamedType)); 1803e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor Types.push_back(T); 1804e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualifiedNameTypes.InsertNode(T, InsertPos); 1805e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 1806e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor} 1807e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1808d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorQualType ASTContext::getTypenameType(NestedNameSpecifier *NNS, 1809d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor const IdentifierInfo *Name, 1810d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType Canon) { 1811d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 1812d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1813d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (Canon.isNull()) { 1814d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 1815d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (CanonNNS != NNS) 1816d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Canon = getTypenameType(CanonNNS, Name); 1817d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1818d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1819d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor llvm::FoldingSetNodeID ID; 1820d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType::Profile(ID, NNS, Name); 1821d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1822d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void *InsertPos = 0; 1823d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType *T 1824d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor = TypenameTypes.FindNodeOrInsertPos(ID, InsertPos); 1825d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (T) 1826d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return QualType(T, 0); 1827d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1828d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor T = new (*this) TypenameType(NNS, Name, Canon); 1829d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Types.push_back(T); 1830d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameTypes.InsertNode(T, InsertPos); 1831d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return QualType(T, 0); 1832d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 1833d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 18341734317845d60307d474b5da8a8d33adbaf5e723Douglas GregorQualType 18351734317845d60307d474b5da8a8d33adbaf5e723Douglas GregorASTContext::getTypenameType(NestedNameSpecifier *NNS, 18361734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *TemplateId, 18371734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType Canon) { 18381734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 18391734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18401734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor if (Canon.isNull()) { 18411734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 18421734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType = getCanonicalType(QualType(TemplateId, 0)); 18431734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor if (CanonNNS != NNS || CanonType != QualType(TemplateId, 0)) { 18441734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *CanonTemplateId 18451734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor = CanonType->getAsTemplateSpecializationType(); 18461734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(CanonTemplateId && 18471734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "Canonical type must also be a template specialization type"); 18481734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Canon = getTypenameType(CanonNNS, CanonTemplateId); 18491734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 18501734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 18511734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18521734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor llvm::FoldingSetNodeID ID; 18531734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType::Profile(ID, NNS, TemplateId); 18541734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18551734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor void *InsertPos = 0; 18561734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType *T 18571734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor = TypenameTypes.FindNodeOrInsertPos(ID, InsertPos); 18581734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor if (T) 18591734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return QualType(T, 0); 18601734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18611734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor T = new (*this) TypenameType(NNS, TemplateId, Canon); 18621734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Types.push_back(T); 18631734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameTypes.InsertNode(T, InsertPos); 18641734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return QualType(T, 0); 18651734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor} 18661734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 186788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// CmpProtocolNames - Comparison predicate for sorting protocols 186888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// alphabetically. 186988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic bool CmpProtocolNames(const ObjCProtocolDecl *LHS, 187088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner const ObjCProtocolDecl *RHS) { 18712e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS->getDeclName() < RHS->getDeclName(); 187288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 187388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 187488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic void SortAndUniqueProtocols(ObjCProtocolDecl **&Protocols, 187588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner unsigned &NumProtocols) { 187688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; 187788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 187888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Sort protocols, keyed by name. 187988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames); 188088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 188188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Remove duplicates. 188288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); 188388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner NumProtocols = ProtocolsEnd-Protocols; 188488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 188588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 1886d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for 1887d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// the given interface decl and the conforming protocol list. 188814108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType ASTContext::getObjCObjectPointerType(QualType InterfaceT, 1889d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCProtocolDecl **Protocols, 1890d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff unsigned NumProtocols) { 1891d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // Sort the protocol list alphabetically to canonicalize it. 1892d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (NumProtocols) 1893d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff SortAndUniqueProtocols(Protocols, NumProtocols); 1894d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1895d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff llvm::FoldingSetNodeID ID; 189614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCObjectPointerType::Profile(ID, InterfaceT, Protocols, NumProtocols); 1897d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1898d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void *InsertPos = 0; 1899d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (ObjCObjectPointerType *QT = 1900d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 1901d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return QualType(QT, 0); 1902d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1903d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // No Match; 1904d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerType *QType = 190514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff new (*this,8) ObjCObjectPointerType(InterfaceT, Protocols, NumProtocols); 1906d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1907d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff Types.push_back(QType); 1908d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerTypes.InsertNode(QType, InsertPos); 1909d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return QualType(QType, 0); 1910d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 191188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 1912c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// getObjCInterfaceType - Return the unique reference to the type for the 1913c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// specified ObjC interface decl. The list of protocols is optional. 1914c15cb2af27514ecc879daba9aa01389c5203685dSteve NaroffQualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 1915a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **Protocols, unsigned NumProtocols) { 1916c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (NumProtocols) 1917c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // Sort the protocol list alphabetically to canonicalize it. 1918c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff SortAndUniqueProtocols(Protocols, NumProtocols); 191988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 19204b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian llvm::FoldingSetNodeID ID; 1921c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceType::Profile(ID, Decl, Protocols, NumProtocols); 19224b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 19234b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void *InsertPos = 0; 1924c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (ObjCInterfaceType *QT = 1925c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceTypes.FindNodeOrInsertPos(ID, InsertPos)) 19264b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QT, 0); 19274b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 19284b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian // No Match; 1929c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceType *QType = 1930c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff new (*this,8) ObjCInterfaceType(const_cast<ObjCInterfaceDecl*>(Decl), 1931c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff Protocols, NumProtocols); 19324b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian Types.push_back(QType); 1933c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceTypes.InsertNode(QType, InsertPos); 19344b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QType, 0); 19354b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian} 19364b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 193772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 193872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType AST's (since expression's are never shared). For example, 19399752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// multiple declarations that refer to "typeof(x)" all contain different 19409752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// DeclRefExpr's. This doesn't effect the type checker, since it operates 19419752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 194272564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorQualType ASTContext::getTypeOfExprType(Expr *tofExpr) { 1943dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType *toe; 1944b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (tofExpr->isTypeDependent()) { 1945b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor llvm::FoldingSetNodeID ID; 1946b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType::Profile(ID, *this, tofExpr); 1947b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor 1948b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void *InsertPos = 0; 1949b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType *Canon 1950b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor = DependentTypeOfExprTypes.FindNodeOrInsertPos(ID, InsertPos); 1951b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (Canon) { 1952b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // We already have a "canonical" version of an identical, dependent 1953b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // typeof(expr) type. Use that as our canonical type. 1954b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor toe = new (*this, 8) TypeOfExprType(tofExpr, 1955b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor QualType((TypeOfExprType*)Canon, 0)); 1956b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 1957b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor else { 1958b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // Build a new, canonical typeof(expr) type. 1959b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor Canon = new (*this, 8) DependentTypeOfExprType(*this, tofExpr); 1960b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprTypes.InsertNode(Canon, InsertPos); 1961b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor toe = Canon; 1962b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 1963b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } else { 1964dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType Canonical = getCanonicalType(tofExpr->getType()); 1965dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor toe = new (*this,8) TypeOfExprType(tofExpr, Canonical); 1966dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 19679752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(toe); 19689752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(toe, 0); 1969d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 1970d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 19719752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// getTypeOfType - Unlike many "get<Type>" functions, we don't unique 19729752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// TypeOfType AST's. The only motivation to unique these nodes would be 19739752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be 19749752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// an issue. This doesn't effect the type checker, since it operates 19759752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 1976d1861fd633d5096a00777c918eb8575ea7162fe7Steve NaroffQualType ASTContext::getTypeOfType(QualType tofType) { 1977f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(tofType); 1978f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff TypeOfType *tot = new (*this,8) TypeOfType(tofType, Canonical); 19799752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(tot); 19809752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(tot, 0); 1981d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 1982d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 198360a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson/// getDecltypeForExpr - Given an expr, will return the decltype for that 198460a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson/// expression, according to the rules in C++0x [dcl.type.simple]p4 198560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlssonstatic QualType getDecltypeForExpr(const Expr *e, ASTContext &Context) { 1986a07c33e64e1169e4261f7748c7f9191091a3ad2eAnders Carlsson if (e->isTypeDependent()) 1987a07c33e64e1169e4261f7748c7f9191091a3ad2eAnders Carlsson return Context.DependentTy; 1988a07c33e64e1169e4261f7748c7f9191091a3ad2eAnders Carlsson 198960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // If e is an id expression or a class member access, decltype(e) is defined 199060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // as the type of the entity named by e. 199160a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(e)) { 199260a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const ValueDecl *VD = dyn_cast<ValueDecl>(DRE->getDecl())) 199360a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return VD->getType(); 199460a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson } 199560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const MemberExpr *ME = dyn_cast<MemberExpr>(e)) { 199660a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) 199760a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return FD->getType(); 199860a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson } 199960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // If e is a function call or an invocation of an overloaded operator, 200060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // (parentheses around e are ignored), decltype(e) is defined as the 200160a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // return type of that function. 200260a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const CallExpr *CE = dyn_cast<CallExpr>(e->IgnoreParens())) 200360a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return CE->getCallReturnType(); 200460a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 200560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson QualType T = e->getType(); 200660a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 200760a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // Otherwise, where T is the type of e, if e is an lvalue, decltype(e) is 200860a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // defined as T&, otherwise decltype(e) is defined as T. 200960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (e->isLvalue(Context) == Expr::LV_Valid) 201060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson T = Context.getLValueReferenceType(T); 201160a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 201260a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return T; 201360a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson} 201460a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 2015395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// getDecltypeType - Unlike many "get<Type>" functions, we don't unique 2016395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType AST's. The only motivation to unique these nodes would be 2017395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// memory savings. Since decltype(t) is fairly uncommon, space shouldn't be 2018395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// an issue. This doesn't effect the type checker, since it operates 2019395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// on canonical type's (which are always unique). 2020395b475a4474f1c7574d927ad142ca0c7997cbcaAnders CarlssonQualType ASTContext::getDecltypeType(Expr *e) { 2021dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor DecltypeType *dt; 20229d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (e->isTypeDependent()) { 20239d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor llvm::FoldingSetNodeID ID; 20249d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType::Profile(ID, *this, e); 20259d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor 20269d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void *InsertPos = 0; 20279d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType *Canon 20289d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos); 20299d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (Canon) { 20309d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // We already have a "canonical" version of an equivalent, dependent 20319d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // decltype type. Use that as our canonical type. 20329d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor dt = new (*this, 8) DecltypeType(e, DependentTy, 20339d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor QualType((DecltypeType*)Canon, 0)); 20349d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 20359d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor else { 20369d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // Build a new, canonical typeof(expr) type. 20379d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor Canon = new (*this, 8) DependentDecltypeType(*this, e); 20389d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeTypes.InsertNode(Canon, InsertPos); 20399d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor dt = Canon; 20409d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 20419d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } else { 2042dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType T = getDecltypeForExpr(e, *this); 2043563a03b1338d31c2462def43253a722bc885d384Anders Carlsson dt = new (*this, 8) DecltypeType(e, T, getCanonicalType(T)); 2044dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 2045395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Types.push_back(dt); 2046395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return QualType(dt, 0); 2047395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 2048395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 20495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTagDeclType - Return the unique reference to the type for the 20505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified TagDecl (struct/union/class/enum) decl. 2051e607ed068334bacb8d7b093996b4671c6ca79e25Mike StumpQualType ASTContext::getTagDeclType(const TagDecl *Decl) { 2052d778f88d32b96a74c9edb7342c81357606a7cdc0Ted Kremenek assert (Decl); 2053e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // FIXME: What is the design on getTagDeclType when it requires casting 2054e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // away const? mutable? 2055e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump return getTypeDeclType(const_cast<TagDecl*>(Decl)); 20565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 20575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 20585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result 20595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and 20605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// needs to agree with the definition in <stddef.h>. 20615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getSizeType() const { 2062b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor return getFromTargetType(Target.getSizeType()); 20635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 20645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 206564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getSignedWCharType - Return the type of "signed wchar_t". 206664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 206764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getSignedWCharType() const { 206864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 206964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return WCharTy; 207064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 207164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 207264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getUnsignedWCharType - Return the type of "unsigned wchar_t". 207364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 207464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getUnsignedWCharType() const { 207564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 207664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return UnsignedIntTy; 207764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 207864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 20798b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 20808b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 20818b9023ba35a86838789e2c9034a6128728c547aaChris LattnerQualType ASTContext::getPointerDiffType() const { 2082b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor return getFromTargetType(Target.getPtrDiffType(0)); 20838b9023ba35a86838789e2c9034a6128728c547aaChris Lattner} 20848b9023ba35a86838789e2c9034a6128728c547aaChris Lattner 2085e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 2086e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner// Type Operators 2087e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 2088e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 208977c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// getCanonicalType - Return the canonical (structural) type corresponding to 209077c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// the specified potentially non-canonical type. The non-canonical version 209177c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// of a type may have many "decorated" versions of types. Decorators can 209277c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// include typedefs, 'typeof' operators, etc. The returned type is guaranteed 209377c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// to be free of any of these, allowing two canonical types to be compared 209477c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// for exact equality with a simple pointer comparison. 209550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas GregorCanQualType ASTContext::getCanonicalType(QualType T) { 209677c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner QualType CanType = T.getTypePtr()->getCanonicalTypeInternal(); 2097c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2098c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the result has type qualifiers, make sure to canonicalize them as well. 2099c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner unsigned TypeQuals = T.getCVRQualifiers() | CanType.getCVRQualifiers(); 210050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor if (TypeQuals == 0) 210150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe(CanType); 2102c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2103c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If the type qualifiers are on an array type, get the canonical type of the 2104c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // array with the qualifiers applied to the element type. 2105c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner ArrayType *AT = dyn_cast<ArrayType>(CanType); 2106c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (!AT) 210750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe(CanType.getQualifiedType(TypeQuals)); 2108c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2109c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the canonical version of the element with the extra qualifiers on it. 2110c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // This can recursively sink qualifiers through multiple levels of arrays. 2111c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType NewEltTy=AT->getElementType().getWithAdditionalQualifiers(TypeQuals); 2112c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner NewEltTy = getCanonicalType(NewEltTy); 2113c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2114c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) 211550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe( 211650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor getConstantArrayType(NewEltTy, CAT->getSize(), 211750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor CAT->getSizeModifier(), 211850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor CAT->getIndexTypeQualifier())); 2119c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) 212050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe( 212150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(), 212250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor IAT->getIndexTypeQualifier())); 2123c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2124898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (DependentSizedArrayType *DSAT = dyn_cast<DependentSizedArrayType>(AT)) 212550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe( 212650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor getDependentSizedArrayType(NewEltTy, 2127bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr() ? 2128bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr()->Retain() : 0, 212950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DSAT->getSizeModifier(), 213050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DSAT->getIndexTypeQualifier(), 213150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DSAT->getBracketsRange())); 2132898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2133c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VariableArrayType *VAT = cast<VariableArrayType>(AT); 213450d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe(getVariableArrayType(NewEltTy, 2135bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr() ? 2136bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr()->Retain() : 0, 213750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor VAT->getSizeModifier(), 213850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor VAT->getIndexTypeQualifier(), 213950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor VAT->getBracketsRange())); 2140c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2141c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 214225a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas GregorTemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) { 214325a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor // If this template name refers to a template, the canonical 214425a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor // template name merely stores the template itself. 214525a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) 214697fbaa2a38804268a024f1a104b43fcf8b4411b0Argyrios Kyrtzidis return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl())); 214725a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 2148d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor // If this template name refers to a set of overloaded function templates, 2149d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor /// the canonical template name merely stores the set of function templates. 21506ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor if (OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl()) { 21516ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor OverloadedFunctionDecl *CanonOvl = 0; 21526ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(), 21536ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor FEnd = Ovl->function_end(); 21546ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor F != FEnd; ++F) { 21556ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor Decl *Canon = F->get()->getCanonicalDecl(); 21566ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor if (CanonOvl || Canon != F->get()) { 21576ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor if (!CanonOvl) 21586ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor CanonOvl = OverloadedFunctionDecl::Create(*this, 21596ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor Ovl->getDeclContext(), 21606ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor Ovl->getDeclName()); 21616ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor 21626ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor CanonOvl->addOverload( 21636ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor AnyFunctionDecl::getFromNamedDecl(cast<NamedDecl>(Canon))); 21646ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor } 21656ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor } 21666ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor 21676ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor return TemplateName(CanonOvl? CanonOvl : Ovl); 21686ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor } 2169d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 217025a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 217125a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor assert(DTN && "Non-dependent template names must refer to template decls."); 217225a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor return DTN->CanonicalTemplateName; 217325a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor} 217425a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 21751275ae098acda31fe0e434510c729fcfed0458a1Douglas GregorTemplateArgument 21761275ae098acda31fe0e434510c729fcfed0458a1Douglas GregorASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) { 21771275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor switch (Arg.getKind()) { 21781275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Null: 21791275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 21801275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 21811275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Expression: 21821275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // FIXME: Build canonical expression? 21831275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 21841275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 21851275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Declaration: 21861275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(SourceLocation(), 21871275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor Arg.getAsDecl()->getCanonicalDecl()); 21881275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 21891275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Integral: 21901275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(SourceLocation(), 21911275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor *Arg.getAsIntegral(), 21921275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor getCanonicalType(Arg.getIntegralType())); 21931275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 21941275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Type: 21951275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(SourceLocation(), 21961275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor getCanonicalType(Arg.getAsType())); 21971275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 21981275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Pack: { 21991275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // FIXME: Allocate in ASTContext 22001275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateArgument *CanonArgs = new TemplateArgument[Arg.pack_size()]; 22011275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor unsigned Idx = 0; 22021275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 22031275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor AEnd = Arg.pack_end(); 22041275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor A != AEnd; (void)++A, ++Idx) 22051275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs[Idx] = getCanonicalTemplateArgument(*A); 22061275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 22071275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateArgument Result; 22081275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor Result.setArgumentPack(CanonArgs, Arg.pack_size(), false); 22091275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Result; 22101275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 22111275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 22121275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 22131275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Silence GCC warning 22141275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor assert(false && "Unhandled template argument kind"); 22151275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(); 22161275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor} 22171275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 2218d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorNestedNameSpecifier * 2219d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) { 2220d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (!NNS) 2221d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 2222d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2223d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor switch (NNS->getKind()) { 2224d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Identifier: 2225d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Canonicalize the prefix but keep the identifier the same. 2226d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NestedNameSpecifier::Create(*this, 2227d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor getCanonicalNestedNameSpecifier(NNS->getPrefix()), 2228d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NNS->getAsIdentifier()); 2229d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2230d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Namespace: 2231d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 2232d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // this namespace and no prefix. 2233d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NestedNameSpecifier::Create(*this, 0, NNS->getAsNamespace()); 2234d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2235d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpec: 2236d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: { 2237d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType T = getCanonicalType(QualType(NNS->getAsType(), 0)); 2238d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *Prefix = 0; 2239d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2240d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // FIXME: This isn't the right check! 2241d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (T->isDependentType()) 2242d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Prefix = getCanonicalNestedNameSpecifier(NNS->getPrefix()); 2243d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2244d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NestedNameSpecifier::Create(*this, Prefix, 2245d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, 2246d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor T.getTypePtr()); 2247d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2248d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2249d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Global: 2250d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // The global specifier is canonical and unique. 2251d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NNS; 2252d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2253d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2254d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Required to silence a GCC warning 2255d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 2256d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 2257d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2258c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2259c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst ArrayType *ASTContext::getAsArrayType(QualType T) { 2260c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the non-qualified case efficiently. 2261c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (T.getCVRQualifiers() == 0) { 2262c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the common positive case fast. 2263c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(T)) 2264c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT; 2265c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 2266c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2267c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the common negative case fast, ignoring CVR qualifiers. 2268c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType CType = T->getCanonicalTypeInternal(); 2269c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2270f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian // Make sure to look through type qualifiers (like ExtQuals) for the negative 2271c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // test. 2272c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (!isa<ArrayType>(CType) && 2273c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner !isa<ArrayType>(CType.getUnqualifiedType())) 2274c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 2275c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2276c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Apply any CVR qualifiers from the array type to the element type. This 2277c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // implements C99 6.7.3p8: "If the specification of an array type includes 2278c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // any type qualifiers, the element type is so qualified, not the array type." 2279c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2280c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we get here, we either have type qualifiers on the type, or we have 2281c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // sugar such as a typedef in the way. If we have type qualifiers on the type 228250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor // we must propagate them down into the element type. 2283c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner unsigned CVRQuals = T.getCVRQualifiers(); 2284c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner unsigned AddrSpace = 0; 2285c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Type *Ty = T.getTypePtr(); 2286c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2287f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian // Rip through ExtQualType's and typedefs to get to a concrete type. 2288c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner while (1) { 2289f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(Ty)) { 2290f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian AddrSpace = EXTQT->getAddressSpace(); 2291f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian Ty = EXTQT->getBaseType(); 2292c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } else { 2293c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner T = Ty->getDesugaredType(); 2294c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (T.getTypePtr() == Ty && T.getCVRQualifiers() == 0) 2295c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner break; 2296c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CVRQuals |= T.getCVRQualifiers(); 2297c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner Ty = T.getTypePtr(); 2298c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 2299c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 2300c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2301c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we have a simple case, just return now. 2302c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *ATy = dyn_cast<ArrayType>(Ty); 2303c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (ATy == 0 || (AddrSpace == 0 && CVRQuals == 0)) 2304c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy; 2305c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2306c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Otherwise, we have an array and we have qualifiers on it. Push the 2307c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // qualifiers into the array element type and return a new array type. 2308c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the canonical version of the element with the extra qualifiers on it. 2309c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // This can recursively sink qualifiers through multiple levels of arrays. 2310c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType NewEltTy = ATy->getElementType(); 2311c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (AddrSpace) 2312f11284ac87daa613bc7b30db9f54bd716d123222Fariborz Jahanian NewEltTy = getAddrSpaceQualType(NewEltTy, AddrSpace); 2313c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner NewEltTy = NewEltTy.getWithAdditionalQualifiers(CVRQuals); 2314c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2315c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(ATy)) 2316c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), 2317c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CAT->getSizeModifier(), 2318c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CAT->getIndexTypeQualifier())); 2319c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy)) 2320c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getIncompleteArrayType(NewEltTy, 2321c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner IAT->getSizeModifier(), 23227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor IAT->getIndexTypeQualifier())); 2323898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2324898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (const DependentSizedArrayType *DSAT 2325898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor = dyn_cast<DependentSizedArrayType>(ATy)) 2326898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return cast<ArrayType>( 2327898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor getDependentSizedArrayType(NewEltTy, 2328bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr() ? 2329bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr()->Retain() : 0, 2330898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DSAT->getSizeModifier(), 23317e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor DSAT->getIndexTypeQualifier(), 23327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor DSAT->getBracketsRange())); 2333c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2334c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const VariableArrayType *VAT = cast<VariableArrayType>(ATy); 23357e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return cast<ArrayType>(getVariableArrayType(NewEltTy, 2336bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr() ? 2337bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr()->Retain() : 0, 2338c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VAT->getSizeModifier(), 23397e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor VAT->getIndexTypeQualifier(), 23407e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor VAT->getBracketsRange())); 234177c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner} 234277c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 234377c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 2344e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// getArrayDecayedType - Return the properly qualified result of decaying the 2345e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// specified array type to a pointer. This operation is non-trivial when 2346e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// handling typedefs etc. The canonical type of "T" must be an array type, 2347e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// this returns a pointer to a properly qualified element of the array. 2348e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// 2349e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 2350e6327747b72bb687c948270f702ff53c30f411a6Chris LattnerQualType ASTContext::getArrayDecayedType(QualType Ty) { 2351c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the element type with 'getAsArrayType' so that we don't lose any 2352c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // typedefs in the element type of the array. This also handles propagation 2353c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // of type qualifiers from the array type into the element type if present 2354c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // (C99 6.7.3p8). 2355c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *PrettyArrayType = getAsArrayType(Ty); 2356c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner assert(PrettyArrayType && "Not an array type!"); 2357e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 2358c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); 2359e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 2360e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner // int x[restrict 4] -> int *restrict 2361c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return PtrTy.getQualifiedType(PrettyArrayType->getIndexTypeQualifier()); 2362e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner} 2363e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 23645e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas GregorQualType ASTContext::getBaseElementType(QualType QT) { 23655e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QualifierSet qualifiers; 23665e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor while (true) { 23675e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor const Type *UT = qualifiers.strip(QT); 23685e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor if (const ArrayType *AT = getAsArrayType(QualType(UT,0))) { 23695e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QT = AT->getElementType(); 23706dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump } else { 23715e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor return qualifiers.apply(QT, *this); 23725e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 23735e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 23745e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 23755e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 2376d786f6a6b791b5901fa9fd39a2bbf924afbc1252Daniel DunbarQualType ASTContext::getBaseElementType(const VariableArrayType *VAT) { 23776183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson QualType ElemTy = VAT->getElementType(); 23786183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 23796183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson if (const VariableArrayType *VAT = getAsVariableArrayType(ElemTy)) 23806183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson return getBaseElementType(VAT); 23816183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 23826183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson return ElemTy; 23836183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson} 23846183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 23855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFloatingRank - Return a relative rank for floating point types. 23865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This routine will assert if passed a built-in type that isn't a float. 2387a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerstatic FloatingRank getFloatingRank(QualType T) { 2388ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb if (const ComplexType *CT = T->getAsComplexType()) 23895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getFloatingRank(CT->getElementType()); 2390a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner 2391d786f6a6b791b5901fa9fd39a2bbf924afbc1252Daniel Dunbar assert(T->getAsBuiltinType() && "getFloatingRank(): not a floating type"); 2392ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb switch (T->getAsBuiltinType()->getKind()) { 2393a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner default: assert(0 && "getFloatingRank(): not a floating type"); 23945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Float: return FloatRank; 23955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Double: return DoubleRank; 23965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::LongDouble: return LongDoubleRank; 23975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 23995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2400716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// getFloatingTypeOfSizeWithinDomain - Returns a real floating 2401716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// point or a complex type (based on typeDomain/typeSize). 2402716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeDomain' is a real floating point or complex type. 2403716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeSize' is a real floating point or complex type. 24041361b11066239ea15764a2a844405352d87296b3Chris LattnerQualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, 24051361b11066239ea15764a2a844405352d87296b3Chris Lattner QualType Domain) const { 24061361b11066239ea15764a2a844405352d87296b3Chris Lattner FloatingRank EltRank = getFloatingRank(Size); 24071361b11066239ea15764a2a844405352d87296b3Chris Lattner if (Domain->isComplexType()) { 24081361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 2409716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff default: assert(0 && "getFloatingRank(): illegal value for rank"); 2410f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case FloatRank: return FloatComplexTy; 2411f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case DoubleRank: return DoubleComplexTy; 2412f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case LongDoubleRank: return LongDoubleComplexTy; 2413f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 2414f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 24151361b11066239ea15764a2a844405352d87296b3Chris Lattner 24161361b11066239ea15764a2a844405352d87296b3Chris Lattner assert(Domain->isRealFloatingType() && "Unknown domain!"); 24171361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 24181361b11066239ea15764a2a844405352d87296b3Chris Lattner default: assert(0 && "getFloatingRank(): illegal value for rank"); 24191361b11066239ea15764a2a844405352d87296b3Chris Lattner case FloatRank: return FloatTy; 24201361b11066239ea15764a2a844405352d87296b3Chris Lattner case DoubleRank: return DoubleTy; 24211361b11066239ea15764a2a844405352d87296b3Chris Lattner case LongDoubleRank: return LongDoubleTy; 24225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24257cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// getFloatingTypeOrder - Compare the rank of the two specified floating 24267cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// point types, ignoring the domain of the type (i.e. 'double' == 24277cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 24287cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// LHS < RHS, return -1. 2429a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerint ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) { 2430a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank LHSR = getFloatingRank(LHS); 2431a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank RHSR = getFloatingRank(RHS); 2432a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner 2433a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR == RHSR) 2434fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 0; 2435a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR > RHSR) 2436fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 1; 2437fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return -1; 24385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2440f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This 2441f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// routine will assert if passed a built-in type that isn't an integer or enum, 2442f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// or if it is not canonicalized. 2443f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanunsigned ASTContext::getIntegerRank(Type *T) { 2444f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner assert(T->isCanonical() && "T should be canonicalized"); 2445f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (EnumType* ET = dyn_cast<EnumType>(T)) 2446f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman T = ET->getDecl()->getIntegerType().getTypePtr(); 2447f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 2448a34267595534a72703290153a6f7e3da1adcec59Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::WChar)) 2449a34267595534a72703290153a6f7e3da1adcec59Eli Friedman T = getFromTargetType(Target.getWCharType()).getTypePtr(); 2450a34267595534a72703290153a6f7e3da1adcec59Eli Friedman 2451f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (T->isSpecificBuiltinType(BuiltinType::Char16)) 2452f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith T = getFromTargetType(Target.getChar16Type()).getTypePtr(); 2453f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 2454f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (T->isSpecificBuiltinType(BuiltinType::Char32)) 2455f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith T = getFromTargetType(Target.getChar32Type()).getTypePtr(); 2456f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 2457f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // There are two things which impact the integer rank: the width, and 2458f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // the ordering of builtins. The builtin ordering is encoded in the 2459f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // bottom three bits; the width is encoded in the bits above that. 24601b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T)) 2461f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return FWIT->getWidth() << 3; 2462f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 2463f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 24647cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner default: assert(0 && "getIntegerRank(): not a built-in integer"); 24657cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Bool: 2466f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 1 + (getIntWidth(BoolTy) << 3); 24677cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_S: 24687cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_U: 24697cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::SChar: 24707cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UChar: 2471f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 2 + (getIntWidth(CharTy) << 3); 24727cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Short: 24737cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UShort: 2474f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 3 + (getIntWidth(ShortTy) << 3); 24757cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Int: 24767cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UInt: 2477f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 4 + (getIntWidth(IntTy) << 3); 24787cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Long: 24797cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULong: 2480f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 5 + (getIntWidth(LongTy) << 3); 24817cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::LongLong: 24827cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULongLong: 2483f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 6 + (getIntWidth(LongLongTy) << 3); 24842df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 24852df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::UInt128: 24862df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return 7 + (getIntWidth(Int128Ty) << 3); 2487f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner } 2488f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner} 2489f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner 249004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \brief Whether this is a promotable bitfield reference according 249104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 249204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// 249304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \returns the type this bit-field will promote to, or NULL if no 249404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// promotion occurs. 249504e8357f6801e9ff52673e7e899a67bbabf9de93Eli FriedmanQualType ASTContext::isPromotableBitField(Expr *E) { 249604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman FieldDecl *Field = E->getBitField(); 249704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (!Field) 249804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 249904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 250004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman QualType FT = Field->getType(); 250104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 250204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman llvm::APSInt BitWidthAP = Field->getBitWidth()->EvaluateAsInt(*this); 250304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t BitWidth = BitWidthAP.getZExtValue(); 250404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 250504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // GCC extension compatibility: if the bit-field size is less than or equal 250604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // to the size of int, it gets promoted no matter what its type is. 250704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // For instance, unsigned long bf : 4 gets promoted to signed int. 250804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth < IntSize) 250904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return IntTy; 251004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 251104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth == IntSize) 251204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return FT->isSignedIntegerType() ? IntTy : UnsignedIntTy; 251304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 251404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // Types bigger than int are not subject to promotions, and therefore act 251504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // like the base type. 251604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // FIXME: This doesn't quite match what gcc does, but what gcc does here 251704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // is ridiculous. 251804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 251904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman} 252004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 2521a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// getPromotedIntegerType - Returns the type that Promotable will 2522a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 2523a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// integer type. 2524a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli FriedmanQualType ASTContext::getPromotedIntegerType(QualType Promotable) { 2525a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(!Promotable.isNull()); 2526a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isPromotableIntegerType()); 2527a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (Promotable->isSignedIntegerType()) 2528a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return IntTy; 2529a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t PromotableSize = getTypeSize(Promotable); 2530a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 2531a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize); 2532a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy; 2533a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 2534a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 25357cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// getIntegerTypeOrder - Returns the highest ranked integer type: 25367cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 25377cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// LHS < RHS, return -1. 25387cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattnerint ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) { 2539f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Type *LHSC = getCanonicalType(LHS).getTypePtr(); 2540f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Type *RHSC = getCanonicalType(RHS).getTypePtr(); 25417cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSC == RHSC) return 0; 25425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2543f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool LHSUnsigned = LHSC->isUnsignedIntegerType(); 2544f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool RHSUnsigned = RHSC->isUnsignedIntegerType(); 25455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25467cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned LHSRank = getIntegerRank(LHSC); 25477cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned RHSRank = getIntegerRank(RHSC); 25485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25497cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. 25507cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank == RHSRank) return 0; 25517cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return LHSRank > RHSRank ? 1 : -1; 25527cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 25537cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 25547cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. 25557cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned) { 25567cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [LHS] type is larger, return it. 25577cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank >= RHSRank) 25587cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 25597cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 25607cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 25617cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 25627cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // powers of two larger than each other, this is always safe. 25637cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 25647cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 25657cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 25667cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [RHS] type is larger, return it. 25677cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (RHSRank >= LHSRank) 25687cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 25695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25707cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 25717cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 25727cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // powers of two larger than each other, this is always safe. 25737cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 25745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 257571993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 257671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson// getCFConstantStringType - Return the type used for constant CFStrings. 257771993dd85eed9cc42c6b2fa61ee5c53026b74817Anders CarlssonQualType ASTContext::getCFConstantStringType() { 257871993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson if (!CFConstantStringTypeDecl) { 25796c2b6eb8d836da19007f7540709e16d5e39a1cbaChris Lattner CFConstantStringTypeDecl = 258039ba4aeca296b1c9f04bde7d9d3cbbf129f1abd3Argyrios Kyrtzidis RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), 2581df042e6c2bf06b2d9ed53c52469599ac1bd93a3fTed Kremenek &Idents.get("NSConstantString")); 2582f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson QualType FieldTypes[4]; 258371993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 258471993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const int *isa; 258571993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson FieldTypes[0] = getPointerType(IntTy.getQualifiedType(QualType::Const)); 2586f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson // int flags; 2587f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[1] = IntTy; 258871993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const char *str; 2589f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[2] = getPointerType(CharTy.getQualifiedType(QualType::Const)); 259071993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // long length; 2591f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[3] = LongTy; 259271993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 259344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor // Create fields 259444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (unsigned i = 0; i < 4; ++i) { 259544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 259644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation(), 0, 2597a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis FieldTypes[i], /*DInfo=*/0, 2598a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis /*BitWidth=*/0, 25994afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /*Mutable=*/false); 260017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis CFConstantStringTypeDecl->addDecl(Field); 260144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 260244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 260344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor CFConstantStringTypeDecl->completeDefinition(*this); 260471993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson } 260571993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 260671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson return getTagDeclType(CFConstantStringTypeDecl); 26078467583c2704e7a9691ea56939a029015f0ade0aGabor Greif} 2608b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 2609319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setCFConstantStringType(QualType T) { 26106217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 2611319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid CFConstantStringType"); 2612319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor CFConstantStringTypeDecl = Rec->getDecl(); 2613319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 2614319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 2615bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders CarlssonQualType ASTContext::getObjCFastEnumerationStateType() 2616bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson{ 2617bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson if (!ObjCFastEnumerationStateTypeDecl) { 261844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCFastEnumerationStateTypeDecl = 261944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), 262044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor &Idents.get("__objcFastEnumerationState")); 262144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 2622bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson QualType FieldTypes[] = { 2623bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson UnsignedLongTy, 2624de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff getPointerType(ObjCIdTypedefType), 2625bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson getPointerType(UnsignedLongTy), 2626bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson getConstantArrayType(UnsignedLongTy, 2627bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson llvm::APInt(32, 5), ArrayType::Normal, 0) 2628bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson }; 2629bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson 263044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (size_t i = 0; i < 4; ++i) { 263144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor FieldDecl *Field = FieldDecl::Create(*this, 263244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCFastEnumerationStateTypeDecl, 263344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation(), 0, 2634a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis FieldTypes[i], /*DInfo=*/0, 2635a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis /*BitWidth=*/0, 26364afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /*Mutable=*/false); 263717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCFastEnumerationStateTypeDecl->addDecl(Field); 263844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 2639bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson 264044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCFastEnumerationStateTypeDecl->completeDefinition(*this); 2641bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson } 2642bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson 2643bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson return getTagDeclType(ObjCFastEnumerationStateTypeDecl); 2644bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson} 2645bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson 2646319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setObjCFastEnumerationStateType(QualType T) { 26476217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 2648319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid ObjCFAstEnumerationStateType"); 2649319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor ObjCFastEnumerationStateTypeDecl = Rec->getDecl(); 2650319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 2651319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 2652e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// This returns true if a type has been typedefed to BOOL: 2653e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// typedef <type> BOOL; 26542d99833e8c956775f2183601cd120b65b569c867Chris Lattnerstatic bool isTypeTypedefedAsBOOL(QualType T) { 2655e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (const TypedefType *TT = dyn_cast<TypedefType>(T)) 2656bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) 2657bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner return II->isStr("BOOL"); 265885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 265985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return false; 266085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 266185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 2662a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingTypeSize returns size of type for objective-c encoding 266333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// purpose. 2664a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekint ASTContext::getObjCEncodingTypeSize(QualType type) { 266598be4943e8dc4f3905629a7102668960873cf863Chris Lattner uint64_t sz = getTypeSize(type); 266633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 266733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Make all integer and enum types at least as large as an int 266833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (sz > 0 && type->isIntegralType()) 266998be4943e8dc4f3905629a7102668960873cf863Chris Lattner sz = std::max(sz, getTypeSize(IntTy)); 267033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Treat arrays as pointers, since that's how they're passed in. 267133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian else if (type->isArrayType()) 267298be4943e8dc4f3905629a7102668960873cf863Chris Lattner sz = getTypeSize(VoidPtrTy); 267398be4943e8dc4f3905629a7102668960873cf863Chris Lattner return sz / getTypeSize(CharTy); 267433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 267533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 2676a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingForMethodDecl - Return the encoded type for this method 267733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// declaration. 2678c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbarvoid ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, 2679e6db3b09a79d4affaa5c7becbfb6bba3c08430c1Chris Lattner std::string& S) { 2680c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 2681ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian // Encode type qualifer, 'in', 'inout', etc. for the return type. 2682a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek getObjCEncodingForTypeQualifier(Decl->getObjCDeclQualifier(), S); 268333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Encode result type. 26840d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar getObjCEncodingForType(Decl->getResultType(), S); 268533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Compute size of all parameters. 268633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Start with computing size of a pointer in number of bytes. 268733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // FIXME: There might(should) be a better way of doing this computation! 268833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian SourceLocation Loc; 268998be4943e8dc4f3905629a7102668960873cf863Chris Lattner int PtrSize = getTypeSize(VoidPtrTy) / getTypeSize(CharTy); 269033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // The first two arguments (self and _cmd) are pointers; account for 269133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // their size. 269233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian int ParmOffset = 2 * PtrSize; 269389951a86b594513c2a013532ed45d197413b1087Chris Lattner for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(), 269489951a86b594513c2a013532ed45d197413b1087Chris Lattner E = Decl->param_end(); PI != E; ++PI) { 269589951a86b594513c2a013532ed45d197413b1087Chris Lattner QualType PType = (*PI)->getType(); 269689951a86b594513c2a013532ed45d197413b1087Chris Lattner int sz = getObjCEncodingTypeSize(PType); 2697a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek assert (sz > 0 && "getObjCEncodingForMethodDecl - Incomplete param type"); 269833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset += sz; 269933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 270033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += llvm::utostr(ParmOffset); 270133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += "@0:"; 270233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += llvm::utostr(PtrSize); 270333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 270433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Argument types. 270533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset = 2 * PtrSize; 270689951a86b594513c2a013532ed45d197413b1087Chris Lattner for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(), 270789951a86b594513c2a013532ed45d197413b1087Chris Lattner E = Decl->param_end(); PI != E; ++PI) { 270889951a86b594513c2a013532ed45d197413b1087Chris Lattner ParmVarDecl *PVDecl = *PI; 27094306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian QualType PType = PVDecl->getOriginalType(); 27104306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian if (const ArrayType *AT = 2711ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 2712ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // Use array's original type only if it has known number of 2713ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // elements. 2714bb3fde337fb712c0e6da8790d431621be4793048Steve Naroff if (!isa<ConstantArrayType>(AT)) 2715ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 2716ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff } else if (PType->isFunctionType()) 2717ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 2718ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian // Process argument qualifiers for user supplied arguments; such as, 271933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // 'in', 'inout', etc. 27204306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian getObjCEncodingForTypeQualifier(PVDecl->getObjCDeclQualifier(), S); 27210d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar getObjCEncodingForType(PType, S); 272233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += llvm::utostr(ParmOffset); 2723a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParmOffset += getObjCEncodingTypeSize(PType); 272433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 272533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 272633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 2727c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// getObjCEncodingForPropertyDecl - Return the encoded type for this 272883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// property declaration. If non-NULL, Container must be either an 2729c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be 2730c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// NULL when getting encodings for protocol properties. 273183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// Property attributes are stored as a comma-delimited C string. The simple 273283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// attributes readonly and bycopy are encoded as single characters. The 273383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// parametrized attributes, getter=name, setter=name, and ivar=name, are 273483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// encoded as single characters, followed by an identifier. Property types 273583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// are also encoded as a parametrized attribute. The characters used to encode 273683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// these attributes are defined by the following enumeration: 273783bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @code 273883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// enum PropertyAttributes { 273983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyReadOnly = 'R', // property is read-only. 274083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyBycopy = 'C', // property is a copy of the value last assigned 274183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyByref = '&', // property is a reference to the value last assigned 274283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyDynamic = 'D', // property is dynamic 274383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyGetter = 'G', // followed by getter selector name 274483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertySetter = 'S', // followed by setter selector name 274583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyInstanceVariable = 'V' // followed by instance variable name 274683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyType = 't' // followed by old-style type encoding. 274783bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyWeak = 'W' // 'weak' property 274883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyStrong = 'P' // property GC'able 274983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyNonAtomic = 'N' // property non-atomic 275083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// }; 275183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @endcode 2752c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbarvoid ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 2753c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const Decl *Container, 2754e6db3b09a79d4affaa5c7becbfb6bba3c08430c1Chris Lattner std::string& S) { 2755c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Collect information from the property implementation decl(s). 2756c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar bool Dynamic = false; 2757c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *SynthesizePID = 0; 2758c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2759c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: Duplicated code due to poor abstraction. 2760c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Container) { 2761c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (const ObjCCategoryImplDecl *CID = 2762c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar dyn_cast<ObjCCategoryImplDecl>(Container)) { 2763c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 276417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = CID->propimpl_begin(), e = CID->propimpl_end(); 2765653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 2766c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *PID = *i; 2767c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 2768c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2769c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 2770c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 2771c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 2772c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2773c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2774c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2775c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 277661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 2777c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 277817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = OID->propimpl_begin(), e = OID->propimpl_end(); 2779653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 2780c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *PID = *i; 2781c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 2782c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2783c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 2784c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 2785c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 2786c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2787c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2788c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2789c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2790c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2791c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2792c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 2793c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S = "T"; 2794c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2795c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Encode result type. 2796090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // GCC has some special rules regarding encoding of properties which 2797090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // closely resembles encoding of ivars. 2798153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar getObjCEncodingForTypeImpl(PD->getType(), S, true, true, 0, 2799090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* outermost type */, 2800090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* encoding for property */); 2801c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2802c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->isReadOnly()) { 2803c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",R"; 2804c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 2805c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar switch (PD->getSetterKind()) { 2806c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Assign: break; 2807c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Copy: S += ",C"; break; 2808c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Retain: S += ",&"; break; 2809c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2810c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2811c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2812c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // It really isn't clear at all what this means, since properties 2813c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // are "dynamic by default". 2814c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Dynamic) 2815c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",D"; 2816c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2817090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic) 2818090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian S += ",N"; 2819090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian 2820c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { 2821c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",G"; 2822077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getGetterName().getAsString(); 2823c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2824c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2825c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { 2826c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",S"; 2827077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getSetterName().getAsString(); 2828c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2829c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2830c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (SynthesizePID) { 2831c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); 2832c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",V"; 283339f34e97d6a468f0a7dfa5664c61217cffc65b74Chris Lattner S += OID->getNameAsString(); 2834c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2835c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2836c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: OBJCGC: weak & strong 2837c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar} 2838c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2839a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// getLegacyIntegralTypeEncoding - 2840a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// Another legacy compatibility encoding: 32-bit longs are encoded as 2841c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian/// 'l' or 'L' , but not always. For typedefs, we need to use 2842a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 'i' or 'I' instead if encoding a struct field, or a pointer! 2843a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 2844a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanianvoid ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { 28458e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(PointeeTy.getTypePtr())) { 2846a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (const BuiltinType *BT = PointeeTy->getAsBuiltinType()) { 2847c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian if (BT->getKind() == BuiltinType::ULong && 2848c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian ((const_cast<ASTContext *>(this))->getIntWidth(PointeeTy) == 32)) 2849a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = UnsignedIntTy; 2850c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian else 2851c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian if (BT->getKind() == BuiltinType::Long && 2852c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian ((const_cast<ASTContext *>(this))->getIntWidth(PointeeTy) == 32)) 2853a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = IntTy; 2854a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2855a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2856a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian} 2857a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 28587d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanianvoid ASTContext::getObjCEncodingForType(QualType T, std::string& S, 2859153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *Field) { 286082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // We follow the behavior of gcc, expanding structures which are 286182a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // directly pointed to, and expanding embedded structures. Note that 286282a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // these rules are sufficient to prevent recursive encoding of the 286382a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // same type. 28645b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09Fariborz Jahanian getObjCEncodingForTypeImpl(T, S, true, true, Field, 28655b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09Fariborz Jahanian true /* outermost type */); 286682a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar} 286782a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar 28688b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanianstatic void EncodeBitField(const ASTContext *Context, std::string& S, 2869153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD) { 28708b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian const Expr *E = FD->getBitWidth(); 28718b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian assert(E && "bitfield width not there - getObjCEncodingForTypeImpl"); 28728b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian ASTContext *Ctx = const_cast<ASTContext*>(Context); 28739a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman unsigned N = E->EvaluateAsInt(*Ctx).getZExtValue(); 28748b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'b'; 28758b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += llvm::utostr(N); 28768b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian} 28778b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian 287882a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbarvoid ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, 287982a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandPointedToStructures, 288082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandStructures, 2881153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD, 2882090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian bool OutermostType, 28836ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor bool EncodingProperty) { 2884e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (const BuiltinType *BT = T->getAsBuiltinType()) { 2885ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD && FD->isBitField()) 2886ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return EncodeBitField(this, S, FD); 2887ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner char encoding; 2888ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner switch (BT->getKind()) { 2889ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner default: assert(0 && "Unhandled builtin type kind"); 2890ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Void: encoding = 'v'; break; 2891ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Bool: encoding = 'B'; break; 2892ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Char_U: 2893ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UChar: encoding = 'C'; break; 2894ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UShort: encoding = 'S'; break; 2895ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UInt: encoding = 'I'; break; 2896ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::ULong: 289772696e17f90d399448d360cb43aebe5eb2007d4fFariborz Jahanian encoding = 2898ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner (const_cast<ASTContext *>(this))->getIntWidth(T) == 32 ? 'L' : 'Q'; 289972696e17f90d399448d360cb43aebe5eb2007d4fFariborz Jahanian break; 2900ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UInt128: encoding = 'T'; break; 2901ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::ULongLong: encoding = 'Q'; break; 2902ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Char_S: 2903ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::SChar: encoding = 'c'; break; 2904ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Short: encoding = 's'; break; 2905ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Int: encoding = 'i'; break; 2906ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Long: 2907ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner encoding = 2908ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner (const_cast<ASTContext *>(this))->getIntWidth(T) == 32 ? 'l' : 'q'; 2909ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner break; 2910ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::LongLong: encoding = 'q'; break; 2911ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Int128: encoding = 't'; break; 2912ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Float: encoding = 'f'; break; 2913ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Double: encoding = 'd'; break; 2914ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::LongDouble: encoding = 'd'; break; 291543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 2916ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 2917ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += encoding; 2918ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 2919ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 2920ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 2921ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ComplexType *CT = T->getAsComplexType()) { 2922c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson S += 'j'; 2923c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, 0, false, 2924c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson false); 2925ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 2926ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 2927ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 29286217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = T->getAs<PointerType>()) { 292985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson QualType PointeeTy = PT->getPointeeType(); 2930a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian bool isReadOnly = false; 2931a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // For historical/compatibility reasons, the read-only qualifier of the 2932a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // pointee gets emitted _before_ the '^'. The read-only qualifier of 2933a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // the pointer itself gets ignored, _unless_ we are looking at a typedef! 2934a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Also, do not emit the 'r' for anything but the outermost type! 29358e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(T.getTypePtr())) { 2936a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (OutermostType && T.isConstQualified()) { 2937a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 2938a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 2939a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 29409fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (OutermostType) { 2941a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType P = PointeeTy; 29426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek while (P->getAs<PointerType>()) 29436217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek P = P->getAs<PointerType>()->getPointeeType(); 2944a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (P.isConstQualified()) { 2945a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 2946a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 2947a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2948a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2949a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (isReadOnly) { 2950a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Another legacy compatibility encoding. Some ObjC qualifier and type 2951a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // combinations need to be rearranged. 2952a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Rewrite "in const" from "nr" to "rn" 2953a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian const char * s = S.c_str(); 2954a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian int len = S.length(); 2955a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (len >= 2 && s[len-2] == 'n' && s[len-1] == 'r') { 2956a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian std::string replace = "rn"; 2957a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S.replace(S.end()-2, S.end(), replace); 2958a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2959a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 296014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (isObjCSelType(PointeeTy)) { 29618baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson S += ':'; 29628baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson return; 2963c2939bc82ce177c0413feb0cd9ce70aefd6235fbFariborz Jahanian } 296485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 296585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson if (PointeeTy->isCharType()) { 296685f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // char pointer types should be encoded as '*' unless it is a 296785f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // type that has been typedef'd to 'BOOL'. 2968e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (!isTypeTypedefedAsBOOL(PointeeTy)) { 296985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '*'; 297085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return; 297185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 29726217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek } else if (const RecordType *RTy = PointeeTy->getAs<RecordType>()) { 29739533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_class *" to "#". 29749533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { 29759533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '#'; 29769533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 29779533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 29789533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_object *" to "@". 29799533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_object")) { 29809533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '@'; 29819533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 29829533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 29839533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // fall through... 298485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 298585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '^'; 2986a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(PointeeTy); 2987a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 2988ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner getObjCEncodingForTypeImpl(PointeeTy, S, false, ExpandPointedToStructures, 298943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian NULL); 2990ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 2991ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 2992ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 2993ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ArrayType *AT = 2994ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Ignore type qualifiers etc. 2995ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { 2996559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson if (isa<IncompleteArrayType>(AT)) { 2997559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson // Incomplete arrays are encoded as a pointer to the array element. 2998559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '^'; 2999559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson 3000559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson getObjCEncodingForTypeImpl(AT->getElementType(), S, 3001559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 3002559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } else { 3003559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '['; 300485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 3005559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) 3006559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += llvm::utostr(CAT->getSize().getZExtValue()); 3007559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson else { 3008559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson //Variable length arrays are encoded as a regular array with 0 elements. 3009559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson assert(isa<VariableArrayType>(AT) && "Unknown array type!"); 3010559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '0'; 3011559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 301285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 3013559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson getObjCEncodingForTypeImpl(AT->getElementType(), S, 3014559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 3015559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += ']'; 3016559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 3017ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3018ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3019ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3020ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (T->getAsFunctionType()) { 3021c0a87b7db06643178ad2cbce0767548c139ea387Anders Carlsson S += '?'; 3022ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3023ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3024ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 30256217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RTy = T->getAs<RecordType>()) { 302682a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar RecordDecl *RDecl = RTy->getDecl(); 3027d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? '(' : '{'; 3028502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar // Anonymous structures print as '?' 3029502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar if (const IdentifierInfo *II = RDecl->getIdentifier()) { 3030502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += II->getName(); 3031502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } else { 3032502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += '?'; 3033502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } 30340d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar if (ExpandStructures) { 30357d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian S += '='; 303617945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 303717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 303844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor Field != FieldEnd; ++Field) { 303943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian if (FD) { 3040d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += '"'; 304144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor S += Field->getNameAsString(); 3042d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += '"'; 3043d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 3044d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar 3045d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar // Special case bit-fields. 304643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian if (Field->isBitField()) { 304743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, 304843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian (*Field)); 3049d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } else { 3050a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType qt = Field->getType(); 3051a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(qt); 3052a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getObjCEncodingForTypeImpl(qt, S, false, true, 305343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian FD); 3054d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 30557d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian } 30566de88a873a4cbe06d72602eef57d68006730a80bFariborz Jahanian } 3057d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? ')' : '}'; 3058ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3059ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3060ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3061ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (T->isEnumeralType()) { 30628b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian if (FD && FD->isBitField()) 30638b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian EncodeBitField(this, S, FD); 30648b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian else 30658b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'i'; 3066ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3067ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3068ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3069ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (T->isBlockPointerType()) { 307021a98b188857d690aa4510c52ac4317ffa0908a8Steve Naroff S += "@?"; // Unlike a pointer-to-function, which is "^?". 3071ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3072ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3073ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3074ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (T->isObjCInterfaceType()) { 307543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian // @encode(class_name) 307643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian ObjCInterfaceDecl *OI = T->getAsObjCInterfaceType()->getDecl(); 307743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '{'; 307843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian const IdentifierInfo *II = OI->getIdentifier(); 307943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += II->getName(); 308043822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '='; 3081f1690858344968358131f8d5690d9ee458883000Chris Lattner llvm::SmallVector<FieldDecl*, 32> RecFields; 308243822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian CollectObjCIvars(OI, RecFields); 3083f1690858344968358131f8d5690d9ee458883000Chris Lattner for (unsigned i = 0, e = RecFields.size(); i != e; ++i) { 308443822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian if (RecFields[i]->isBitField()) 308543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true, 308643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian RecFields[i]); 308743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian else 308843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true, 308943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian FD); 309043822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 309143822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '}'; 3092ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 309343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 3094ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3095ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ObjCObjectPointerType *OPT = T->getAsObjCObjectPointerType()) { 309614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->isObjCIdType()) { 309714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '@'; 309814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 3099ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3100ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3101ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCClassType()) { 310214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '#'; 310314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 3104ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3105ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3106ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCQualifiedIdType()) { 310714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff getObjCEncodingForTypeImpl(getObjCIdType(), S, 310814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandPointedToStructures, 310914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandStructures, FD); 311014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (FD || EncodingProperty) { 311114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Note that we do extended encoding of protocol qualifer list 311214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Only when doing ivar or property encoding. 311314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 311467ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 311567ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 311614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '<'; 311714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += (*I)->getNameAsString(); 311814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '>'; 311914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 312014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 312114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 312214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 3123ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3124ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3125ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner QualType PointeeTy = OPT->getPointeeType(); 3126ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (!EncodingProperty && 3127ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner isa<TypedefType>(PointeeTy.getTypePtr())) { 3128ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Another historical/compatibility reason. 3129ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // We encode the underlying type which comes out as 3130ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // {...}; 3131ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '^'; 3132ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner getObjCEncodingForTypeImpl(PointeeTy, S, 3133ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner false, ExpandPointedToStructures, 3134ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner NULL); 313514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 313614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3137ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3138ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '@'; 3139ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD || EncodingProperty) { 3140ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 314167ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff S += OPT->getInterfaceDecl()->getNameAsCString(); 314267ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 314367ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 3144ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '<'; 3145ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += (*I)->getNameAsString(); 3146ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '>'; 3147ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3148ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 3149ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3150ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3151ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3152ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3153ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner assert(0 && "@encode for type not implemented!"); 315485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 315585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 3156a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 3157ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian std::string& S) const { 3158ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_In) 3159ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'n'; 3160ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Inout) 3161ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'N'; 3162ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Out) 3163ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'o'; 3164ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Bycopy) 3165ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'O'; 3166ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Byref) 3167ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'R'; 3168ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Oneway) 3169ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'V'; 3170ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian} 3171ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian 3172ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setBuiltinVaListType(QualType T) { 3173b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson assert(BuiltinVaListType.isNull() && "__builtin_va_list type already set!"); 3174b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 3175b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson BuiltinVaListType = T; 3176b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson} 3177b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 3178ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCIdType(QualType T) { 3179de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCIdTypedefType = T; 31807e219e47de26346885d667131977bd9ca2d7662aSteve Naroff} 31817e219e47de26346885d667131977bd9ca2d7662aSteve Naroff 3182ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCSelType(QualType T) { 3183319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor ObjCSelType = T; 3184319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 3185319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor const TypedefType *TT = T->getAsTypedefType(); 3186319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor if (!TT) 3187319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor return; 3188319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor TypedefDecl *TD = TT->getDecl(); 3189b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 3190b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian // typedef struct objc_selector *SEL; 31916217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const PointerType *ptr = TD->getUnderlyingType()->getAs<PointerType>(); 3192c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian if (!ptr) 3193c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian return; 3194b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian const RecordType *rec = ptr->getPointeeType()->getAsStructureType(); 3195c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian if (!rec) 3196c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian return; 3197b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian SelStructType = rec; 3198b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian} 3199b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 3200ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCProtoType(QualType QT) { 3201a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtoType = QT; 3202390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian} 3203390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3204ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCClassType(QualType T) { 3205de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClassTypedefType = T; 32068baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson} 32078baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson 3208a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { 3209a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek assert(ObjCConstantStringType.isNull() && 32102198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff "'NSConstantString' type already set!"); 32112198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff 3212a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = getObjCInterfaceType(Decl); 32132198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff} 32142198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff 32157532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a qualified 32167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c std::vector. 32177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 32187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool TemplateKeyword, 32197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateDecl *Template) { 32207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 32217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 32227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 32247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateName *QTN = 32257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 32267532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (!QTN) { 32277532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) QualifiedTemplateName(NNS, TemplateKeyword, Template); 32287532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 32297532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 32307532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32317532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 32327532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 32337532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 3234d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// \brief Retrieve the template name that represents a qualified 3235d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// template name such as \c std::vector. 3236d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas GregorTemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 3237d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor bool TemplateKeyword, 3238d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor OverloadedFunctionDecl *Template) { 3239d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor llvm::FoldingSetNodeID ID; 3240d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 3241d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 3242d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor void *InsertPos = 0; 3243d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName *QTN = 3244d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 3245d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor if (!QTN) { 3246d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QTN = new (*this,4) QualifiedTemplateName(NNS, TemplateKeyword, Template); 3247d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 3248d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor } 3249d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 3250d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor return TemplateName(QTN); 3251d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor} 3252d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 32537532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a dependent 32547532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c MetaFun::template apply. 32557532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorTemplateName ASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 32567532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const IdentifierInfo *Name) { 32577532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor assert(NNS->isDependent() && "Nested name specifier must be dependent"); 32587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 32607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName::Profile(ID, NNS, Name); 32617532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 32637532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName *QTN = 32647532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 32657532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32667532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (QTN) 32677532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 32687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32697532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 32707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (CanonNNS == NNS) { 32717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Name); 32727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } else { 32737532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Name); 32747532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Name, Canon); 32757532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 32767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 32787532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 32797532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 32807532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 3281b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor/// getFromTargetType - Given one of the integer types provided by 3282d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// TargetInfo, produce the corresponding type. The unsigned @p Type 3283d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// is actually a value of type @c TargetInfo::IntType. 3284d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas GregorQualType ASTContext::getFromTargetType(unsigned Type) const { 3285b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor switch (Type) { 3286b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::NoInt: return QualType(); 3287b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedShort: return ShortTy; 3288b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedShort: return UnsignedShortTy; 3289b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedInt: return IntTy; 3290b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedInt: return UnsignedIntTy; 3291b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLong: return LongTy; 3292b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLong: return UnsignedLongTy; 3293b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLongLong: return LongLongTy; 3294b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; 3295b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor } 3296b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor 3297b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor assert(false && "Unhandled TargetInfo::IntType value"); 3298b3ac5434ab936f092b8cc48349cb01db3a1e1c76Daniel Dunbar return QualType(); 3299b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor} 3300b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 3301b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 3302b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek// Type Predicates. 3303b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 3304b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 3305fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// isObjCNSObjectType - Return true if this is an NSObject object using 3306fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// NSObject attribute on a c-style pointer type. 3307fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// FIXME - Make it work directly on types. 3308f49545602089be5b1f744e04326b8a566f6d8773Steve Naroff/// FIXME: Move to Type. 3309fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// 3310fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanianbool ASTContext::isObjCNSObjectType(QualType Ty) const { 3311fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { 3312fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian if (TypedefDecl *TD = TDT->getDecl()) 331340b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (TD->getAttr<ObjCNSObjectAttr>()) 3314fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian return true; 3315fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian } 3316fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian return false; 3317fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian} 3318fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian 33194fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 33204fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// garbage collection attribute. 33214fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// 33224fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz JahanianQualType::GCAttrTypes ASTContext::getObjCGCAttrKind(const QualType &Ty) const { 3323b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner QualType::GCAttrTypes GCAttrs = QualType::GCNone; 33244fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian if (getLangOptions().ObjC1 && 33254fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian getLangOptions().getGCMode() != LangOptions::NonGC) { 3326b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner GCAttrs = Ty.getObjCGCAttr(); 33274fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian // Default behavious under objective-c's gc is for objective-c pointers 3328a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian // (or pointers to them) be treated as though they were declared 3329a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian // as __strong. 3330a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian if (GCAttrs == QualType::GCNone) { 3331f49545602089be5b1f744e04326b8a566f6d8773Steve Naroff if (Ty->isObjCObjectPointerType()) 3332a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian GCAttrs = QualType::Strong; 3333a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian else if (Ty->isPointerType()) 33346217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getObjCGCAttrKind(Ty->getAs<PointerType>()->getPointeeType()); 3335a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian } 3336c2112181b96349eb595dc5e8b7073b81ecdec0dbFariborz Jahanian // Non-pointers have none gc'able attribute regardless of the attribute 3337c2112181b96349eb595dc5e8b7073b81ecdec0dbFariborz Jahanian // set on them. 3338f49545602089be5b1f744e04326b8a566f6d8773Steve Naroff else if (!Ty->isAnyPointerType() && !Ty->isBlockPointerType()) 3339c2112181b96349eb595dc5e8b7073b81ecdec0dbFariborz Jahanian return QualType::GCNone; 33404fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian } 3341b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return GCAttrs; 33424fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian} 33434fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian 33446ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 33456ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner// Type Compatibility Testing 33466ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 3347770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner 33486ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner/// areCompatVectorTypes - Return true if the two specified vector types are 33496ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner/// compatible. 33506ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattnerstatic bool areCompatVectorTypes(const VectorType *LHS, 33516ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner const VectorType *RHS) { 33526ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner assert(LHS->isCanonical() && RHS->isCanonical()); 33536ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return LHS->getElementType() == RHS->getElementType() && 335461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner LHS->getNumElements() == RHS->getNumElements(); 33556ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 33566ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 33574084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 33584084c306635b70f37029dca938444e6013f08684Steve Naroff// ObjCQualifiedIdTypesAreCompatible - Compatibility testing for qualified id's. 33594084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 33604084c306635b70f37029dca938444e6013f08684Steve Naroff 33614084c306635b70f37029dca938444e6013f08684Steve Naroff/// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the 33624084c306635b70f37029dca938444e6013f08684Steve Naroff/// inheritance hierarchy of 'rProto'. 33630fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanianbool ASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 33640fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian ObjCProtocolDecl *rProto) { 33654084c306635b70f37029dca938444e6013f08684Steve Naroff if (lProto == rProto) 336614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return true; 33674084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(), 33684084c306635b70f37029dca938444e6013f08684Steve Naroff E = rProto->protocol_end(); PI != E; ++PI) 33694084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lProto, *PI)) 33704084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 33714084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 33724084c306635b70f37029dca938444e6013f08684Steve Naroff} 337314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 33744084c306635b70f37029dca938444e6013f08684Steve Naroff/// QualifiedIdConformsQualifiedId - compare id<p,...> with id<p1,...> 33754084c306635b70f37029dca938444e6013f08684Steve Naroff/// return true if lhs's protocols conform to rhs's protocol; false 33764084c306635b70f37029dca938444e6013f08684Steve Naroff/// otherwise. 33774084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) { 33784084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType()) 33794084c306635b70f37029dca938444e6013f08684Steve Naroff return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false); 33804084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 33814084c306635b70f37029dca938444e6013f08684Steve Naroff} 33824084c306635b70f37029dca938444e6013f08684Steve Naroff 33834084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an 33844084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIDType. 33854084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, 33864084c306635b70f37029dca938444e6013f08684Steve Naroff bool compare) { 33874084c306635b70f37029dca938444e6013f08684Steve Naroff // Allow id<P..> and an 'id' or void* type in all cases. 33884084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhs->isVoidPointerType() || 33894084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->isObjCIdType() || lhs->isObjCClassType()) 33904084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 33914084c306635b70f37029dca938444e6013f08684Steve Naroff else if (rhs->isVoidPointerType() || 33924084c306635b70f37029dca938444e6013f08684Steve Naroff rhs->isObjCIdType() || rhs->isObjCClassType()) 33934084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 33944084c306635b70f37029dca938444e6013f08684Steve Naroff 33954084c306635b70f37029dca938444e6013f08684Steve Naroff if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { 33964084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *rhsOPT = rhs->getAsObjCObjectPointerType(); 33974084c306635b70f37029dca938444e6013f08684Steve Naroff 33984084c306635b70f37029dca938444e6013f08684Steve Naroff if (!rhsOPT) return false; 33994084c306635b70f37029dca938444e6013f08684Steve Naroff 34004084c306635b70f37029dca938444e6013f08684Steve Naroff if (rhsOPT->qual_empty()) { 34014084c306635b70f37029dca938444e6013f08684Steve Naroff // If the RHS is a unqualified interface pointer "NSString*", 34024084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 34034084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 34044084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 34054084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 34064084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 34074084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 34084084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 34090fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (!rhsID->ClassImplementsProtocol(*I, true)) 34104084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 34114084c306635b70f37029dca938444e6013f08684Steve Naroff } 34124084c306635b70f37029dca938444e6013f08684Steve Naroff } 34134084c306635b70f37029dca938444e6013f08684Steve Naroff // If there are no qualifiers and no interface, we have an 'id'. 34144084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 34154084c306635b70f37029dca938444e6013f08684Steve Naroff } 3416de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // Both the right and left sides have qualifiers. 34174084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 34184084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 34194084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 34204084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 3421de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff 3422de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // when comparing an id<P> on lhs with a static type on rhs, 3423de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // see if static class implements all of id's protocols, directly or 3424de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // through its super class and categories. 34254084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 34264084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsOPT->qual_end(); J != E; ++J) { 34274084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 34284084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 34294084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 34304084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 34318f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 34328f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 3433de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 34344084c306635b70f37029dca938444e6013f08684Steve Naroff // If the RHS is a qualified interface pointer "NSString<P>*", 34354084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 34364084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 34374084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 34384084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 34394084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 34404084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 34414084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 34420fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (rhsID->ClassImplementsProtocol(*I, true)) { 34434084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 34444084c306635b70f37029dca938444e6013f08684Steve Naroff break; 34454084c306635b70f37029dca938444e6013f08684Steve Naroff } 34464084c306635b70f37029dca938444e6013f08684Steve Naroff } 34474084c306635b70f37029dca938444e6013f08684Steve Naroff } 34484084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 3449de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return false; 3450de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 34514084c306635b70f37029dca938444e6013f08684Steve Naroff 3452de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return true; 3453de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 34544084c306635b70f37029dca938444e6013f08684Steve Naroff 34554084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType(); 34564084c306635b70f37029dca938444e6013f08684Steve Naroff assert(rhsQID && "One of the LHS/RHS should be id<x>"); 34574084c306635b70f37029dca938444e6013f08684Steve Naroff 34584084c306635b70f37029dca938444e6013f08684Steve Naroff if (const ObjCObjectPointerType *lhsOPT = 34594084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->getAsObjCInterfacePointerType()) { 34604084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhsOPT->qual_empty()) { 34614084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 34624084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { 34634084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = rhsQID->qual_begin(), 34644084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); I != E; ++I) { 34654084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 34664084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 34674084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 34680fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (lhsID->ClassImplementsProtocol(*I, true)) { 34694084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 34704084c306635b70f37029dca938444e6013f08684Steve Naroff break; 34714084c306635b70f37029dca938444e6013f08684Steve Naroff } 34724084c306635b70f37029dca938444e6013f08684Steve Naroff } 34734084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 34744084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 34754084c306635b70f37029dca938444e6013f08684Steve Naroff } 34764084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 34774084c306635b70f37029dca938444e6013f08684Steve Naroff } 34784084c306635b70f37029dca938444e6013f08684Steve Naroff // Both the right and left sides have qualifiers. 34794084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsOPT->qual_begin(), 34804084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsOPT->qual_end(); I != E; ++I) { 34814084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 34824084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 34834084c306635b70f37029dca938444e6013f08684Steve Naroff 34844084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 34854084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 34864084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 34874084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 34884084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); J != E; ++J) { 34894084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 34904084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 34914084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 34924084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 34934084c306635b70f37029dca938444e6013f08684Steve Naroff break; 34944084c306635b70f37029dca938444e6013f08684Steve Naroff } 34954084c306635b70f37029dca938444e6013f08684Steve Naroff } 34964084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 34974084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 34984084c306635b70f37029dca938444e6013f08684Steve Naroff } 34994084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 35004084c306635b70f37029dca938444e6013f08684Steve Naroff } 35014084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 35024084c306635b70f37029dca938444e6013f08684Steve Naroff} 35034084c306635b70f37029dca938444e6013f08684Steve Naroff 35044084c306635b70f37029dca938444e6013f08684Steve Naroff/// canAssignObjCInterfaces - Return true if the two interface types are 35054084c306635b70f37029dca938444e6013f08684Steve Naroff/// compatible for assignment from RHS to LHS. This handles validation of any 35064084c306635b70f37029dca938444e6013f08684Steve Naroff/// protocol qualifiers on the LHS or RHS. 35074084c306635b70f37029dca938444e6013f08684Steve Naroff/// 35084084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 35094084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *RHSOPT) { 35104084c306635b70f37029dca938444e6013f08684Steve Naroff // If either type represents the built-in 'id' or 'Class' types, return true. 35114084c306635b70f37029dca938444e6013f08684Steve Naroff if (LHSOPT->isObjCBuiltinType() || RHSOPT->isObjCBuiltinType()) 35124084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 35134084c306635b70f37029dca938444e6013f08684Steve Naroff 35144084c306635b70f37029dca938444e6013f08684Steve Naroff if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) 35154084c306635b70f37029dca938444e6013f08684Steve Naroff return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 35164084c306635b70f37029dca938444e6013f08684Steve Naroff QualType(RHSOPT,0), 35174084c306635b70f37029dca938444e6013f08684Steve Naroff false); 35184084c306635b70f37029dca938444e6013f08684Steve Naroff 35194084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); 35204084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); 35214084c306635b70f37029dca938444e6013f08684Steve Naroff if (LHS && RHS) // We have 2 user-defined types. 35224084c306635b70f37029dca938444e6013f08684Steve Naroff return canAssignObjCInterfaces(LHS, RHS); 35234084c306635b70f37029dca938444e6013f08684Steve Naroff 35244084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 352514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 352614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 35273d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedmanbool ASTContext::canAssignObjCInterfaces(const ObjCInterfaceType *LHS, 35283d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ObjCInterfaceType *RHS) { 35296ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Verify that the base decls are compatible: the RHS must be a subclass of 35306ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // the LHS. 35316ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner if (!LHS->getDecl()->isSuperClassOf(RHS->getDecl())) 35326ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return false; 35336ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 35346ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // RHS must have a superset of the protocols in the LHS. If the LHS is not 35356ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // protocol qualified at all, then we are good. 3536c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (LHS->getNumProtocols() == 0) 35376ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; 35386ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 35396ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Okay, we know the LHS has protocol qualifiers. If the RHS doesn't, then it 35406ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // isn't a superset. 3541c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (RHS->getNumProtocols() == 0) 35426ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; // FIXME: should return false! 35436ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 3544c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (ObjCInterfaceType::qual_iterator LHSPI = LHS->qual_begin(), 3545c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff LHSPE = LHS->qual_end(); 354691b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff LHSPI != LHSPE; LHSPI++) { 354791b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff bool RHSImplementsProtocol = false; 354891b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff 354991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // If the RHS doesn't implement the protocol on the left, the types 355091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // are incompatible. 3551c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (ObjCInterfaceType::qual_iterator RHSPI = RHS->qual_begin(), 35524084c306635b70f37029dca938444e6013f08684Steve Naroff RHSPE = RHS->qual_end(); 35538f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff RHSPI != RHSPE; RHSPI++) { 35548f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff if ((*RHSPI)->lookupProtocolNamed((*LHSPI)->getIdentifier())) { 355591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff RHSImplementsProtocol = true; 35568f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 35578f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 355891b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 355991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // FIXME: For better diagnostics, consider passing back the protocol name. 356091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff if (!RHSImplementsProtocol) 356191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return false; 356291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 356391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // The RHS implements all protocols listed on the LHS. 356491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return true; 35656ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 35666ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 3567389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroffbool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { 3568389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff // get the "pointed to" types 356914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *LHSOPT = LHS->getAsObjCObjectPointerType(); 357014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff const ObjCObjectPointerType *RHSOPT = RHS->getAsObjCObjectPointerType(); 3571389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff 357214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (!LHSOPT || !RHSOPT) 3573389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff return false; 357414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 357514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return canAssignObjCInterfaces(LHSOPT, RHSOPT) || 357614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff canAssignObjCInterfaces(RHSOPT, LHSOPT); 3577389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff} 3578389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff 3579ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, 3580ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// both shall have the identically qualified version of a compatible type. 3581ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// C99 6.2.7p1: Two types have compatible types if their types are the 3582ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// same. See 6.7.[2,3,5] for additional rules. 35833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedmanbool ASTContext::typesAreCompatible(QualType LHS, QualType RHS) { 35843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return !mergeTypes(LHS, RHS).isNull(); 35853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 35863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 35873d815e7eb56c25d7ed812eced32e41df43039f9aEli FriedmanQualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs) { 35883d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const FunctionType *lbase = lhs->getAsFunctionType(); 35893d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const FunctionType *rbase = rhs->getAsFunctionType(); 359072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *lproto = dyn_cast<FunctionProtoType>(lbase); 359172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *rproto = dyn_cast<FunctionProtoType>(rbase); 35923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allLTypes = true; 35933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allRTypes = true; 35943d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 35953d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check return type 35963d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType retType = mergeTypes(lbase->getResultType(), rbase->getResultType()); 35973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (retType.isNull()) return QualType(); 359861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(retType) != getCanonicalType(lbase->getResultType())) 359961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 360061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(retType) != getCanonicalType(rbase->getResultType())) 360161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 36026dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump // FIXME: double check this 36032455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn = lbase->getNoReturnAttr() || rbase->getNoReturnAttr(); 36042455636163fdd18581d7fdae816433f886d88213Mike Stump if (NoReturn != lbase->getNoReturnAttr()) 36052455636163fdd18581d7fdae816433f886d88213Mike Stump allLTypes = false; 36062455636163fdd18581d7fdae816433f886d88213Mike Stump if (NoReturn != rbase->getNoReturnAttr()) 36072455636163fdd18581d7fdae816433f886d88213Mike Stump allRTypes = false; 36082455636163fdd18581d7fdae816433f886d88213Mike Stump 36093d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto && rproto) { // two C99 style function prototypes 3610465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && 3611465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl "C++ shouldn't be here"); 36123d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned lproto_nargs = lproto->getNumArgs(); 36133d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned rproto_nargs = rproto->getNumArgs(); 36143d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36153d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Compatible functions must have the same number of arguments 36163d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto_nargs != rproto_nargs) 36173d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 36183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36193d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Variadic and non-variadic functions aren't compatible 36203d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto->isVariadic() != rproto->isVariadic()) 36213d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 36223d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36237fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis if (lproto->getTypeQuals() != rproto->getTypeQuals()) 36247fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis return QualType(); 36257fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis 36263d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check argument compatibility 36273d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman llvm::SmallVector<QualType, 10> types; 36283d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < lproto_nargs; i++) { 36293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType largtype = lproto->getArgType(i).getUnqualifiedType(); 36303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType rargtype = rproto->getArgType(i).getUnqualifiedType(); 36313d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argtype = mergeTypes(largtype, rargtype); 36323d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argtype.isNull()) return QualType(); 36333d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman types.push_back(argtype); 363461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(largtype)) 363561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 363661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(rargtype)) 363761710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 36383d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 36393d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 36403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 36413d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, types.begin(), types.size(), 36422455636163fdd18581d7fdae816433f886d88213Mike Stump lproto->isVariadic(), lproto->getTypeQuals(), 36432455636163fdd18581d7fdae816433f886d88213Mike Stump NoReturn); 36443d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 36453d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto) allRTypes = false; 36473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (rproto) allLTypes = false; 36483d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 364972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *proto = lproto ? lproto : rproto; 36503d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto) { 3651465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!proto->hasExceptionSpec() && "C++ shouldn't be here"); 36523d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto->isVariadic()) return QualType(); 36533d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check that the types are compatible with the types that 36543d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // would result from default argument promotions (C99 6.7.5.3p15). 36553d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // The only types actually affected are promotable integer 36563d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // types and floats, which would be passed as a different 36573d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // type depending on whether the prototype is visible. 36583d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned proto_nargs = proto->getNumArgs(); 36593d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < proto_nargs; ++i) { 36603d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argTy = proto->getArgType(i); 36613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argTy->isPromotableIntegerType() || 36623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman getCanonicalType(argTy).getUnqualifiedType() == FloatTy) 36633d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 36643d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 36653d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36663d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 36673d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 36683d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, proto->arg_type_begin(), 36692d3c191e1d5545e1724ee6e0550c70eef54beff2Mike Stump proto->getNumArgs(), proto->isVariadic(), 36702d3c191e1d5545e1724ee6e0550c70eef54beff2Mike Stump proto->getTypeQuals(), NoReturn); 36713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 36723d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 36743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 36752455636163fdd18581d7fdae816433f886d88213Mike Stump return getFunctionNoProtoType(retType, NoReturn); 36763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 36773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36783d815e7eb56c25d7ed812eced32e41df43039f9aEli FriedmanQualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { 367943d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // C++ [expr]: If an expression initially has the type "reference to T", the 368043d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // type is adjusted to "T" prior to any further analysis, the expression 368143d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // designates the object or function denoted by the reference, and the 36827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // expression is an lvalue unless the reference is an rvalue reference and 36837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // the expression is a function call (possibly inside parentheses). 36843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: C++ shouldn't be going through here! The rules are different 36853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // enough that they should be handled separately. 36867c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // FIXME: Merging of lvalue and rvalue references is incorrect. C++ *really* 36877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // shouldn't be going through here! 36886217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RT = LHS->getAs<ReferenceType>()) 3689c4e405996217f4be20f73186da53b23b5c4783dcChris Lattner LHS = RT->getPointeeType(); 36906217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RT = RHS->getAs<ReferenceType>()) 3691c4e405996217f4be20f73186da53b23b5c4783dcChris Lattner RHS = RT->getPointeeType(); 36923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSCan = getCanonicalType(LHS), 36943d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman RHSCan = getCanonicalType(RHS); 36953d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 3696f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner // If two types are identical, they are compatible. 36973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LHSCan == RHSCan) 36983d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 36993d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37003d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // If the qualifiers are different, the types aren't compatible 37015a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // Note that we handle extended qualifiers later, in the 37025a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // case for ExtQualType. 37035a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman if (LHSCan.getCVRQualifiers() != RHSCan.getCVRQualifiers()) 37043d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 37053d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 3706852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass LHSClass = LHSCan->getTypeClass(); 3707852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass RHSClass = RHSCan->getTypeClass(); 3708f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner 37091adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // We want to consider the two function types to be the same for these 37101adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // comparisons, just force one to the other. 37111adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; 37121adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; 37134c721d381fb279899337d120edd4a24d405e56b2Eli Friedman 371407d258756dc856c6987c394a0972884e6ed46765Eli Friedman // Strip off objc_gc attributes off the top level so they can be merged. 371507d258756dc856c6987c394a0972884e6ed46765Eli Friedman // This is a complete mess, but the attribute itself doesn't make much sense. 3716585f7b2f5c818d7579cffc91590bdc9e3d8b645dFariborz Jahanian if (RHSClass == Type::ExtQual) { 371707d258756dc856c6987c394a0972884e6ed46765Eli Friedman QualType::GCAttrTypes GCAttr = RHSCan.getObjCGCAttr(); 371807d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (GCAttr != QualType::GCNone) { 371986f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian QualType::GCAttrTypes GCLHSAttr = LHSCan.getObjCGCAttr(); 37208df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian // __weak attribute must appear on both declarations. 372186f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian // __strong attribue is redundant if other decl is an objective-c 372286f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian // object pointer (or decorated with __strong attribute); otherwise 372386f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian // issue error. 372486f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian if ((GCAttr == QualType::Weak && GCLHSAttr != GCAttr) || 372586f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian (GCAttr == QualType::Strong && GCLHSAttr != GCAttr && 372614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff !LHSCan->isObjCObjectPointerType())) 37278df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian return QualType(); 37288df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian 372907d258756dc856c6987c394a0972884e6ed46765Eli Friedman RHS = QualType(cast<ExtQualType>(RHS.getDesugaredType())->getBaseType(), 373007d258756dc856c6987c394a0972884e6ed46765Eli Friedman RHS.getCVRQualifiers()); 373107d258756dc856c6987c394a0972884e6ed46765Eli Friedman QualType Result = mergeTypes(LHS, RHS); 37328df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian if (!Result.isNull()) { 37338df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian if (Result.getObjCGCAttr() == QualType::GCNone) 37348df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian Result = getObjCGCQualType(Result, GCAttr); 37358df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian else if (Result.getObjCGCAttr() != GCAttr) 37368df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian Result = QualType(); 37378df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian } 373807d258756dc856c6987c394a0972884e6ed46765Eli Friedman return Result; 373907d258756dc856c6987c394a0972884e6ed46765Eli Friedman } 3740585f7b2f5c818d7579cffc91590bdc9e3d8b645dFariborz Jahanian } 3741585f7b2f5c818d7579cffc91590bdc9e3d8b645dFariborz Jahanian if (LHSClass == Type::ExtQual) { 374207d258756dc856c6987c394a0972884e6ed46765Eli Friedman QualType::GCAttrTypes GCAttr = LHSCan.getObjCGCAttr(); 374307d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (GCAttr != QualType::GCNone) { 37448df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian QualType::GCAttrTypes GCRHSAttr = RHSCan.getObjCGCAttr(); 37458df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian // __weak attribute must appear on both declarations. __strong 374686f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian // __strong attribue is redundant if other decl is an objective-c 374786f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian // object pointer (or decorated with __strong attribute); otherwise 374886f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian // issue error. 374986f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian if ((GCAttr == QualType::Weak && GCRHSAttr != GCAttr) || 375086f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian (GCAttr == QualType::Strong && GCRHSAttr != GCAttr && 375114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff !RHSCan->isObjCObjectPointerType())) 37528df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian return QualType(); 375386f4385536a0b2202860ad4e20d84f9330b1a4f4Fariborz Jahanian 375407d258756dc856c6987c394a0972884e6ed46765Eli Friedman LHS = QualType(cast<ExtQualType>(LHS.getDesugaredType())->getBaseType(), 375507d258756dc856c6987c394a0972884e6ed46765Eli Friedman LHS.getCVRQualifiers()); 375607d258756dc856c6987c394a0972884e6ed46765Eli Friedman QualType Result = mergeTypes(LHS, RHS); 37578df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian if (!Result.isNull()) { 37588df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian if (Result.getObjCGCAttr() == QualType::GCNone) 37598df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian Result = getObjCGCQualType(Result, GCAttr); 37608df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian else if (Result.getObjCGCAttr() != GCAttr) 37618df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian Result = QualType(); 37628df7a28269a1c0f4444928d0baea402b410e95f1Fariborz Jahanian } 3763354e53da656237e25518b3fafa3bf84de6e6f57eEli Friedman return Result; 376407d258756dc856c6987c394a0972884e6ed46765Eli Friedman } 3765585f7b2f5c818d7579cffc91590bdc9e3d8b645dFariborz Jahanian } 3766585f7b2f5c818d7579cffc91590bdc9e3d8b645dFariborz Jahanian 37674c721d381fb279899337d120edd4a24d405e56b2Eli Friedman // Same as above for arrays 3768a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) 3769a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner LHSClass = Type::ConstantArray; 3770a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) 3771a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner RHSClass = Type::ConstantArray; 3772a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner 3773213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman // Canonicalize ExtVector -> Vector. 3774213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; 3775213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; 3776ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff 37774e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff // If the canonical type classes don't match. 37784e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff if (LHSClass != RHSClass) { 37791adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, 37801adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // a signed integer type, or an unsigned integer type. 37813d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (const EnumType* ETy = LHS->getAsEnumType()) { 37823d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ETy->getDecl()->getIntegerType() == RHSCan.getUnqualifiedType()) 37833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 3784bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 37853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (const EnumType* ETy = RHS->getAsEnumType()) { 37863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ETy->getDecl()->getIntegerType() == LHSCan.getUnqualifiedType()) 37873d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 3788bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 37891adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner 37903d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 3791ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 37923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37934a74678ed6c3dedac05d02b1ee341f1db869f049Steve Naroff // The canonical type classes match. 37941adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner switch (LHSClass) { 379572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 379672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 379772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 379872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 379972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 380072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor assert(false && "Non-canonical and dependent types shouldn't get here"); 380172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 380272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 38037c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 38047c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 380572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::MemberPointer: 380672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor assert(false && "C++ should never be in mergeTypes"); 380772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 380872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 380972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 381072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::VariableArray: 381172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::FunctionProto: 381272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::ExtVector: 381372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor assert(false && "Types are eliminated above"); 381472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 381572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 38161adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Pointer: 38173d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 38183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Merge two pointer types, while trying to preserve typedef info 38196217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<PointerType>()->getPointeeType(); 38206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<PointerType>()->getPointeeType(); 38213d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType ResultType = mergeTypes(LHSPointee, RHSPointee); 38223d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 382307d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 382461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 382507d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 382661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 38273d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getPointerType(ResultType); 38283d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 3829c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff case Type::BlockPointer: 3830c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff { 3831c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff // Merge two block pointer types, while trying to preserve typedef info 38326217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<BlockPointerType>()->getPointeeType(); 38336217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<BlockPointerType>()->getPointeeType(); 3834c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff QualType ResultType = mergeTypes(LHSPointee, RHSPointee); 3835c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (ResultType.isNull()) return QualType(); 3836c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 3837c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return LHS; 3838c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 3839c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return RHS; 3840c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return getBlockPointerType(ResultType); 3841c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff } 38421adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::ConstantArray: 38433d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 38443d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); 38453d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); 38463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) 38473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 38483d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 38493d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSElem = getAsArrayType(LHS)->getElementType(); 38503d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType RHSElem = getAsArrayType(RHS)->getElementType(); 38513d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType ResultType = mergeTypes(LHSElem, RHSElem); 38523d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 385361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 385461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 385561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 385661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 38573bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), 38583bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 38593bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), 38603bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 38613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* LVAT = getAsVariableArrayType(LHS); 38623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* RVAT = getAsVariableArrayType(RHS); 386361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 386461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 386561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 386661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 38673d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LVAT) { 38683d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 38693d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of LHS, but the type 38703d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 38713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 38723d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 38733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (RVAT) { 38743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 38753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of RHS, but the type 38763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 38773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 38783d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 38793bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; 38803bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; 38817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return getIncompleteArrayType(ResultType, 38827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier(), 0); 38833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 38841adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::FunctionNoProto: 38853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return mergeFunctionTypes(LHS, RHS); 388672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 388772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: 38883d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 38891adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Builtin: 38903cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner // Only exactly equal builtin types are compatible, which is tested above. 38913d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 389264cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar case Type::Complex: 389364cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar // Distinct complex types are incompatible. 389464cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar return QualType(); 38953cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner case Type::Vector: 38965a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: The merged type should be an ExtVector! 38973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (areCompatVectorTypes(LHS->getAsVectorType(), RHS->getAsVectorType())) 38983d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 389961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return QualType(); 390061490e9a965cfee8a78c12c6802138844f04250dCedric Venet case Type::ObjCInterface: { 39015fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff // Check if the interfaces are assignment compatible. 39025a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: This should be type compatibility, e.g. whether 39035a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // "LHS x; RHS x;" at global scope is legal. 39045fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff const ObjCInterfaceType* LHSIface = LHS->getAsObjCInterfaceType(); 39055fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff const ObjCInterfaceType* RHSIface = RHS->getAsObjCInterfaceType(); 39065fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff if (LHSIface && RHSIface && 39075fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff canAssignObjCInterfaces(LHSIface, RHSIface)) 39085fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff return LHS; 39095fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff 39103d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 391161490e9a965cfee8a78c12c6802138844f04250dCedric Venet } 391214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case Type::ObjCObjectPointer: { 391314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (canAssignObjCInterfaces(LHS->getAsObjCObjectPointerType(), 391414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff RHS->getAsObjCObjectPointerType())) 391514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return LHS; 391614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3917bc76dd06eb881c70c9775b74bab8b88cd747f173Steve Naroff return QualType(); 391814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 39195a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman case Type::FixedWidthInt: 39205a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // Distinct fixed-width integers are not compatible. 39215a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return QualType(); 39225a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman case Type::ExtQual: 39235a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: ExtQual types can be compatible even if they're not 39245a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // identical! 39255a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return QualType(); 39265a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // First attempt at an implementation, but I'm not really sure it's 39275a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // right... 39285a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman#if 0 39295a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ExtQualType* LQual = cast<ExtQualType>(LHSCan); 39305a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ExtQualType* RQual = cast<ExtQualType>(RHSCan); 39315a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman if (LQual->getAddressSpace() != RQual->getAddressSpace() || 39325a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman LQual->getObjCGCAttr() != RQual->getObjCGCAttr()) 39335a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return QualType(); 39345a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman QualType LHSBase, RHSBase, ResultType, ResCanUnqual; 39355a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman LHSBase = QualType(LQual->getBaseType(), 0); 39365a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman RHSBase = QualType(RQual->getBaseType(), 0); 39375a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ResultType = mergeTypes(LHSBase, RHSBase); 39385a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman if (ResultType.isNull()) return QualType(); 39395a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ResCanUnqual = getCanonicalType(ResultType).getUnqualifiedType(); 39405a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman if (LHSCan.getUnqualifiedType() == ResCanUnqual) 39415a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return LHS; 39425a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman if (RHSCan.getUnqualifiedType() == ResCanUnqual) 39435a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return RHS; 39445a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ResultType = getAddrSpaceQualType(ResultType, LQual->getAddressSpace()); 39455a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ResultType = getObjCGCQualType(ResultType, LQual->getObjCGCAttr()); 39465a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman ResultType.setCVRQualifiers(LHSCan.getCVRQualifiers()); 39475a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return ResultType; 39485a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman#endif 39497532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 39507532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor case Type::TemplateSpecialization: 39517532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor assert(false && "Dependent types have no size"); 39527532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 3953ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 395472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 395572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 3956ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff} 39577192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek 39585426bf6456a5aeac416a9150de157904d101c819Chris Lattner//===----------------------------------------------------------------------===// 3959ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman// Integer Predicates 3960ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman//===----------------------------------------------------------------------===// 396188054dee0402e4d3c1f64e6b697acc47195c0d72Chris Lattner 3962ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedmanunsigned ASTContext::getIntWidth(QualType T) { 3963ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman if (T == BoolTy) 3964ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return 1; 3965f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T)) { 3966f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return FWIT->getWidth(); 3967f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman } 3968f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // For builtin types, just use the standard type sizing method 3969ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return (unsigned)getTypeSize(T); 3970ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 3971ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 3972ad74a758189180b8ab8faea648e4766c3bfd7fcbEli FriedmanQualType ASTContext::getCorrespondingUnsignedType(QualType T) { 3973ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman assert(T->isSignedIntegerType() && "Unexpected type"); 3974ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman if (const EnumType* ETy = T->getAsEnumType()) 3975ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman T = ETy->getDecl()->getIntegerType(); 3976ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman const BuiltinType* BTy = T->getAsBuiltinType(); 3977ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman assert (BTy && "Unexpected signed integer type"); 3978ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman switch (BTy->getKind()) { 3979ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Char_S: 3980ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::SChar: 3981ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedCharTy; 3982ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Short: 3983ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedShortTy; 3984ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Int: 3985ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedIntTy; 3986ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Long: 3987ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongTy; 3988ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::LongLong: 3989ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongLongTy; 39902df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 39912df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return UnsignedInt128Ty; 3992ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman default: 3993ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman assert(0 && "Unexpected signed integer type"); 3994ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return QualType(); 3995ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman } 3996ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 3997ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 39982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorExternalASTSource::~ExternalASTSource() { } 39992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 40002cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ExternalASTSource::PrintStats() { } 400186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 400286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 400386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 400486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner// Builtin Type Computation 400586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 400686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 400786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the 400886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// pointer over the consumed characters. This returns the resultant type. 400986df27bbdbb98c39ec2184695c0561209f91beddChris Lattnerstatic QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context, 401086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ASTContext::GetBuiltinTypeError &Error, 401186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool AllowTypeModifiers = true) { 401286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Modifiers. 401386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner int HowLong = 0; 401486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Signed = false, Unsigned = false; 401586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 401686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the modifiers first. 401786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Done = false; 401886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 401986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 402086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner default: Done = true; --Str; break; 402186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'S': 402286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use both 'S' and 'U' modifiers!"); 402386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use 'S' modifier multiple times!"); 402486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Signed = true; 402586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 402686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'U': 402786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use both 'S' and 'U' modifiers!"); 402886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use 'S' modifier multiple times!"); 402986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Unsigned = true; 403086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 403186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'L': 403286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong <= 2 && "Can't have LLLL modifier"); 403386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ++HowLong; 403486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 403586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 403686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 403786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 403886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Type; 403986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 404086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the base type. 404186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 404286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner default: assert(0 && "Unknown builtin type letter!"); 404386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'v': 404486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 404586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'v'!"); 404686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.VoidTy; 404786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 404886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'f': 404986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 405086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'f'!"); 405186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.FloatTy; 405286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 405386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'd': 405486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong < 2 && !Signed && !Unsigned && 405586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'd'!"); 405686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong) 405786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.LongDoubleTy; 405886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 405986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.DoubleTy; 406086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 406186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 's': 406286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 's'!"); 406386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Unsigned) 406486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedShortTy; 406586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 406686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.ShortTy; 406786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 406886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'i': 406986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong == 3) 407086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty; 407186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 2) 407286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy; 407386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 1) 407486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy; 407586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 407686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy; 407786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 407886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'c': 407986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 'c'!"); 408086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Signed) 408186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.SignedCharTy; 408286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (Unsigned) 408386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedCharTy; 408486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 408586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.CharTy; 408686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 408786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'b': // boolean 408886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!"); 408986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.BoolTy; 409086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 409186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'z': // size_t. 409286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!"); 409386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getSizeType(); 409486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 409586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'F': 409686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getCFConstantStringType(); 409786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 409886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'a': 409986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 410086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 410186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 410286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'A': 410386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // This is a "reference" to a va_list; however, what exactly 410486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // this means depends on how va_list is defined. There are two 410586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // different kinds of va_list: ones passed by value, and ones 410686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // passed by reference. An example of a by-value va_list is 410786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // x86, where va_list is a char*. An example of by-ref va_list 410886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // is x86-64, where va_list is a __va_list_tag[1]. For x86, 410986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // we want this argument to be a char*&; for x86-64, we want 411086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // it to be a __va_list_tag*. 411186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 411286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 411386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Type->isArrayType()) { 411486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getArrayDecayedType(Type); 411586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } else { 411686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 411786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 411886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 411986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'V': { 412086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner char *End; 412186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner unsigned NumElements = strtoul(Str, &End, 10); 412286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(End != Str && "Missing vector size"); 412386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 412486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Str = End; 412586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 412686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, false); 412786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getVectorType(ElementType, NumElements); 412886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 412986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 41309a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'P': 4131c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor Type = Context.getFILEType(); 4132c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor if (Type.isNull()) { 4133f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_stdio; 413486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 413586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 4136fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 41379a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'J': 4138f711c41dd9412a8182793259d355c4f6979ed5edMike Stump if (Signed) 4139782fa308a765aeac2acb39c4e697c937ec21185bMike Stump Type = Context.getsigjmp_bufType(); 4140f711c41dd9412a8182793259d355c4f6979ed5edMike Stump else 4141f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Type = Context.getjmp_bufType(); 4142f711c41dd9412a8182793259d355c4f6979ed5edMike Stump 4143fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump if (Type.isNull()) { 4144f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_setjmp; 4145fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump return QualType(); 4146fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump } 4147fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 4148782fa308a765aeac2acb39c4e697c937ec21185bMike Stump } 414986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 415086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (!AllowTypeModifiers) 415186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 415286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 415386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Done = false; 415486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 415586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 415686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner default: Done = true; --Str; break; 415786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case '*': 415886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getPointerType(Type); 415986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 416086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case '&': 416186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 416286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 416386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // FIXME: There's no way to have a built-in with an rvalue ref arg. 416486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'C': 416586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Type.getQualifiedType(QualType::Const); 416686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 416786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 416886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 416986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 417086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 417186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 417286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 417386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// GetBuiltinType - Return the type for the specified builtin. 417486df27bbdbb98c39ec2184695c0561209f91beddChris LattnerQualType ASTContext::GetBuiltinType(unsigned id, 417586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner GetBuiltinTypeError &Error) { 417686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner const char *TypeStr = BuiltinInfo.GetTypeString(id); 417786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 417886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner llvm::SmallVector<QualType, 8> ArgTypes; 417986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 418086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Error = GE_None; 418186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error); 418286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 418386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 418486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (TypeStr[0] && TypeStr[0] != '.') { 418586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error); 418686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 418786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 418886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 418986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Do array -> pointer decay. The builtin should use the decayed type. 419086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Ty->isArrayType()) 419186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Ty = getArrayDecayedType(Ty); 419286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 419386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ArgTypes.push_back(Ty); 419486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 419586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 419686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert((TypeStr[0] != '.' || TypeStr[1] == 0) && 419786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "'.' should only occur at end of builtin type list!"); 419886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 419986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // handle untyped/variadic arguments "T c99Style();" or "T cppStyle(...);". 420086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (ArgTypes.size() == 0 && TypeStr[0] == '.') 420186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return getFunctionNoProtoType(ResType); 420286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return getFunctionType(ResType, ArgTypes.data(), ArgTypes.size(), 420386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner TypeStr[0] == '.', 0); 420486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 4205a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4206a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli FriedmanQualType 4207a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli FriedmanASTContext::UsualArithmeticConversionsType(QualType lhs, QualType rhs) { 4208a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Perform the usual unary conversions. We do this early so that 4209a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // integral promotions to "int" can allow us to exit early, in the 4210a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // lhs == rhs check. Also, for conversion purposes, we ignore any 4211a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // qualifiers. For example, "const float" and "float" are 4212a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // equivalent. 4213a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isPromotableIntegerType()) 4214a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman lhs = getPromotedIntegerType(lhs); 4215a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman else 4216a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman lhs = lhs.getUnqualifiedType(); 4217a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isPromotableIntegerType()) 4218a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhs = getPromotedIntegerType(rhs); 4219a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman else 4220a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhs = rhs.getUnqualifiedType(); 4221a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4222a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // If both types are identical, no conversion is needed. 4223a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs == rhs) 4224a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4225a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4226a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // If either side is a non-arithmetic type (e.g. a pointer), we are done. 4227a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The caller can deal with this (e.g. pointer + int). 4228a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (!lhs->isArithmeticType() || !rhs->isArithmeticType()) 4229a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4230a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4231a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // At this point, we have two different arithmetic types. 4232a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4233a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Handle complex types first (C99 6.3.1.8p1). 4234a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isComplexType() || rhs->isComplexType()) { 4235a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // if we have an integer operand, the result is the complex type. 4236a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isIntegerType() || rhs->isComplexIntegerType()) { 4237a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the rhs to the lhs complex type. 4238a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4239a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4240a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isIntegerType() || lhs->isComplexIntegerType()) { 4241a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the lhs to the rhs complex type. 4242a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4243a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4244a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // This handles complex/complex, complex/float, or float/complex. 4245a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // When both operands are complex, the shorter operand is converted to the 4246a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // type of the longer, and that is the type of the result. This corresponds 4247a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // to what is done when combining two real floating-point operands. 4248a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The fun begins when size promotion occur across type domains. 4249a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // From H&S 6.3.4: When one operand is complex and the other is a real 4250a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // floating-point type, the less precise type is converted, within it's 4251a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // real or complex domain, to the precision of the other type. For example, 4252a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // when combining a "long double" with a "double _Complex", the 4253a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // "double _Complex" is promoted to "long double _Complex". 4254a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman int result = getFloatingTypeOrder(lhs, rhs); 4255a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4256a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (result > 0) { // The left side is bigger, convert rhs. 4257a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhs = getFloatingTypeOfSizeWithinDomain(lhs, rhs); 4258a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (result < 0) { // The right side is bigger, convert lhs. 4259a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman lhs = getFloatingTypeOfSizeWithinDomain(rhs, lhs); 4260a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4261a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // At this point, lhs and rhs have the same rank/size. Now, make sure the 4262a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // domains match. This is a requirement for our implementation, C99 4263a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // does not require this promotion. 4264a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs != rhs) { // Domains don't match, we have complex/float mix. 4265a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isRealFloatingType()) { // handle "double, _Complex double". 4266a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4267a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else { // handle "_Complex double, double". 4268a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4269a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4270a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4271a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; // The domain/size match exactly. 4272a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4273a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Now handle "real" floating types (i.e. float, double, long double). 4274a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) { 4275a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // if we have an integer operand, the result is the real floating type. 4276a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isIntegerType()) { 4277a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert rhs to the lhs floating point type. 4278a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4279a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4280a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isComplexIntegerType()) { 4281a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert rhs to the complex floating point type. 4282a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return getComplexType(lhs); 4283a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4284a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isIntegerType()) { 4285a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert lhs to the rhs floating point type. 4286a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4287a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4288a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isComplexIntegerType()) { 4289a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert lhs to the complex floating point type. 4290a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return getComplexType(rhs); 4291a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4292a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // We have two real floating types, float/complex combos were handled above. 4293a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Convert the smaller operand to the bigger result. 4294a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman int result = getFloatingTypeOrder(lhs, rhs); 4295a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (result > 0) // convert the rhs 4296a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4297a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(result < 0 && "illegal float comparison"); 4298a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; // convert the lhs 4299a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4300a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isComplexIntegerType() || rhs->isComplexIntegerType()) { 4301a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Handle GCC complex int extension. 4302a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman const ComplexType *lhsComplexInt = lhs->getAsComplexIntegerType(); 4303a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman const ComplexType *rhsComplexInt = rhs->getAsComplexIntegerType(); 4304a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4305a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhsComplexInt && rhsComplexInt) { 4306a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (getIntegerTypeOrder(lhsComplexInt->getElementType(), 4307a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhsComplexInt->getElementType()) >= 0) 4308a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; // convert the rhs 4309a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4310a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (lhsComplexInt && rhs->isIntegerType()) { 4311a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the rhs to the lhs complex type. 4312a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4313a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (rhsComplexInt && lhs->isIntegerType()) { 4314a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the lhs to the rhs complex type. 4315a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4316a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4317a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4318a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Finally, we have two differing integer types. 4319a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The rules for this case are in C99 6.3.1.8 4320a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman int compare = getIntegerTypeOrder(lhs, rhs); 4321a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman bool lhsSigned = lhs->isSignedIntegerType(), 4322a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhsSigned = rhs->isSignedIntegerType(); 4323a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman QualType destType; 4324a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhsSigned == rhsSigned) { 4325a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Same signedness; use the higher-ranked type 4326a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = compare >= 0 ? lhs : rhs; 4327a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (compare != (lhsSigned ? 1 : -1)) { 4328a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The unsigned type has greater than or equal rank to the 4329a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // signed type, so use the unsigned type 4330a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = lhsSigned ? rhs : lhs; 4331a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (getIntWidth(lhs) != getIntWidth(rhs)) { 4332a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The two types are different widths; if we are here, that 4333a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // means the signed type is larger than the unsigned type, so 4334a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // use the signed type. 4335a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = lhsSigned ? lhs : rhs; 4336a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else { 4337a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The signed type is higher-ranked than the unsigned type, 4338a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // but isn't actually any bigger (like unsigned int and long 4339a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // on most 32-bit systems). Use the unsigned type corresponding 4340a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // to the signed type. 4341a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = getCorrespondingUnsignedType(lhsSigned ? lhs : rhs); 4342a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4343a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return destType; 4344a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 4345