ASTContext.cpp revision d3a23b238a2b2c0f11e6ac4951c7410a8c5717bf
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, 401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool FreeMem, unsigned size_reserve) : 411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump GlobalNestedNameSpecifier(0), CFConstantStringTypeDecl(0), 42782fa308a765aeac2acb39c4e697c937ec21185bMike Stump ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), jmp_bufDecl(0), 431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump sigjmp_bufDecl(0), SourceMgr(SM), LangOpts(LOpts), 441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump LoadedExternalComments(false), FreeMemory(FreeMem), Target(t), 452e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Idents(idents), Selectors(sels), 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump BuiltinInfo(builtins), ExternalSource(0), PrintingPolicy(LOpts) { 470f436560640a1cff5b6d96f80f540770f139453fDavid Chisnall ObjCIdRedefinitionType = QualType(); 480f436560640a1cff5b6d96f80f540770f139453fDavid Chisnall ObjCClassRedefinitionType = QualType(); 491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 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 { 620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::FoldingSet<ExtQuals>::iterator 630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall I = ExtQualNodes.begin(), E = ExtQualNodes.end(); 640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall while (I != E) 650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Deallocate(&*I++); 660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall { 69b74668edbc119880eb0a7e563432314432cb775dNuno Lopes llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator 70b74668edbc119880eb0a7e563432314432cb775dNuno Lopes I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); 71b74668edbc119880eb0a7e563432314432cb775dNuno Lopes while (I != E) { 72b74668edbc119880eb0a7e563432314432cb775dNuno Lopes ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second); 73b74668edbc119880eb0a7e563432314432cb775dNuno Lopes delete R; 74b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 75b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 76b74668edbc119880eb0a7e563432314432cb775dNuno Lopes 77b74668edbc119880eb0a7e563432314432cb775dNuno Lopes { 78b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>::iterator 79b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar I = ObjCLayouts.begin(), E = ObjCLayouts.end(); 80b74668edbc119880eb0a7e563432314432cb775dNuno Lopes while (I != E) { 81b74668edbc119880eb0a7e563432314432cb775dNuno Lopes ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second); 82b74668edbc119880eb0a7e563432314432cb775dNuno Lopes delete R; 83b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 84b74668edbc119880eb0a7e563432314432cb775dNuno Lopes } 85b74668edbc119880eb0a7e563432314432cb775dNuno Lopes 86ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor // Destroy nested-name-specifiers. 871ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor for (llvm::FoldingSet<NestedNameSpecifier>::iterator 881ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor NNS = NestedNameSpecifiers.begin(), 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NNSEnd = NestedNameSpecifiers.end(); 901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NNS != NNSEnd; 911ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor /* Increment in loop */) 921ae0afaf14b7ce9bed33c1fe51077d01a313434dDouglas Gregor (*NNS++).Destroy(*this); 93ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 94ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor if (GlobalNestedNameSpecifier) 95ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor GlobalNestedNameSpecifier->Destroy(*this); 96ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 97b26153c2b06934b6d39886cae2a379988d9c3e2bEli Friedman TUDecl->Destroy(*this); 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 1012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorASTContext::setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source) { 1022cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource.reset(Source.take()); 1032cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 1042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::PrintStats() const { 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer fprintf(stderr, "*** AST Context Stats:\n"); 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer fprintf(stderr, " %d types total.\n", (int)Types.size()); 1087c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 109dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned counts[] = { 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump#define TYPE(Name, Parent) 0, 111dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 112dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 113dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor 0 // Extra 114dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor }; 115c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0, e = Types.size(); i != e; ++i) { 1175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *T = Types[i]; 118dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor counts[(unsigned)T->getTypeClass()]++; 1195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 121dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned Idx = 0; 122dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned TotalBytes = 0; 123dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define TYPE(Name, Parent) \ 124dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor if (counts[Idx]) \ 125dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor fprintf(stderr, " %d %s types\n", (int)counts[Idx], #Name); \ 126dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor TotalBytes += counts[Idx] * sizeof(Name##Type); \ 127dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor ++Idx; 128dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 129dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 131dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor fprintf(stderr, "Total bytes = %d\n", int(TotalBytes)); 1322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 1332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (ExternalSource.get()) { 1342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor fprintf(stderr, "\n"); 1352cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource->PrintStats(); 1362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::InitBuiltinType(QualType &R, BuiltinType::Kind K) { 1416b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); 1426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall R = QualType(Ty, 0); 1436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Types.push_back(Ty); 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::InitBuiltinTypes() { 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(VoidTy.isNull() && "Context reinitialized?"); 1481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p19. 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(VoidTy, BuiltinType::Void); 1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p2. 1535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(BoolTy, BuiltinType::Bool); 1545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p3. 15515b91764d08e886391c865c4a444d7b51141c284Eli Friedman if (LangOpts.CharIsSigned) 1565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_S); 1575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 1585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_U); 1595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p4. 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(SignedCharTy, BuiltinType::SChar); 1615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(ShortTy, BuiltinType::Short); 1625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(IntTy, BuiltinType::Int); 1635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongTy, BuiltinType::Long); 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongLongTy, BuiltinType::LongLong); 1651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p6. 1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); 1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); 1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); 1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); 1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); 1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p10. 1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(FloatTy, BuiltinType::Float); 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(DoubleTy, BuiltinType::Double); 1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); 17764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 1782df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner // GNU extension, 128-bit integers. 1792df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(Int128Ty, BuiltinType::Int128); 1802df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); 1812df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner 1823a2503227c3db04a3619735127483263c1075ef7Chris Lattner if (LangOpts.CPlusPlus) // C++ 3.9.1p5 1833a2503227c3db04a3619735127483263c1075ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar); 1843a2503227c3db04a3619735127483263c1075ef7Chris Lattner else // C99 1853a2503227c3db04a3619735127483263c1075ef7Chris Lattner WCharTy = getFromTargetType(Target.getWCharType()); 18664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 187f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 188f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char16Ty, BuiltinType::Char16); 189f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 190f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16Ty = getFromTargetType(Target.getChar16Type()); 191f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 192f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 193f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char32Ty, BuiltinType::Char32); 194f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 195f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32Ty = getFromTargetType(Target.getChar32Type()); 196f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 1978e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor // Placeholder type for functions. 198898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(OverloadTy, BuiltinType::Overload); 199898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 200898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Placeholder type for type-dependent expressions whose type is 201898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // completely unknown. No code should ever check a type against 202898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // DependentTy and users should never see it; however, it is here to 203898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // help diagnose failures to properly check for type-dependent 204898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // expressions. 205898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(DependentTy, BuiltinType::Dependent); 2068e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 2071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Placeholder type for C++0x auto declarations whose real type has 208e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson // not yet been deduced. 209e89d15944dd3be750a09805ad21222d2fa9321faAnders Carlsson InitBuiltinType(UndeducedAutoTy, BuiltinType::UndeducedAuto); 2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p11. 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FloatComplexTy = getComplexType(FloatTy); 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DoubleComplexTy = getComplexType(DoubleTy); 2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongDoubleComplexTy = getComplexType(LongDoubleTy); 2158e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 2167e219e47de26346885d667131977bd9ca2d7662aSteve Naroff BuiltinVaListType = QualType(); 2171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 218de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // "Builtin" typedefs set by Sema::ActOnTranslationUnitScope(). 219de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCIdTypedefType = QualType(); 220de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClassTypedefType = QualType(); 2211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 222de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // Builtin types for 'id' and 'Class'. 223de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); 224de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); 22514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 226a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = QualType(); 2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // void * type 22933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian VoidPtrTy = getPointerType(VoidTy); 2306e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 2316e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // nullptr type (C++0x 2.14.7) 2326e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2357caa6825f42a0f7e97d6fc06233133c42b218e46Douglas GregorVarDecl *ASTContext::getInstantiatedFromStaticDataMember(VarDecl *Var) { 2367caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Var->isStaticDataMember() && "Not a static data member"); 2377caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor llvm::DenseMap<VarDecl *, VarDecl *>::iterator Pos 2387caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor = InstantiatedFromStaticDataMember.find(Var); 2397caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor if (Pos == InstantiatedFromStaticDataMember.end()) 2407caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return 0; 2411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2427caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return Pos->second; 2437caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 2447caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 2451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 2467caa6825f42a0f7e97d6fc06233133c42b218e46Douglas GregorASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl) { 2477caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Inst->isStaticDataMember() && "Not a static data member"); 2487caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Tmpl->isStaticDataMember() && "Not a static data member"); 2497caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(!InstantiatedFromStaticDataMember[Inst] && 2507caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor "Already noted what static data member was instantiated from"); 2517caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor InstantiatedFromStaticDataMember[Inst] = Tmpl; 2527caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 2537caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 2540d8df780aef1acda5962347a32591efc629b6748Anders CarlssonUnresolvedUsingDecl * 2550d8df780aef1acda5962347a32591efc629b6748Anders CarlssonASTContext::getInstantiatedFromUnresolvedUsingDecl(UsingDecl *UUD) { 2561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::DenseMap<UsingDecl *, UnresolvedUsingDecl *>::iterator Pos 2570d8df780aef1acda5962347a32591efc629b6748Anders Carlsson = InstantiatedFromUnresolvedUsingDecl.find(UUD); 2580d8df780aef1acda5962347a32591efc629b6748Anders Carlsson if (Pos == InstantiatedFromUnresolvedUsingDecl.end()) 2590d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return 0; 2601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2610d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return Pos->second; 2620d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 2630d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 2640d8df780aef1acda5962347a32591efc629b6748Anders Carlssonvoid 2650d8df780aef1acda5962347a32591efc629b6748Anders CarlssonASTContext::setInstantiatedFromUnresolvedUsingDecl(UsingDecl *UD, 2660d8df780aef1acda5962347a32591efc629b6748Anders Carlsson UnresolvedUsingDecl *UUD) { 2670d8df780aef1acda5962347a32591efc629b6748Anders Carlsson assert(!InstantiatedFromUnresolvedUsingDecl[UD] && 2680d8df780aef1acda5962347a32591efc629b6748Anders Carlsson "Already noted what using decl what instantiated from"); 2690d8df780aef1acda5962347a32591efc629b6748Anders Carlsson InstantiatedFromUnresolvedUsingDecl[UD] = UUD; 2700d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 2710d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 272d8b285fee4471f393da8ee30f552ceacdc362afaAnders CarlssonFieldDecl *ASTContext::getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) { 273d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos 274d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson = InstantiatedFromUnnamedFieldDecl.find(Field); 275d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (Pos == InstantiatedFromUnnamedFieldDecl.end()) 276d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return 0; 2771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 278d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return Pos->second; 279d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 280d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 281d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlssonvoid ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, 282d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson FieldDecl *Tmpl) { 283d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Inst->getDeclName() && "Instantiated field decl is not unnamed"); 284d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Tmpl->getDeclName() && "Template field decl is not unnamed"); 285d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!InstantiatedFromUnnamedFieldDecl[Inst] && 286d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson "Already noted what unnamed field was instantiated from"); 2871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 288d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl; 289d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 290d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 2912e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregornamespace { 2921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump class BeforeInTranslationUnit 2932e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor : std::binary_function<SourceRange, SourceRange, bool> { 2942e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceManager *SourceMgr; 2951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2962e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor public: 2972e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor explicit BeforeInTranslationUnit(SourceManager *SM) : SourceMgr(SM) { } 2981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2992e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor bool operator()(SourceRange X, SourceRange Y) { 3002e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return SourceMgr->isBeforeInTranslationUnit(X.getBegin(), Y.getBegin()); 3012e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 3022e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor }; 3032e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor} 3042e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3052e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \brief Determine whether the given comment is a Doxygen-style comment. 3062e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// 3072e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \param Start the start of the comment text. 3082e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// 3092e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \param End the end of the comment text. 3102e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// 3112e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \param Member whether we want to check whether this is a member comment 3122e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// (which requires a < after the Doxygen-comment delimiter). Otherwise, 3132e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// we only return true when we find a non-member comment. 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic bool 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpisDoxygenComment(SourceManager &SourceMgr, SourceRange Comment, 3162e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor bool Member = false) { 3171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const char *BufferStart 3182e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getBufferData(SourceMgr.getFileID(Comment.getBegin())).first; 3192e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor const char *Start = BufferStart + SourceMgr.getFileOffset(Comment.getBegin()); 3202e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor const char* End = BufferStart + SourceMgr.getFileOffset(Comment.getEnd()); 3211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3222e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (End - Start < 4) 3232e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return false; 3242e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3252e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor assert(Start[0] == '/' && "Not a comment?"); 3262e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Start[1] == '*' && !(Start[2] == '!' || Start[2] == '*')) 3272e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return false; 3282e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Start[1] == '/' && !(Start[2] == '!' || Start[2] == '/')) 3292e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return false; 3302e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3312e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return (Start[3] == '<') == Member; 3322e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor} 3332e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3342e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor/// \brief Retrieve the comment associated with the given declaration, if 3351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// it has one. 3362e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregorconst char *ASTContext::getCommentForDecl(const Decl *D) { 3372e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!D) 3382e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3402e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Check whether we have cached a comment string for this declaration 3412e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // already. 3421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump llvm::DenseMap<const Decl *, std::string>::iterator Pos 3432e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = DeclComments.find(D); 3442e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Pos != DeclComments.end()) 3452e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return Pos->second.c_str(); 3462e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If we have an external AST source and have not yet loaded comments from 3482e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // that source, do so now. 3492e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (ExternalSource && !LoadedExternalComments) { 3502e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::vector<SourceRange> LoadedComments; 3512e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ExternalSource->ReadComments(LoadedComments); 3521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3532e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!LoadedComments.empty()) 3542e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Comments.insert(Comments.begin(), LoadedComments.begin(), 3552e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LoadedComments.end()); 3561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3572e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LoadedExternalComments = true; 3582e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If there are no comments anywhere, we won't find anything. 3612e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Comments.empty()) 3622e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3632e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3642e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the declaration doesn't map directly to a location in a file, we 3652e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // can't find the comment. 3662e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceLocation DeclStartLoc = D->getLocStart(); 3672e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (DeclStartLoc.isInvalid() || !DeclStartLoc.isFileID()) 3682e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 3692e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 3702e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Find the comment that occurs just before this declaration. 3712e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::vector<SourceRange>::iterator LastComment 3721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump = std::lower_bound(Comments.begin(), Comments.end(), 3732e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceRange(DeclStartLoc), 3742e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor BeforeInTranslationUnit(&SourceMgr)); 3751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3762e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Decompose the location for the start of the declaration and find the 3772e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // beginning of the file buffer. 3781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<FileID, unsigned> DeclStartDecomp 3792e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(DeclStartLoc); 3801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const char *FileBufferStart 3812e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getBufferData(DeclStartDecomp.first).first; 3821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3832e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // First check whether we have a comment for a member. 3842e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (LastComment != Comments.end() && 3852e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor !isa<TagDecl>(D) && !isa<NamespaceDecl>(D) && 3862e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor isDoxygenComment(SourceMgr, *LastComment, true)) { 3872e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> LastCommentEndDecomp 3882e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(LastComment->getEnd()); 3892e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (DeclStartDecomp.first == LastCommentEndDecomp.first && 3902e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second) 3911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump == SourceMgr.getLineNumber(LastCommentEndDecomp.first, 3922e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LastCommentEndDecomp.second)) { 3932e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // The Doxygen member comment comes after the declaration starts and 3942e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // is on the same line and in the same file as the declaration. This 3952e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // is the comment we want. 3962e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::string &Result = DeclComments[D]; 3971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Result.append(FileBufferStart + 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceMgr.getFileOffset(LastComment->getBegin()), 3992e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor FileBufferStart + LastCommentEndDecomp.second + 1); 4002e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return Result.c_str(); 4012e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4022e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4042e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (LastComment == Comments.begin()) 4052e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 4062e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor --LastComment; 4072e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 4082e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Decompose the end of the comment. 4092e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> LastCommentEndDecomp 4102e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(LastComment->getEnd()); 4111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4122e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the comment and the declaration aren't in the same file, then they 4132e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // aren't related. 4142e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (DeclStartDecomp.first != LastCommentEndDecomp.first) 4152e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 4161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4172e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Check that we actually have a Doxygen comment. 4182e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!isDoxygenComment(SourceMgr, *LastComment)) 4192e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 4201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4212e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Compute the starting line for the declaration and for the end of the 4222e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // comment (this is expensive). 4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned DeclStartLine 4242e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getLineNumber(DeclStartDecomp.first, DeclStartDecomp.second); 4252e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor unsigned CommentEndLine 4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump = SourceMgr.getLineNumber(LastCommentEndDecomp.first, 4272e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor LastCommentEndDecomp.second); 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4292e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the comment does not end on the line prior to the declaration, then 4302e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // the comment is not associated with the declaration at all. 4312e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (CommentEndLine + 1 != DeclStartLine) 4322e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return 0; 4331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4342e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // We have a comment, but there may be more comments on the previous lines. 4352e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Keep looking so long as the comments are still Doxygen comments and are 4362e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // still adjacent. 4371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump unsigned ExpectedLine 4382e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getSpellingLineNumber(LastComment->getBegin()) - 1; 4392e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::vector<SourceRange>::iterator FirstComment = LastComment; 4402e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor while (FirstComment != Comments.begin()) { 4412e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Look at the previous comment 4422e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor --FirstComment; 4432e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> Decomp 4442e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); 4451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4462e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If this previous comment is in a different file, we're done. 4472e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Decomp.first != DeclStartDecomp.first) { 4482e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4492e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor break; 4502e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4522e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If this comment is not a Doxygen comment, we're done. 4532e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (!isDoxygenComment(SourceMgr, *FirstComment)) { 4542e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4552e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor break; 4562e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4582e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // If the line number is not what we expected, we're done. 4592e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor unsigned Line = SourceMgr.getLineNumber(Decomp.first, Decomp.second); 4602e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor if (Line != ExpectedLine) { 4612e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4622e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor break; 4632e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4652e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Set the next expected line number. 4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ExpectedLine 4672e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getSpellingLineNumber(FirstComment->getBegin()) - 1; 4682e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4702e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // The iterator range [FirstComment, LastComment] contains all of the 4712e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // BCPL comments that, together, are associated with this declaration. 4722e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Form a single comment block string for this declaration that concatenates 4732e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // all of these comments. 4742e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::string &Result = DeclComments[D]; 4752e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor while (FirstComment != LastComment) { 4762e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> DecompStart 4772e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(FirstComment->getBegin()); 4782e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor std::pair<FileID, unsigned> DecompEnd 4792e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor = SourceMgr.getDecomposedLoc(FirstComment->getEnd()); 4802e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor Result.append(FileBufferStart + DecompStart.second, 4812e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor FileBufferStart + DecompEnd.second + 1); 4822e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor ++FirstComment; 4832e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor } 4841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4852e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor // Append the last comment line. 4861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Result.append(FileBufferStart + 4871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceMgr.getFileOffset(LastComment->getBegin()), 4882e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor FileBufferStart + LastCommentEndDecomp.second + 1); 4892e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor return Result.c_str(); 4902e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor} 4912e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor 492464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 493464175bba1318bef7905122e9fda20cff926df78Chris Lattner// Type Sizing and Analysis 494464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 495a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 496b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 497b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// scalar floating point type. 498b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattnerconst llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 499183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const BuiltinType *BT = T->getAs<BuiltinType>(); 500b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(BT && "Not a floating point type!"); 501b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner switch (BT->getKind()) { 502b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner default: assert(0 && "Not a floating point type!"); 503b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case BuiltinType::Float: return Target.getFloatFormat(); 504b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case BuiltinType::Double: return Target.getDoubleFormat(); 505b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner case BuiltinType::LongDouble: return Target.getLongDoubleFormat(); 506b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 507b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 508b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 509196efbf095d75180305a45f3033caa1003746604Mike Stump/// getDeclAlignInBytes - Return a conservative estimate of the alignment of the 510af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// specified decl. Note that bitfields do not have a valid alignment, so 511af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// this method will assert on them. 512b7d0844c887a72064b624dc6df12cbe1441f69d0Daniel Dunbarunsigned ASTContext::getDeclAlignInBytes(const Decl *D) { 513dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman unsigned Align = Target.getCharWidth(); 514dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 51540b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (const AlignedAttr* AA = D->getAttr<AlignedAttr>()) 516dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman Align = std::max(Align, AA->getAlignment()); 517dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 518af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 519af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner QualType T = VD->getType(); 5206217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType* RT = T->getAs<ReferenceType>()) { 5214cc2cfd48d7c2d11141871cad590db7b52ce00a0Anders Carlsson unsigned AS = RT->getPointeeType().getAddressSpace(); 522f0930235ce58a91aa3b840bece9052f44d630536Anders Carlsson Align = Target.getPointerAlign(AS); 5234cc2cfd48d7c2d11141871cad590db7b52ce00a0Anders Carlsson } else if (!T->isIncompleteType() && !T->isFunctionType()) { 5244cc2cfd48d7c2d11141871cad590db7b52ce00a0Anders Carlsson // Incomplete or function types default to 1. 525dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman while (isa<VariableArrayType>(T) || isa<IncompleteArrayType>(T)) 526dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman T = cast<ArrayType>(T)->getElementType(); 527dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 528dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); 529dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman } 530af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner } 531dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 532dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman return Align / Target.getCharWidth(); 533af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner} 534b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 535a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner/// getTypeSize - Return the size of the specified type, in bits. This method 536a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner/// does not work on incomplete types. 5370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 5380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// FIXME: Pointers into different addr spaces could have different sizes and 5390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// alignment requirements: getPointerInfo should take an AddrSpace, this 5400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// should take a QualType, &c. 541d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattnerstd::pair<uint64_t, unsigned> 5421d75118af76cae2bfc06389cde410e14bd0a19fcDaniel DunbarASTContext::getTypeInfo(const Type *T) { 5435e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump uint64_t Width=0; 5445e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump unsigned Align=8; 545a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (T->getTypeClass()) { 54672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 54772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 54818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor#define NON_CANONICAL_TYPE(Class, Base) 54972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 55072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 55118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor assert(false && "Should not see dependent types"); 55272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor break; 55372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 5545d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionNoProto: 5555d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionProto: 55618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(function) = 32 bits 55718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 55818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 32; 55918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 56018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 56172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 562fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::VariableArray: 56318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 56418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = getTypeAlign(cast<ArrayType>(T)->getElementType()); 56518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 56618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 5677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor case Type::ConstantArrayWithExpr: 5687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor case Type::ConstantArrayWithoutExpr: 569fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::ConstantArray: { 5701d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ConstantArrayType *CAT = cast<ConstantArrayType>(T); 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57298be4943e8dc4f3905629a7102668960873cf863Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType()); 5739e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*CAT->getSize().getZExtValue(); 574030d8846c7e520330007087e949f621989876e3aChris Lattner Align = EltInfo.second; 575030d8846c7e520330007087e949f621989876e3aChris Lattner break; 5765c09a02a5db85e08a432b6eeced9aa656349710dChristopher Lamb } 577213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case Type::ExtVector: 578030d8846c7e520330007087e949f621989876e3aChris Lattner case Type::Vector: { 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> EltInfo = 58098be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<VectorType>(T)->getElementType()); 5819e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*cast<VectorType>(T)->getNumElements(); 5824bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman Align = Width; 5836fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // If the alignment is not a power of 2, round up to the next power of 2. 5846fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // This happens for non-power-of-2 length vectors. 5856fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // FIXME: this should probably be a target property. 5866fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman Align = 1 << llvm::Log2_32_Ceil(Align); 587030d8846c7e520330007087e949f621989876e3aChris Lattner break; 588030d8846c7e520330007087e949f621989876e3aChris Lattner } 5895d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner 5909e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner case Type::Builtin: 591a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 592692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner default: assert(0 && "Unknown builtin type!"); 593d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner case BuiltinType::Void: 59418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(void) = 8 bits. 59518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 59618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 8; 59718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 59818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 5996f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Bool: 6009e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getBoolWidth(); 6019e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getBoolAlign(); 6026f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 603692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_S: 604692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_U: 605692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UChar: 6066f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::SChar: 6079e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getCharWidth(); 6089e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getCharAlign(); 6096f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 61064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis case BuiltinType::WChar: 61164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Width = Target.getWCharWidth(); 61264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis Align = Target.getWCharAlign(); 61364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis break; 614f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char16: 615f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Width = Target.getChar16Width(); 616f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Align = Target.getChar16Align(); 617f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 618f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char32: 619f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Width = Target.getChar32Width(); 620f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Align = Target.getChar32Align(); 621f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 622692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UShort: 6236f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Short: 6249e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getShortWidth(); 6259e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getShortAlign(); 6266f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 627692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UInt: 6286f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Int: 6299e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getIntWidth(); 6309e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getIntAlign(); 6316f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 632692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULong: 6336f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Long: 6349e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getLongWidth(); 6359e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getLongAlign(); 6366f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 637692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULongLong: 6386f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongLong: 6399e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getLongLongWidth(); 6409e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getLongLongAlign(); 6416f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 642ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::Int128: 643ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::UInt128: 644ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Width = 128; 645ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Align = 128; // int128_t is 128-bit aligned on all targets. 646ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner break; 6476f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Float: 6489e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getFloatWidth(); 6499e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getFloatAlign(); 6506f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 6516f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Double: 6525426bf6456a5aeac416a9150de157904d101c819Chris Lattner Width = Target.getDoubleWidth(); 6535426bf6456a5aeac416a9150de157904d101c819Chris Lattner Align = Target.getDoubleAlign(); 6546f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 6556f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongDouble: 6569e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = Target.getLongDoubleWidth(); 6579e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Align = Target.getLongDoubleAlign(); 6586f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 6596e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case BuiltinType::NullPtr: 6606e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl Width = Target.getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) 6616e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl Align = Target.getPointerAlign(0); // == sizeof(void*) 6621590d9c0fec4c710c2962e4bb71f76979b5163d3Sebastian Redl break; 663a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 664bfef6d7c67831a135d6ab79931f010f750a730adChris Lattner break; 665f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman case Type::FixedWidthInt: 666f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // FIXME: This isn't precisely correct; the width/alignment should depend 667f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // on the available types for the target 668f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Width = cast<FixedWidthIntType>(T)->getWidth(); 669736166b38235cf6d0ffb67638960d95fb2afcbd6Chris Lattner Width = std::max(llvm::NextPowerOf2(Width - 1), (uint64_t)8); 670f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Align = Width; 671f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman break; 672d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case Type::ObjCObjectPointer: 6735426bf6456a5aeac416a9150de157904d101c819Chris Lattner Width = Target.getPointerWidth(0); 674f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner Align = Target.getPointerAlign(0); 6756f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 676485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff case Type::BlockPointer: { 677485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff unsigned AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace(); 678485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff Width = Target.getPointerWidth(AS); 679485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff Align = Target.getPointerAlign(AS); 680485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff break; 681485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff } 682f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner case Type::Pointer: { 683f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner unsigned AS = cast<PointerType>(T)->getPointeeType().getAddressSpace(); 6845426bf6456a5aeac416a9150de157904d101c819Chris Lattner Width = Target.getPointerWidth(AS); 685f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner Align = Target.getPointerAlign(AS); 686f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner break; 687f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner } 6887c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 6897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 6907ab2ed8e881ffdc84e890f5265c41b930df17ceeChris Lattner // "When applied to a reference or a reference type, the result is the size 6915d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // of the referenced type." C++98 5.3.3p2: expr.sizeof. 6926f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner // FIXME: This is wrong for struct layout: a reference in a struct has 6936f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner // pointer size. 694bdcd637c29ec1540f912ea6860c88b910e78c329Chris Lattner return getTypeInfo(cast<ReferenceType>(T)->getPointeeType()); 695f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case Type::MemberPointer: { 6961cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson // FIXME: This is ABI dependent. We use the Itanium C++ ABI. 6971cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson // http://www.codesourcery.com/public/cxx-abi/abi.html#member-pointers 6981cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson // If we ever want to support other ABIs this needs to be abstracted. 6991cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson 700f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Pointee = cast<MemberPointerType>(T)->getPointeeType(); 7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> PtrDiffInfo = 7021cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson getTypeInfo(getPointerDiffType()); 7031cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Width = PtrDiffInfo.first; 704f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (Pointee->isFunctionType()) 705f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Width *= 2; 7061cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Align = PtrDiffInfo.second; 7071cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson break; 708f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 7095d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::Complex: { 7105d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // Complex types have the same alignment as their elements, but twice the 7115d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // size. 7121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> EltInfo = 71398be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<ComplexType>(T)->getElementType()); 7149e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*2; 7155d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner Align = EltInfo.second; 7165d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner break; 7175d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner } 71844a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel case Type::ObjCInterface: { 7191d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); 72044a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); 72144a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel Width = Layout.getSize(); 72244a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel Align = Layout.getAlignment(); 72344a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel break; 72444a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel } 72572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 72672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: { 7271d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const TagType *TT = cast<TagType>(T); 7281d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar 7291d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (TT->getDecl()->isInvalidDecl()) { 7308389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner Width = 1; 7318389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner Align = 1; 7328389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner break; 7338389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner } 7341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7351d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (const EnumType *ET = dyn_cast<EnumType>(TT)) 7367176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner return getTypeInfo(ET->getDecl()->getIntegerType()); 7377176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner 7381d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const RecordType *RT = cast<RecordType>(TT); 7397176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 7407176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner Width = Layout.getSize(); 7417176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner Align = Layout.getAlignment(); 742dc0d73e6495404418acf8548875aeaff07791a74Chris Lattner break; 743a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 7447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 7457da2431c23ef1ee8acb114e39692246e1801afc2John McCall case Type::Elaborated: { 7467da2431c23ef1ee8acb114e39692246e1801afc2John McCall return getTypeInfo(cast<ElaboratedType>(T)->getUnderlyingType().getTypePtr()); 7477da2431c23ef1ee8acb114e39692246e1801afc2John McCall } 7487da2431c23ef1ee8acb114e39692246e1801afc2John McCall 74918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::Typedef: { 75018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); 75140b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (const AlignedAttr *Aligned = Typedef->getAttr<AlignedAttr>()) { 75218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = Aligned->getAlignment(); 75318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = getTypeSize(Typedef->getUnderlyingType().getTypePtr()); 75418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } else 75518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 7567532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 7577176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner } 75818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 75918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOfExpr: 76018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType() 76118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor .getTypePtr()); 76218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 76318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOf: 76418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfType>(T)->getUnderlyingType().getTypePtr()); 76518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 766395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson case Type::Decltype: 767395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return getTypeInfo(cast<DecltypeType>(T)->getUnderlyingExpr()->getType() 768395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson .getTypePtr()); 769395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 77018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::QualifiedName: 77118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<QualifiedNameType>(T)->getNamedType().getTypePtr()); 7721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TemplateSpecialization: 7741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(getCanonicalType(T) != T && 77518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor "Cannot request the size of a dependent type"); 77618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // FIXME: this is likely to be wrong once we support template 77718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // aliases, since a template alias could refer to a typedef that 77818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // has an __aligned__ attribute on it. 77918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(getCanonicalType(T)); 78018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } 7811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 782464175bba1318bef7905122e9fda20cff926df78Chris Lattner assert(Align && (Align & (Align-1)) == 0 && "Alignment must be power of 2"); 7839e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner return std::make_pair(Width, Align); 784a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner} 785a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 78634ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// getPreferredTypeAlign - Return the "preferred" alignment of the specified 78734ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// type for the current target in bits. This can be different than the ABI 78834ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// alignment in cases where it is beneficial for performance to overalign 78934ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// a data type. 79034ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattnerunsigned ASTContext::getPreferredTypeAlign(const Type *T) { 79134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner unsigned ABIAlign = getTypeAlign(T); 7921eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 7931eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman // Double and long long should be naturally aligned if possible. 794183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType* CT = T->getAs<ComplexType>()) 7951eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T = CT->getElementType().getTypePtr(); 7961eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::Double) || 7971eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T->isSpecificBuiltinType(BuiltinType::LongLong)) 7981eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman return std::max(ABIAlign, (unsigned)getTypeSize(T)); 7991eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 80034ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner return ABIAlign; 80134ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner} 80234ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner 803a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbarstatic void CollectLocalObjCIvars(ASTContext *Ctx, 804a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar const ObjCInterfaceDecl *OI, 805a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar llvm::SmallVectorImpl<FieldDecl*> &Fields) { 806a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 807a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian E = OI->ivar_end(); I != E; ++I) { 808f1690858344968358131f8d5690d9ee458883000Chris Lattner ObjCIvarDecl *IVDecl = *I; 809a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian if (!IVDecl->isInvalidDecl()) 810a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian Fields.push_back(cast<FieldDecl>(IVDecl)); 811a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian } 812a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian} 813a769c004a2874504c17ea8afccbc4ad35fc33c9fFariborz Jahanian 814a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbarvoid ASTContext::CollectObjCIvars(const ObjCInterfaceDecl *OI, 815a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar llvm::SmallVectorImpl<FieldDecl*> &Fields) { 816a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) 817a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar CollectObjCIvars(SuperClass, Fields); 818a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar CollectLocalObjCIvars(this, OI, Fields); 819a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar} 820a80a0f6398df06c018af779a7ca82a29172c45d1Daniel Dunbar 8218e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian/// ShallowCollectObjCIvars - 8228e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian/// Collect all ivars, including those synthesized, in the current class. 8238e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian/// 8248e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanianvoid ASTContext::ShallowCollectObjCIvars(const ObjCInterfaceDecl *OI, 8258e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars, 8268e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian bool CollectSynthesized) { 8278e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 8288e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian E = OI->ivar_end(); I != E; ++I) { 8298e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian Ivars.push_back(*I); 8308e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian } 8318e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if (CollectSynthesized) 8328e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian CollectSynthesizedIvars(OI, Ivars); 8338e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 8348e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8359820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanianvoid ASTContext::CollectProtocolSynthesizedIvars(const ObjCProtocolDecl *PD, 8369820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { 83717945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(), 83817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = PD->prop_end(); I != E; ++I) 8399820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 8409820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian Ivars.push_back(Ivar); 8411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8429820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian // Also look into nested protocols. 8439820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 8449820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian E = PD->protocol_end(); P != E; ++P) 8459820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian CollectProtocolSynthesizedIvars(*P, Ivars); 8469820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 8479820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 8489820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// CollectSynthesizedIvars - 8499820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// This routine collect synthesized ivars for the designated class. 8509820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// 8519820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanianvoid ASTContext::CollectSynthesizedIvars(const ObjCInterfaceDecl *OI, 8529820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) { 85317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(), 85417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = OI->prop_end(); I != E; ++I) { 8559820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl()) 8569820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian Ivars.push_back(Ivar); 8579820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian } 8589820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian // Also look into interface's protocol list for properties declared 8599820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian // in the protocol and whose ivars are synthesized. 8609820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 8619820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian PE = OI->protocol_end(); P != PE; ++P) { 8629820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian ObjCProtocolDecl *PD = (*P); 8639820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian CollectProtocolSynthesizedIvars(PD, Ivars); 8649820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian } 8659820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 8669820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 8678e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanianunsigned ASTContext::CountProtocolSynthesizedIvars(const ObjCProtocolDecl *PD) { 8688e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian unsigned count = 0; 86917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCContainerDecl::prop_iterator I = PD->prop_begin(), 87017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = PD->prop_end(); I != E; ++I) 8718e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if ((*I)->getPropertyIvarDecl()) 8728e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian ++count; 8738e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8748e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian // Also look into nested protocols. 8758e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = PD->protocol_begin(), 8768e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian E = PD->protocol_end(); P != E; ++P) 8778e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian count += CountProtocolSynthesizedIvars(*P); 8788e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 8798e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 8808e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpunsigned ASTContext::CountSynthesizedIvars(const ObjCInterfaceDecl *OI) { 8828e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian unsigned count = 0; 88317945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(), 88417945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis E = OI->prop_end(); I != E; ++I) { 8858e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if ((*I)->getPropertyIvarDecl()) 8868e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian ++count; 8878e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian } 8888e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian // Also look into interface's protocol list for properties declared 8898e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian // in the protocol and whose ivars are synthesized. 8908e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian for (ObjCInterfaceDecl::protocol_iterator P = OI->protocol_begin(), 8918e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian PE = OI->protocol_end(); P != PE; ++P) { 8928e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian ObjCProtocolDecl *PD = (*P); 8938e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian count += CountProtocolSynthesizedIvars(PD); 8948e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian } 8958e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 8968e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 8978e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 8988a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 8998a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCImplementationDecl *ASTContext::getObjCImplementation(ObjCInterfaceDecl *D) { 9008a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 9018a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 9028a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 9038a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCImplementationDecl>(I->second); 9048a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 9058a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 9068a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 9078a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCCategoryImplDecl *ASTContext::getObjCImplementation(ObjCCategoryDecl *D) { 9088a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 9098a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 9108a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 9118a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCCategoryImplDecl>(I->second); 9128a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 9138a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 9148a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 9158a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCInterfaceDecl. 9168a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCInterfaceDecl *IFaceD, 9178a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *ImplD) { 9188a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(IFaceD && ImplD && "Passed null params"); 9198a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[IFaceD] = ImplD; 9208a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 9218a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCCategoryDecl. 9228a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCCategoryDecl *CatD, 9238a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *ImplD) { 9248a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(CatD && ImplD && "Passed null params"); 9258a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[CatD] = ImplD; 9268a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 9278a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 928b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \brief Allocate an uninitialized DeclaratorInfo. 929b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 930b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// The caller should initialize the memory held by DeclaratorInfo using 931b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// the TypeLoc wrappers. 932b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// 933b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// \param T the type that will be the basis for type source info. This type 934b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// should refer to how the declarator was written in source code, not to 935b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis/// what type semantic analysis resolved the declarator to. 936b17166c8077cd900cca83a895c43b30ea6660598Argyrios KyrtzidisDeclaratorInfo *ASTContext::CreateDeclaratorInfo(QualType T) { 937b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis unsigned DataSize = TypeLoc::getFullDataSizeForType(T); 938b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis DeclaratorInfo *DInfo = 939b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis (DeclaratorInfo*)BumpAlloc.Allocate(sizeof(DeclaratorInfo) + DataSize, 8); 940b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis new (DInfo) DeclaratorInfo(T); 941b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis return DInfo; 942b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 943b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 944b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// getInterfaceLayoutImpl - Get or compute information about the 945b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// layout of the given interface. 946b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// 947b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// \param Impl - If given, also include the layout of the interface's 948b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar/// implementation. This may differ by including synthesized ivars. 94944a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patelconst ASTRecordLayout & 950b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel DunbarASTContext::getObjCLayout(const ObjCInterfaceDecl *D, 951b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar const ObjCImplementationDecl *Impl) { 952532d4daa038d972240138e2fd6e1122517340833Daniel Dunbar assert(!D->isForwardDecl() && "Invalid interface decl!"); 953532d4daa038d972240138e2fd6e1122517340833Daniel Dunbar 95444a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel // Look up this layout, if already laid out, return what we have. 9551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCContainerDecl *Key = 956d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar Impl ? (ObjCContainerDecl*) Impl : (ObjCContainerDecl*) D; 957d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar if (const ASTRecordLayout *Entry = ObjCLayouts[Key]) 958d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar return *Entry; 95944a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel 960453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // Add in synthesized ivar count if laying out an implementation. 961453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar if (Impl) { 96229445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson unsigned FieldCount = D->ivar_size(); 9638e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian unsigned SynthCount = CountSynthesizedIvars(D); 9648e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian FieldCount += SynthCount; 965d8fd6ff0ea47ba63f836d0f4e6a1bee49863f64aDaniel Dunbar // If there aren't any sythesized ivars then reuse the interface 966453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // entry. Note we can't cache this because we simply free all 967453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // entries later; however we shouldn't look up implementations 968453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar // frequently. 9698e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian if (SynthCount == 0) 970453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar return getObjCLayout(D, 0); 971453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar } 972453addbaea98f9678e2f9858057722a028f1ae3cDaniel Dunbar 9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ASTRecordLayout *NewEntry = 97429445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson ASTRecordLayoutBuilder::ComputeLayout(*this, D, Impl); 97529445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson ObjCLayouts[Key] = NewEntry; 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97744a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel return *NewEntry; 97844a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel} 97944a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel 980b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 981b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel DunbarASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) { 982b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D, 0); 983b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 984b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 985b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 986b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel DunbarASTContext::getASTObjCImplementationLayout(const ObjCImplementationDecl *D) { 987b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D->getClassInterface(), D); 988b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 989b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 99088a981b47c7face1b1fdaa9074256245107b9ca9Devang Patel/// getASTRecordLayout - Get or compute information about the layout of the 991464175bba1318bef7905122e9fda20cff926df78Chris Lattner/// specified record (struct/union/class), which indicates its size and field 992464175bba1318bef7905122e9fda20cff926df78Chris Lattner/// position information. 99398be4943e8dc4f3905629a7102668960873cf863Chris Lattnerconst ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) { 9944b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek D = D->getDefinition(*this); 9954b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek assert(D && "Cannot get layout of forward declarations!"); 9964bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman 997464175bba1318bef7905122e9fda20cff926df78Chris Lattner // Look up this layout, if already laid out, return what we have. 998ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman // Note that we can't save a reference to the entry because this function 999ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman // is recursive. 1000ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman const ASTRecordLayout *Entry = ASTRecordLayouts[D]; 1001464175bba1318bef7905122e9fda20cff926df78Chris Lattner if (Entry) return *Entry; 10024bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman 10031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const ASTRecordLayout *NewEntry = 100429445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson ASTRecordLayoutBuilder::ComputeLayout(*this, D); 1005ab22c43320ae813e4f6214f48968216b7cb09b90Eli Friedman ASTRecordLayouts[D] = NewEntry; 10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10075d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner return *NewEntry; 1008464175bba1318bef7905122e9fda20cff926df78Chris Lattner} 1009464175bba1318bef7905122e9fda20cff926df78Chris Lattner 1010a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1011a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner// Type creation/memoization methods 1012a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1013a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 10140953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType ASTContext::getExtQualType(const Type *TypeNode, Qualifiers Quals) { 10150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall unsigned Fast = Quals.getFastQualifiers(); 10160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.removeFastQualifiers(); 10170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 10180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Check if we've already instantiated this type. 10190953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::FoldingSetNodeID ID; 10200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ExtQuals::Profile(ID, TypeNode, Quals); 10210953e767ff7817f97b3ab20896b229891eeff45bJohn McCall void *InsertPos = 0; 10220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (ExtQuals *EQ = ExtQualNodes.FindNodeOrInsertPos(ID, InsertPos)) { 10230953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(EQ->getQualifiers() == Quals); 10240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = QualType(EQ, Fast); 10250953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 10260953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 10270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 10286b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtQuals *New = new (*this, TypeAlignment) ExtQuals(*this, TypeNode, Quals); 10290953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ExtQualNodes.InsertNode(New, InsertPos); 10300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType T = QualType(New, Fast); 10310953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return T; 10320953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 10330953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 10340953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualType ASTContext::getVolatileType(QualType T) { 10350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType CanT = getCanonicalType(T); 10360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (CanT.isVolatileQualified()) return T; 10370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 10380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 10390953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 10400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addVolatile(); 10410953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 10420953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 10430953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 10440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 1045f11284ac87daa613bc7b30db9f54bd716d123222Fariborz JahanianQualType ASTContext::getAddrSpaceQualType(QualType T, unsigned AddressSpace) { 1046f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType CanT = getCanonicalType(T); 1047f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner if (CanT.getAddressSpace() == AddressSpace) 1048f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return T; 1049b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 10500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 10510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 10520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 10530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 10541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an address space specified, it cannot get 10560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 10570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasAddressSpace() && 10580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot be in multiple addr spaces!"); 10590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addAddressSpace(AddressSpace); 10601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1062ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1063ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1064b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris LattnerQualType ASTContext::getObjCGCQualType(QualType T, 10650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GCAttr) { 1066d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CanT = getCanonicalType(T); 1067b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (CanT.getObjCGCAttr() == GCAttr) 1068d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return T; 10691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10704027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian if (T->isPointerType()) { 10716217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType Pointee = T->getAs<PointerType>()->getPointeeType(); 107258f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff if (Pointee->isAnyPointerType()) { 10734027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian QualType ResultType = getObjCGCQualType(Pointee, GCAttr); 10744027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian return getPointerType(ResultType); 10754027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 10764027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 10790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 10800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 10810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 10821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an ObjCGC specified, it cannot get 10840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 10850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasObjCGCAttr() && 10860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot have multiple ObjCGCs!"); 10870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addObjCGCAttr(GCAttr); 10881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1090d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1091a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 10922455636163fdd18581d7fdae816433f886d88213Mike StumpQualType ASTContext::getNoReturnType(QualType T) { 10930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType ResultType; 10942455636163fdd18581d7fdae816433f886d88213Mike Stump if (T->isPointerType()) { 10956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType Pointee = T->getAs<PointerType>()->getPointeeType(); 10960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ResultType = getNoReturnType(Pointee); 10976dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump ResultType = getPointerType(ResultType); 10980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } else if (T->isBlockPointerType()) { 10996217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType Pointee = T->getAs<BlockPointerType>()->getPointeeType(); 11000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ResultType = getNoReturnType(Pointee); 11016dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump ResultType = getBlockPointerType(ResultType); 11020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } else { 11030953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert (T->isFunctionType() 11040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall && "can't noreturn qualify non-pointer to function or block type"); 11051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1106bdbeeb50c5d182c591bd8797dc0485921df19e9dBenjamin Kramer if (const FunctionNoProtoType *FNPT = T->getAs<FunctionNoProtoType>()) { 1107bdbeeb50c5d182c591bd8797dc0485921df19e9dBenjamin Kramer ResultType = getFunctionNoProtoType(FNPT->getResultType(), true); 11080953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } else { 11090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const FunctionProtoType *F = T->getAs<FunctionProtoType>(); 11100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ResultType 11110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall = getFunctionType(F->getResultType(), F->arg_type_begin(), 11120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall F->getNumArgs(), F->isVariadic(), F->getTypeQuals(), 11130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall F->hasExceptionSpec(), F->hasAnyExceptionSpec(), 11140953e767ff7817f97b3ab20896b229891eeff45bJohn McCall F->getNumExceptions(), F->exception_begin(), true); 11150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 11162455636163fdd18581d7fdae816433f886d88213Mike Stump } 11170953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 11180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getQualifiedType(ResultType, T.getQualifiers()); 11192455636163fdd18581d7fdae816433f886d88213Mike Stump} 11202455636163fdd18581d7fdae816433f886d88213Mike Stump 11215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getComplexType - Return the uniqued reference to the type for a complex 11225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// number with the specified element type. 11235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getComplexType(QualType T) { 11245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 11255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 11265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 11275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType::Profile(ID, T); 11281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 11305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) 11315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(CT, 0); 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 11345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 11355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 11365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!T->isCanonical()) { 1137f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getComplexType(getCanonicalType(T)); 11381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 11405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); 1141f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 11425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ComplexType *New = new (*this, TypeAlignment) ComplexType(T, Canonical); 11445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 11455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexTypes.InsertNode(New, InsertPos); 11465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 11475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1149f98aba35e6c3da5aae61843fc01334939e4e12ecEli FriedmanQualType ASTContext::getFixedWidthIntType(unsigned Width, bool Signed) { 1150f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman llvm::DenseMap<unsigned, FixedWidthIntType*> &Map = Signed ? 1151f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman SignedFixedWidthIntTypes : UnsignedFixedWidthIntTypes; 1152f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman FixedWidthIntType *&Entry = Map[Width]; 1153f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (!Entry) 1154f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman Entry = new FixedWidthIntType(Width, Signed); 1155f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return QualType(Entry, 0); 1156f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman} 11575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getPointerType - Return the uniqued reference to the type for a pointer to 11595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the specified type. 11605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getPointerType(QualType T) { 11615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 11625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 11635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 11645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType::Profile(ID, T); 11651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 11675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 11685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(PT, 0); 11691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 11715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 11725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 11735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!T->isCanonical()) { 1174f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getPointerType(getCanonicalType(T)); 11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 11775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1178f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 11806b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall PointerType *New = new (*this, TypeAlignment) PointerType(T, Canonical); 11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerTypes.InsertNode(New, InsertPos); 11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 11845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 11855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getBlockPointerType - Return the uniqued reference to the type for 11875618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// a pointer to the specified block. 11885618bd4a52c45fbbb605e3ba885663b2164db8a3Steve NaroffQualType ASTContext::getBlockPointerType(QualType T) { 1189296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff assert(T->isFunctionType() && "block of function types only"); 1190296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // Unique pointers, to guarantee there is only one block of a particular 11915618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // structure. 11925618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff llvm::FoldingSetNodeID ID; 11935618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType::Profile(ID, T); 11941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11955618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void *InsertPos = 0; 11965618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (BlockPointerType *PT = 11975618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 11985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(PT, 0); 11991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the block pointee type isn't canonical, this won't be a canonical 12015618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // type either so fill in the canonical type field. 12025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType Canonical; 12035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (!T->isCanonical()) { 12045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Canonical = getBlockPointerType(getCanonicalType(T)); 12051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12065618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the new insert position for the node we care about. 12075618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType *NewIP = 12085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1209f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 12105618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 12116b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BlockPointerType *New 12126b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) BlockPointerType(T, Canonical); 12135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Types.push_back(New); 12145618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.InsertNode(New, InsertPos); 12155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(New, 0); 12165618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 12175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 12187c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getLValueReferenceType - Return the uniqued reference to the type for an 12197c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// lvalue reference to the specified type. 12207c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian RedlQualType ASTContext::getLValueReferenceType(QualType T) { 12215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 12225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 12235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 12245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ReferenceType::Profile(ID, T); 12255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 12277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (LValueReferenceType *RT = 12287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 12295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(RT, 0); 12307c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the referencee type isn't canonical, this won't be a canonical type 12325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // either, so fill in the canonical type field. 12335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 12345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!T->isCanonical()) { 12357c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Canonical = getLValueReferenceType(getCanonicalType(T)); 12367c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12377c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Get the new insert position for the node we care about. 12387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType *NewIP = 12397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 12407c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 12417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 12427c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall LValueReferenceType *New 12446b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) LValueReferenceType(T, Canonical); 12457c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Types.push_back(New); 12467c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.InsertNode(New, InsertPos); 12477c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(New, 0); 12487c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 12497c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getRValueReferenceType - Return the uniqued reference to the type for an 12517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// rvalue reference to the specified type. 12527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian RedlQualType ASTContext::getRValueReferenceType(QualType T) { 12537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 12547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // structure. 12557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl llvm::FoldingSetNodeID ID; 12567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl ReferenceType::Profile(ID, T); 12577c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12587c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl void *InsertPos = 0; 12597c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (RValueReferenceType *RT = 12607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 12617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(RT, 0); 12627c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // If the referencee type isn't canonical, this won't be a canonical type 12647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // either, so fill in the canonical type field. 12657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl QualType Canonical; 12667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (!T->isCanonical()) { 12677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Canonical = getRValueReferenceType(getCanonicalType(T)); 12687c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 12695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 12707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType *NewIP = 12717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 1272f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 12735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 12745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 12756b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall RValueReferenceType *New 12766b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); 12775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 12787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.InsertNode(New, InsertPos); 12795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 12805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 12815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1282f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// getMemberPointerType - Return the uniqued reference to the type for a 1283f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// member pointer to the specified type, in the specified class. 12841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) { 1285f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 1286f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // structure. 1287f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl llvm::FoldingSetNodeID ID; 1288f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType::Profile(ID, T, Cls); 1289f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1290f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *InsertPos = 0; 1291f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (MemberPointerType *PT = 1292f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 1293f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(PT, 0); 1294f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1295f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // If the pointee or class type isn't canonical, this won't be a canonical 1296f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type either, so fill in the canonical type field. 1297f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Canonical; 1298f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (!T->isCanonical()) { 1299f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls)); 1300f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1301f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Get the new insert position for the node we care about. 1302f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType *NewIP = 1303f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1304f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 1305f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 13066b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall MemberPointerType *New 13076b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); 1308f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Types.push_back(New); 1309f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.InsertNode(New, InsertPos); 1310f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(New, 0); 1311f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 1312f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getConstantArrayType - Return the unique reference to the type for an 1314fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff/// array of the specified element type. 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getConstantArrayType(QualType EltTy, 131638aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner const llvm::APInt &ArySizeIn, 1317c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 1318c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff unsigned EltTypeQuals) { 1319587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman assert((EltTy->isDependentType() || EltTy->isConstantSizeType()) && 1320587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman "Constant array of VLAs is illegal!"); 1321587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman 132238aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // Convert the array size into a canonical width matching the pointer size for 132338aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // the target. 132438aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner llvm::APInt ArySize(ArySizeIn); 132538aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); 13261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 13280be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, EltTypeQuals); 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 13311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ConstantArrayType *ATP = 13327192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 13335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(ATP, 0); 13341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 13365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 13375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 13385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!EltTy->isCanonical()) { 13391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Canonical = getConstantArrayType(getCanonicalType(EltTy), ArySize, 1340c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ASM, EltTypeQuals); 13415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 13421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstantArrayType *NewIP = 13437192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 1344f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 13455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13476b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayType *New = new(*this,TypeAlignment) 13486b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayType(EltTy, Canonical, ArySize, ASM, EltTypeQuals); 13497192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.InsertNode(New, InsertPos); 13505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13547e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// getConstantArrayWithExprType - Return a reference to the type for 13557e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// an array of the specified element type. 13567e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType 13577e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorASTContext::getConstantArrayWithExprType(QualType EltTy, 13587e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &ArySizeIn, 13597e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *ArySizeExpr, 13607e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier ASM, 13617e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals, 13627e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets) { 13637e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Convert the array size into a canonical width matching the pointer 13647e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // size for the target. 13657e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor llvm::APInt ArySize(ArySizeIn); 13667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); 13677e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13687e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Compute the canonical ConstantArrayType. 13697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor QualType Canonical = getConstantArrayType(getCanonicalType(EltTy), 13707e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize, ASM, EltTypeQuals); 13717e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Since we don't unique expressions, it isn't possible to unique VLA's 13727e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // that have an expression provided for their size. 13736b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayWithExprType *New = new(*this, TypeAlignment) 13746b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayWithExprType(EltTy, Canonical, ArySize, ArySizeExpr, 13756b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ASM, EltTypeQuals, Brackets); 13767e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Types.push_back(New); 13777e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return QualType(New, 0); 13787e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor} 13797e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13807e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// getConstantArrayWithoutExprType - Return a reference to the type for 13817e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor/// an array of the specified element type. 13827e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType 13837e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorASTContext::getConstantArrayWithoutExprType(QualType EltTy, 13847e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor const llvm::APInt &ArySizeIn, 13857e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier ASM, 13867e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals) { 13877e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Convert the array size into a canonical width matching the pointer 13887e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // size for the target. 13897e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor llvm::APInt ArySize(ArySizeIn); 13907e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize.zextOrTrunc(Target.getPointerWidth(EltTy.getAddressSpace())); 13917e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 13927e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor // Compute the canonical ConstantArrayType. 13937e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor QualType Canonical = getConstantArrayType(getCanonicalType(EltTy), 13947e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArySize, ASM, EltTypeQuals); 13956b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayWithoutExprType *New = new(*this, TypeAlignment) 13966b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayWithoutExprType(EltTy, Canonical, ArySize, ASM, EltTypeQuals); 13977e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Types.push_back(New); 13987e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return QualType(New, 0); 13997e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor} 14007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor 1401bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// getVariableArrayType - Returns a non-unique reference to the type for a 1402bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// variable array of the specified element type. 14037e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getVariableArrayType(QualType EltTy, 14047e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 1405c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 14067e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals, 14077e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets) { 1408c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Since we don't unique expressions, it isn't possible to unique VLA's 1409c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // that have an expression provided for their size. 1410c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 14116b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VariableArrayType *New = new(*this, TypeAlignment) 14126b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VariableArrayType(EltTy, QualType(), NumElts, ASM, EltTypeQuals, Brackets); 1413c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1414c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman VariableArrayTypes.push_back(New); 1415c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 1416c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 1417c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman} 1418c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1419898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// getDependentSizedArrayType - Returns a non-unique reference to 1420898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// the type for a dependently-sized array of the specified element 142104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor/// type. 14227e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getDependentSizedArrayType(QualType EltTy, 14237e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 1424898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArrayType::ArraySizeModifier ASM, 14257e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor unsigned EltTypeQuals, 14267e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor SourceRange Brackets) { 14271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((NumElts->isTypeDependent() || NumElts->isValueDependent()) && 1428898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor "Size must be type- or value-dependent!"); 1429898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 143004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor llvm::FoldingSetNodeID ID; 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedArrayType::Profile(ID, *this, getCanonicalType(EltTy), ASM, 143204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor EltTypeQuals, NumElts); 1433898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 143404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor void *InsertPos = 0; 143504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayType *Canon 143604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor = DependentSizedArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 143704d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayType *New; 143804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor if (Canon) { 143904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor // We already have a canonical version of this array type; use it as 144004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor // the canonical type for a newly-built type. 14416b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 14426b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedArrayType(*this, EltTy, QualType(Canon, 0), 14436b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall NumElts, ASM, EltTypeQuals, Brackets); 144404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } else { 144504d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType CanonEltTy = getCanonicalType(EltTy); 144604d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor if (CanonEltTy == EltTy) { 14476b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 14486b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedArrayType(*this, EltTy, QualType(), 14496b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall NumElts, ASM, EltTypeQuals, Brackets); 145004d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor DependentSizedArrayTypes.InsertNode(New, InsertPos); 145104d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } else { 145204d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor QualType Canon = getDependentSizedArrayType(CanonEltTy, NumElts, 145304d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor ASM, EltTypeQuals, 145404d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor SourceRange()); 14556b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 14566b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedArrayType(*this, EltTy, Canon, 14576b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall NumElts, ASM, EltTypeQuals, Brackets); 145804d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } 145904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor } 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1461898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor Types.push_back(New); 1462898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return QualType(New, 0); 1463898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1464898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1465c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli FriedmanQualType ASTContext::getIncompleteArrayType(QualType EltTy, 1466c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArrayType::ArraySizeModifier ASM, 1467c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman unsigned EltTypeQuals) { 1468c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman llvm::FoldingSetNodeID ID; 14690be2ef2321b1283ead38ebeb83b451335d90e0feChris Lattner IncompleteArrayType::Profile(ID, EltTy, ASM, EltTypeQuals); 1470c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1471c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman void *InsertPos = 0; 14721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (IncompleteArrayType *ATP = 1473c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 1474c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(ATP, 0); 1475c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1476c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // If the element type isn't canonical, this won't be a canonical type 1477c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // either, so fill in the canonical type field. 1478c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman QualType Canonical; 1479c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1480c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman if (!EltTy->isCanonical()) { 1481f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getIncompleteArrayType(getCanonicalType(EltTy), 14822bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek ASM, EltTypeQuals); 1483c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1484c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Get the new insert position for the node we care about. 1485c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayType *NewIP = 1486c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 1487f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 14882bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 1489c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 14906b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall IncompleteArrayType *New = new (*this, TypeAlignment) 14916b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall IncompleteArrayType(EltTy, Canonical, ASM, EltTypeQuals); 1492c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 1493c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman IncompleteArrayTypes.InsertNode(New, InsertPos); 1494c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 1495c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 1496fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff} 1497fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 149873322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// getVectorType - Return the unique reference to a vector type of 149973322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 150073322924127c873c13101b705dd823f5539ffa5fSteve NaroffQualType ASTContext::getVectorType(QualType vecType, unsigned NumElts) { 15015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BuiltinType *baseType; 15021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1503f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner baseType = dyn_cast<BuiltinType>(getCanonicalType(vecType).getTypePtr()); 150473322924127c873c13101b705dd823f5539ffa5fSteve Naroff assert(baseType != 0 && "getVectorType(): Expecting a built-in type"); 15051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Check if we've already instantiated a vector of this type. 15075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 15081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType::Profile(ID, vecType, NumElts, Type::Vector); 15095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 15105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 15115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(VTP, 0); 15125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 15135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 15145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 15155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 15165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!vecType->isCanonical()) { 1517f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getVectorType(getCanonicalType(vecType), NumElts); 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 15205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 1521f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 15225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 15236b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VectorType *New = new (*this, TypeAlignment) 15246b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VectorType(vecType, NumElts, Canonical); 15255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorTypes.InsertNode(New, InsertPos); 15265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 15275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 15285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 15295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1530213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// getExtVectorType - Return the unique reference to an extended vector type of 153173322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 1532213541a68a3e137d11d2cefb612c6cdb410d7e8eNate BegemanQualType ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) { 153373322924127c873c13101b705dd823f5539ffa5fSteve Naroff BuiltinType *baseType; 15341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1535f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner baseType = dyn_cast<BuiltinType>(getCanonicalType(vecType).getTypePtr()); 1536213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman assert(baseType != 0 && "getExtVectorType(): Expecting a built-in type"); 15371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 153873322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Check if we've already instantiated a vector of this type. 153973322924127c873c13101b705dd823f5539ffa5fSteve Naroff llvm::FoldingSetNodeID ID; 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump VectorType::Profile(ID, vecType, NumElts, Type::ExtVector); 154173322924127c873c13101b705dd823f5539ffa5fSteve Naroff void *InsertPos = 0; 154273322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 154373322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(VTP, 0); 154473322924127c873c13101b705dd823f5539ffa5fSteve Naroff 154573322924127c873c13101b705dd823f5539ffa5fSteve Naroff // If the element type isn't canonical, this won't be a canonical type either, 154673322924127c873c13101b705dd823f5539ffa5fSteve Naroff // so fill in the canonical type field. 154773322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType Canonical; 154873322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (!vecType->isCanonical()) { 1549213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); 15501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155173322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Get the new insert position for the node we care about. 155273322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 1553f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 155473322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 15556b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType *New = new (*this, TypeAlignment) 15566b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType(vecType, NumElts, Canonical); 155773322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorTypes.InsertNode(New, InsertPos); 155873322924127c873c13101b705dd823f5539ffa5fSteve Naroff Types.push_back(New); 155973322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(New, 0); 156073322924127c873c13101b705dd823f5539ffa5fSteve Naroff} 156173322924127c873c13101b705dd823f5539ffa5fSteve Naroff 15621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getDependentSizedExtVectorType(QualType vecType, 15639cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Expr *SizeExpr, 15649cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor SourceLocation AttrLoc) { 15652ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor llvm::FoldingSetNodeID ID; 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), 15672ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr); 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15692ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void *InsertPos = 0; 15702ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *Canon 15712ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 15722ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *New; 15732ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (Canon) { 15742ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // We already have a canonical version of this array type; use it as 15752ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // the canonical type for a newly-built type. 15766b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 15776b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(Canon, 0), 15786b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall SizeExpr, AttrLoc); 15792ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 15802ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType CanonVecTy = getCanonicalType(vecType); 15812ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (CanonVecTy == vecType) { 15826b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 15836b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(), SizeExpr, 15846b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall AttrLoc); 15852ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorTypes.InsertNode(New, InsertPos); 15862ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 15872ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, 15882ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SourceLocation()); 15896b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 15906b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, Canon, SizeExpr, AttrLoc); 15912ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 15922ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15949cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Types.push_back(New); 15959cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(New, 0); 15969cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 15979cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 159872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 15995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 16002455636163fdd18581d7fdae816433f886d88213Mike StumpQualType ASTContext::getFunctionNoProtoType(QualType ResultTy, bool NoReturn) { 16015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 16025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 16035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 16042455636163fdd18581d7fdae816433f886d88213Mike Stump FunctionNoProtoType::Profile(ID, ResultTy, NoReturn); 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 16071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionNoProtoType *FT = 160872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 16095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FT, 0); 16101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 16125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!ResultTy->isCanonical()) { 16132455636163fdd18581d7fdae816433f886d88213Mike Stump Canonical = getFunctionNoProtoType(getCanonicalType(ResultTy), NoReturn); 16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 161672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType *NewIP = 161772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 1618f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 16195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16216b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall FunctionNoProtoType *New = new (*this, TypeAlignment) 16226b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall FunctionNoProtoType(ResultTy, Canonical, NoReturn); 16235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 162472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.InsertNode(New, InsertPos); 16255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 16265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFunctionType - Return a normal function type with a typed argument 16295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// list. isVariadic indicates whether the argument list includes '...'. 163061710854be2b098428aff5316e64bd34b30fbcb7Chris LattnerQualType ASTContext::getFunctionType(QualType ResultTy,const QualType *ArgArray, 1631971c4fae6092976338b755af1d47dac07c8f16e3Argyrios Kyrtzidis unsigned NumArgs, bool isVariadic, 1632465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl unsigned TypeQuals, bool hasExceptionSpec, 1633465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl bool hasAnyExceptionSpec, unsigned NumExs, 16342455636163fdd18581d7fdae816433f886d88213Mike Stump const QualType *ExArray, bool NoReturn) { 163583913e36c847052966d9ff60d760ea7231ed8b6bAnders Carlsson if (LangOpts.CPlusPlus) { 163683913e36c847052966d9ff60d760ea7231ed8b6bAnders Carlsson for (unsigned i = 0; i != NumArgs; ++i) 16370953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!ArgArray[i].hasQualifiers() && 16380953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "C++ arguments can't have toplevel qualifiers!"); 163983913e36c847052966d9ff60d760ea7231ed8b6bAnders Carlsson } 164083913e36c847052966d9ff60d760ea7231ed8b6bAnders Carlsson 16415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 16425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 16435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 164472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, isVariadic, 1645465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl TypeQuals, hasExceptionSpec, hasAnyExceptionSpec, 16462455636163fdd18581d7fdae816433f886d88213Mike Stump NumExs, ExArray, NoReturn); 16475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionProtoType *FTP = 165072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 16515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 1652465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1653465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Determine whether the type being created is already canonical or not. 16545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool isCanonical = ResultTy->isCanonical(); 1655465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl if (hasExceptionSpec) 1656465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl isCanonical = false; 16575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs && isCanonical; ++i) 16585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!ArgArray[i]->isCanonical()) 16595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer isCanonical = false; 16605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this type isn't canonical, get the canonical version of it. 1662465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // The exception spec is not part of the canonical type. 16635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 16645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (!isCanonical) { 16655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::SmallVector<QualType, 16> CanonicalArgs; 16665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CanonicalArgs.reserve(NumArgs); 16675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 1668f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner CanonicalArgs.push_back(getCanonicalType(ArgArray[i])); 1669465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 1670f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getFunctionType(getCanonicalType(ResultTy), 1671beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad CanonicalArgs.data(), NumArgs, 167247259d9ca7840dd66f06f5f11da7768b23d1e0fdDouglas Gregor isVariadic, TypeQuals, false, 167347259d9ca7840dd66f06f5f11da7768b23d1e0fdDouglas Gregor false, 0, 0, NoReturn); 1674465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 16755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 167672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType *NewIP = 167772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 1678f6e764fe722440eaed18dad9eeff3d7e89a4d7afChris Lattner assert(NewIP == 0 && "Shouldn't be in the map!"); NewIP = NewIP; 16795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1680465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 168172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor // FunctionProtoType objects are allocated with extra bytes after them 1682465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // for two variable size arrays (for parameter and exception types) at the 1683465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // end of them. 16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FunctionProtoType *FTP = 1685465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl (FunctionProtoType*)Allocate(sizeof(FunctionProtoType) + 1686465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl NumArgs*sizeof(QualType) + 16876b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall NumExs*sizeof(QualType), TypeAlignment); 168872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, isVariadic, 1689465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl TypeQuals, hasExceptionSpec, hasAnyExceptionSpec, 16902455636163fdd18581d7fdae816433f886d88213Mike Stump ExArray, NumExs, Canonical, NoReturn); 16915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(FTP); 169272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.InsertNode(FTP, InsertPos); 16935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 16945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 16955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 16962ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// getTypeDeclType - Return the unique reference to the type for the 16972ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// specified type declaration. 16984b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed KremenekQualType ASTContext::getTypeDeclType(TypeDecl *Decl, TypeDecl* PrevDecl) { 16991e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis assert(Decl && "Passed null for Decl param"); 17002ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 17011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17021e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis if (TypedefDecl *Typedef = dyn_cast<TypedefDecl>(Decl)) 17032ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getTypedefType(Typedef); 1704fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor else if (isa<TemplateTypeParmDecl>(Decl)) { 1705fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor assert(false && "Template type parameter types are always available."); 17069fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (ObjCInterfaceDecl *ObjCInterface 17079fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump = dyn_cast<ObjCInterfaceDecl>(Decl)) 17082ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getObjCInterfaceType(ObjCInterface); 170949aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 1710c1efaecf0373f1a55c5ef4c234357cf726fc0600Douglas Gregor if (RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) { 1711566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek if (PrevDecl) 1712566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek Decl->TypeForDecl = PrevDecl->TypeForDecl; 1713f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff else 17146b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Decl->TypeForDecl = new (*this, TypeAlignment) RecordType(Record); 17159fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) { 1716566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek if (PrevDecl) 1717566c2ba743065ec090f5154d5c30cf593aa12a6eTed Kremenek Decl->TypeForDecl = PrevDecl->TypeForDecl; 1718f83820bd7a0dc4c253071b31c443a316a49ce5aaSteve Naroff else 17196b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Decl->TypeForDecl = new (*this, TypeAlignment) EnumType(Enum); 17209fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else 17212ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor assert(false && "TypeDecl without a type?"); 172249aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 17234b7c98378ae0c1a3635f0b7756848b4a9923f8bcTed Kremenek if (!PrevDecl) Types.push_back(Decl->TypeForDecl); 172449aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis return QualType(Decl->TypeForDecl, 0); 17252ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor} 17262ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 17275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTypedefType - Return the unique reference to the type for the 17285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified typename decl. 17295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getTypedefType(TypedefDecl *Decl) { 17305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1732f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(Decl->getUnderlyingType()); 17336b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Decl->TypeForDecl = new(*this, TypeAlignment) 17346b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypedefType(Type::Typedef, Decl, Canonical); 17355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(Decl->TypeForDecl); 17365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(Decl->TypeForDecl, 0); 17375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 17385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1739fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor/// \brief Retrieve the template type parameter type for a template 17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parameter or parameter pack with the given depth, index, and (optionally) 174176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson/// name. 17421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, 174376e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool ParameterPack, 1744fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor IdentifierInfo *Name) { 1745fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor llvm::FoldingSetNodeID ID; 174676e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, Name); 1747fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void *InsertPos = 0; 17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType *TypeParm 1749fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 1750fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1751fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor if (TypeParm) 1752fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson if (Name) { 175576e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); 17566b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeParm = new (*this, TypeAlignment) 17576b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TemplateTypeParmType(Depth, Index, ParameterPack, Name, Canon); 175876e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson } else 17596b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeParm = new (*this, TypeAlignment) 17606b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TemplateTypeParmType(Depth, Index, ParameterPack); 1761fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1762fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Types.push_back(TypeParm); 1763fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); 1764fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 1765fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 1766fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor} 1767fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 17681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 17697532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorASTContext::getTemplateSpecializationType(TemplateName Template, 17707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 17717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, 17727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualType Canon) { 1773b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor if (!Canon.isNull()) 1774b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor Canon = getCanonicalType(Canon); 1775b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor else { 1776b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor // Build the canonical template specialization type. 17771275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateName CanonTemplate = getCanonicalTemplateName(Template); 17781275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor llvm::SmallVector<TemplateArgument, 4> CanonArgs; 17791275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs.reserve(NumArgs); 17801275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) 17811275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); 17821275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 17831275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Determine whether this canonical template specialization type already 17841275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // exists. 17851275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor llvm::FoldingSetNodeID ID; 17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateSpecializationType::Profile(ID, CanonTemplate, 1787828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor CanonArgs.data(), NumArgs, *this); 17881275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 17891275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor void *InsertPos = 0; 17901275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateSpecializationType *Spec 17911275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 17921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17931275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor if (!Spec) { 17941275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate a new canonical template specialization type. 17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void *Mem = Allocate((sizeof(TemplateSpecializationType) + 17961275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor sizeof(TemplateArgument) * NumArgs), 17976b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment); 17981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Spec = new (Mem) TemplateSpecializationType(*this, CanonTemplate, 17991275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs.data(), NumArgs, 1800b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor Canon); 18011275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor Types.push_back(Spec); 18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateSpecializationTypes.InsertNode(Spec, InsertPos); 18031275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 18041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1805b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor if (Canon.isNull()) 1806b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor Canon = QualType(Spec, 0); 18071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(Canon->isDependentType() && 18081275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor "Non-dependent template-id type must have a canonical type"); 1809b88e888404ad0a2bdd9bfae457e8530bb38a87c5Douglas Gregor } 1810fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 18111275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate the (non-canonical) template specialization type, but don't 18121275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // try to unique it: these types typically have location information that 18131275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // we don't unique and don't want to lose. 18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void *Mem = Allocate((sizeof(TemplateSpecializationType) + 181540808ce6ac04b102c3b56244a635d6b98eed6d97Douglas Gregor sizeof(TemplateArgument) * NumArgs), 18166b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment); 18171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateSpecializationType *Spec 18181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump = new (Mem) TemplateSpecializationType(*this, Template, Args, NumArgs, 1819828e226ab7ed08b3eb766549e9d3306432137460Douglas Gregor Canon); 18201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 182155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor Types.push_back(Spec); 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(Spec, 0); 182355f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 182455f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 18251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 1826ab452ba8323d1985e08bade2bced588cddf2cc28Douglas GregorASTContext::getQualifiedNameType(NestedNameSpecifier *NNS, 1827e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualType NamedType) { 1828e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor llvm::FoldingSetNodeID ID; 1829ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor QualifiedNameType::Profile(ID, NNS, NamedType); 1830e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 1831e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void *InsertPos = 0; 18321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualifiedNameType *T 1833e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor = QualifiedNameTypes.FindNodeOrInsertPos(ID, InsertPos); 1834e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor if (T) 1835e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 1836e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 18371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump T = new (*this) QualifiedNameType(NNS, NamedType, 1838ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor getCanonicalType(NamedType)); 1839e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor Types.push_back(T); 1840e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor QualifiedNameTypes.InsertNode(T, InsertPos); 1841e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 1842e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor} 1843e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 18441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getTypenameType(NestedNameSpecifier *NNS, 1845d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor const IdentifierInfo *Name, 1846d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType Canon) { 1847d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 1848d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1849d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (Canon.isNull()) { 1850d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 1851d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (CanonNNS != NNS) 1852d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Canon = getTypenameType(CanonNNS, Name); 1853d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 1854d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1855d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor llvm::FoldingSetNodeID ID; 1856d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameType::Profile(ID, NNS, Name); 1857d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1858d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void *InsertPos = 0; 18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypenameType *T 1860d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor = TypenameTypes.FindNodeOrInsertPos(ID, InsertPos); 1861d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (T) 1862d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return QualType(T, 0); 1863d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 1864d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor T = new (*this) TypenameType(NNS, Name, Canon); 1865d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Types.push_back(T); 1866d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor TypenameTypes.InsertNode(T, InsertPos); 18671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 1868d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 1869d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 18701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 18711eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpASTContext::getTypenameType(NestedNameSpecifier *NNS, 18721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *TemplateId, 18731734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType Canon) { 18741734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 18751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor if (Canon.isNull()) { 18771734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 18781734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor QualType CanonType = getCanonicalType(QualType(TemplateId, 0)); 18791734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor if (CanonNNS != NNS || CanonType != QualType(TemplateId, 0)) { 18801734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor const TemplateSpecializationType *CanonTemplateId 1881183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall = CanonType->getAs<TemplateSpecializationType>(); 18821734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor assert(CanonTemplateId && 18831734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor "Canonical type must also be a template specialization type"); 18841734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Canon = getTypenameType(CanonNNS, CanonTemplateId); 18851734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 18861734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor } 18871734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18881734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor llvm::FoldingSetNodeID ID; 18891734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameType::Profile(ID, NNS, TemplateId); 18901734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18911734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor void *InsertPos = 0; 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TypenameType *T 18931734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor = TypenameTypes.FindNodeOrInsertPos(ID, InsertPos); 18941734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor if (T) 18951734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor return QualType(T, 0); 18961734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 18971734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor T = new (*this) TypenameType(NNS, TemplateId, Canon); 18981734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Types.push_back(T); 18991734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor TypenameTypes.InsertNode(T, InsertPos); 19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 19011734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor} 19021734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 19037da2431c23ef1ee8acb114e39692246e1801afc2John McCallQualType 19047da2431c23ef1ee8acb114e39692246e1801afc2John McCallASTContext::getElaboratedType(QualType UnderlyingType, 19057da2431c23ef1ee8acb114e39692246e1801afc2John McCall ElaboratedType::TagKind Tag) { 19067da2431c23ef1ee8acb114e39692246e1801afc2John McCall llvm::FoldingSetNodeID ID; 19077da2431c23ef1ee8acb114e39692246e1801afc2John McCall ElaboratedType::Profile(ID, UnderlyingType, Tag); 19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19097da2431c23ef1ee8acb114e39692246e1801afc2John McCall void *InsertPos = 0; 19107da2431c23ef1ee8acb114e39692246e1801afc2John McCall ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 19117da2431c23ef1ee8acb114e39692246e1801afc2John McCall if (T) 19127da2431c23ef1ee8acb114e39692246e1801afc2John McCall return QualType(T, 0); 19137da2431c23ef1ee8acb114e39692246e1801afc2John McCall 19147da2431c23ef1ee8acb114e39692246e1801afc2John McCall QualType Canon = getCanonicalType(UnderlyingType); 19157da2431c23ef1ee8acb114e39692246e1801afc2John McCall 19167da2431c23ef1ee8acb114e39692246e1801afc2John McCall T = new (*this) ElaboratedType(UnderlyingType, Tag, Canon); 19177da2431c23ef1ee8acb114e39692246e1801afc2John McCall Types.push_back(T); 19187da2431c23ef1ee8acb114e39692246e1801afc2John McCall ElaboratedTypes.InsertNode(T, InsertPos); 19197da2431c23ef1ee8acb114e39692246e1801afc2John McCall return QualType(T, 0); 19207da2431c23ef1ee8acb114e39692246e1801afc2John McCall} 19217da2431c23ef1ee8acb114e39692246e1801afc2John McCall 192288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// CmpProtocolNames - Comparison predicate for sorting protocols 192388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// alphabetically. 192488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic bool CmpProtocolNames(const ObjCProtocolDecl *LHS, 192588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner const ObjCProtocolDecl *RHS) { 19262e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS->getDeclName() < RHS->getDeclName(); 192788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 192888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 192988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic void SortAndUniqueProtocols(ObjCProtocolDecl **&Protocols, 193088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner unsigned &NumProtocols) { 193188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; 19321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 193388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Sort protocols, keyed by name. 193488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames); 193588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 193688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Remove duplicates. 193788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); 193888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner NumProtocols = ProtocolsEnd-Protocols; 193988cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 194088cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 1941d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for 1942d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff/// the given interface decl and the conforming protocol list. 194314108da7f7fc059772711e4ffee1322a27b152a7Steve NaroffQualType ASTContext::getObjCObjectPointerType(QualType InterfaceT, 19441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCProtocolDecl **Protocols, 1945d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff unsigned NumProtocols) { 1946d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // Sort the protocol list alphabetically to canonicalize it. 1947d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (NumProtocols) 1948d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff SortAndUniqueProtocols(Protocols, NumProtocols); 1949d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1950d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff llvm::FoldingSetNodeID ID; 195114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ObjCObjectPointerType::Profile(ID, InterfaceT, Protocols, NumProtocols); 1952d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1953d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void *InsertPos = 0; 1954d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff if (ObjCObjectPointerType *QT = 1955d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 1956d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return QualType(QT, 0); 1957d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 1958d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff // No Match; 19596b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ObjCObjectPointerType *QType = new (*this, TypeAlignment) 19606b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ObjCObjectPointerType(InterfaceT, Protocols, NumProtocols); 19611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1962d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff Types.push_back(QType); 1963d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff ObjCObjectPointerTypes.InsertNode(QType, InsertPos); 1964d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff return QualType(QType, 0); 1965d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 196688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 1967c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// getObjCInterfaceType - Return the unique reference to the type for the 1968c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff/// specified ObjC interface decl. The list of protocols is optional. 1969c15cb2af27514ecc879daba9aa01389c5203685dSteve NaroffQualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 1970a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtocolDecl **Protocols, unsigned NumProtocols) { 19711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (NumProtocols) 1972c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff // Sort the protocol list alphabetically to canonicalize it. 1973c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff SortAndUniqueProtocols(Protocols, NumProtocols); 19741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19754b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian llvm::FoldingSetNodeID ID; 1976c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceType::Profile(ID, Decl, Protocols, NumProtocols); 19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19784b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void *InsertPos = 0; 1979c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (ObjCInterfaceType *QT = 1980c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceTypes.FindNodeOrInsertPos(ID, InsertPos)) 19814b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QT, 0); 19821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19834b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian // No Match; 19846b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ObjCInterfaceType *QType = new (*this, TypeAlignment) 19856b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ObjCInterfaceType(const_cast<ObjCInterfaceDecl*>(Decl), 19866b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Protocols, NumProtocols); 19874b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian Types.push_back(QType); 1988c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff ObjCInterfaceTypes.InsertNode(QType, InsertPos); 19894b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QType, 0); 19904b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian} 19914b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian 199272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 199372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType AST's (since expression's are never shared). For example, 19949752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// multiple declarations that refer to "typeof(x)" all contain different 19951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// DeclRefExpr's. This doesn't effect the type checker, since it operates 19969752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 199772564e73277e29f6db3305d1f27ba408abb7ed88Douglas GregorQualType ASTContext::getTypeOfExprType(Expr *tofExpr) { 1998dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType *toe; 1999b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (tofExpr->isTypeDependent()) { 2000b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor llvm::FoldingSetNodeID ID; 2001b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType::Profile(ID, *this, tofExpr); 20021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2003b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void *InsertPos = 0; 2004b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType *Canon 2005b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor = DependentTypeOfExprTypes.FindNodeOrInsertPos(ID, InsertPos); 2006b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (Canon) { 2007b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // We already have a "canonical" version of an identical, dependent 2008b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // typeof(expr) type. Use that as our canonical type. 20096b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, 2010b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor QualType((TypeOfExprType*)Canon, 0)); 2011b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 2012b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor else { 2013b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // Build a new, canonical typeof(expr) type. 20146b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon 20156b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) DependentTypeOfExprType(*this, tofExpr); 2016b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprTypes.InsertNode(Canon, InsertPos); 2017b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor toe = Canon; 2018b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 2019b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } else { 2020dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType Canonical = getCanonicalType(tofExpr->getType()); 20216b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, Canonical); 2022dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 20239752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(toe); 20249752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(toe, 0); 2025d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 2026d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 20279752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// getTypeOfType - Unlike many "get<Type>" functions, we don't unique 20289752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// TypeOfType AST's. The only motivation to unique these nodes would be 20299752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be 20301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 20319752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 2032d1861fd633d5096a00777c918eb8575ea7162fe7Steve NaroffQualType ASTContext::getTypeOfType(QualType tofType) { 2033f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(tofType); 20346b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeOfType *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); 20359752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(tot); 20369752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(tot, 0); 2037d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 2038d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 203960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson/// getDecltypeForExpr - Given an expr, will return the decltype for that 204060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson/// expression, according to the rules in C++0x [dcl.type.simple]p4 204160a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlssonstatic QualType getDecltypeForExpr(const Expr *e, ASTContext &Context) { 2042a07c33e64e1169e4261f7748c7f9191091a3ad2eAnders Carlsson if (e->isTypeDependent()) 2043a07c33e64e1169e4261f7748c7f9191091a3ad2eAnders Carlsson return Context.DependentTy; 20441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 204560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // If e is an id expression or a class member access, decltype(e) is defined 204660a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // as the type of the entity named by e. 204760a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(e)) { 204860a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const ValueDecl *VD = dyn_cast<ValueDecl>(DRE->getDecl())) 204960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return VD->getType(); 205060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson } 205160a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const MemberExpr *ME = dyn_cast<MemberExpr>(e)) { 205260a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) 205360a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return FD->getType(); 205460a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson } 205560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // If e is a function call or an invocation of an overloaded operator, 205660a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // (parentheses around e are ignored), decltype(e) is defined as the 205760a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // return type of that function. 205860a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (const CallExpr *CE = dyn_cast<CallExpr>(e->IgnoreParens())) 205960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return CE->getCallReturnType(); 20601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 206160a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson QualType T = e->getType(); 20621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Otherwise, where T is the type of e, if e is an lvalue, decltype(e) is 206460a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson // defined as T&, otherwise decltype(e) is defined as T. 206560a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson if (e->isLvalue(Context) == Expr::LV_Valid) 206660a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson T = Context.getLValueReferenceType(T); 20671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 206860a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson return T; 206960a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson} 207060a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 2071395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// getDecltypeType - Unlike many "get<Type>" functions, we don't unique 2072395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType AST's. The only motivation to unique these nodes would be 2073395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// memory savings. Since decltype(t) is fairly uncommon, space shouldn't be 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 2075395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// on canonical type's (which are always unique). 2076395b475a4474f1c7574d927ad142ca0c7997cbcaAnders CarlssonQualType ASTContext::getDecltypeType(Expr *e) { 2077dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor DecltypeType *dt; 20789d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (e->isTypeDependent()) { 20799d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor llvm::FoldingSetNodeID ID; 20809d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType::Profile(ID, *this, e); 20811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20829d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void *InsertPos = 0; 20839d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType *Canon 20849d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos); 20859d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (Canon) { 20869d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // We already have a "canonical" version of an equivalent, dependent 20879d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // decltype type. Use that as our canonical type. 20886b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall dt = new (*this, TypeAlignment) DecltypeType(e, DependentTy, 20899d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor QualType((DecltypeType*)Canon, 0)); 20909d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 20919d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor else { 20929d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // Build a new, canonical typeof(expr) type. 20936b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon = new (*this, TypeAlignment) DependentDecltypeType(*this, e); 20949d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeTypes.InsertNode(Canon, InsertPos); 20959d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor dt = Canon; 20969d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 20979d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } else { 2098dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType T = getDecltypeForExpr(e, *this); 20996b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall dt = new (*this, TypeAlignment) DecltypeType(e, T, getCanonicalType(T)); 2100dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 2101395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Types.push_back(dt); 2102395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return QualType(dt, 0); 2103395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 2104395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 21055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTagDeclType - Return the unique reference to the type for the 21065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified TagDecl (struct/union/class/enum) decl. 2107e607ed068334bacb8d7b093996b4671c6ca79e25Mike StumpQualType ASTContext::getTagDeclType(const TagDecl *Decl) { 2108d778f88d32b96a74c9edb7342c81357606a7cdc0Ted Kremenek assert (Decl); 2109e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // FIXME: What is the design on getTagDeclType when it requires casting 2110e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // away const? mutable? 2111e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump return getTypeDeclType(const_cast<TagDecl*>(Decl)); 21125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 21135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result 21151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and 21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// needs to agree with the definition in <stddef.h>. 21175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerQualType ASTContext::getSizeType() const { 2118b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor return getFromTargetType(Target.getSizeType()); 21195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 21205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 212164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getSignedWCharType - Return the type of "signed wchar_t". 212264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 212364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getSignedWCharType() const { 212464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 212564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return WCharTy; 212664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 212764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 212864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getUnsignedWCharType - Return the type of "unsigned wchar_t". 212964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 213064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getUnsignedWCharType() const { 213164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 213264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return UnsignedIntTy; 213364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 213464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 21358b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?) 21368b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 21378b9023ba35a86838789e2c9034a6128728c547aaChris LattnerQualType ASTContext::getPointerDiffType() const { 2138b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor return getFromTargetType(Target.getPtrDiffType(0)); 21398b9023ba35a86838789e2c9034a6128728c547aaChris Lattner} 21408b9023ba35a86838789e2c9034a6128728c547aaChris Lattner 2141e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 2142e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner// Type Operators 2143e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 2144e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 214577c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// getCanonicalType - Return the canonical (structural) type corresponding to 214677c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// the specified potentially non-canonical type. The non-canonical version 214777c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// of a type may have many "decorated" versions of types. Decorators can 214877c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// include typedefs, 'typeof' operators, etc. The returned type is guaranteed 214977c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// to be free of any of these, allowing two canonical types to be compared 215077c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner/// for exact equality with a simple pointer comparison. 215150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas GregorCanQualType ASTContext::getCanonicalType(QualType T) { 21520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 21530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ptr = Quals.strip(T); 21540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType CanType = Ptr->getCanonicalTypeInternal(); 21550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 21560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // The canonical internal type will be the canonical type *except* 21570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // that we push type qualifiers down through array types. 21581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If there are no new qualifiers to push down, stop here. 21600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!Quals.hasQualifiers()) 216150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe(CanType); 2162c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 21630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the type qualifiers are on an array type, get the canonical 21640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // type of the array with the qualifiers applied to the element 21650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // type. 2166c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner ArrayType *AT = dyn_cast<ArrayType>(CanType); 2167c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (!AT) 21680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return CanQualType::CreateUnsafe(getQualifiedType(CanType, Quals)); 21691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2170c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the canonical version of the element with the extra qualifiers on it. 2171c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // This can recursively sink qualifiers through multiple levels of arrays. 21720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType NewEltTy = getQualifiedType(AT->getElementType(), Quals); 2173c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner NewEltTy = getCanonicalType(NewEltTy); 21741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2175c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) 217650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe( 217750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor getConstantArrayType(NewEltTy, CAT->getSize(), 217850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor CAT->getSizeModifier(), 21790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CAT->getIndexTypeCVRQualifiers())); 2180c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) 218150d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe( 218250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor getIncompleteArrayType(NewEltTy, IAT->getSizeModifier(), 21830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall IAT->getIndexTypeCVRQualifiers())); 21841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2185898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (DependentSizedArrayType *DSAT = dyn_cast<DependentSizedArrayType>(AT)) 218650d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe( 218750d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor getDependentSizedArrayType(NewEltTy, 2188bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr() ? 2189bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr()->Retain() : 0, 219050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DSAT->getSizeModifier(), 21910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall DSAT->getIndexTypeCVRQualifiers(), 219250d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor DSAT->getBracketsRange())); 2193898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 2194c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VariableArrayType *VAT = cast<VariableArrayType>(AT); 219550d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor return CanQualType::CreateUnsafe(getVariableArrayType(NewEltTy, 2196bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr() ? 2197bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr()->Retain() : 0, 219850d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor VAT->getSizeModifier(), 21990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall VAT->getIndexTypeCVRQualifiers(), 220050d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor VAT->getBracketsRange())); 2201c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner} 2202c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 220325a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas GregorTemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) { 220425a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor // If this template name refers to a template, the canonical 220525a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor // template name merely stores the template itself. 220625a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) 220797fbaa2a38804268a024f1a104b43fcf8b4411b0Argyrios Kyrtzidis return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl())); 220825a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 22091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If this template name refers to a set of overloaded function templates, 2210d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor /// the canonical template name merely stores the set of function templates. 22116ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor if (OverloadedFunctionDecl *Ovl = Name.getAsOverloadedFunctionDecl()) { 22126ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor OverloadedFunctionDecl *CanonOvl = 0; 22136ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(), 22146ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor FEnd = Ovl->function_end(); 22156ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor F != FEnd; ++F) { 22166ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor Decl *Canon = F->get()->getCanonicalDecl(); 22176ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor if (CanonOvl || Canon != F->get()) { 22186ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor if (!CanonOvl) 22191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CanonOvl = OverloadedFunctionDecl::Create(*this, 22201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Ovl->getDeclContext(), 22216ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor Ovl->getDeclName()); 22221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22236ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor CanonOvl->addOverload( 22246ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor AnyFunctionDecl::getFromNamedDecl(cast<NamedDecl>(Canon))); 22256ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor } 22266ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor } 22271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22286ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor return TemplateName(CanonOvl? CanonOvl : Ovl); 22296ebd15e81a4d44ac51c24bffe2705586d5edffeeDouglas Gregor } 22301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 223125a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 223225a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor assert(DTN && "Non-dependent template names must refer to template decls."); 223325a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor return DTN->CanonicalTemplateName; 223425a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor} 223525a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 22361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateArgument 22371275ae098acda31fe0e434510c729fcfed0458a1Douglas GregorASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) { 22381275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor switch (Arg.getKind()) { 22391275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Null: 22401275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 22411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22421275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Expression: 22431275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // FIXME: Build canonical expression? 22441275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 22451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22461275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Declaration: 22471275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(SourceLocation(), 22481275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor Arg.getAsDecl()->getCanonicalDecl()); 22491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22501275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Integral: 22511275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(SourceLocation(), 22521275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor *Arg.getAsIntegral(), 22531275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor getCanonicalType(Arg.getIntegralType())); 22541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22551275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Type: 22561275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(SourceLocation(), 22571275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor getCanonicalType(Arg.getAsType())); 22581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22591275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Pack: { 22601275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // FIXME: Allocate in ASTContext 22611275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateArgument *CanonArgs = new TemplateArgument[Arg.pack_size()]; 22621275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor unsigned Idx = 0; 22631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 22641275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor AEnd = Arg.pack_end(); 22651275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor A != AEnd; (void)++A, ++Idx) 22661275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs[Idx] = getCanonicalTemplateArgument(*A); 22671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22681275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor TemplateArgument Result; 22691275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor Result.setArgumentPack(CanonArgs, Arg.pack_size(), false); 22701275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Result; 22711275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 22721275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 22731275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 22741275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Silence GCC warning 22751275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor assert(false && "Unhandled template argument kind"); 22761275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return TemplateArgument(); 22771275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor} 22781275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 2279d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorNestedNameSpecifier * 2280d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) { 22811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!NNS) 2282d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 2283d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2284d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor switch (NNS->getKind()) { 2285d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Identifier: 2286d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Canonicalize the prefix but keep the identifier the same. 22871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return NestedNameSpecifier::Create(*this, 2288d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor getCanonicalNestedNameSpecifier(NNS->getPrefix()), 2289d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NNS->getAsIdentifier()); 2290d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2291d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Namespace: 2292d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 2293d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // this namespace and no prefix. 2294d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NestedNameSpecifier::Create(*this, 0, NNS->getAsNamespace()); 2295d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2296d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpec: 2297d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: { 2298d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType T = getCanonicalType(QualType(NNS->getAsType(), 0)); 22991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return NestedNameSpecifier::Create(*this, 0, 23001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, 2301d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor T.getTypePtr()); 2302d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2303d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2304d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Global: 2305d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // The global specifier is canonical and unique. 2306d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NNS; 2307d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2308d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2309d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Required to silence a GCC warning 2310d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 2311d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 2312d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2313c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 2314c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattnerconst ArrayType *ASTContext::getAsArrayType(QualType T) { 2315c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the non-qualified case efficiently. 23160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!T.hasQualifiers()) { 2317c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the common positive case fast. 2318c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(T)) 2319c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT; 2320c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 23211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23220953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Handle the common negative case fast. 2323c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType CType = T->getCanonicalTypeInternal(); 23240953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (!isa<ArrayType>(CType)) 2325c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 23261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23270953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Apply any qualifiers from the array type to the element type. This 2328c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // implements C99 6.7.3p8: "If the specification of an array type includes 2329c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // any type qualifiers, the element type is so qualified, not the array type." 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2331c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we get here, we either have type qualifiers on the type, or we have 2332c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // sugar such as a typedef in the way. If we have type qualifiers on the type 233350d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor // we must propagate them down into the element type. 23340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 23350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 23360953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *Ty = Qs.strip(T.getDesugaredType()); 23371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2338c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we have a simple case, just return now. 2339c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *ATy = dyn_cast<ArrayType>(Ty); 23400953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (ATy == 0 || Qs.empty()) 2341c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy; 23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2343c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Otherwise, we have an array and we have qualifiers on it. Push the 2344c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // qualifiers into the array element type and return a new array type. 2345c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the canonical version of the element with the extra qualifiers on it. 2346c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // This can recursively sink qualifiers through multiple levels of arrays. 23470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualType NewEltTy = getQualifiedType(ATy->getElementType(), Qs); 23481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2349c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(ATy)) 2350c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), 2351c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CAT->getSizeModifier(), 23520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CAT->getIndexTypeCVRQualifiers())); 2353c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy)) 2354c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getIncompleteArrayType(NewEltTy, 2355c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner IAT->getSizeModifier(), 23560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall IAT->getIndexTypeCVRQualifiers())); 2357898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 23581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const DependentSizedArrayType *DSAT 2359898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor = dyn_cast<DependentSizedArrayType>(ATy)) 2360898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return cast<ArrayType>( 23611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDependentSizedArrayType(NewEltTy, 2362bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr() ? 2363bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman DSAT->getSizeExpr()->Retain() : 0, 2364898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DSAT->getSizeModifier(), 23650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall DSAT->getIndexTypeCVRQualifiers(), 23667e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor DSAT->getBracketsRange())); 23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2368c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const VariableArrayType *VAT = cast<VariableArrayType>(ATy); 23697e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return cast<ArrayType>(getVariableArrayType(NewEltTy, 2370bbed6b964414145b29e7b60b3e538093734ea3f8Eli Friedman VAT->getSizeExpr() ? 23710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall VAT->getSizeExpr()->Retain() : 0, 2372c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VAT->getSizeModifier(), 23730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall VAT->getIndexTypeCVRQualifiers(), 23747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor VAT->getBracketsRange())); 237577c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner} 237677c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 237777c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 2378e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// getArrayDecayedType - Return the properly qualified result of decaying the 2379e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// specified array type to a pointer. This operation is non-trivial when 2380e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// handling typedefs etc. The canonical type of "T" must be an array type, 2381e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// this returns a pointer to a properly qualified element of the array. 2382e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// 2383e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 2384e6327747b72bb687c948270f702ff53c30f411a6Chris LattnerQualType ASTContext::getArrayDecayedType(QualType Ty) { 2385c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the element type with 'getAsArrayType' so that we don't lose any 2386c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // typedefs in the element type of the array. This also handles propagation 2387c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // of type qualifiers from the array type into the element type if present 2388c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // (C99 6.7.3p8). 2389c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *PrettyArrayType = getAsArrayType(Ty); 2390c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner assert(PrettyArrayType && "Not an array type!"); 23911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2392c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); 2393e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 2394e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner // int x[restrict 4] -> int *restrict 23950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getQualifiedType(PtrTy, PrettyArrayType->getIndexTypeQualifiers()); 2396e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner} 2397e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 23985e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas GregorQualType ASTContext::getBaseElementType(QualType QT) { 23990953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Qs; 24005e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor while (true) { 24010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *UT = Qs.strip(QT); 24025e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor if (const ArrayType *AT = getAsArrayType(QualType(UT,0))) { 24035e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor QT = AT->getElementType(); 24046dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump } else { 24050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qs.apply(QT); 24065e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 24075e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor } 24085e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 24095e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 2410fbbce49c116aa8c8c7c0707cb6048b55f70461a9Anders CarlssonQualType ASTContext::getBaseElementType(const ArrayType *AT) { 2411fbbce49c116aa8c8c7c0707cb6048b55f70461a9Anders Carlsson QualType ElemTy = AT->getElementType(); 24121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2413fbbce49c116aa8c8c7c0707cb6048b55f70461a9Anders Carlsson if (const ArrayType *AT = getAsArrayType(ElemTy)) 2414fbbce49c116aa8c8c7c0707cb6048b55f70461a9Anders Carlsson return getBaseElementType(AT); 24151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24166183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson return ElemTy; 24176183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson} 24186183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 24190de78998e7bda473b408437053e48661b510d453Fariborz Jahanian/// getConstantArrayElementCount - Returns number of constant array elements. 24201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpuint64_t 24210de78998e7bda473b408437053e48661b510d453Fariborz JahanianASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { 24220de78998e7bda473b408437053e48661b510d453Fariborz Jahanian uint64_t ElementCount = 1; 24230de78998e7bda473b408437053e48661b510d453Fariborz Jahanian do { 24240de78998e7bda473b408437053e48661b510d453Fariborz Jahanian ElementCount *= CA->getSize().getZExtValue(); 24250de78998e7bda473b408437053e48661b510d453Fariborz Jahanian CA = dyn_cast<ConstantArrayType>(CA->getElementType()); 24260de78998e7bda473b408437053e48661b510d453Fariborz Jahanian } while (CA); 24270de78998e7bda473b408437053e48661b510d453Fariborz Jahanian return ElementCount; 24280de78998e7bda473b408437053e48661b510d453Fariborz Jahanian} 24290de78998e7bda473b408437053e48661b510d453Fariborz Jahanian 24305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFloatingRank - Return a relative rank for floating point types. 24315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This routine will assert if passed a built-in type that isn't a float. 2432a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerstatic FloatingRank getFloatingRank(QualType T) { 2433183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) 24345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getFloatingRank(CT->getElementType()); 2435a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner 2436183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall assert(T->getAs<BuiltinType>() && "getFloatingRank(): not a floating type"); 2437183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall switch (T->getAs<BuiltinType>()->getKind()) { 2438a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner default: assert(0 && "getFloatingRank(): not a floating type"); 24395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Float: return FloatRank; 24405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Double: return DoubleRank; 24415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::LongDouble: return LongDoubleRank; 24425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getFloatingTypeOfSizeWithinDomain - Returns a real floating 24461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// point or a complex type (based on typeDomain/typeSize). 2447716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeDomain' is a real floating point or complex type. 2448716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeSize' is a real floating point or complex type. 24491361b11066239ea15764a2a844405352d87296b3Chris LattnerQualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, 24501361b11066239ea15764a2a844405352d87296b3Chris Lattner QualType Domain) const { 24511361b11066239ea15764a2a844405352d87296b3Chris Lattner FloatingRank EltRank = getFloatingRank(Size); 24521361b11066239ea15764a2a844405352d87296b3Chris Lattner if (Domain->isComplexType()) { 24531361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 2454716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff default: assert(0 && "getFloatingRank(): illegal value for rank"); 2455f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case FloatRank: return FloatComplexTy; 2456f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case DoubleRank: return DoubleComplexTy; 2457f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case LongDoubleRank: return LongDoubleComplexTy; 2458f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 2459f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 24601361b11066239ea15764a2a844405352d87296b3Chris Lattner 24611361b11066239ea15764a2a844405352d87296b3Chris Lattner assert(Domain->isRealFloatingType() && "Unknown domain!"); 24621361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 24631361b11066239ea15764a2a844405352d87296b3Chris Lattner default: assert(0 && "getFloatingRank(): illegal value for rank"); 24641361b11066239ea15764a2a844405352d87296b3Chris Lattner case FloatRank: return FloatTy; 24651361b11066239ea15764a2a844405352d87296b3Chris Lattner case DoubleRank: return DoubleTy; 24661361b11066239ea15764a2a844405352d87296b3Chris Lattner case LongDoubleRank: return LongDoubleTy; 24675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24707cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// getFloatingTypeOrder - Compare the rank of the two specified floating 24717cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// point types, ignoring the domain of the type (i.e. 'double' == 24727cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 2474a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerint ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) { 2475a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank LHSR = getFloatingRank(LHS); 2476a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank RHSR = getFloatingRank(RHS); 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2478a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR == RHSR) 2479fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 0; 2480a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR > RHSR) 2481fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 1; 2482fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return -1; 24835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2485f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This 2486f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// routine will assert if passed a built-in type that isn't an integer or enum, 2487f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// or if it is not canonicalized. 2488f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedmanunsigned ASTContext::getIntegerRank(Type *T) { 2489f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner assert(T->isCanonical() && "T should be canonicalized"); 2490f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (EnumType* ET = dyn_cast<EnumType>(T)) 2491f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman T = ET->getDecl()->getIntegerType().getTypePtr(); 2492f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 2493a34267595534a72703290153a6f7e3da1adcec59Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::WChar)) 2494a34267595534a72703290153a6f7e3da1adcec59Eli Friedman T = getFromTargetType(Target.getWCharType()).getTypePtr(); 2495a34267595534a72703290153a6f7e3da1adcec59Eli Friedman 2496f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (T->isSpecificBuiltinType(BuiltinType::Char16)) 2497f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith T = getFromTargetType(Target.getChar16Type()).getTypePtr(); 2498f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 2499f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (T->isSpecificBuiltinType(BuiltinType::Char32)) 2500f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith T = getFromTargetType(Target.getChar32Type()).getTypePtr(); 2501f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 2502f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // There are two things which impact the integer rank: the width, and 2503f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // the ordering of builtins. The builtin ordering is encoded in the 2504f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // bottom three bits; the width is encoded in the bits above that. 25051b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T)) 2506f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return FWIT->getWidth() << 3; 2507f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman 2508f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 25097cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner default: assert(0 && "getIntegerRank(): not a built-in integer"); 25107cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Bool: 2511f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 1 + (getIntWidth(BoolTy) << 3); 25127cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_S: 25137cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_U: 25147cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::SChar: 25157cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UChar: 2516f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 2 + (getIntWidth(CharTy) << 3); 25177cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Short: 25187cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UShort: 2519f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 3 + (getIntWidth(ShortTy) << 3); 25207cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Int: 25217cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UInt: 2522f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 4 + (getIntWidth(IntTy) << 3); 25237cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Long: 25247cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULong: 2525f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 5 + (getIntWidth(LongTy) << 3); 25267cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::LongLong: 25277cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULongLong: 2528f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 6 + (getIntWidth(LongLongTy) << 3); 25292df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 25302df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::UInt128: 25312df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return 7 + (getIntWidth(Int128Ty) << 3); 2532f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner } 2533f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner} 2534f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner 253504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \brief Whether this is a promotable bitfield reference according 253604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 253704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// 253804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \returns the type this bit-field will promote to, or NULL if no 253904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// promotion occurs. 254004e8357f6801e9ff52673e7e899a67bbabf9de93Eli FriedmanQualType ASTContext::isPromotableBitField(Expr *E) { 254104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman FieldDecl *Field = E->getBitField(); 254204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (!Field) 254304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 254404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 254504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman QualType FT = Field->getType(); 254604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 254704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman llvm::APSInt BitWidthAP = Field->getBitWidth()->EvaluateAsInt(*this); 254804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t BitWidth = BitWidthAP.getZExtValue(); 254904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 255004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // GCC extension compatibility: if the bit-field size is less than or equal 255104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // to the size of int, it gets promoted no matter what its type is. 255204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // For instance, unsigned long bf : 4 gets promoted to signed int. 255304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth < IntSize) 255404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return IntTy; 255504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 255604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth == IntSize) 255704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return FT->isSignedIntegerType() ? IntTy : UnsignedIntTy; 255804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 255904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // Types bigger than int are not subject to promotions, and therefore act 256004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // like the base type. 256104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // FIXME: This doesn't quite match what gcc does, but what gcc does here 256204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // is ridiculous. 256304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 256404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman} 256504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 2566a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// getPromotedIntegerType - Returns the type that Promotable will 2567a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 2568a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// integer type. 2569a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli FriedmanQualType ASTContext::getPromotedIntegerType(QualType Promotable) { 2570a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(!Promotable.isNull()); 2571a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isPromotableIntegerType()); 2572a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (Promotable->isSignedIntegerType()) 2573a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return IntTy; 2574a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t PromotableSize = getTypeSize(Promotable); 2575a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 2576a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize); 2577a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy; 2578a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 2579a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 25801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getIntegerTypeOrder - Returns the highest ranked integer type: 25817cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 25821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 25837cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattnerint ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) { 2584f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Type *LHSC = getCanonicalType(LHS).getTypePtr(); 2585f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Type *RHSC = getCanonicalType(RHS).getTypePtr(); 25867cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSC == RHSC) return 0; 25871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2588f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool LHSUnsigned = LHSC->isUnsignedIntegerType(); 2589f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool RHSUnsigned = RHSC->isUnsignedIntegerType(); 25901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25917cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned LHSRank = getIntegerRank(LHSC); 25927cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned RHSRank = getIntegerRank(RHSC); 25931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25947cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. 25957cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank == RHSRank) return 0; 25967cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return LHSRank > RHSRank ? 1 : -1; 25977cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 25981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25997cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. 26007cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned) { 26017cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [LHS] type is larger, return it. 26027cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank >= RHSRank) 26037cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 26041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26057cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 26067cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 26071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 26087cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 26097cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 26107cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 26117cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [RHS] type is larger, return it. 26127cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (RHSRank >= LHSRank) 26137cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 26141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26157cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 26167cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 26171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 26187cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 26195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 262071993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 26211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// getCFConstantStringType - Return the type used for constant CFStrings. 262271993dd85eed9cc42c6b2fa61ee5c53026b74817Anders CarlssonQualType ASTContext::getCFConstantStringType() { 262371993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson if (!CFConstantStringTypeDecl) { 26241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CFConstantStringTypeDecl = 26251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), 2626df042e6c2bf06b2d9ed53c52469599ac1bd93a3fTed Kremenek &Idents.get("NSConstantString")); 2627f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson QualType FieldTypes[4]; 26281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 262971993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const int *isa; 26300953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[0] = getPointerType(IntTy.withConst()); 2631f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson // int flags; 2632f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[1] = IntTy; 263371993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const char *str; 26340953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[2] = getPointerType(CharTy.withConst()); 263571993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // long length; 26361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldTypes[3] = LongTy; 26371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 263844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor // Create fields 263944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (unsigned i = 0; i < 4; ++i) { 26401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 264144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation(), 0, 2642a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis FieldTypes[i], /*DInfo=*/0, 26431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /*BitWidth=*/0, 26444afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /*Mutable=*/false); 264517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis CFConstantStringTypeDecl->addDecl(Field); 264644b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 264744b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 264844b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor CFConstantStringTypeDecl->completeDefinition(*this); 264971993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson } 26501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 265171993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson return getTagDeclType(CFConstantStringTypeDecl); 26528467583c2704e7a9691ea56939a029015f0ade0aGabor Greif} 2653b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 2654319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setCFConstantStringType(QualType T) { 26556217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 2656319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid CFConstantStringType"); 2657319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor CFConstantStringTypeDecl = Rec->getDecl(); 2658319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 2659319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 26601eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getObjCFastEnumerationStateType() { 2661bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson if (!ObjCFastEnumerationStateTypeDecl) { 266244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCFastEnumerationStateTypeDecl = 266344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor RecordDecl::Create(*this, TagDecl::TK_struct, TUDecl, SourceLocation(), 266444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor &Idents.get("__objcFastEnumerationState")); 26651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2666bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson QualType FieldTypes[] = { 2667bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson UnsignedLongTy, 2668de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff getPointerType(ObjCIdTypedefType), 2669bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson getPointerType(UnsignedLongTy), 2670bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson getConstantArrayType(UnsignedLongTy, 2671bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson llvm::APInt(32, 5), ArrayType::Normal, 0) 2672bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson }; 26731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 267444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (size_t i = 0; i < 4; ++i) { 26751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldDecl *Field = FieldDecl::Create(*this, 26761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCFastEnumerationStateTypeDecl, 26771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation(), 0, 2678a1d5662d96465f0fddf8819d245da4d19b892effArgyrios Kyrtzidis FieldTypes[i], /*DInfo=*/0, 26791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /*BitWidth=*/0, 26804afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /*Mutable=*/false); 268117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis ObjCFastEnumerationStateTypeDecl->addDecl(Field); 268244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 26831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 268444b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor ObjCFastEnumerationStateTypeDecl->completeDefinition(*this); 2685bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson } 26861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2687bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson return getTagDeclType(ObjCFastEnumerationStateTypeDecl); 2688bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson} 2689bd4c1ada2e8668f43a865dc2c662085cf61940c4Anders Carlsson 2690319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setObjCFastEnumerationStateType(QualType T) { 26916217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 2692319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid ObjCFAstEnumerationStateType"); 2693319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor ObjCFastEnumerationStateTypeDecl = Rec->getDecl(); 2694319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 2695319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 2696e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// This returns true if a type has been typedefed to BOOL: 2697e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// typedef <type> BOOL; 26982d99833e8c956775f2183601cd120b65b569c867Chris Lattnerstatic bool isTypeTypedefedAsBOOL(QualType T) { 2699e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (const TypedefType *TT = dyn_cast<TypedefType>(T)) 2700bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) 2701bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner return II->isStr("BOOL"); 27021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 270385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return false; 270485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 270585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 2706a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingTypeSize returns size of type for objective-c encoding 270733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// purpose. 2708a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekint ASTContext::getObjCEncodingTypeSize(QualType type) { 270998be4943e8dc4f3905629a7102668960873cf863Chris Lattner uint64_t sz = getTypeSize(type); 27101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 271133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Make all integer and enum types at least as large as an int 271233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian if (sz > 0 && type->isIntegralType()) 271398be4943e8dc4f3905629a7102668960873cf863Chris Lattner sz = std::max(sz, getTypeSize(IntTy)); 271433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Treat arrays as pointers, since that's how they're passed in. 271533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian else if (type->isArrayType()) 271698be4943e8dc4f3905629a7102668960873cf863Chris Lattner sz = getTypeSize(VoidPtrTy); 271798be4943e8dc4f3905629a7102668960873cf863Chris Lattner return sz / getTypeSize(CharTy); 271833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 271933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 2720a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingForMethodDecl - Return the encoded type for this method 272133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// declaration. 27221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, 2723e6db3b09a79d4affaa5c7becbfb6bba3c08430c1Chris Lattner std::string& S) { 2724c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 2725ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian // Encode type qualifer, 'in', 'inout', etc. for the return type. 2726a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek getObjCEncodingForTypeQualifier(Decl->getObjCDeclQualifier(), S); 272733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Encode result type. 27280d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar getObjCEncodingForType(Decl->getResultType(), S); 272933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Compute size of all parameters. 273033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Start with computing size of a pointer in number of bytes. 273133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // FIXME: There might(should) be a better way of doing this computation! 273233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian SourceLocation Loc; 273398be4943e8dc4f3905629a7102668960873cf863Chris Lattner int PtrSize = getTypeSize(VoidPtrTy) / getTypeSize(CharTy); 273433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // The first two arguments (self and _cmd) are pointers; account for 273533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // their size. 273633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian int ParmOffset = 2 * PtrSize; 273789951a86b594513c2a013532ed45d197413b1087Chris Lattner for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(), 273889951a86b594513c2a013532ed45d197413b1087Chris Lattner E = Decl->param_end(); PI != E; ++PI) { 273989951a86b594513c2a013532ed45d197413b1087Chris Lattner QualType PType = (*PI)->getType(); 274089951a86b594513c2a013532ed45d197413b1087Chris Lattner int sz = getObjCEncodingTypeSize(PType); 2741a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek assert (sz > 0 && "getObjCEncodingForMethodDecl - Incomplete param type"); 274233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset += sz; 274333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 274433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += llvm::utostr(ParmOffset); 274533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += "@0:"; 274633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += llvm::utostr(PtrSize); 27471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 274833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Argument types. 274933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset = 2 * PtrSize; 275089951a86b594513c2a013532ed45d197413b1087Chris Lattner for (ObjCMethodDecl::param_iterator PI = Decl->param_begin(), 275189951a86b594513c2a013532ed45d197413b1087Chris Lattner E = Decl->param_end(); PI != E; ++PI) { 275289951a86b594513c2a013532ed45d197413b1087Chris Lattner ParmVarDecl *PVDecl = *PI; 27531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType PType = PVDecl->getOriginalType(); 27544306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian if (const ArrayType *AT = 2755ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 2756ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // Use array's original type only if it has known number of 2757ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // elements. 2758bb3fde337fb712c0e6da8790d431621be4793048Steve Naroff if (!isa<ConstantArrayType>(AT)) 2759ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 2760ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff } else if (PType->isFunctionType()) 2761ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 2762ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian // Process argument qualifiers for user supplied arguments; such as, 276333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // 'in', 'inout', etc. 27644306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian getObjCEncodingForTypeQualifier(PVDecl->getObjCDeclQualifier(), S); 27650d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar getObjCEncodingForType(PType, S); 276633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += llvm::utostr(ParmOffset); 2767a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ParmOffset += getObjCEncodingTypeSize(PType); 276833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 276933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 277033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 2771c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// getObjCEncodingForPropertyDecl - Return the encoded type for this 277283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// property declaration. If non-NULL, Container must be either an 2773c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be 2774c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// NULL when getting encodings for protocol properties. 27751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Property attributes are stored as a comma-delimited C string. The simple 27761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// attributes readonly and bycopy are encoded as single characters. The 27771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parametrized attributes, getter=name, setter=name, and ivar=name, are 27781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// encoded as single characters, followed by an identifier. Property types 27791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// are also encoded as a parametrized attribute. The characters used to encode 278083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// these attributes are defined by the following enumeration: 278183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @code 278283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// enum PropertyAttributes { 278383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyReadOnly = 'R', // property is read-only. 278483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyBycopy = 'C', // property is a copy of the value last assigned 278583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyByref = '&', // property is a reference to the value last assigned 278683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyDynamic = 'D', // property is dynamic 278783bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyGetter = 'G', // followed by getter selector name 278883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertySetter = 'S', // followed by setter selector name 278983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyInstanceVariable = 'V' // followed by instance variable name 279083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyType = 't' // followed by old-style type encoding. 279183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyWeak = 'W' // 'weak' property 279283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyStrong = 'P' // property GC'able 279383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyNonAtomic = 'N' // property non-atomic 279483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// }; 279583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @endcode 27961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 2797c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const Decl *Container, 2798e6db3b09a79d4affaa5c7becbfb6bba3c08430c1Chris Lattner std::string& S) { 2799c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Collect information from the property implementation decl(s). 2800c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar bool Dynamic = false; 2801c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *SynthesizePID = 0; 2802c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2803c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: Duplicated code due to poor abstraction. 2804c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Container) { 28051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCCategoryImplDecl *CID = 2806c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar dyn_cast<ObjCCategoryImplDecl>(Container)) { 2807c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 280817945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = CID->propimpl_begin(), e = CID->propimpl_end(); 2809653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 2810c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *PID = *i; 2811c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 2812c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2813c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 2814c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 2815c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 2816c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2817c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2818c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2819c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 282061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 2821c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 282217945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = OID->propimpl_begin(), e = OID->propimpl_end(); 2823653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 2824c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *PID = *i; 2825c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 2826c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 2827c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 2828c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 2829c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 2830c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2831c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 28321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2833c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2834c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2835c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2836c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 2837c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S = "T"; 2838c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2839c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Encode result type. 2840090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // GCC has some special rules regarding encoding of properties which 2841090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // closely resembles encoding of ivars. 28421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PD->getType(), S, true, true, 0, 2843090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* outermost type */, 2844090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* encoding for property */); 2845c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2846c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->isReadOnly()) { 2847c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",R"; 2848c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 2849c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar switch (PD->getSetterKind()) { 2850c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Assign: break; 2851c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Copy: S += ",C"; break; 28521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case ObjCPropertyDecl::Retain: S += ",&"; break; 2853c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2854c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2855c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2856c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // It really isn't clear at all what this means, since properties 2857c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // are "dynamic by default". 2858c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Dynamic) 2859c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",D"; 2860c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2861090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic) 2862090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian S += ",N"; 28631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2864c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { 2865c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",G"; 2866077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getGetterName().getAsString(); 2867c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2868c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2869c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { 2870c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",S"; 2871077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getSetterName().getAsString(); 2872c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2873c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2874c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (SynthesizePID) { 2875c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); 2876c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",V"; 287739f34e97d6a468f0a7dfa5664c61217cffc65b74Chris Lattner S += OID->getNameAsString(); 2878c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 2879c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2880c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: OBJCGC: weak & strong 2881c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar} 2882c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 2883a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// getLegacyIntegralTypeEncoding - 28841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Another legacy compatibility encoding: 32-bit longs are encoded as 28851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 'l' or 'L' , but not always. For typedefs, we need to use 2886a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 'i' or 'I' instead if encoding a struct field, or a pointer! 2887a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 2888a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanianvoid ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { 28898e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(PointeeTy.getTypePtr())) { 2890183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = PointeeTy->getAs<BuiltinType>()) { 2891c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian if (BT->getKind() == BuiltinType::ULong && 2892c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian ((const_cast<ASTContext *>(this))->getIntWidth(PointeeTy) == 32)) 2893a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = UnsignedIntTy; 28941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else 2895c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian if (BT->getKind() == BuiltinType::Long && 2896c657eba43f0159bd81227fa0812b92a0b03f00d0Fariborz Jahanian ((const_cast<ASTContext *>(this))->getIntWidth(PointeeTy) == 32)) 2897a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = IntTy; 2898a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2899a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2900a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian} 2901a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 29027d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanianvoid ASTContext::getObjCEncodingForType(QualType T, std::string& S, 2903153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *Field) { 290482a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // We follow the behavior of gcc, expanding structures which are 290582a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // directly pointed to, and expanding embedded structures. Note that 290682a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // these rules are sufficient to prevent recursive encoding of the 290782a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // same type. 29081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(T, S, true, true, Field, 29095b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09Fariborz Jahanian true /* outermost type */); 291082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar} 291182a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar 29121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic void EncodeBitField(const ASTContext *Context, std::string& S, 2913153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD) { 29148b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian const Expr *E = FD->getBitWidth(); 29158b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian assert(E && "bitfield width not there - getObjCEncodingForTypeImpl"); 29168b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian ASTContext *Ctx = const_cast<ASTContext*>(Context); 29179a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman unsigned N = E->EvaluateAsInt(*Ctx).getZExtValue(); 29188b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'b'; 29198b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += llvm::utostr(N); 29208b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian} 29218b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian 292282a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbarvoid ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, 292382a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandPointedToStructures, 292482a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandStructures, 2925153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD, 2926090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian bool OutermostType, 29276ab3524f72a6e64aa04973fa9433b5559abb3525Douglas Gregor bool EncodingProperty) { 2928183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = T->getAs<BuiltinType>()) { 2929ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD && FD->isBitField()) 2930ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return EncodeBitField(this, S, FD); 2931ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner char encoding; 2932ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner switch (BT->getKind()) { 29331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: assert(0 && "Unhandled builtin type kind"); 2934ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Void: encoding = 'v'; break; 2935ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Bool: encoding = 'B'; break; 2936ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Char_U: 2937ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UChar: encoding = 'C'; break; 2938ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UShort: encoding = 'S'; break; 2939ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UInt: encoding = 'I'; break; 29401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case BuiltinType::ULong: 29411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump encoding = 29421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (const_cast<ASTContext *>(this))->getIntWidth(T) == 32 ? 'L' : 'Q'; 294372696e17f90d399448d360cb43aebe5eb2007d4fFariborz Jahanian break; 2944ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::UInt128: encoding = 'T'; break; 2945ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::ULongLong: encoding = 'Q'; break; 2946ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Char_S: 2947ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::SChar: encoding = 'c'; break; 2948ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Short: encoding = 's'; break; 2949ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Int: encoding = 'i'; break; 29501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case BuiltinType::Long: 29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump encoding = 29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (const_cast<ASTContext *>(this))->getIntWidth(T) == 32 ? 'l' : 'q'; 2953ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner break; 2954ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::LongLong: encoding = 'q'; break; 2955ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Int128: encoding = 't'; break; 2956ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Float: encoding = 'f'; break; 2957ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::Double: encoding = 'd'; break; 2958ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner case BuiltinType::LongDouble: encoding = 'd'; break; 295943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 29601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2961ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += encoding; 2962ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 2963ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 29641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2965183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) { 2966c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson S += 'j'; 29671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, 0, false, 2968c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson false); 2969ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 2970ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 29711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 29726217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = T->getAs<PointerType>()) { 297385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson QualType PointeeTy = PT->getPointeeType(); 2974a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian bool isReadOnly = false; 2975a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // For historical/compatibility reasons, the read-only qualifier of the 2976a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // pointee gets emitted _before_ the '^'. The read-only qualifier of 2977a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // the pointer itself gets ignored, _unless_ we are looking at a typedef! 29781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Also, do not emit the 'r' for anything but the outermost type! 29798e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(T.getTypePtr())) { 2980a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (OutermostType && T.isConstQualified()) { 2981a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 2982a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 2983a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 29849fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (OutermostType) { 2985a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType P = PointeeTy; 29866217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek while (P->getAs<PointerType>()) 29876217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek P = P->getAs<PointerType>()->getPointeeType(); 2988a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (P.isConstQualified()) { 2989a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 2990a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 2991a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2992a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 2993a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (isReadOnly) { 2994a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Another legacy compatibility encoding. Some ObjC qualifier and type 2995a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // combinations need to be rearranged. 2996a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Rewrite "in const" from "nr" to "rn" 2997a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian const char * s = S.c_str(); 2998a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian int len = S.length(); 2999a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (len >= 2 && s[len-2] == 'n' && s[len-1] == 'r') { 3000a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian std::string replace = "rn"; 3001a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S.replace(S.end()-2, S.end(), replace); 3002a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 3003a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 300414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (isObjCSelType(PointeeTy)) { 30058baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson S += ':'; 30068baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson return; 3007c2939bc82ce177c0413feb0cd9ce70aefd6235fbFariborz Jahanian } 30081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 300985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson if (PointeeTy->isCharType()) { 301085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // char pointer types should be encoded as '*' unless it is a 301185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // type that has been typedef'd to 'BOOL'. 3012e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (!isTypeTypedefedAsBOOL(PointeeTy)) { 301385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '*'; 301485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return; 301585f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 30166217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek } else if (const RecordType *RTy = PointeeTy->getAs<RecordType>()) { 30179533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_class *" to "#". 30189533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { 30199533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '#'; 30209533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 30219533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 30229533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_object *" to "@". 30239533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_object")) { 30249533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '@'; 30259533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 30269533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 30279533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // fall through... 302885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 302985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '^'; 3030a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(PointeeTy); 3031a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 30321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, false, ExpandPointedToStructures, 303343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian NULL); 3034ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3035ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 30361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3037ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ArrayType *AT = 3038ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Ignore type qualifiers etc. 3039ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { 3040559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson if (isa<IncompleteArrayType>(AT)) { 3041559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson // Incomplete arrays are encoded as a pointer to the array element. 3042559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '^'; 3043559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson 30441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 3045559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 3046559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } else { 3047559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '['; 30481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3049559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) 3050559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += llvm::utostr(CAT->getSize().getZExtValue()); 3051559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson else { 3052559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson //Variable length arrays are encoded as a regular array with 0 elements. 3053559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson assert(isa<VariableArrayType>(AT) && "Unknown array type!"); 3054559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '0'; 3055559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 30561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 3058559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 3059559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += ']'; 3060559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 3061ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3062ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 30631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3064183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (T->getAs<FunctionType>()) { 3065c0a87b7db06643178ad2cbce0767548c139ea387Anders Carlsson S += '?'; 3066ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3067ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 30681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 30696217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RTy = T->getAs<RecordType>()) { 307082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar RecordDecl *RDecl = RTy->getDecl(); 3071d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? '(' : '{'; 3072502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar // Anonymous structures print as '?' 3073502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar if (const IdentifierInfo *II = RDecl->getIdentifier()) { 3074502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += II->getName(); 3075502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } else { 3076502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += '?'; 3077502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } 30780d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar if (ExpandStructures) { 30797d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian S += '='; 308017945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 308117945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 308244b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor Field != FieldEnd; ++Field) { 308343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian if (FD) { 3084d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += '"'; 308544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor S += Field->getNameAsString(); 3086d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += '"'; 3087d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 30881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3089d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar // Special case bit-fields. 309043822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian if (Field->isBitField()) { 30911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(Field->getType(), S, false, true, 309243822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian (*Field)); 3093d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } else { 3094a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType qt = Field->getType(); 3095a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(qt); 30961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(qt, S, false, true, 309743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian FD); 3098d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 30997d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian } 31006de88a873a4cbe06d72602eef57d68006730a80bFariborz Jahanian } 3101d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? ')' : '}'; 3102ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3103ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3105ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (T->isEnumeralType()) { 31068b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian if (FD && FD->isBitField()) 31078b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian EncodeBitField(this, S, FD); 31088b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian else 31098b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'i'; 3110ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3111ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3113ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (T->isBlockPointerType()) { 311421a98b188857d690aa4510c52ac4317ffa0908a8Steve Naroff S += "@?"; // Unlike a pointer-to-function, which is "^?". 3115ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3116ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 31180953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) { 311943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian // @encode(class_name) 31200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ObjCInterfaceDecl *OI = OIT->getDecl(); 312143822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '{'; 312243822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian const IdentifierInfo *II = OI->getIdentifier(); 312343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += II->getName(); 312443822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '='; 3125f1690858344968358131f8d5690d9ee458883000Chris Lattner llvm::SmallVector<FieldDecl*, 32> RecFields; 312643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian CollectObjCIvars(OI, RecFields); 3127f1690858344968358131f8d5690d9ee458883000Chris Lattner for (unsigned i = 0, e = RecFields.size(); i != e; ++i) { 312843822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian if (RecFields[i]->isBitField()) 31291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true, 313043822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian RecFields[i]); 313143822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian else 31321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(RecFields[i]->getType(), S, false, true, 313343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian FD); 313443822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 313543822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '}'; 3136ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 313743822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 31381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3139183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) { 314014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->isObjCIdType()) { 314114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '@'; 314214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 3143ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3145ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCClassType()) { 314614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '#'; 314714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 3148ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3150ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCQualifiedIdType()) { 31511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(getObjCIdType(), S, 315214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandPointedToStructures, 315314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandStructures, FD); 315414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (FD || EncodingProperty) { 315514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Note that we do extended encoding of protocol qualifer list 315614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Only when doing ivar or property encoding. 315714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 315867ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 315967ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 316014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '<'; 316114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += (*I)->getNameAsString(); 316214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '>'; 316314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 316414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 316514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 316614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 3167ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3169ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner QualType PointeeTy = OPT->getPointeeType(); 3170ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (!EncodingProperty && 3171ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner isa<TypedefType>(PointeeTy.getTypePtr())) { 3172ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Another historical/compatibility reason. 31731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // We encode the underlying type which comes out as 3174ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // {...}; 3175ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '^'; 31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, 31771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump false, ExpandPointedToStructures, 3178ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner NULL); 317914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 318014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 3181ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 3182ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '@'; 3183ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD || EncodingProperty) { 3184ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 318567ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff S += OPT->getInterfaceDecl()->getNameAsCString(); 318667ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 318767ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 3188ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '<'; 3189ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += (*I)->getNameAsString(); 3190ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '>'; 31911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 3192ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 3193ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 3194ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 3195ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 31961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3197ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner assert(0 && "@encode for type not implemented!"); 319885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 319985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 3201ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian std::string& S) const { 3202ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_In) 3203ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'n'; 3204ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Inout) 3205ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'N'; 3206ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Out) 3207ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'o'; 3208ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Bycopy) 3209ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'O'; 3210ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Byref) 3211ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'R'; 3212ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Oneway) 3213ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'V'; 3214ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian} 3215ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian 3216ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setBuiltinVaListType(QualType T) { 3217b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson assert(BuiltinVaListType.isNull() && "__builtin_va_list type already set!"); 32181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3219b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson BuiltinVaListType = T; 3220b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson} 3221b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 3222ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCIdType(QualType T) { 3223de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCIdTypedefType = T; 32247e219e47de26346885d667131977bd9ca2d7662aSteve Naroff} 32257e219e47de26346885d667131977bd9ca2d7662aSteve Naroff 3226ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCSelType(QualType T) { 3227319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor ObjCSelType = T; 3228319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 3229183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const TypedefType *TT = T->getAs<TypedefType>(); 3230319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor if (!TT) 3231319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor return; 3232319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor TypedefDecl *TD = TT->getDecl(); 3233b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 3234b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian // typedef struct objc_selector *SEL; 32356217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const PointerType *ptr = TD->getUnderlyingType()->getAs<PointerType>(); 3236c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian if (!ptr) 3237c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian return; 3238b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian const RecordType *rec = ptr->getPointeeType()->getAsStructureType(); 3239c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian if (!rec) 3240c55a24095c3488fa6e99b537be64e57a2905477bFariborz Jahanian return; 3241b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian SelStructType = rec; 3242b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian} 3243b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 3244ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCProtoType(QualType QT) { 3245a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCProtoType = QT; 3246390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian} 3247390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 3248ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattnervoid ASTContext::setObjCClassType(QualType T) { 3249de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff ObjCClassTypedefType = T; 32508baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson} 32518baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson 3252a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { 32531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(ObjCConstantStringType.isNull() && 32542198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff "'NSConstantString' type already set!"); 32551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3256a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = getObjCInterfaceType(Decl); 32572198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff} 32582198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff 32597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a qualified 32607532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c std::vector. 32611eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 32627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor bool TemplateKeyword, 32637532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateDecl *Template) { 32647532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 32657532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 32667532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32677532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 32687532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateName *QTN = 32697532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 32707532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (!QTN) { 32717532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) QualifiedTemplateName(NNS, TemplateKeyword, Template); 32727532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 32737532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 32747532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 32757532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 32767532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 32777532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 3278d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// \brief Retrieve the template name that represents a qualified 3279d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// template name such as \c std::vector. 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName ASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 3281d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor bool TemplateKeyword, 3282d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor OverloadedFunctionDecl *Template) { 3283d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor llvm::FoldingSetNodeID ID; 3284d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 32851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3286d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor void *InsertPos = 0; 3287d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName *QTN = 3288d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 3289d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor if (!QTN) { 3290d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QTN = new (*this,4) QualifiedTemplateName(NNS, TemplateKeyword, Template); 3291d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 3292d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor } 32931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3294d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor return TemplateName(QTN); 3295d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor} 3296d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 32977532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a dependent 32987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c MetaFun::template apply. 32991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName ASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 33007532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const IdentifierInfo *Name) { 33011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!NNS || NNS->isDependent()) && 33023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor "Nested name specifier must be dependent"); 33037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 33047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 33057532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName::Profile(ID, NNS, Name); 33067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 33077532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 33087532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName *QTN = 33097532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 33107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 33117532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (QTN) 33127532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 33137532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 33147532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 33157532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (CanonNNS == NNS) { 33167532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Name); 33177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } else { 33187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Name); 33197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor QTN = new (*this,4) DependentTemplateName(NNS, Name, Canon); 33207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 33217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 33227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 33237532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 33247532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 33257532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 3326b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor/// getFromTargetType - Given one of the integer types provided by 3327d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// TargetInfo, produce the corresponding type. The unsigned @p Type 3328d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// is actually a value of type @c TargetInfo::IntType. 3329d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas GregorQualType ASTContext::getFromTargetType(unsigned Type) const { 3330b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor switch (Type) { 33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case TargetInfo::NoInt: return QualType(); 3332b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedShort: return ShortTy; 3333b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedShort: return UnsignedShortTy; 3334b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedInt: return IntTy; 3335b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedInt: return UnsignedIntTy; 3336b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLong: return LongTy; 3337b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLong: return UnsignedLongTy; 3338b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLongLong: return LongLongTy; 3339b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; 3340b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor } 3341b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor 3342b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor assert(false && "Unhandled TargetInfo::IntType value"); 3343b3ac5434ab936f092b8cc48349cb01db3a1e1c76Daniel Dunbar return QualType(); 3344b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor} 3345b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 3346b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 3347b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek// Type Predicates. 3348b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 3349b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 3350fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// isObjCNSObjectType - Return true if this is an NSObject object using 3351fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// NSObject attribute on a c-style pointer type. 3352fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// FIXME - Make it work directly on types. 3353f49545602089be5b1f744e04326b8a566f6d8773Steve Naroff/// FIXME: Move to Type. 3354fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian/// 3355fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanianbool ASTContext::isObjCNSObjectType(QualType Ty) const { 3356fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian if (TypedefType *TDT = dyn_cast<TypedefType>(Ty)) { 3357fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian if (TypedefDecl *TD = TDT->getDecl()) 335840b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (TD->getAttr<ObjCNSObjectAttr>()) 3359fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian return true; 3360fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian } 33611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return false; 3362fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian} 3363fa23c1d9adc99c662c1c0e192817185809d95614Fariborz Jahanian 33644fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 33654fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// garbage collection attribute. 33664fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// 33670953e767ff7817f97b3ab20896b229891eeff45bJohn McCallQualifiers::GC ASTContext::getObjCGCAttrKind(const QualType &Ty) const { 33680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GCAttrs = Qualifiers::GCNone; 33694fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian if (getLangOptions().ObjC1 && 33704fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian getLangOptions().getGCMode() != LangOptions::NonGC) { 3371b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner GCAttrs = Ty.getObjCGCAttr(); 33724fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian // Default behavious under objective-c's gc is for objective-c pointers 33731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // (or pointers to them) be treated as though they were declared 3374a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian // as __strong. 33750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GCAttrs == Qualifiers::GCNone) { 337675212ee91313bc1b6dd826d9b173541bc4016539Fariborz Jahanian if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) 33770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall GCAttrs = Qualifiers::Strong; 3378a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian else if (Ty->isPointerType()) 33796217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getObjCGCAttrKind(Ty->getAs<PointerType>()->getPointeeType()); 3380a223cca7751637f8ec1a860010c4148757fb4752Fariborz Jahanian } 3381c2112181b96349eb595dc5e8b7073b81ecdec0dbFariborz Jahanian // Non-pointers have none gc'able attribute regardless of the attribute 3382c2112181b96349eb595dc5e8b7073b81ecdec0dbFariborz Jahanian // set on them. 3383f49545602089be5b1f744e04326b8a566f6d8773Steve Naroff else if (!Ty->isAnyPointerType() && !Ty->isBlockPointerType()) 33840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return Qualifiers::GCNone; 33854fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian } 3386b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return GCAttrs; 33874fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian} 33884fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian 33896ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 33906ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner// Type Compatibility Testing 33916ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 3392770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner 33931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// areCompatVectorTypes - Return true if the two specified vector types are 33946ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner/// compatible. 33956ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattnerstatic bool areCompatVectorTypes(const VectorType *LHS, 33966ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner const VectorType *RHS) { 33976ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner assert(LHS->isCanonical() && RHS->isCanonical()); 33986ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return LHS->getElementType() == RHS->getElementType() && 339961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner LHS->getNumElements() == RHS->getNumElements(); 34006ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 34016ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 34024084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 34034084c306635b70f37029dca938444e6013f08684Steve Naroff// ObjCQualifiedIdTypesAreCompatible - Compatibility testing for qualified id's. 34044084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 34054084c306635b70f37029dca938444e6013f08684Steve Naroff 34064084c306635b70f37029dca938444e6013f08684Steve Naroff/// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the 34074084c306635b70f37029dca938444e6013f08684Steve Naroff/// inheritance hierarchy of 'rProto'. 34080fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanianbool ASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 34090fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian ObjCProtocolDecl *rProto) { 34104084c306635b70f37029dca938444e6013f08684Steve Naroff if (lProto == rProto) 341114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return true; 34124084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(), 34134084c306635b70f37029dca938444e6013f08684Steve Naroff E = rProto->protocol_end(); PI != E; ++PI) 34144084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lProto, *PI)) 34154084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 34164084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 34174084c306635b70f37029dca938444e6013f08684Steve Naroff} 341814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 34194084c306635b70f37029dca938444e6013f08684Steve Naroff/// QualifiedIdConformsQualifiedId - compare id<p,...> with id<p1,...> 34204084c306635b70f37029dca938444e6013f08684Steve Naroff/// return true if lhs's protocols conform to rhs's protocol; false 34214084c306635b70f37029dca938444e6013f08684Steve Naroff/// otherwise. 34224084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) { 34234084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType()) 34244084c306635b70f37029dca938444e6013f08684Steve Naroff return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false); 34254084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 34264084c306635b70f37029dca938444e6013f08684Steve Naroff} 34274084c306635b70f37029dca938444e6013f08684Steve Naroff 34284084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an 34294084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIDType. 34304084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, 34314084c306635b70f37029dca938444e6013f08684Steve Naroff bool compare) { 34324084c306635b70f37029dca938444e6013f08684Steve Naroff // Allow id<P..> and an 'id' or void* type in all cases. 34331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (lhs->isVoidPointerType() || 34344084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->isObjCIdType() || lhs->isObjCClassType()) 34354084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 34361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else if (rhs->isVoidPointerType() || 34374084c306635b70f37029dca938444e6013f08684Steve Naroff rhs->isObjCIdType() || rhs->isObjCClassType()) 34384084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 34394084c306635b70f37029dca938444e6013f08684Steve Naroff 34404084c306635b70f37029dca938444e6013f08684Steve Naroff if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { 3441183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 34421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34434084c306635b70f37029dca938444e6013f08684Steve Naroff if (!rhsOPT) return false; 34441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 34454084c306635b70f37029dca938444e6013f08684Steve Naroff if (rhsOPT->qual_empty()) { 34461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a unqualified interface pointer "NSString*", 34474084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 34484084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 34494084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 34504084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 34514084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 34524084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 34534084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 34540fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (!rhsID->ClassImplementsProtocol(*I, true)) 34554084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 34564084c306635b70f37029dca938444e6013f08684Steve Naroff } 34574084c306635b70f37029dca938444e6013f08684Steve Naroff } 34584084c306635b70f37029dca938444e6013f08684Steve Naroff // If there are no qualifiers and no interface, we have an 'id'. 34594084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 34604084c306635b70f37029dca938444e6013f08684Steve Naroff } 34611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Both the right and left sides have qualifiers. 34624084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 34634084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 34644084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 34654084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 3466de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff 3467de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // when comparing an id<P> on lhs with a static type on rhs, 3468de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // see if static class implements all of id's protocols, directly or 3469de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // through its super class and categories. 34704084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 34714084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsOPT->qual_end(); J != E; ++J) { 34724084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 34734084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 34744084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 34754084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 34768f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 34778f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 3478de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 34791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a qualified interface pointer "NSString<P>*", 34804084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 34814084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 34824084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 34834084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 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. 34870fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (rhsID->ClassImplementsProtocol(*I, true)) { 34884084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 34894084c306635b70f37029dca938444e6013f08684Steve Naroff break; 34904084c306635b70f37029dca938444e6013f08684Steve Naroff } 34914084c306635b70f37029dca938444e6013f08684Steve Naroff } 34924084c306635b70f37029dca938444e6013f08684Steve Naroff } 34934084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 3494de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return false; 3495de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 34961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3497de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return true; 3498de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 34991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35004084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType(); 35014084c306635b70f37029dca938444e6013f08684Steve Naroff assert(rhsQID && "One of the LHS/RHS should be id<x>"); 35024084c306635b70f37029dca938444e6013f08684Steve Naroff 35031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCObjectPointerType *lhsOPT = 35044084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->getAsObjCInterfacePointerType()) { 35054084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhsOPT->qual_empty()) { 35064084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 35074084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { 35084084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = rhsQID->qual_begin(), 35094084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); I != E; ++I) { 35104084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 35114084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 35124084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 35130fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (lhsID->ClassImplementsProtocol(*I, true)) { 35144084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 35154084c306635b70f37029dca938444e6013f08684Steve Naroff break; 35164084c306635b70f37029dca938444e6013f08684Steve Naroff } 35174084c306635b70f37029dca938444e6013f08684Steve Naroff } 35184084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 35194084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 35204084c306635b70f37029dca938444e6013f08684Steve Naroff } 35214084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 35224084c306635b70f37029dca938444e6013f08684Steve Naroff } 35231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Both the right and left sides have qualifiers. 35244084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsOPT->qual_begin(), 35254084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsOPT->qual_end(); I != E; ++I) { 35264084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 35274084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 35284084c306635b70f37029dca938444e6013f08684Steve Naroff 35294084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 35304084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 35314084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 35324084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 35334084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); J != E; ++J) { 35344084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 35354084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 35364084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 35374084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 35384084c306635b70f37029dca938444e6013f08684Steve Naroff break; 35394084c306635b70f37029dca938444e6013f08684Steve Naroff } 35404084c306635b70f37029dca938444e6013f08684Steve Naroff } 35414084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 35424084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 35434084c306635b70f37029dca938444e6013f08684Steve Naroff } 35444084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 35454084c306635b70f37029dca938444e6013f08684Steve Naroff } 35464084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 35474084c306635b70f37029dca938444e6013f08684Steve Naroff} 35484084c306635b70f37029dca938444e6013f08684Steve Naroff 35494084c306635b70f37029dca938444e6013f08684Steve Naroff/// canAssignObjCInterfaces - Return true if the two interface types are 35504084c306635b70f37029dca938444e6013f08684Steve Naroff/// compatible for assignment from RHS to LHS. This handles validation of any 35514084c306635b70f37029dca938444e6013f08684Steve Naroff/// protocol qualifiers on the LHS or RHS. 35524084c306635b70f37029dca938444e6013f08684Steve Naroff/// 35534084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 35544084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *RHSOPT) { 35554084c306635b70f37029dca938444e6013f08684Steve Naroff // If either type represents the built-in 'id' or 'Class' types, return true. 35564084c306635b70f37029dca938444e6013f08684Steve Naroff if (LHSOPT->isObjCBuiltinType() || RHSOPT->isObjCBuiltinType()) 35574084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 35584084c306635b70f37029dca938444e6013f08684Steve Naroff 35594084c306635b70f37029dca938444e6013f08684Steve Naroff if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) 35601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 35611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType(RHSOPT,0), 35624084c306635b70f37029dca938444e6013f08684Steve Naroff false); 35634084c306635b70f37029dca938444e6013f08684Steve Naroff 35644084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); 35654084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); 35664084c306635b70f37029dca938444e6013f08684Steve Naroff if (LHS && RHS) // We have 2 user-defined types. 35674084c306635b70f37029dca938444e6013f08684Steve Naroff return canAssignObjCInterfaces(LHS, RHS); 35681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35694084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 357014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 357114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 35723d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedmanbool ASTContext::canAssignObjCInterfaces(const ObjCInterfaceType *LHS, 35733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ObjCInterfaceType *RHS) { 35746ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Verify that the base decls are compatible: the RHS must be a subclass of 35756ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // the LHS. 35766ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner if (!LHS->getDecl()->isSuperClassOf(RHS->getDecl())) 35776ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return false; 35781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35796ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // RHS must have a superset of the protocols in the LHS. If the LHS is not 35806ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // protocol qualified at all, then we are good. 3581c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (LHS->getNumProtocols() == 0) 35826ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; 35831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35846ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Okay, we know the LHS has protocol qualifiers. If the RHS doesn't, then it 35856ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // isn't a superset. 3586c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (RHS->getNumProtocols() == 0) 35876ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; // FIXME: should return false! 35881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3589c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (ObjCInterfaceType::qual_iterator LHSPI = LHS->qual_begin(), 3590c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff LHSPE = LHS->qual_end(); 359191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff LHSPI != LHSPE; LHSPI++) { 359291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff bool RHSImplementsProtocol = false; 359391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff 359491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // If the RHS doesn't implement the protocol on the left, the types 359591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // are incompatible. 3596c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff for (ObjCInterfaceType::qual_iterator RHSPI = RHS->qual_begin(), 35974084c306635b70f37029dca938444e6013f08684Steve Naroff RHSPE = RHS->qual_end(); 35988f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff RHSPI != RHSPE; RHSPI++) { 35998f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff if ((*RHSPI)->lookupProtocolNamed((*LHSPI)->getIdentifier())) { 360091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff RHSImplementsProtocol = true; 36018f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 36028f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 360391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 360491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // FIXME: For better diagnostics, consider passing back the protocol name. 360591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff if (!RHSImplementsProtocol) 360691b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return false; 360791b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 360891b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // The RHS implements all protocols listed on the LHS. 360991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return true; 36106ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 36116ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 3612389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroffbool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { 3613389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff // get the "pointed to" types 3614183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *LHSOPT = LHS->getAs<ObjCObjectPointerType>(); 3615183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *RHSOPT = RHS->getAs<ObjCObjectPointerType>(); 36161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 361714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (!LHSOPT || !RHSOPT) 3618389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff return false; 361914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 362014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return canAssignObjCInterfaces(LHSOPT, RHSOPT) || 362114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff canAssignObjCInterfaces(RHSOPT, LHSOPT); 3622389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff} 3623389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff 36241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, 3625ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// both shall have the identically qualified version of a compatible type. 36261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C99 6.2.7p1: Two types have compatible types if their types are the 3627ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// same. See 6.7.[2,3,5] for additional rules. 36283d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedmanbool ASTContext::typesAreCompatible(QualType LHS, QualType RHS) { 36293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return !mergeTypes(LHS, RHS).isNull(); 36303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 36313d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36323d815e7eb56c25d7ed812eced32e41df43039f9aEli FriedmanQualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs) { 3633183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *lbase = lhs->getAs<FunctionType>(); 3634183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *rbase = rhs->getAs<FunctionType>(); 363572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *lproto = dyn_cast<FunctionProtoType>(lbase); 363672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *rproto = dyn_cast<FunctionProtoType>(rbase); 36373d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allLTypes = true; 36383d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allRTypes = true; 36393d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check return type 36413d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType retType = mergeTypes(lbase->getResultType(), rbase->getResultType()); 36423d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (retType.isNull()) return QualType(); 364361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(retType) != getCanonicalType(lbase->getResultType())) 364461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 364561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(retType) != getCanonicalType(rbase->getResultType())) 364661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 36476dcbc294f9b2c45680dd3227e885712c2814ec0eMike Stump // FIXME: double check this 36482455636163fdd18581d7fdae816433f886d88213Mike Stump bool NoReturn = lbase->getNoReturnAttr() || rbase->getNoReturnAttr(); 36492455636163fdd18581d7fdae816433f886d88213Mike Stump if (NoReturn != lbase->getNoReturnAttr()) 36502455636163fdd18581d7fdae816433f886d88213Mike Stump allLTypes = false; 36512455636163fdd18581d7fdae816433f886d88213Mike Stump if (NoReturn != rbase->getNoReturnAttr()) 36522455636163fdd18581d7fdae816433f886d88213Mike Stump allRTypes = false; 36531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36543d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto && rproto) { // two C99 style function prototypes 3655465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && 3656465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl "C++ shouldn't be here"); 36573d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned lproto_nargs = lproto->getNumArgs(); 36583d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned rproto_nargs = rproto->getNumArgs(); 36593d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36603d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Compatible functions must have the same number of arguments 36613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto_nargs != rproto_nargs) 36623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 36633d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36643d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Variadic and non-variadic functions aren't compatible 36653d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto->isVariadic() != rproto->isVariadic()) 36663d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 36673d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36687fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis if (lproto->getTypeQuals() != rproto->getTypeQuals()) 36697fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis return QualType(); 36707fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis 36713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check argument compatibility 36723d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman llvm::SmallVector<QualType, 10> types; 36733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < lproto_nargs; i++) { 36743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType largtype = lproto->getArgType(i).getUnqualifiedType(); 36753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType rargtype = rproto->getArgType(i).getUnqualifiedType(); 36763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argtype = mergeTypes(largtype, rargtype); 36773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argtype.isNull()) return QualType(); 36783d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman types.push_back(argtype); 367961710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(largtype)) 368061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 368161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(rargtype)) 368261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 36833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 36843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 36853d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 36863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, types.begin(), types.size(), 36872455636163fdd18581d7fdae816433f886d88213Mike Stump lproto->isVariadic(), lproto->getTypeQuals(), 36882455636163fdd18581d7fdae816433f886d88213Mike Stump NoReturn); 36893d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 36903d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 36913d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto) allRTypes = false; 36923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (rproto) allLTypes = false; 36933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 369472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *proto = lproto ? lproto : rproto; 36953d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto) { 3696465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!proto->hasExceptionSpec() && "C++ shouldn't be here"); 36973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto->isVariadic()) return QualType(); 36983d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check that the types are compatible with the types that 36993d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // would result from default argument promotions (C99 6.7.5.3p15). 37003d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // The only types actually affected are promotable integer 37013d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // types and floats, which would be passed as a different 37023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // type depending on whether the prototype is visible. 37033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned proto_nargs = proto->getNumArgs(); 37043d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < proto_nargs; ++i) { 37053d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argTy = proto->getArgType(i); 37063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argTy->isPromotableIntegerType() || 37073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman getCanonicalType(argTy).getUnqualifiedType() == FloatTy) 37083d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 37093d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 37103d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37113d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 37123d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 37133d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, proto->arg_type_begin(), 37142d3c191e1d5545e1724ee6e0550c70eef54beff2Mike Stump proto->getNumArgs(), proto->isVariadic(), 37152d3c191e1d5545e1724ee6e0550c70eef54beff2Mike Stump proto->getTypeQuals(), NoReturn); 37163d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 37173d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 37193d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 37202455636163fdd18581d7fdae816433f886d88213Mike Stump return getFunctionNoProtoType(retType, NoReturn); 37213d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 37223d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37233d815e7eb56c25d7ed812eced32e41df43039f9aEli FriedmanQualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { 372443d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // C++ [expr]: If an expression initially has the type "reference to T", the 372543d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // type is adjusted to "T" prior to any further analysis, the expression 372643d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // designates the object or function denoted by the reference, and the 37277c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // expression is an lvalue unless the reference is an rvalue reference and 37287c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // the expression is a function call (possibly inside parentheses). 37293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: C++ shouldn't be going through here! The rules are different 37303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // enough that they should be handled separately. 37317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // FIXME: Merging of lvalue and rvalue references is incorrect. C++ *really* 37327c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // shouldn't be going through here! 37336217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RT = LHS->getAs<ReferenceType>()) 3734c4e405996217f4be20f73186da53b23b5c4783dcChris Lattner LHS = RT->getPointeeType(); 37356217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType *RT = RHS->getAs<ReferenceType>()) 3736c4e405996217f4be20f73186da53b23b5c4783dcChris Lattner RHS = RT->getPointeeType(); 37373d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37383d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSCan = getCanonicalType(LHS), 37393d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman RHSCan = getCanonicalType(RHS); 37403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 3741f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner // If two types are identical, they are compatible. 37423d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LHSCan == RHSCan) 37433d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 37443d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 37450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the qualifiers are different, the types aren't compatible... mostly. 37460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers LQuals = LHSCan.getQualifiers(); 37470953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers RQuals = RHSCan.getQualifiers(); 37480953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals != RQuals) { 37490953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If any of these qualifiers are different, we have a type 37500953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // mismatch. 37510953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 37520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall LQuals.getAddressSpace() != RQuals.getAddressSpace()) 37530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 37540953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 37550953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Exactly one GC qualifier difference is allowed: __strong is 37560953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // okay if the other type has no GC qualifier but is an Objective 37570953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // C object pointer (i.e. implicitly strong by default). We fix 37580953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this by pretending that the unqualified type was actually 37590953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualified __strong. 37600953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 37610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 37620953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 37630953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 37640953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 37650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 37660953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 37670953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Strong && RHSCan->isObjCObjectPointerType()) { 37680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(LHS, getObjCGCQualType(RHS, Qualifiers::Strong)); 37690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 37700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_R == Qualifiers::Strong && LHSCan->isObjCObjectPointerType()) { 37710953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(getObjCGCQualType(LHS, Qualifiers::Strong), RHS); 37720953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 37733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 37740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 37750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 37760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Okay, qualifiers are equal. 37773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 3778852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass LHSClass = LHSCan->getTypeClass(); 3779852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass RHSClass = RHSCan->getTypeClass(); 3780f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner 37811adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // We want to consider the two function types to be the same for these 37821adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // comparisons, just force one to the other. 37831adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; 37841adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; 37854c721d381fb279899337d120edd4a24d405e56b2Eli Friedman 37864c721d381fb279899337d120edd4a24d405e56b2Eli Friedman // Same as above for arrays 3787a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) 3788a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner LHSClass = Type::ConstantArray; 3789a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) 3790a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner RHSClass = Type::ConstantArray; 37911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3792213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman // Canonicalize ExtVector -> Vector. 3793213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; 3794213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; 37951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37964e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff // If the canonical type classes don't match. 37974e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff if (LHSClass != RHSClass) { 37981adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, 37991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // a signed integer type, or an unsigned integer type. 3800183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = LHS->getAs<EnumType>()) { 38013d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ETy->getDecl()->getIntegerType() == RHSCan.getUnqualifiedType()) 38023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 3803bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 3804183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = RHS->getAs<EnumType>()) { 38053d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ETy->getDecl()->getIntegerType() == LHSCan.getUnqualifiedType()) 38063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 3807bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 38081adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner 38093d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 3810ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 38113d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 38124a74678ed6c3dedac05d02b1ee341f1db869f049Steve Naroff // The canonical type classes match. 38131adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner switch (LHSClass) { 381472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 381572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 381672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 381772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 381872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 381972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor assert(false && "Non-canonical and dependent types shouldn't get here"); 382072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 382172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 38227c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 38237c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 382472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::MemberPointer: 382572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor assert(false && "C++ should never be in mergeTypes"); 382672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 382772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 382872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 382972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::VariableArray: 383072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::FunctionProto: 383172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::ExtVector: 383272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor assert(false && "Types are eliminated above"); 383372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 383472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 38351adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Pointer: 38363d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 38373d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Merge two pointer types, while trying to preserve typedef info 38386217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<PointerType>()->getPointeeType(); 38396217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<PointerType>()->getPointeeType(); 38403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType ResultType = mergeTypes(LHSPointee, RHSPointee); 38413d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 384207d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 384361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 384407d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 384561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 38463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getPointerType(ResultType); 38473d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 3848c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff case Type::BlockPointer: 3849c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff { 3850c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff // Merge two block pointer types, while trying to preserve typedef info 38516217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<BlockPointerType>()->getPointeeType(); 38526217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<BlockPointerType>()->getPointeeType(); 3853c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff QualType ResultType = mergeTypes(LHSPointee, RHSPointee); 3854c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (ResultType.isNull()) return QualType(); 3855c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 3856c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return LHS; 3857c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 3858c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return RHS; 3859c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return getBlockPointerType(ResultType); 3860c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff } 38611adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::ConstantArray: 38623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 38633d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); 38643d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); 38653d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) 38663d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 38673d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 38683d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSElem = getAsArrayType(LHS)->getElementType(); 38693d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType RHSElem = getAsArrayType(RHS)->getElementType(); 38703d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType ResultType = mergeTypes(LHSElem, RHSElem); 38713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 387261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 387361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 387461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 387561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 38763bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), 38773bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 38783bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), 38793bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 38803d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* LVAT = getAsVariableArrayType(LHS); 38813d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* RVAT = getAsVariableArrayType(RHS); 388261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 388361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 388461710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 388561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 38863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LVAT) { 38873d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 38883d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of LHS, but the type 38893d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 38903d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 38913d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 38923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (RVAT) { 38933d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 38943d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of RHS, but the type 38953d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 38963d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 38973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 38983bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; 38993bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; 39007e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return getIncompleteArrayType(ResultType, 39017e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier(), 0); 39023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 39031adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::FunctionNoProto: 39043d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return mergeFunctionTypes(LHS, RHS); 390572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 390672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: 39073d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 39081adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Builtin: 39093cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner // Only exactly equal builtin types are compatible, which is tested above. 39103d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 391164cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar case Type::Complex: 391264cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar // Distinct complex types are incompatible. 391364cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar return QualType(); 39143cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner case Type::Vector: 39155a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: The merged type should be an ExtVector! 3916183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (areCompatVectorTypes(LHS->getAs<VectorType>(), RHS->getAs<VectorType>())) 39173d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 391861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return QualType(); 391961490e9a965cfee8a78c12c6802138844f04250dCedric Venet case Type::ObjCInterface: { 39205fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff // Check if the interfaces are assignment compatible. 39215a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: This should be type compatibility, e.g. whether 39225a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // "LHS x; RHS x;" at global scope is legal. 3923183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCInterfaceType* LHSIface = LHS->getAs<ObjCInterfaceType>(); 3924183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCInterfaceType* RHSIface = RHS->getAs<ObjCInterfaceType>(); 39255fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff if (LHSIface && RHSIface && 39265fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff canAssignObjCInterfaces(LHSIface, RHSIface)) 39275fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff return LHS; 39285fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff 39293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 393061490e9a965cfee8a78c12c6802138844f04250dCedric Venet } 393114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case Type::ObjCObjectPointer: { 3932183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (canAssignObjCInterfaces(LHS->getAs<ObjCObjectPointerType>(), 3933183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall RHS->getAs<ObjCObjectPointerType>())) 393414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return LHS; 393514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 3936bc76dd06eb881c70c9775b74bab8b88cd747f173Steve Naroff return QualType(); 393714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 39385a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman case Type::FixedWidthInt: 39395a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // Distinct fixed-width integers are not compatible. 39405a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman return QualType(); 39417532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor case Type::TemplateSpecialization: 39427532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor assert(false && "Dependent types have no size"); 39437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 3944ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 394572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 394672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor return QualType(); 3947ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff} 39487192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek 39495426bf6456a5aeac416a9150de157904d101c819Chris Lattner//===----------------------------------------------------------------------===// 3950ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman// Integer Predicates 3951ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman//===----------------------------------------------------------------------===// 395288054dee0402e4d3c1f64e6b697acc47195c0d72Chris Lattner 3953ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedmanunsigned ASTContext::getIntWidth(QualType T) { 3954ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman if (T == BoolTy) 3955ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return 1; 3956f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman if (FixedWidthIntType* FWIT = dyn_cast<FixedWidthIntType>(T)) { 3957f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return FWIT->getWidth(); 3958f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman } 3959f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // For builtin types, just use the standard type sizing method 3960ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return (unsigned)getTypeSize(T); 3961ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 3962ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 3963ad74a758189180b8ab8faea648e4766c3bfd7fcbEli FriedmanQualType ASTContext::getCorrespondingUnsignedType(QualType T) { 3964ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman assert(T->isSignedIntegerType() && "Unexpected type"); 3965183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = T->getAs<EnumType>()) 3966ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman T = ETy->getDecl()->getIntegerType(); 3967183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const BuiltinType* BTy = T->getAs<BuiltinType>(); 3968ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman assert (BTy && "Unexpected signed integer type"); 3969ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman switch (BTy->getKind()) { 3970ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Char_S: 3971ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::SChar: 3972ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedCharTy; 3973ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Short: 3974ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedShortTy; 3975ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Int: 3976ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedIntTy; 3977ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Long: 3978ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongTy; 3979ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::LongLong: 3980ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongLongTy; 39812df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 39822df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return UnsignedInt128Ty; 3983ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman default: 3984ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman assert(0 && "Unexpected signed integer type"); 3985ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return QualType(); 3986ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman } 3987ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 3988ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 39892cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas GregorExternalASTSource::~ExternalASTSource() { } 39902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 39912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorvoid ExternalASTSource::PrintStats() { } 399286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 399386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 399486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 399586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner// Builtin Type Computation 399686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 399786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 399886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the 399986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// pointer over the consumed characters. This returns the resultant type. 40001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpstatic QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context, 400186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ASTContext::GetBuiltinTypeError &Error, 400286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool AllowTypeModifiers = true) { 400386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Modifiers. 400486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner int HowLong = 0; 400586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Signed = false, Unsigned = false; 40061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 400786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the modifiers first. 400886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Done = false; 400986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 401086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 40111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: Done = true; --Str; break; 401286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'S': 401386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use both 'S' and 'U' modifiers!"); 401486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use 'S' modifier multiple times!"); 401586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Signed = true; 401686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 401786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'U': 401886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use both 'S' and 'U' modifiers!"); 401986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use 'S' modifier multiple times!"); 402086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Unsigned = true; 402186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 402286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'L': 402386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong <= 2 && "Can't have LLLL modifier"); 402486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ++HowLong; 402586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 402686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 402786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 402886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 402986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Type; 40301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 403186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the base type. 403286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 403386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner default: assert(0 && "Unknown builtin type letter!"); 403486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'v': 403586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 403686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'v'!"); 403786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.VoidTy; 403886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 403986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'f': 404086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 404186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'f'!"); 404286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.FloatTy; 404386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 404486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'd': 404586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong < 2 && !Signed && !Unsigned && 404686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'd'!"); 404786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong) 404886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.LongDoubleTy; 404986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 405086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.DoubleTy; 405186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 405286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 's': 405386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 's'!"); 405486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Unsigned) 405586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedShortTy; 405686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 405786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.ShortTy; 405886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 405986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'i': 406086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong == 3) 406186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty; 406286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 2) 406386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy; 406486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 1) 406586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy; 406686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 406786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy; 406886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 406986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'c': 407086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 'c'!"); 407186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Signed) 407286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.SignedCharTy; 407386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (Unsigned) 407486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedCharTy; 407586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 407686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.CharTy; 407786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 407886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'b': // boolean 407986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!"); 408086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.BoolTy; 408186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 408286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'z': // size_t. 408386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!"); 408486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getSizeType(); 408586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 408686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'F': 408786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getCFConstantStringType(); 408886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 408986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'a': 409086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 409186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 409286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 409386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'A': 409486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // This is a "reference" to a va_list; however, what exactly 409586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // this means depends on how va_list is defined. There are two 409686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // different kinds of va_list: ones passed by value, and ones 409786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // passed by reference. An example of a by-value va_list is 409886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // x86, where va_list is a char*. An example of by-ref va_list 409986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // is x86-64, where va_list is a __va_list_tag[1]. For x86, 410086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // we want this argument to be a char*&; for x86-64, we want 410186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // it to be a __va_list_tag*. 410286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 410386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 410486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Type->isArrayType()) { 410586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getArrayDecayedType(Type); 410686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } else { 410786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 410886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 410986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 411086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'V': { 411186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner char *End; 411286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner unsigned NumElements = strtoul(Str, &End, 10); 411386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(End != Str && "Missing vector size"); 41141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 411586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Str = End; 41161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 411786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, false); 411886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getVectorType(ElementType, NumElements); 411986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 412086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 4121d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor case 'X': { 4122d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor QualType ElementType = DecodeTypeFromStr(Str, Context, Error, false); 4123d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor Type = Context.getComplexType(ElementType); 4124d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor break; 4125d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor } 41269a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'P': 4127c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor Type = Context.getFILEType(); 4128c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor if (Type.isNull()) { 4129f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_stdio; 413086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 413186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 4132fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 41339a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'J': 4134f711c41dd9412a8182793259d355c4f6979ed5edMike Stump if (Signed) 4135782fa308a765aeac2acb39c4e697c937ec21185bMike Stump Type = Context.getsigjmp_bufType(); 4136f711c41dd9412a8182793259d355c4f6979ed5edMike Stump else 4137f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Type = Context.getjmp_bufType(); 4138f711c41dd9412a8182793259d355c4f6979ed5edMike Stump 4139fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump if (Type.isNull()) { 4140f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_setjmp; 4141fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump return QualType(); 4142fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump } 4143fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 4144782fa308a765aeac2acb39c4e697c937ec21185bMike Stump } 41451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 414686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (!AllowTypeModifiers) 414786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 41481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 414986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Done = false; 415086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 415186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 415286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner default: Done = true; --Str; break; 415386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case '*': 415486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getPointerType(Type); 415586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 415686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case '&': 415786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 415886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 415986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // FIXME: There's no way to have a built-in with an rvalue ref arg. 416086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'C': 41610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Type = Type.withConst(); 416286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 416386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 416486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 41651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 416686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 416786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 416886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 416986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// GetBuiltinType - Return the type for the specified builtin. 417086df27bbdbb98c39ec2184695c0561209f91beddChris LattnerQualType ASTContext::GetBuiltinType(unsigned id, 417186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner GetBuiltinTypeError &Error) { 417286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner const char *TypeStr = BuiltinInfo.GetTypeString(id); 41731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner llvm::SmallVector<QualType, 8> ArgTypes; 41751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Error = GE_None; 417786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error); 417886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 417986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 418086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (TypeStr[0] && TypeStr[0] != '.') { 418186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error); 418286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 418386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 418486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 418586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Do array -> pointer decay. The builtin should use the decayed type. 418686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Ty->isArrayType()) 418786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Ty = getArrayDecayedType(Ty); 41881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 418986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ArgTypes.push_back(Ty); 419086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 419186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 419286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert((TypeStr[0] != '.' || TypeStr[1] == 0) && 419386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "'.' should only occur at end of builtin type list!"); 419486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 419586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // handle untyped/variadic arguments "T c99Style();" or "T cppStyle(...);". 419686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (ArgTypes.size() == 0 && TypeStr[0] == '.') 419786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return getFunctionNoProtoType(ResType); 419886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return getFunctionType(ResType, ArgTypes.data(), ArgTypes.size(), 419986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner TypeStr[0] == '.', 0); 420086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 4201a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4202a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli FriedmanQualType 4203a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli FriedmanASTContext::UsualArithmeticConversionsType(QualType lhs, QualType rhs) { 4204a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Perform the usual unary conversions. We do this early so that 4205a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // integral promotions to "int" can allow us to exit early, in the 4206a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // lhs == rhs check. Also, for conversion purposes, we ignore any 4207a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // qualifiers. For example, "const float" and "float" are 4208a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // equivalent. 4209a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isPromotableIntegerType()) 4210a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman lhs = getPromotedIntegerType(lhs); 4211a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman else 4212a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman lhs = lhs.getUnqualifiedType(); 4213a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isPromotableIntegerType()) 4214a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhs = getPromotedIntegerType(rhs); 4215a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman else 4216a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhs = rhs.getUnqualifiedType(); 4217a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4218a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // If both types are identical, no conversion is needed. 4219a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs == rhs) 4220a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 42211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4222a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // If either side is a non-arithmetic type (e.g. a pointer), we are done. 4223a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The caller can deal with this (e.g. pointer + int). 4224a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (!lhs->isArithmeticType() || !rhs->isArithmeticType()) 4225a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 42261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // At this point, we have two different arithmetic types. 42281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4229a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Handle complex types first (C99 6.3.1.8p1). 4230a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isComplexType() || rhs->isComplexType()) { 4231a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // if we have an integer operand, the result is the complex type. 42321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (rhs->isIntegerType() || rhs->isComplexIntegerType()) { 4233a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the rhs to the lhs complex type. 4234a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4235a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 42361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (lhs->isIntegerType() || lhs->isComplexIntegerType()) { 4237a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the lhs to the rhs complex type. 4238a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4239a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4240a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // This handles complex/complex, complex/float, or float/complex. 42411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // When both operands are complex, the shorter operand is converted to the 42421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // type of the longer, and that is the type of the result. This corresponds 42431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // to what is done when combining two real floating-point operands. 42441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // The fun begins when size promotion occur across type domains. 4245a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // From H&S 6.3.4: When one operand is complex and the other is a real 42461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // floating-point type, the less precise type is converted, within it's 4247a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // real or complex domain, to the precision of the other type. For example, 42481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // when combining a "long double" with a "double _Complex", the 4249a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // "double _Complex" is promoted to "long double _Complex". 4250a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman int result = getFloatingTypeOrder(lhs, rhs); 42511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (result > 0) { // The left side is bigger, convert rhs. 4253a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhs = getFloatingTypeOfSizeWithinDomain(lhs, rhs); 42541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } else if (result < 0) { // The right side is bigger, convert lhs. 4255a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman lhs = getFloatingTypeOfSizeWithinDomain(rhs, lhs); 42561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 4257a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // At this point, lhs and rhs have the same rank/size. Now, make sure the 4258a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // domains match. This is a requirement for our implementation, C99 4259a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // does not require this promotion. 4260a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs != rhs) { // Domains don't match, we have complex/float mix. 4261a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isRealFloatingType()) { // handle "double, _Complex double". 4262a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4263a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else { // handle "_Complex double, double". 4264a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4265a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4266a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4267a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; // The domain/size match exactly. 4268a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4269a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Now handle "real" floating types (i.e. float, double, long double). 4270a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) { 4271a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // if we have an integer operand, the result is the real floating type. 4272a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isIntegerType()) { 4273a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert rhs to the lhs floating point type. 4274a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4275a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4276a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (rhs->isComplexIntegerType()) { 4277a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert rhs to the complex floating point type. 4278a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return getComplexType(lhs); 4279a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4280a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isIntegerType()) { 4281a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert lhs to the rhs floating point type. 4282a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4283a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 42841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (lhs->isComplexIntegerType()) { 4285a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert lhs to the complex floating point type. 4286a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return getComplexType(rhs); 4287a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4288a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // We have two real floating types, float/complex combos were handled above. 4289a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Convert the smaller operand to the bigger result. 4290a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman int result = getFloatingTypeOrder(lhs, rhs); 4291a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (result > 0) // convert the rhs 4292a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4293a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(result < 0 && "illegal float comparison"); 4294a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; // convert the lhs 4295a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4296a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhs->isComplexIntegerType() || rhs->isComplexIntegerType()) { 4297a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Handle GCC complex int extension. 4298a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman const ComplexType *lhsComplexInt = lhs->getAsComplexIntegerType(); 4299a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman const ComplexType *rhsComplexInt = rhs->getAsComplexIntegerType(); 4300a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 4301a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhsComplexInt && rhsComplexInt) { 43021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (getIntegerTypeOrder(lhsComplexInt->getElementType(), 4303a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhsComplexInt->getElementType()) >= 0) 4304a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; // convert the rhs 4305a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4306a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (lhsComplexInt && rhs->isIntegerType()) { 4307a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the rhs to the lhs complex type. 4308a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return lhs; 4309a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (rhsComplexInt && lhs->isIntegerType()) { 4310a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // convert the lhs to the rhs complex type. 4311a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return rhs; 4312a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4313a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4314a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Finally, we have two differing integer types. 4315a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The rules for this case are in C99 6.3.1.8 4316a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman int compare = getIntegerTypeOrder(lhs, rhs); 4317a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman bool lhsSigned = lhs->isSignedIntegerType(), 4318a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman rhsSigned = rhs->isSignedIntegerType(); 4319a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman QualType destType; 4320a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (lhsSigned == rhsSigned) { 4321a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // Same signedness; use the higher-ranked type 4322a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = compare >= 0 ? lhs : rhs; 4323a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (compare != (lhsSigned ? 1 : -1)) { 4324a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The unsigned type has greater than or equal rank to the 4325a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // signed type, so use the unsigned type 4326a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = lhsSigned ? rhs : lhs; 4327a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else if (getIntWidth(lhs) != getIntWidth(rhs)) { 4328a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The two types are different widths; if we are here, that 4329a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // means the signed type is larger than the unsigned type, so 4330a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // use the signed type. 4331a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = lhsSigned ? lhs : rhs; 4332a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } else { 4333a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // The signed type is higher-ranked than the unsigned type, 4334a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // but isn't actually any bigger (like unsigned int and long 4335a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // on most 32-bit systems). Use the unsigned type corresponding 4336a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman // to the signed type. 4337a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman destType = getCorrespondingUnsignedType(lhsSigned ? lhs : rhs); 4338a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman } 4339a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return destType; 4340a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 4341