ASTContext.cpp revision a6c66cedc022c9e5d45a937d6b8cff491a6bf81b
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" 15bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck#include "clang/AST/CharUnits.h" 16aa58081902ad31927df02e8537d972eabe29d6dfDmitri Gribenko#include "clang/AST/CommentCommandTraits.h" 1749aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis#include "clang/AST/DeclCXX.h" 18980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff#include "clang/AST/DeclObjC.h" 19aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 20b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis#include "clang/AST/TypeLoc.h" 21e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/Expr.h" 22ea1471e0e967548c596a71469702f8846dbaf3c0John McCall#include "clang/AST/ExprCXX.h" 232cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "clang/AST/ExternalASTSource.h" 247b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis#include "clang/AST/ASTMutationListener.h" 2519cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 2614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne#include "clang/AST/Mangle.h" 271b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 28a9376d470ccb0eac74fe09a6b2a18a890f1d17c4Chris Lattner#include "clang/Basic/SourceManager.h" 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/TargetInfo.h" 30f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "llvm/ADT/SmallString.h" 3185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson#include "llvm/ADT/StringExtras.h" 326fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman#include "llvm/Support/MathExtras.h" 33f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "llvm/Support/raw_ostream.h" 340c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek#include "llvm/Support/Capacity.h" 35071cc7deffad608165b1ddd5263e8bf181861520Charles Davis#include "CXXABI.h" 362636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis#include <map> 3729445a0542d128cd7ee587ee52229670b9b54a12Anders Carlsson 385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 401827403a7138946305c0058f262e02b595cf882fDouglas Gregorunsigned ASTContext::NumImplicitDefaultConstructors; 411827403a7138946305c0058f262e02b595cf882fDouglas Gregorunsigned ASTContext::NumImplicitDefaultConstructorsDeclared; 42225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregorunsigned ASTContext::NumImplicitCopyConstructors; 43225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregorunsigned ASTContext::NumImplicitCopyConstructorsDeclared; 44ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveConstructors; 45ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveConstructorsDeclared; 46a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregorunsigned ASTContext::NumImplicitCopyAssignmentOperators; 47a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregorunsigned ASTContext::NumImplicitCopyAssignmentOperatorsDeclared; 48ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveAssignmentOperators; 49ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Huntunsigned ASTContext::NumImplicitMoveAssignmentOperatorsDeclared; 504923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorunsigned ASTContext::NumImplicitDestructors; 514923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorunsigned ASTContext::NumImplicitDestructorsDeclared; 524923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor 535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerenum FloatingRank { 54aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov HalfRank, FloatRank, DoubleRank, LongDoubleRank 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 57a5ef44ff5d93a3be6ca67782828157a71894cf0cDmitri GribenkoRawComment *ASTContext::getRawCommentForDeclNoCache(const Decl *D) const { 58aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (!CommentsLoaded && ExternalSource) { 59aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko ExternalSource->ReadComments(); 60aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko CommentsLoaded = true; 61aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 62aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 63aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko assert(D); 64aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 65c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko // User can not attach documentation to implicit declarations. 66c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko if (D->isImplicit()) 67c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko return NULL; 68c3fee3539fd00a6ce21dc1f574baf76686640072Dmitri Gribenko 69c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko // User can not attach documentation to implicit instantiations. 70c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 71c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 72c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return NULL; 73c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko } 74c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko 75dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 76dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (VD->isStaticDataMember() && 77dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 78dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko return NULL; 79dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko } 80dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko 81dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) { 82dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (CRD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 83dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko return NULL; 84dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko } 85dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko 86dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (const EnumDecl *ED = dyn_cast<EnumDecl>(D)) { 87dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko if (ED->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) 88dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko return NULL; 89dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko } 90dce750b15eb5eb797ac9bbea118333d7d1896831Dmitri Gribenko 91aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // TODO: handle comments for function parameters properly. 92aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (isa<ParmVarDecl>(D)) 93aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 94aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 9596b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko // TODO: we could look up template parameter documentation in the template 9696b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko // documentation. 9796b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko if (isa<TemplateTypeParmDecl>(D) || 9896b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko isa<NonTypeTemplateParmDecl>(D) || 9996b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko isa<TemplateTemplateParmDecl>(D)) 10096b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko return NULL; 10196b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko 102811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko ArrayRef<RawComment *> RawComments = Comments.getComments(); 103aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 104aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If there are no comments anywhere, we won't find anything. 105aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (RawComments.empty()) 106aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 107aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 108abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // Find declaration location. 109abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // For Objective-C declarations we generally don't expect to have multiple 110abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // declarators, thus use declaration starting location as the "declaration 111abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // location". 112abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // For all other declarations multiple declarators are used quite frequently, 113abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko // so we use the location of the identifier as the "declaration location". 114abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko SourceLocation DeclLoc; 115abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) || 11696b098674908eaa59a9128f3305cda6fbbdad563Dmitri Gribenko isa<ObjCPropertyDecl>(D) || 117c27bc80a98b9558513b50956c930eedc9e461ae0Dmitri Gribenko isa<RedeclarableTemplateDecl>(D) || 118c27bc80a98b9558513b50956c930eedc9e461ae0Dmitri Gribenko isa<ClassTemplateSpecializationDecl>(D)) 119abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko DeclLoc = D->getLocStart(); 120abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko else 121abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko DeclLoc = D->getLocation(); 122abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko 123aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If the declaration doesn't map directly to a location in a file, we 124aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // can't find the comment. 125aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLoc.isInvalid() || !DeclLoc.isFileID()) 126aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 127aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 128aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Find the comment that occurs just after this declaration. 129a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko ArrayRef<RawComment *>::iterator Comment; 130a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko { 131a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // When searching for comments during parsing, the comment we are looking 132a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // for is usually among the last two comments we parsed -- check them 133a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // first. 134a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko RawComment CommentAtDeclLoc(SourceMgr, SourceRange(DeclLoc)); 135a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko BeforeThanCompare<RawComment> Compare(SourceMgr); 136a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko ArrayRef<RawComment *>::iterator MaybeBeforeDecl = RawComments.end() - 1; 137a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko bool Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); 138a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko if (!Found && RawComments.size() >= 2) { 139a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko MaybeBeforeDecl--; 140a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Found = Compare(*MaybeBeforeDecl, &CommentAtDeclLoc); 141a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 142a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko 143a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko if (Found) { 144a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Comment = MaybeBeforeDecl + 1; 145a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko assert(Comment == std::lower_bound(RawComments.begin(), RawComments.end(), 146a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko &CommentAtDeclLoc, Compare)); 147a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } else { 148a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko // Slow path. 149a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko Comment = std::lower_bound(RawComments.begin(), RawComments.end(), 150a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko &CommentAtDeclLoc, Compare); 151a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 152a444f1856459130bd3a1bb8995331c9e367db04fDmitri Gribenko } 153aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 154aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Decompose the location for the declaration and find the beginning of the 155aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // file buffer. 156aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> DeclLocDecomp = SourceMgr.getDecomposedLoc(DeclLoc); 157aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 158aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // First check whether we have a trailing comment. 159aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Comment != RawComments.end() && 160811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko (*Comment)->isDocumentation() && (*Comment)->isTrailingComment() && 1619c00676f2393335dc60c61faf944d4f8f622fac6Dmitri Gribenko (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D))) { 162aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> CommentBeginDecomp 163811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getBegin()); 164aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check that Doxygen trailing comment comes after the declaration, starts 165aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // on the same line and in the same file as the declaration. 166aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLocDecomp.first == CommentBeginDecomp.first && 167aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko SourceMgr.getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) 168aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko == SourceMgr.getLineNumber(CommentBeginDecomp.first, 169aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko CommentBeginDecomp.second)) { 170811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko return *Comment; 171aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 172aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko } 173aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 174aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // The comment just after the declaration was not a trailing comment. 175aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Let's look at the previous comment. 176aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Comment == RawComments.begin()) 177aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 178aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko --Comment; 179aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 180aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Check that we actually have a non-member Doxygen comment. 181811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko if (!(*Comment)->isDocumentation() || (*Comment)->isTrailingComment()) 182aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 183aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 184aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Decompose the end of the comment. 185aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko std::pair<FileID, unsigned> CommentEndDecomp 186811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko = SourceMgr.getDecomposedLoc((*Comment)->getSourceRange().getEnd()); 187aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 188aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // If the comment and the declaration aren't in the same file, then they 189aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // aren't related. 190aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (DeclLocDecomp.first != CommentEndDecomp.first) 191aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 192aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 193aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Get the corresponding buffer. 194aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko bool Invalid = false; 195aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko const char *Buffer = SourceMgr.getBufferData(DeclLocDecomp.first, 196aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko &Invalid).data(); 197aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko if (Invalid) 198aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 199aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 200aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko // Extract text between the comment and declaration. 201aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko StringRef Text(Buffer + CommentEndDecomp.second, 202aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko DeclLocDecomp.second - CommentEndDecomp.second); 203aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 2048bdb58a7835a9a90dd9b9791fccf269cbc1dcef3Dmitri Gribenko // There should be no other declarations or preprocessor directives between 2058bdb58a7835a9a90dd9b9791fccf269cbc1dcef3Dmitri Gribenko // comment and declaration. 206abd56c816e9164b17bb3e7154a511b0c9896ffdbDmitri Gribenko if (Text.find_first_of(",;{}#@") != StringRef::npos) 207aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return NULL; 208aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 209811c820257746b1799b790b6adc7804f44154011Dmitri Gribenko return *Comment; 210aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 211aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 212c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenkonamespace { 213c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko/// If we have a 'templated' declaration for a template, adjust 'D' to 214c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko/// refer to the actual template. 2152125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko/// If we have an implicit instantiation, adjust 'D' to refer to template. 216c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenkoconst Decl *adjustDeclToTemplate(const Decl *D) { 217cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 2182125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Is this function declaration part of a function template? 219cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor if (const FunctionTemplateDecl *FTD = FD->getDescribedFunctionTemplate()) 2202125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return FTD; 2212125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2222125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Nothing to do if function is not an implicit instantiation. 2232125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (FD->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) 2242125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2252125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2262125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Function is an implicit instantiation of a function template? 2272125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const FunctionTemplateDecl *FTD = FD->getPrimaryTemplate()) 2282125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return FTD; 2292125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2302125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Function is instantiated from a member definition of a class template? 2312125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const FunctionDecl *MemberDecl = 2322125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko FD->getInstantiatedFromMemberFunction()) 2332125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return MemberDecl; 2342125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2352125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2362125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2372125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 2382125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Static data member is instantiated from a member definition of a class 2392125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // template? 2402125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (VD->isStaticDataMember()) 2412125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const VarDecl *MemberDecl = VD->getInstantiatedFromStaticDataMember()) 2422125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return MemberDecl; 2432125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2442125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2452125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2462125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) { 2472125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Is this class declaration part of a class template? 2482125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const ClassTemplateDecl *CTD = CRD->getDescribedClassTemplate()) 2492125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return CTD; 2502125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2512125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Class is an implicit instantiation of a class template or partial 2522125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // specialization? 2532125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const ClassTemplateSpecializationDecl *CTSD = 2542125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko dyn_cast<ClassTemplateSpecializationDecl>(CRD)) { 2552125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (CTSD->getSpecializationKind() != TSK_ImplicitInstantiation) 2562125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2572125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko llvm::PointerUnion<ClassTemplateDecl *, 2582125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko ClassTemplatePartialSpecializationDecl *> 2592125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko PU = CTSD->getSpecializedTemplateOrPartial(); 2602125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return PU.is<ClassTemplateDecl*>() ? 2612125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko static_cast<const Decl*>(PU.get<ClassTemplateDecl *>()) : 2622125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko static_cast<const Decl*>( 2632125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko PU.get<ClassTemplatePartialSpecializationDecl *>()); 2642125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2652125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2662125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Class is instantiated from a member definition of a class template? 2672125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const MemberSpecializationInfo *Info = 2682125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko CRD->getMemberSpecializationInfo()) 2692125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return Info->getInstantiatedFrom(); 2702125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2712125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 2722125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko } 2732125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const EnumDecl *ED = dyn_cast<EnumDecl>(D)) { 2742125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // Enum is instantiated from a member definition of a class template? 2752125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko if (const EnumDecl *MemberDecl = ED->getInstantiatedFromMemberEnum()) 2762125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return MemberDecl; 2772125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko 2782125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko return D; 279cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor } 2802125c9010e259548a8c476fa998a561889555c95Dmitri Gribenko // FIXME: Adjust alias templates? 281c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return D; 282c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko} 283c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko} // unnamed namespace 284c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko 2851599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenkoconst RawComment *ASTContext::getRawCommentForAnyRedecl( 2861599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl *D, 2871599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl **OriginalDecl) const { 288c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko D = adjustDeclToTemplate(D); 289cd81df2dcff4e13eea6edfbfd52a4458d978d174Douglas Gregor 290f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko // Check whether we have cached a comment for this declaration already. 291f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko { 292f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko llvm::DenseMap<const Decl *, RawCommentAndCacheFlags>::iterator Pos = 293f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RedeclComments.find(D); 294f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (Pos != RedeclComments.end()) { 295f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko const RawCommentAndCacheFlags &Raw = Pos->second; 2961599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { 2971599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (OriginalDecl) 2981599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko *OriginalDecl = Raw.getOriginalDecl(); 299f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko return Raw.getRaw(); 3001599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko } 301f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 302f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 303f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 304f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko // Search for comments attached to declarations in the redeclaration chain. 305f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko const RawComment *RC = NULL; 3061599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl *OriginalDeclForRC = NULL; 307f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko for (Decl::redecl_iterator I = D->redecls_begin(), 308f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko E = D->redecls_end(); 309f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko I != E; ++I) { 310f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko llvm::DenseMap<const Decl *, RawCommentAndCacheFlags>::iterator Pos = 311f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RedeclComments.find(*I); 312f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (Pos != RedeclComments.end()) { 313f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko const RawCommentAndCacheFlags &Raw = Pos->second; 314f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { 315f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RC = Raw.getRaw(); 3161599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko OriginalDeclForRC = Raw.getOriginalDecl(); 317f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko break; 318f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 319f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } else { 320f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RC = getRawCommentForDeclNoCache(*I); 3211599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko OriginalDeclForRC = *I; 322f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RawCommentAndCacheFlags Raw; 323f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (RC) { 324f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setRaw(RC); 325f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setKind(RawCommentAndCacheFlags::FromDecl); 326f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } else 327f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setKind(RawCommentAndCacheFlags::NoCommentInDecl); 3281599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko Raw.setOriginalDecl(*I); 329f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RedeclComments[*I] = Raw; 330f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (RC) 331f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko break; 332f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 3338d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko } 334aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 3358376f5934a18b950ac7323d8a38ed231623010faDmitri Gribenko // If we found a comment, it should be a documentation comment. 3368376f5934a18b950ac7323d8a38ed231623010faDmitri Gribenko assert(!RC || RC->isDocumentation()); 337f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 3381599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (OriginalDecl) 3391599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko *OriginalDecl = OriginalDeclForRC; 3401599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko 341f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko // Update cache for every declaration in the redeclaration chain. 342f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RawCommentAndCacheFlags Raw; 343f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setRaw(RC); 344f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko Raw.setKind(RawCommentAndCacheFlags::FromRedecl); 3451599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko Raw.setOriginalDecl(OriginalDeclForRC); 346f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 347f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko for (Decl::redecl_iterator I = D->redecls_begin(), 348f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko E = D->redecls_end(); 349f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko I != E; ++I) { 350f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko RawCommentAndCacheFlags &R = RedeclComments[*I]; 351f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko if (R.getKind() == RawCommentAndCacheFlags::NoCommentInDecl) 352f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko R = Raw; 353f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko } 354f50555eedef33fd5a67d369aa0ae8a6f1d201543Dmitri Gribenko 355aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko return RC; 356aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko} 357aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko 3588d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenkocomments::FullComment *ASTContext::getCommentForDecl(const Decl *D) const { 359c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko D = adjustDeclToTemplate(D); 360c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko const Decl *Canonical = D->getCanonicalDecl(); 361c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko llvm::DenseMap<const Decl *, comments::FullComment *>::iterator Pos = 362c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko ParsedComments.find(Canonical); 363c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko if (Pos != ParsedComments.end()) 364c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return Pos->second; 365c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko 3661599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const Decl *OriginalDecl; 3671599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko const RawComment *RC = getRawCommentForAnyRedecl(D, &OriginalDecl); 3688d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko if (!RC) 3698d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko return NULL; 3708d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 3714b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // If the RawComment was attached to other redeclaration of this Decl, we 3724b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // should parse the comment in context of that other Decl. This is important 3734b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // because comments can contain references to parameter names which can be 3744b41c65feb93eeb6f6d27b49a2045ea1b72de9d1Dmitri Gribenko // different across redeclarations. 3751599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko if (D != OriginalDecl) 3761599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko return getCommentForDecl(OriginalDecl); 3771599eac40a3b28de0824013dc2fb90551dfa01b0Dmitri Gribenko 378c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko comments::FullComment *FC = RC->parse(*this, D); 379c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko ParsedComments[Canonical] = FC; 380c41ace950dcf2254c9aa48e73647b89c35109f80Dmitri Gribenko return FC; 3818d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko} 3828d3ba23f2d9e6c87794d059412a0808c9cbacb25Dmitri Gribenko 3833e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregorvoid 3843e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID, 3853e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *Parm) { 3863e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Parm->getDepth()); 3873e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Parm->getPosition()); 38861c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor ID.AddBoolean(Parm->isParameterPack()); 3893e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 3903e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList *Params = Parm->getTemplateParameters(); 3913e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(Params->size()); 3923e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 3933e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PEnd = Params->end(); 3943e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor P != PEnd; ++P) { 3953e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) { 3963e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(0); 3973e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddBoolean(TTP->isParameterPack()); 3983e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor continue; 3993e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4003e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4013e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { 4023e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(1); 40361c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor ID.AddBoolean(NTTP->isParameterPack()); 4049e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr()); 4056952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (NTTP->isExpandedParameterPack()) { 4066952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddBoolean(true); 4076952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddInteger(NTTP->getNumExpansionTypes()); 4089e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { 4099e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman QualType T = NTTP->getExpansionType(I); 4109e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman ID.AddPointer(T.getCanonicalType().getAsOpaquePtr()); 4119e9c454b12671a624f666fc6fbf132fdf183effcEli Friedman } 4126952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else 4136952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ID.AddBoolean(false); 4143e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor continue; 4153e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4163e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4173e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P); 4183e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ID.AddInteger(2); 4193e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Profile(ID, TTP); 4203e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4213e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 4223e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4233e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorTemplateTemplateParmDecl * 4243e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas GregorASTContext::getCanonicalTemplateTemplateParmDecl( 4254ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad TemplateTemplateParmDecl *TTP) const { 4263e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Check if we already have a canonical template template parameter. 4273e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor llvm::FoldingSetNodeID ID; 4283e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonicalTemplateTemplateParm::Profile(ID, TTP); 4293e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor void *InsertPos = 0; 4303e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonicalTemplateTemplateParm *Canonical 4313e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); 4323e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (Canonical) 4333e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return Canonical->getParam(); 4343e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4353e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Build a canonical template parameter list. 4363e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList *Params = TTP->getTemplateParameters(); 4375f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<NamedDecl *, 4> CanonParams; 4383e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.reserve(Params->size()); 4393e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (TemplateParameterList::const_iterator P = Params->begin(), 4403e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PEnd = Params->end(); 4413e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor P != PEnd; ++P) { 4423e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) 4433e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.push_back( 4443e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTypeParmDecl::Create(*this, getTranslationUnitDecl(), 445344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara SourceLocation(), 446344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara SourceLocation(), 447344577e6b58f42d18dc8118c8903b49a85dc005eAbramo Bagnara TTP->getDepth(), 4483e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TTP->getIndex(), 0, false, 4493e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TTP->isParameterPack())); 4503e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor else if (NonTypeTemplateParmDecl *NTTP 4516952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor = dyn_cast<NonTypeTemplateParmDecl>(*P)) { 4526952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor QualType T = getCanonicalType(NTTP->getType()); 4536952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(T); 4546952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NonTypeTemplateParmDecl *Param; 4556952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor if (NTTP->isExpandedParameterPack()) { 4565f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 2> ExpandedTypes; 4575f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TypeSourceInfo *, 2> ExpandedTInfos; 4586952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor for (unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) { 4596952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.push_back(getCanonicalType(NTTP->getExpansionType(I))); 4606952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTInfos.push_back( 4616952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor getTrivialTypeSourceInfo(ExpandedTypes.back())); 4626952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } 4636952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor 4646952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 465ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 466ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 4676952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getDepth(), 4686952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getPosition(), 0, 4696952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor T, 4706952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TInfo, 4716952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.data(), 4726952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTypes.size(), 4736952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor ExpandedTInfos.data()); 4746952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else { 4756952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor Param = NonTypeTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 476ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 477ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 4786952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getDepth(), 4796952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->getPosition(), 0, 4806952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor T, 4816952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor NTTP->isParameterPack(), 4826952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor TInfo); 4836952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } 4846952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor CanonParams.push_back(Param); 4856952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor 4866952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor } else 4873e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.push_back(getCanonicalTemplateTemplateParmDecl( 4883e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor cast<TemplateTemplateParmDecl>(*P))); 4893e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 4903e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 4913e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateTemplateParmDecl *CanonTTP 4923e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor = TemplateTemplateParmDecl::Create(*this, getTranslationUnitDecl(), 4933e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation(), TTP->getDepth(), 49461c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor TTP->getPosition(), 49561c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor TTP->isParameterPack(), 49661c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor 0, 4973e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor TemplateParameterList::Create(*this, SourceLocation(), 4983e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation(), 4993e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.data(), 5003e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonParams.size(), 5013e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor SourceLocation())); 5023e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 5033e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Get the new insert position for the node we care about. 5043e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos); 5053e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor assert(Canonical == 0 && "Shouldn't be in the map!"); 5063e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor (void)Canonical; 5073e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 5083e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // Create the canonical template template parameter entry. 5093e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Canonical = new (*this) CanonicalTemplateTemplateParm(CanonTTP); 5103e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos); 5113e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return CanonTTP; 5123e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 5133e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 514071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCXXABI *ASTContext::createCXXABI(const TargetInfo &T) { 515ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall if (!LangOpts.CPlusPlus) return 0; 516ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall 51720cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis switch (T.getCXXABI()) { 518ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall case CXXABI_ARM: 519ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall return CreateARMCXXABI(*this); 520ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall case CXXABI_Itanium: 521071cc7deffad608165b1ddd5263e8bf181861520Charles Davis return CreateItaniumCXXABI(*this); 52220cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis case CXXABI_Microsoft: 52320cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis return CreateMicrosoftCXXABI(*this); 52420cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis } 5257530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid CXXABI type!"); 526071cc7deffad608165b1ddd5263e8bf181861520Charles Davis} 527071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 528bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorstatic const LangAS::Map *getAddressSpaceMap(const TargetInfo &T, 529207f4d8543529221932af82836016a2ef066c917Peter Collingbourne const LangOptions &LOpts) { 530207f4d8543529221932af82836016a2ef066c917Peter Collingbourne if (LOpts.FakeAddressSpaceMap) { 531207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // The fake address space map must have a distinct entry for each 532207f4d8543529221932af82836016a2ef066c917Peter Collingbourne // language-specific address space. 533207f4d8543529221932af82836016a2ef066c917Peter Collingbourne static const unsigned FakeAddrSpaceMap[] = { 534207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 1, // opencl_global 535207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 2, // opencl_local 5364dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 3, // opencl_constant 5374dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 4, // cuda_device 5384dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 5, // cuda_constant 5394dc34ebf2a0716bf77ba110dab6777a3fc4397ddPeter Collingbourne 6 // cuda_shared 540207f4d8543529221932af82836016a2ef066c917Peter Collingbourne }; 541bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return &FakeAddrSpaceMap; 542207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } else { 543bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return &T.getAddressSpaceMap(); 544207f4d8543529221932af82836016a2ef066c917Peter Collingbourne } 545207f4d8543529221932af82836016a2ef066c917Peter Collingbourne} 546207f4d8543529221932af82836016a2ef066c917Peter Collingbourne 5473e3cd93b2fd9644e970c389e715c13883faf68b6Douglas GregorASTContext::ASTContext(LangOptions& LOpts, SourceManager &SM, 548bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor const TargetInfo *t, 549e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar IdentifierTable &idents, SelectorTable &sels, 5501b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner Builtin::Context &builtins, 551bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned size_reserve, 552bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor bool DelayInitialization) 553bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor : FunctionProtoTypes(this_()), 554bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor TemplateSpecializationTypes(this_()), 555bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor DependentTemplateSpecializationTypes(this_()), 556bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor SubstTemplateTemplateParmPacks(this_()), 557bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor GlobalNestedNameSpecifier(0), 558bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Int128Decl(0), UInt128Decl(0), 559c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge BuiltinVaListDecl(0), 560a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0), ObjCProtocolClassDecl(0), 561961713055e636170da59d7006a878cb4ba518a5dFariborz Jahanian BOOLDecl(0), 562e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor CFConstantStringTypeDecl(0), ObjCInstanceTypeDecl(0), 563bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor FILEDecl(0), 564e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola jmp_bufDecl(0), sigjmp_bufDecl(0), ucontext_tDecl(0), 565e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola BlockDescriptorType(0), BlockDescriptorExtendedType(0), 566e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola cudaConfigureCallDecl(0), 567e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor NullTypeSourceInfo(QualType()), 568e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor FirstLocalImport(), LastLocalImport(), 569bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor SourceMgr(SM), LangOpts(LOpts), 57030c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor AddrSpaceMap(0), Target(t), PrintingPolicy(LOpts), 571bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Idents(idents), Selectors(sels), 572bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor BuiltinInfo(builtins), 573bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor DeclarationNames(*this), 57430c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor ExternalSource(0), Listener(0), 575aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko Comments(SM), CommentsLoaded(false), 576bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor LastSDM(0, 0), 577bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor UniqueBlockByRefTypeID(0) 578bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor{ 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (size_reserve > 0) Types.reserve(size_reserve); 580e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar TUDecl = TranslationUnitDecl::Create(*this); 581bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 582bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor if (!DelayInitialization) { 583bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor assert(t && "No target supplied for ASTContext initialization"); 584bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor InitBuiltinTypes(*t); 585bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor } 586e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar} 587e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar 5885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerASTContext::~ASTContext() { 5893478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek // Release the DenseMaps associated with DeclContext objects. 5903478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek // FIXME: Is this the ideal solution? 5913478eb6872d836600caf45b0f81c2065d685d6e0Ted Kremenek ReleaseDeclContextMaps(); 5927d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 59363fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // Call all of the deallocation functions. 59463fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor for (unsigned I = 0, N = Deallocations.size(); I != N; ++I) 59563fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor Deallocations[I].first(Deallocations[I].second); 5960054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 597dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek // ASTRecordLayout objects in ASTRecordLayouts must always be destroyed 59863fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // because they can contain DenseMaps. 59963fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor for (llvm::DenseMap<const ObjCContainerDecl*, 60063fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor const ASTRecordLayout*>::iterator 60163fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; ) 60263fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor // Increment in loop to prevent using deallocated memory. 60363fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second)) 60463fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor R->Destroy(*this); 60563fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor 606dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator 607dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) { 608dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek // Increment in loop to prevent using deallocated memory. 609dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek if (ASTRecordLayout *R = const_cast<ASTRecordLayout*>((I++)->second)) 610dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek R->Destroy(*this); 611dcfcfbec478f7ed96cd8d92f30c29bd4e30d5b9cTed Kremenek } 6126320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 6136320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(), 6146320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor AEnd = DeclAttrs.end(); 6156320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor A != AEnd; ++A) 6166320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor A->second->~AttrVec(); 6176320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 618ab452ba8323d1985e08bade2bced588cddf2cc28Douglas Gregor 6190054531488928a424666ac11fcdc6bcc5112de52Douglas Gregorvoid ASTContext::AddDeallocation(void (*Callback)(void*), void *Data) { 6200054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor Deallocations.push_back(std::make_pair(Callback, Data)); 6210054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor} 6220054531488928a424666ac11fcdc6bcc5112de52Douglas Gregor 6231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 6246f42b62b6194f53bcbc349f5d17388e1936535d7Dylan NoblesmithASTContext::setExternalSource(OwningPtr<ExternalASTSource> &Source) { 6252cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource.reset(Source.take()); 6262cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} 6272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor 6285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencervoid ASTContext::PrintStats() const { 629cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "\n*** AST Context Stats:\n"; 630cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << " " << Types.size() << " types total.\n"; 6317c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 632dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned counts[] = { 6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump#define TYPE(Name, Parent) 0, 634dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 635dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 636dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor 0 // Extra 637dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor }; 638c2ee10d79f70036af652a395ac1f8273f3d04e12Douglas Gregor 6395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0, e = Types.size(); i != e; ++i) { 6405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Type *T = Types[i]; 641dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor counts[(unsigned)T->getTypeClass()]++; 6425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 6435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 644dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned Idx = 0; 645dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor unsigned TotalBytes = 0; 646dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define TYPE(Name, Parent) \ 647dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor if (counts[Idx]) \ 648cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << " " << counts[Idx] << " " << #Name \ 649cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " types\n"; \ 650dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor TotalBytes += counts[Idx] * sizeof(Name##Type); \ 651dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor ++Idx; 652dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#define ABSTRACT_TYPE(Name, Parent) 653dbe833da54e1b6192991b64fc453cd50b5ee7909Douglas Gregor#include "clang/AST/TypeNodes.def" 6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 655cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "Total bytes = " << TotalBytes << "\n"; 656cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 6574923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor // Implicit special member functions. 658cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitDefaultConstructorsDeclared << "/" 659cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitDefaultConstructors 660cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit default constructors created\n"; 661cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitCopyConstructorsDeclared << "/" 662cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitCopyConstructors 663cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit copy constructors created\n"; 6644e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 665cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitMoveConstructorsDeclared << "/" 666cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitMoveConstructors 667cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit move constructors created\n"; 668cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitCopyAssignmentOperatorsDeclared << "/" 669cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitCopyAssignmentOperators 670cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit copy assignment operators created\n"; 6714e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 672cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitMoveAssignmentOperatorsDeclared << "/" 673cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitMoveAssignmentOperators 674cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit move assignment operators created\n"; 675cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << NumImplicitDestructorsDeclared << "/" 676cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << NumImplicitDestructors 677cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth << " implicit destructors created\n"; 678cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 6792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor if (ExternalSource.get()) { 680cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth llvm::errs() << "\n"; 6812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor ExternalSource->PrintStats(); 6822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor } 683cd92a65edc7cbbbb7e3aee8d31008594de90fa51Chandler Carruth 68463fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor BumpAlloc.PrintStats(); 6855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 687772eeaefef2c883aabe35caf4543e7e32d290183Douglas GregorTypedefDecl *ASTContext::getInt128Decl() const { 688772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (!Int128Decl) { 689772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(Int128Ty); 690772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor Int128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 691772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor getTranslationUnitDecl(), 692772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 693772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 694772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor &Idents.get("__int128_t"), 695772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TInfo); 696772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor } 697772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 698772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor return Int128Decl; 699772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor} 700772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 701772eeaefef2c883aabe35caf4543e7e32d290183Douglas GregorTypedefDecl *ASTContext::getUInt128Decl() const { 702772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor if (!UInt128Decl) { 703772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TypeSourceInfo *TInfo = getTrivialTypeSourceInfo(UnsignedInt128Ty); 704772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor UInt128Decl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 705772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor getTranslationUnitDecl(), 706772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 707772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor SourceLocation(), 708772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor &Idents.get("__uint128_t"), 709772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor TInfo); 710772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor } 711772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor 712772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor return UInt128Decl; 713772eeaefef2c883aabe35caf4543e7e32d290183Douglas Gregor} 7145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 715e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCallvoid ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { 7166b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BuiltinType *Ty = new (*this, TypeAlignment) BuiltinType(K); 717e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCall R = CanQualType::CreateUnsafe(QualType(Ty, 0)); 7186b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Types.push_back(Ty); 7195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 721bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregorvoid ASTContext::InitBuiltinTypes(const TargetInfo &Target) { 722bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor assert((!this->Target || this->Target == &Target) && 723bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor "Incorrect target reinitialization"); 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer assert(VoidTy.isNull() && "Context reinitialized?"); 7251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 726bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor this->Target = &Target; 727bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 728bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor ABI.reset(createCXXABI(Target)); 729bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor AddrSpaceMap = getAddressSpaceMap(Target, LangOpts); 730bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor 7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p19. 7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(VoidTy, BuiltinType::Void); 7331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p2. 7355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(BoolTy, BuiltinType::Bool); 7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p3. 73715b91764d08e886391c865c4a444d7b51141c284Eli Friedman if (LangOpts.CharIsSigned) 7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_S); 7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer else 7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(CharTy, BuiltinType::Char_U); 7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p4. 7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(SignedCharTy, BuiltinType::SChar); 7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(ShortTy, BuiltinType::Short); 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(IntTy, BuiltinType::Int); 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongTy, BuiltinType::Long); 7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongLongTy, BuiltinType::LongLong); 7471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p6. 7495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedCharTy, BuiltinType::UChar); 7505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedShortTy, BuiltinType::UShort); 7515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedIntTy, BuiltinType::UInt); 7525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongTy, BuiltinType::ULong); 7535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(UnsignedLongLongTy, BuiltinType::ULongLong); 7541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p10. 7565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(FloatTy, BuiltinType::Float); 7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(DoubleTy, BuiltinType::Double); 7585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer InitBuiltinType(LongDoubleTy, BuiltinType::LongDouble); 75964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 7602df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner // GNU extension, 128-bit integers. 7612df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(Int128Ty, BuiltinType::Int128); 7622df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128); 7632df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner 7643f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner if (LangOpts.CPlusPlus) { // C++ 3.9.1p5 765d3d77cd138f8e830f6547b6f83fcd5721ccf5f5dEli Friedman if (TargetInfo::isTypeSigned(Target.getWCharType())) 7663f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar_S); 7673f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner else // -fshort-wchar makes wchar_t be unsigned. 7683f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner InitBuiltinType(WCharTy, BuiltinType::WChar_U); 7693f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner } else // C99 7703a2503227c3db04a3619735127483263c1075ef7Chris Lattner WCharTy = getFromTargetType(Target.getWCharType()); 77164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 772392da48160bd92ceb486792780467cbfdb2d0e8cJames Molloy WIntTy = getFromTargetType(Target.getWIntType()); 773392da48160bd92ceb486792780467cbfdb2d0e8cJames Molloy 774f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 775f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char16Ty, BuiltinType::Char16); 776f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 777f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char16Ty = getFromTargetType(Target.getChar16Type()); 778f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 779f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith if (LangOpts.CPlusPlus) // C++0x 3.9.1p5, extension for C++ 780f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith InitBuiltinType(Char32Ty, BuiltinType::Char32); 781f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith else // C99 782f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith Char32Ty = getFromTargetType(Target.getChar32Type()); 783f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 784898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // Placeholder type for type-dependent expressions whose type is 785898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // completely unknown. No code should ever check a type against 786898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // DependentTy and users should never see it; however, it is here to 787898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // help diagnose failures to properly check for type-dependent 788898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor // expressions. 789898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor InitBuiltinType(DependentTy, BuiltinType::Dependent); 7908e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 7912a984cad5ac3fdceeff2bd99daa7b90979313475John McCall // Placeholder type for functions. 7922a984cad5ac3fdceeff2bd99daa7b90979313475John McCall InitBuiltinType(OverloadTy, BuiltinType::Overload); 7932a984cad5ac3fdceeff2bd99daa7b90979313475John McCall 794864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall // Placeholder type for bound members. 795864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall InitBuiltinType(BoundMemberTy, BuiltinType::BoundMember); 796864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall 7973c3b7f90a863af43fa63043d396553ecf205351cJohn McCall // Placeholder type for pseudo-objects. 7983c3b7f90a863af43fa63043d396553ecf205351cJohn McCall InitBuiltinType(PseudoObjectTy, BuiltinType::PseudoObject); 7993c3b7f90a863af43fa63043d396553ecf205351cJohn McCall 8001de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall // "any" type; useful for debugger-like clients. 8011de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall InitBuiltinType(UnknownAnyTy, BuiltinType::UnknownAny); 8021de4d4e8cb2e9c88809fea8092bc6e835a5473d2John McCall 8030ddaeb9b031070ec64afe92d9892875ac44df427John McCall // Placeholder type for unbridged ARC casts. 8040ddaeb9b031070ec64afe92d9892875ac44df427John McCall InitBuiltinType(ARCUnbridgedCastTy, BuiltinType::ARCUnbridgedCast); 8050ddaeb9b031070ec64afe92d9892875ac44df427John McCall 806a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman // Placeholder type for builtin functions. 807a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman InitBuiltinType(BuiltinFnTy, BuiltinType::BuiltinFn); 808a6c66cedc022c9e5d45a937d6b8cff491a6bf81bEli Friedman 8095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // C99 6.2.5p11. 8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer FloatComplexTy = getComplexType(FloatTy); 8115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer DoubleComplexTy = getComplexType(DoubleTy); 8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LongDoubleComplexTy = getComplexType(LongDoubleTy); 8138e9bebdea69c590dedfbf27374114cb76fe12fbdDouglas Gregor 81413dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian // Builtin types for 'id', 'Class', and 'SEL'. 815de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId); 816de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass); 81713dcd00615de5c4279d97bdf63cd5f0a14fd9dccFariborz Jahanian InitBuiltinType(ObjCBuiltinSelTy, BuiltinType::ObjCSel); 818ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 819ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Builtin type for __objc_yes and __objc_no 82093a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian ObjCBuiltinBoolTy = (Target.useSignedCharForObjCBool() ? 82193a49944e0e68e32bc22d45d44ee136b34beffb3Fariborz Jahanian SignedCharTy : BoolTy); 822ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 823a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = QualType(); 8241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 82533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // void * type 82633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian VoidPtrTy = getPointerType(VoidTy); 8276e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 8286e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // nullptr type (C++0x 2.14.7) 8296e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl InitBuiltinType(NullPtrTy, BuiltinType::NullPtr); 830aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov 831aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov // half type (OpenCL 6.1.1.1) / ARM NEON __fp16 832aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov InitBuiltinType(HalfTy, BuiltinType::Half); 833fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 834fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // Builtin type used to help define __builtin_va_list. 835fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge VaListTagTy = QualType(); 8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 838d6471f7c1921c7802804ce3ff6fe9768310f72b9David BlaikieDiagnosticsEngine &ASTContext::getDiagnostics() const { 83978a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis return SourceMgr.getDiagnostics(); 84078a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis} 84178a916ec5ff5b66adec3c499e1b9af7b87668309Argyrios Kyrtzidis 8426320064d0c60fa8683f5623881c9394fd4aa7689Douglas GregorAttrVec& ASTContext::getDeclAttrs(const Decl *D) { 8436320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor AttrVec *&Result = DeclAttrs[D]; 8446320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor if (!Result) { 8456320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor void *Mem = Allocate(sizeof(AttrVec)); 8466320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor Result = new (Mem) AttrVec; 8476320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor } 8486320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 8496320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor return *Result; 8506320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 8516320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 8526320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor/// \brief Erase the attributes corresponding to the given declaration. 8536320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregorvoid ASTContext::eraseDeclAttrs(const Decl *D) { 8546320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D); 8556320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor if (Pos != DeclAttrs.end()) { 8566320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor Pos->second->~AttrVec(); 8576320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor DeclAttrs.erase(Pos); 8586320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor } 8596320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor} 8606320064d0c60fa8683f5623881c9394fd4aa7689Douglas Gregor 861251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas GregorMemberSpecializationInfo * 862663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas GregorASTContext::getInstantiatedFromStaticDataMember(const VarDecl *Var) { 8637caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Var->isStaticDataMember() && "Not a static data member"); 864663b5a0be7261c29bc4c526a71cffcfa02d4153eDouglas Gregor llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *>::iterator Pos 8657caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor = InstantiatedFromStaticDataMember.find(Var); 8667caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor if (Pos == InstantiatedFromStaticDataMember.end()) 8677caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return 0; 8681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8697caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor return Pos->second; 8707caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 8717caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 8721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid 873251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas GregorASTContext::setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 8749421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis TemplateSpecializationKind TSK, 8759421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis SourceLocation PointOfInstantiation) { 8767caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Inst->isStaticDataMember() && "Not a static data member"); 8777caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(Tmpl->isStaticDataMember() && "Not a static data member"); 8787caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor assert(!InstantiatedFromStaticDataMember[Inst] && 8797caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor "Already noted what static data member was instantiated from"); 880251b4ff2578e26959a4c036140ccd61c5e9292f2Douglas Gregor InstantiatedFromStaticDataMember[Inst] 8819421adc43891e272156fab640e5d5ee5054b779cArgyrios Kyrtzidis = new (*this) MemberSpecializationInfo(Tmpl, TSK, PointOfInstantiation); 8827caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor} 8837caa6825f42a0f7e97d6fc06233133c42b218e46Douglas Gregor 884af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois PichetFunctionDecl *ASTContext::getClassScopeSpecializationPattern( 885af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet const FunctionDecl *FD){ 886af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(FD && "Specialization is 0"); 887af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet llvm::DenseMap<const FunctionDecl*, FunctionDecl *>::const_iterator Pos 8880d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet = ClassScopeSpecializationPattern.find(FD); 8890d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet if (Pos == ClassScopeSpecializationPattern.end()) 890af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet return 0; 891af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 892af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet return Pos->second; 893af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet} 894af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 895af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichetvoid ASTContext::setClassScopeSpecializationPattern(FunctionDecl *FD, 896af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet FunctionDecl *Pattern) { 897af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(FD && "Specialization is 0"); 898af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet assert(Pattern && "Class scope specialization pattern is 0"); 8990d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet ClassScopeSpecializationPattern[FD] = Pattern; 900af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet} 901af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet 9027ba107a1863ddfa1664555854f0d7bdb3c491c92John McCallNamedDecl * 903ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::getInstantiatedFromUsingDecl(UsingDecl *UUD) { 9047ba107a1863ddfa1664555854f0d7bdb3c491c92John McCall llvm::DenseMap<UsingDecl *, NamedDecl *>::const_iterator Pos 905ed97649e9574b9d854fa4d6109c9333ae0993554John McCall = InstantiatedFromUsingDecl.find(UUD); 906ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Pos == InstantiatedFromUsingDecl.end()) 9070d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return 0; 9081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9090d8df780aef1acda5962347a32591efc629b6748Anders Carlsson return Pos->second; 9100d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 9110d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 9120d8df780aef1acda5962347a32591efc629b6748Anders Carlssonvoid 913ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern) { 914ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert((isa<UsingDecl>(Pattern) || 915ed97649e9574b9d854fa4d6109c9333ae0993554John McCall isa<UnresolvedUsingValueDecl>(Pattern) || 916ed97649e9574b9d854fa4d6109c9333ae0993554John McCall isa<UnresolvedUsingTypenameDecl>(Pattern)) && 917ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "pattern decl is not a using decl"); 918ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(!InstantiatedFromUsingDecl[Inst] && "pattern already exists"); 919ed97649e9574b9d854fa4d6109c9333ae0993554John McCall InstantiatedFromUsingDecl[Inst] = Pattern; 920ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 921ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 922ed97649e9574b9d854fa4d6109c9333ae0993554John McCallUsingShadowDecl * 923ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst) { 924ed97649e9574b9d854fa4d6109c9333ae0993554John McCall llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos 925ed97649e9574b9d854fa4d6109c9333ae0993554John McCall = InstantiatedFromUsingShadowDecl.find(Inst); 926ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Pos == InstantiatedFromUsingShadowDecl.end()) 927ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return 0; 928ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 929ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Pos->second; 930ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 931ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 932ed97649e9574b9d854fa4d6109c9333ae0993554John McCallvoid 933ed97649e9574b9d854fa4d6109c9333ae0993554John McCallASTContext::setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 934ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingShadowDecl *Pattern) { 935ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(!InstantiatedFromUsingShadowDecl[Inst] && "pattern already exists"); 936ed97649e9574b9d854fa4d6109c9333ae0993554John McCall InstantiatedFromUsingShadowDecl[Inst] = Pattern; 9370d8df780aef1acda5962347a32591efc629b6748Anders Carlsson} 9380d8df780aef1acda5962347a32591efc629b6748Anders Carlsson 939d8b285fee4471f393da8ee30f552ceacdc362afaAnders CarlssonFieldDecl *ASTContext::getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field) { 940d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos 941d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson = InstantiatedFromUnnamedFieldDecl.find(Field); 942d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (Pos == InstantiatedFromUnnamedFieldDecl.end()) 943d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return 0; 9441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 945d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return Pos->second; 946d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 947d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 948d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlssonvoid ASTContext::setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, 949d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson FieldDecl *Tmpl) { 950d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Inst->getDeclName() && "Instantiated field decl is not unnamed"); 951d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Tmpl->getDeclName() && "Template field decl is not unnamed"); 952d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!InstantiatedFromUnnamedFieldDecl[Inst] && 953d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson "Already noted what unnamed field was instantiated from"); 9541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 955d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl; 956d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson} 957d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson 95814d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanianbool ASTContext::ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 95914d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian const FieldDecl *LastFD) const { 96014d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian return (FD->isBitField() && LastFD && !LastFD->isBitField() && 961a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) == 0); 96214d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian} 96314d56ef43ff4921c6749f7340212fbb743fdbb9bFariborz Jahanian 964340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanianbool ASTContext::ZeroBitfieldFollowsBitfield(const FieldDecl *FD, 965340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian const FieldDecl *LastFD) const { 966340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian return (FD->isBitField() && LastFD && LastFD->isBitField() && 967a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) == 0 && 968a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this) != 0); 969340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian} 970340fa242130c2d8d74c83edca0952e771aebe0e6Fariborz Jahanian 9719b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanianbool ASTContext::BitfieldFollowsBitfield(const FieldDecl *FD, 9729b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian const FieldDecl *LastFD) const { 9739b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian return (FD->isBitField() && LastFD && LastFD->isBitField() && 974a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this) && 975a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this)); 9769b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian} 9779b3acaa32548d0ce78b9c39a3911397f6738a47cFariborz Jahanian 978dd7fddb5b6883326e52b278a9b7e9cefea29aae0Chad Rosierbool ASTContext::NonBitfieldFollowsBitfield(const FieldDecl *FD, 97952bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian const FieldDecl *LastFD) const { 98052bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian return (!FD->isBitField() && LastFD && LastFD->isBitField() && 981a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith LastFD->getBitWidthValue(*this)); 98252bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian} 98352bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian 984dd7fddb5b6883326e52b278a9b7e9cefea29aae0Chad Rosierbool ASTContext::BitfieldFollowsNonBitfield(const FieldDecl *FD, 98552bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian const FieldDecl *LastFD) const { 98652bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian return (FD->isBitField() && LastFD && !LastFD->isBitField() && 987a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith FD->getBitWidthValue(*this)); 98852bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian} 98952bbe7a1133c3cb57e9246f1b96c12940ea3821aFariborz Jahanian 9907d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_cxx_method_iterator 9917d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_methods_begin(const CXXMethodDecl *Method) const { 9927d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 9937d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor = OverriddenMethods.find(Method); 9947d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor if (Pos == OverriddenMethods.end()) 9957d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return 0; 9967d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 9977d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return Pos->second.begin(); 9987d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 9997d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 10007d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_cxx_method_iterator 10017d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas GregorASTContext::overridden_methods_end(const CXXMethodDecl *Method) const { 10027d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 10037d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor = OverriddenMethods.find(Method); 10047d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor if (Pos == OverriddenMethods.end()) 10057d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return 0; 10067d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 10077d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor return Pos->second.end(); 10087d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 10097d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 1010c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidisunsigned 1011c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios KyrtzidisASTContext::overridden_methods_size(const CXXMethodDecl *Method) const { 1012c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos 1013c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis = OverriddenMethods.find(Method); 1014c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis if (Pos == OverriddenMethods.end()) 1015c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis return 0; 1016c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis 1017c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis return Pos->second.size(); 1018c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis} 1019c91e9f439ae85d5f79a6b65672f1d7d1b55ccda0Argyrios Kyrtzidis 10207d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregorvoid ASTContext::addOverriddenMethod(const CXXMethodDecl *Method, 10217d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor const CXXMethodDecl *Overridden) { 10227d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor OverriddenMethods[Method].push_back(Overridden); 10237d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor} 10247d10b7eb670b821741b4c96f6cf7afbc3bb39abeDouglas Gregor 1025e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregorvoid ASTContext::addedLocalImportDecl(ImportDecl *Import) { 1026e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor assert(!Import->NextLocalImport && "Import declaration already in the chain"); 1027e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor assert(!Import->isFromASTFile() && "Non-local import declaration"); 1028e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor if (!FirstLocalImport) { 1029e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor FirstLocalImport = Import; 1030e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport = Import; 1031e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor return; 1032e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor } 1033e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor 1034e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport->NextLocalImport = Import; 1035e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor LastLocalImport = Import; 1036e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor} 1037e664977aca2a05a77abab5a06dc0fb69e870cfb9Douglas Gregor 1038464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 1039464175bba1318bef7905122e9fda20cff926df78Chris Lattner// Type Sizing and Analysis 1040464175bba1318bef7905122e9fda20cff926df78Chris Lattner//===----------------------------------------------------------------------===// 1041a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1042b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 1043b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner/// scalar floating point type. 1044b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattnerconst llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { 1045183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const BuiltinType *BT = T->getAs<BuiltinType>(); 1046b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner assert(BT && "Not a floating point type!"); 1047b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner switch (BT->getKind()) { 1048b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Not a floating point type!"); 1049aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: return Target->getHalfFormat(); 1050bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::Float: return Target->getFloatFormat(); 1051bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::Double: return Target->getDoubleFormat(); 1052bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor case BuiltinType::LongDouble: return Target->getLongDoubleFormat(); 1053b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner } 1054b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner} 1055b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 10568b752f10c394b140f9ef89e049cbad1a7676fc25Ken Dyck/// getDeclAlign - Return a conservative estimate of the alignment of the 1057af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// specified decl. Note that bitfields do not have a valid alignment, so 1058af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner/// this method will assert on them. 10595d484e8cf710207010720589d89602233de61d01Sebastian Redl/// If @p RefAsPointee, references are treated like their underlying type 10605d484e8cf710207010720589d89602233de61d01Sebastian Redl/// (for alignof), else they're treated like pointers (for CodeGen). 10614ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const { 1062bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned Align = Target->getCharWidth(); 1063dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 10644081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall bool UseAlignAttrOnly = false; 10654081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (unsigned AlignFromAttr = D->getMaxAlignment()) { 10664081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall Align = AlignFromAttr; 10674081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall 10684081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // __attribute__((aligned)) can increase or decrease alignment 10694081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // *except* on a struct or struct member, where it only increases 10704081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // alignment unless 'packed' is also specified. 10714081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // 107282d0b0aab9088e977c2a44c4a5a90479c63149fePeter Collingbourne // It is an error for alignas to decrease alignment, so we can 10734081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall // ignore that possibility; Sema should diagnose it. 10744081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (isa<FieldDecl>(D)) { 10754081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall UseAlignAttrOnly = D->hasAttr<PackedAttr>() || 10764081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); 10774081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } else { 10784081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall UseAlignAttrOnly = true; 10794081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } 10804081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } 108178a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian else if (isa<FieldDecl>(D)) 108278a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian UseAlignAttrOnly = 108378a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian D->hasAttr<PackedAttr>() || 108478a7d7d79964119a3f35b262eb154b5cbf1001edFariborz Jahanian cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>(); 1085dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 1086ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // If we're using the align attribute only, just ignore everything 1087ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // else about the declaration and its type. 10884081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall if (UseAlignAttrOnly) { 1089ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // do nothing 1090ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 10914081a5c5f1381c4ec77f8ab3866693917e4329c4John McCall } else if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 1092af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner QualType T = VD->getType(); 10936217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const ReferenceType* RT = T->getAs<ReferenceType>()) { 10945d484e8cf710207010720589d89602233de61d01Sebastian Redl if (RefAsPointee) 10955d484e8cf710207010720589d89602233de61d01Sebastian Redl T = RT->getPointeeType(); 10965d484e8cf710207010720589d89602233de61d01Sebastian Redl else 10975d484e8cf710207010720589d89602233de61d01Sebastian Redl T = getPointerType(RT->getPointeeType()); 10985d484e8cf710207010720589d89602233de61d01Sebastian Redl } 10995d484e8cf710207010720589d89602233de61d01Sebastian Redl if (!T->isIncompleteType() && !T->isFunctionType()) { 11003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Adjust alignments of declarations with array type by the 11013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // large-array alignment on the target. 1102bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor unsigned MinWidth = Target->getLargeArrayMinWidth(); 11033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const ArrayType *arrayType; 11043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (MinWidth && (arrayType = getAsArrayType(T))) { 11053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (isa<VariableArrayType>(arrayType)) 1106bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = std::max(Align, Target->getLargeArrayAlign()); 11073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall else if (isa<ConstantArrayType>(arrayType) && 11083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall MinWidth <= getTypeSize(cast<ConstantArrayType>(arrayType))) 1109bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = std::max(Align, Target->getLargeArrayAlign()); 11103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 11113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Walk through any array types while we're at it. 11123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall T = getBaseElementType(arrayType); 11136deecb0d46bcfd048e651d2db7c4fb0d6407da96Rafael Espindola } 11149f1210c3280104417a4ad30f0a00825ac8fa718aChad Rosier Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); 1115dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman } 1116ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1117ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Fields can be subject to extra alignment constraints, like if 1118ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // the field is packed, the struct is packed, or the struct has a 1119ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // a max-field-alignment constraint (#pragma pack). So calculate 1120ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // the actual alignment of the field within the struct, and then 1121ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // (as we're expected to) constrain that by the alignment of the type. 1122ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (const FieldDecl *field = dyn_cast<FieldDecl>(VD)) { 1123ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // So calculate the alignment of the field. 1124ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall const ASTRecordLayout &layout = getASTRecordLayout(field->getParent()); 1125ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1126ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Start with the record's overall alignment. 1127dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck unsigned fieldAlign = toBits(layout.getAlignment()); 1128ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1129ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Use the GCD of that and the offset within the record. 1130ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall uint64_t offset = layout.getFieldOffset(field->getFieldIndex()); 1131ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (offset > 0) { 1132ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // Alignment is always a power of 2, so the GCD will be a power of 2, 1133ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall // which means we get to do this crazy thing instead of Euclid's. 1134ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall uint64_t lowBitOfOffset = offset & (~offset + 1); 1135ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall if (lowBitOfOffset < fieldAlign) 1136ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall fieldAlign = static_cast<unsigned>(lowBitOfOffset); 1137ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall } 1138ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall 1139ba4f5d5754c8291690d01ca9581926673d69b24cJohn McCall Align = std::min(Align, fieldAlign); 114005f62474dd2b0f1cb69adbe0787f2868788aa949Charles Davis } 1141af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner } 1142dcdafb6a701aa9d81edcb088915f58933315dc05Eli Friedman 1143eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(Align); 1144af707ab8fbb9451e8febb8d766f6c043628125c4Chris Lattner} 1145b7cfe88e88cb4f46308de89cf3f0c81bfe624128Chris Lattner 1146929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// getTypeInfoDataSizeInChars - Return the size of a type, in 1147929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// chars. If the type is a record, its data size is returned. This is 1148929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// the size of the memcpy that's performed when assigning this type 1149929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall// using a trivial copy/move assignment operator. 1150929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCallstd::pair<CharUnits, CharUnits> 1151929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCallASTContext::getTypeInfoDataSizeInChars(QualType T) const { 1152929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall std::pair<CharUnits, CharUnits> sizeAndAlign = getTypeInfoInChars(T); 1153929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall 1154929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall // In C++, objects can sometimes be allocated into the tail padding 1155929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall // of a base-class subobject. We decide whether that's possible 1156929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall // during class layout, so here we can just trust the layout results. 1157929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall if (getLangOpts().CPlusPlus) { 1158929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall if (const RecordType *RT = T->getAs<RecordType>()) { 1159929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall const ASTRecordLayout &layout = getASTRecordLayout(RT->getDecl()); 1160929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall sizeAndAlign.first = layout.getDataSize(); 1161929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall } 1162929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall } 1163929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall 1164929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall return sizeAndAlign; 1165929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall} 1166929bbfb0b69165b55da3c56abf22aa10e20dadc6John McCall 1167ea1471e0e967548c596a71469702f8846dbaf3c0John McCallstd::pair<CharUnits, CharUnits> 1168bee5a79fc95e3003d755031e3d2bb4410a71e1c1Ken DyckASTContext::getTypeInfoInChars(const Type *T) const { 1169ea1471e0e967548c596a71469702f8846dbaf3c0John McCall std::pair<uint64_t, unsigned> Info = getTypeInfo(T); 1170eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return std::make_pair(toCharUnitsFromBits(Info.first), 1171eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck toCharUnitsFromBits(Info.second)); 1172ea1471e0e967548c596a71469702f8846dbaf3c0John McCall} 1173ea1471e0e967548c596a71469702f8846dbaf3c0John McCall 1174ea1471e0e967548c596a71469702f8846dbaf3c0John McCallstd::pair<CharUnits, CharUnits> 1175bee5a79fc95e3003d755031e3d2bb4410a71e1c1Ken DyckASTContext::getTypeInfoInChars(QualType T) const { 1176ea1471e0e967548c596a71469702f8846dbaf3c0John McCall return getTypeInfoInChars(T.getTypePtr()); 1177ea1471e0e967548c596a71469702f8846dbaf3c0John McCall} 1178ea1471e0e967548c596a71469702f8846dbaf3c0John McCall 1179bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbarstd::pair<uint64_t, unsigned> ASTContext::getTypeInfo(const Type *T) const { 1180bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar TypeInfoMap::iterator it = MemoizedTypeInfo.find(T); 1181bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar if (it != MemoizedTypeInfo.end()) 1182bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar return it->second; 1183bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar 1184bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar std::pair<uint64_t, unsigned> Info = getTypeInfoImpl(T); 1185bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar MemoizedTypeInfo.insert(std::make_pair(T, Info)); 1186bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar return Info; 1187bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar} 1188bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar 1189bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar/// getTypeInfoImpl - Return the size of the specified type, in bits. This 1190bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar/// method does not work on incomplete types. 11910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// 11920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// FIXME: Pointers into different addr spaces could have different sizes and 11930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// alignment requirements: getPointerInfo should take an AddrSpace, this 11940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall/// should take a QualType, &c. 1195d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattnerstd::pair<uint64_t, unsigned> 1196bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel DunbarASTContext::getTypeInfoImpl(const Type *T) const { 11975e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump uint64_t Width=0; 11985e301007e31e14c8ff647288e1b8bd8dbf8a5fe4Mike Stump unsigned Align=8; 1199a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (T->getTypeClass()) { 120072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 120172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 120218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor#define NON_CANONICAL_TYPE(Class, Base) 120372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 120472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 1205d3d49bb27c7ffd9accc0a6c00e887111c0348845John McCall llvm_unreachable("Should not see dependent types"); 120672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 12075d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionNoProto: 12085d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::FunctionProto: 120918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(function) = 32 bits 121018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 121118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 32; 121218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 121318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 121472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 1215fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::VariableArray: 121618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 121718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = getTypeAlign(cast<ArrayType>(T)->getElementType()); 121818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 121918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 1220fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff case Type::ConstantArray: { 12211d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ConstantArrayType *CAT = cast<ConstantArrayType>(T); 12221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 122398be4943e8dc4f3905629a7102668960873cf863Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(CAT->getElementType()); 1224fea966a4103ed9c018d1494b95e9d09b161f5a70Abramo Bagnara uint64_t Size = CAT->getSize().getZExtValue(); 1225bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar assert((Size == 0 || EltInfo.first <= (uint64_t)(-1)/Size) && 1226bc5419a2edc4030d1a623576fe339fbd3eed17a6Daniel Dunbar "Overflow in array type bit size evaluation"); 1227fea966a4103ed9c018d1494b95e9d09b161f5a70Abramo Bagnara Width = EltInfo.first*Size; 1228030d8846c7e520330007087e949f621989876e3aChris Lattner Align = EltInfo.second; 1229cd88b4171753dcb2bc0a21d78f1597c796bb8a20Argyrios Kyrtzidis Width = llvm::RoundUpToAlignment(Width, Align); 1230030d8846c7e520330007087e949f621989876e3aChris Lattner break; 12315c09a02a5db85e08a432b6eeced9aa656349710dChristopher Lamb } 1232213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case Type::ExtVector: 1233030d8846c7e520330007087e949f621989876e3aChris Lattner case Type::Vector: { 12349fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner const VectorType *VT = cast<VectorType>(T); 12359fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner std::pair<uint64_t, unsigned> EltInfo = getTypeInfo(VT->getElementType()); 12369fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Width = EltInfo.first*VT->getNumElements(); 12374bd998bbc228915d2b9cae5b67879de48940d05eEli Friedman Align = Width; 12386fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // If the alignment is not a power of 2, round up to the next power of 2. 12396fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman // This happens for non-power-of-2 length vectors. 12408eefcd353c1d06a10104f69e5079ebab3183f9a3Dan Gohman if (Align & (Align-1)) { 12419fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Align = llvm::NextPowerOf2(Align); 12429fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner Width = llvm::RoundUpToAlignment(Width, Align); 12439fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner } 1244f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier // Adjust the alignment based on the target max. 1245f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier uint64_t TargetVectorAlign = Target->getMaxVectorAlign(); 1246f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier if (TargetVectorAlign && TargetVectorAlign < Align) 1247f9e9af7df0cea6e997ac04131c7af6ca4384b0ccChad Rosier Align = TargetVectorAlign; 1248030d8846c7e520330007087e949f621989876e3aChris Lattner break; 1249030d8846c7e520330007087e949f621989876e3aChris Lattner } 12505d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner 12519e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner case Type::Builtin: 1252a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 1253b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown builtin type!"); 1254d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner case BuiltinType::Void: 125518857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor // GCC extension: alignof(void) = 8 bits. 125618857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Width = 0; 125718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor Align = 8; 125818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor break; 125918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 12606f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Bool: 1261bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getBoolWidth(); 1262bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getBoolAlign(); 12636f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1264692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_S: 1265692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::Char_U: 1266692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UChar: 12676f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::SChar: 1268bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getCharWidth(); 1269bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getCharAlign(); 12706f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 12713f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 12723f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 1273bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getWCharWidth(); 1274bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getWCharAlign(); 127564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis break; 1276f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char16: 1277bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getChar16Width(); 1278bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getChar16Align(); 1279f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1280f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith case BuiltinType::Char32: 1281bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getChar32Width(); 1282bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getChar32Align(); 1283f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith break; 1284692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UShort: 12856f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Short: 1286bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getShortWidth(); 1287bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getShortAlign(); 12886f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1289692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::UInt: 12906f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Int: 1291bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getIntWidth(); 1292bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getIntAlign(); 12936f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1294692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULong: 12956f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Long: 1296bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongWidth(); 1297bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongAlign(); 12986f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1299692233e90a99c3a81dd04879d36eb9688f137c44Chris Lattner case BuiltinType::ULongLong: 13006f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongLong: 1301bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongLongWidth(); 1302bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongLongAlign(); 13036f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1304ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::Int128: 1305ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner case BuiltinType::UInt128: 1306ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Width = 128; 1307ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner Align = 128; // int128_t is 128-bit aligned on all targets. 1308ec16cb9b5a481d62a73ad47fa59034ced4d62022Chris Lattner break; 1309aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: 1310aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov Width = Target->getHalfWidth(); 1311aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov Align = Target->getHalfAlign(); 1312aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov break; 13136f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Float: 1314bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getFloatWidth(); 1315bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getFloatAlign(); 13166f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 13176f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::Double: 1318bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getDoubleWidth(); 1319bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getDoubleAlign(); 13206f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 13216f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner case BuiltinType::LongDouble: 1322bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getLongDoubleWidth(); 1323bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getLongDoubleAlign(); 13246f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 13256e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl case BuiltinType::NullPtr: 1326bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); // C++ 3.9.1p11: sizeof(nullptr_t) 1327bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); // == sizeof(void*) 13281590d9c0fec4c710c2962e4bb71f76979b5163d3Sebastian Redl break; 1329e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCId: 1330e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCClass: 1331e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian case BuiltinType::ObjCSel: 1332bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); 1333bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); 1334e04f5fc25cf49e8a5b836459d836c20dc3229a95Fariborz Jahanian break; 1335a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 1336bfef6d7c67831a135d6ab79931f010f750a730adChris Lattner break; 1337d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff case Type::ObjCObjectPointer: 1338bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(0); 1339bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(0); 13406f62c2abd8077bf70d2166d37e8caa426b34d8e4Chris Lattner break; 1341485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff case Type::BlockPointer: { 1342207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace( 1343207f4d8543529221932af82836016a2ef066c917Peter Collingbourne cast<BlockPointerType>(T)->getPointeeType()); 1344bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1345bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 1346485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff break; 1347485eeff9ba73376c8e01179bf1a501b1723446cbSteve Naroff } 13485d484e8cf710207010720589d89602233de61d01Sebastian Redl case Type::LValueReference: 13495d484e8cf710207010720589d89602233de61d01Sebastian Redl case Type::RValueReference: { 13505d484e8cf710207010720589d89602233de61d01Sebastian Redl // alignof and sizeof should never enter this code path here, so we go 13515d484e8cf710207010720589d89602233de61d01Sebastian Redl // the pointer route. 1352207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace( 1353207f4d8543529221932af82836016a2ef066c917Peter Collingbourne cast<ReferenceType>(T)->getPointeeType()); 1354bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1355bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 13565d484e8cf710207010720589d89602233de61d01Sebastian Redl break; 13575d484e8cf710207010720589d89602233de61d01Sebastian Redl } 1358f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner case Type::Pointer: { 1359207f4d8543529221932af82836016a2ef066c917Peter Collingbourne unsigned AS = getTargetAddressSpace(cast<PointerType>(T)->getPointeeType()); 1360bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Width = Target->getPointerWidth(AS); 1361bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor Align = Target->getPointerAlign(AS); 1362f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner break; 1363f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643Chris Lattner } 1364f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl case Type::MemberPointer: { 1365071cc7deffad608165b1ddd5263e8bf181861520Charles Davis const MemberPointerType *MPT = cast<MemberPointerType>(T); 13661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> PtrDiffInfo = 13671cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson getTypeInfo(getPointerDiffType()); 1368071cc7deffad608165b1ddd5263e8bf181861520Charles Davis Width = PtrDiffInfo.first * ABI->getMemberPointerSize(MPT); 13691cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson Align = PtrDiffInfo.second; 13701cca74ef3627a3a0ab14501d23e336548f6611b2Anders Carlsson break; 1371f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 13725d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner case Type::Complex: { 13735d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // Complex types have the same alignment as their elements, but twice the 13745d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner // size. 13751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump std::pair<uint64_t, unsigned> EltInfo = 137698be4943e8dc4f3905629a7102668960873cf863Chris Lattner getTypeInfo(cast<ComplexType>(T)->getElementType()); 13779e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner Width = EltInfo.first*2; 13785d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner Align = EltInfo.second; 13795d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner break; 13805d2a6303467184b1f159bb6556efc434e50e3c28Chris Lattner } 1381c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCObject: 1382c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr()); 138344a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel case Type::ObjCInterface: { 13841d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); 138544a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); 1386dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck Width = toBits(Layout.getSize()); 1387dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck Align = toBits(Layout.getAlignment()); 138844a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel break; 138944a3dded8080c5c9cfdad208ade8f8f7850d9a4fDevang Patel } 139072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 139172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: { 13921d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const TagType *TT = cast<TagType>(T); 13931d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar 13941d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (TT->getDecl()->isInvalidDecl()) { 139522ce41d9fc8509da65858c75bf5b3c4dae2d8c04Douglas Gregor Width = 8; 139622ce41d9fc8509da65858c75bf5b3c4dae2d8c04Douglas Gregor Align = 8; 13978389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner break; 13988389eab190afef3462f6418b8d8fb70fb01c4005Chris Lattner } 13991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14001d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar if (const EnumType *ET = dyn_cast<EnumType>(TT)) 14017176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner return getTypeInfo(ET->getDecl()->getIntegerType()); 14027176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner 14031d75118af76cae2bfc06389cde410e14bd0a19fcDaniel Dunbar const RecordType *RT = cast<RecordType>(TT); 14047176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); 1405dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck Width = toBits(Layout.getSize()); 1406dac54c124e302d6f028ea5723c425b7f66fc7c71Ken Dyck Align = toBits(Layout.getAlignment()); 1407dc0d73e6495404418acf8548875aeaff07791a74Chris Lattner break; 1408a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner } 14097532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 14109fcfe926432f3c3f7e9a61219e55c352fd358e45Chris Lattner case Type::SubstTemplateTypeParm: 141149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return getTypeInfo(cast<SubstTemplateTypeParmType>(T)-> 141249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall getReplacementType().getTypePtr()); 141349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 141434b41d939a1328f484511c6002ba2456db879a29Richard Smith case Type::Auto: { 141534b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *A = cast<AutoType>(T); 141634b41d939a1328f484511c6002ba2456db879a29Richard Smith assert(A->isDeduced() && "Cannot request the size of a dependent type"); 1417dc856aff4428380baa9afb5577ea04f8fb6beb13Matt Beaumont-Gay return getTypeInfo(A->getDeducedType().getTypePtr()); 141834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 141934b41d939a1328f484511c6002ba2456db879a29Richard Smith 1420075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara case Type::Paren: 1421075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr()); 1422075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 142318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::Typedef: { 1424162e1c1b487352434552147967c3dd296ebee2f7Richard Smith const TypedefNameDecl *Typedef = cast<TypedefType>(T)->getDecl(); 1425df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor std::pair<uint64_t, unsigned> Info 1426df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor = getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); 1427c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // If the typedef has an aligned attribute on it, it overrides any computed 1428c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // alignment we have. This violates the GCC documentation (which says that 1429c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner // attribute(aligned) can only round up) but matches its implementation. 1430c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner if (unsigned AttrAlign = Typedef->getMaxAlignment()) 1431c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner Align = AttrAlign; 1432c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner else 1433c1de52de64725945e5ae87e6f99ddedf161856e5Chris Lattner Align = Info.second; 1434df1367af26cb2959775e9511108f12dcd2370a27Douglas Gregor Width = Info.first; 14357532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor break; 14367176331b0f5cfaaa2b5aa487a6660e859e371119Chris Lattner } 143718857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 143818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOfExpr: 143918857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType() 144018857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor .getTypePtr()); 144118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 144218857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor case Type::TypeOf: 144318857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor return getTypeInfo(cast<TypeOfType>(T)->getUnderlyingType().getTypePtr()); 144418857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor 1445395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson case Type::Decltype: 1446395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return getTypeInfo(cast<DecltypeType>(T)->getUnderlyingExpr()->getType() 1447395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson .getTypePtr()); 1448395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 1449ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case Type::UnaryTransform: 1450ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return getTypeInfo(cast<UnaryTransformType>(T)->getUnderlyingType()); 1451ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 1452465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara case Type::Elaborated: 1453465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr()); 14541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall case Type::Attributed: 14569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return getTypeInfo( 14579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall cast<AttributedType>(T)->getEquivalentType().getTypePtr()); 14589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 14593e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith case Type::TemplateSpecialization: { 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(getCanonicalType(T) != T && 146118857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor "Cannot request the size of a dependent type"); 14623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith const TemplateSpecializationType *TST = cast<TemplateSpecializationType>(T); 14633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // A type alias template specialization may refer to a typedef with the 14643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // aligned attribute on it. 14653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (TST->isTypeAlias()) 14663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return getTypeInfo(TST->getAliasedType().getTypePtr()); 14673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else 14683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return getTypeInfo(getCanonicalType(T)); 14693e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 14703e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 1471b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: { 14722be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman std::pair<uint64_t, unsigned> Info 14732be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman = getTypeInfo(cast<AtomicType>(T)->getValueType()); 14742be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Width = Info.first; 14752be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Align = Info.second; 14762be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman if (Width != 0 && Width <= Target->getMaxAtomicPromoteWidth() && 14772be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman llvm::isPowerOf2_64(Width)) { 14782be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // We can potentially perform lock-free atomic operations for this 14792be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // type; promote the alignment appropriately. 14802be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // FIXME: We could potentially promote the width here as well... 14812be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // is that worthwhile? (Non-struct atomic types generally have 14822be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // power-of-two size anyway, but structs might not. Requires a bit 14832be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman // of implementation work to make sure we zero out the extra bits.) 14842be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman Align = static_cast<unsigned>(Width); 14852be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman } 1486b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 1487b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 148818857644059c45da6776f1a288eec7b4cf3a844aDouglas Gregor } 14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14902be460723940f8184ec36529b6f6ddf59c04e411Eli Friedman assert(llvm::isPowerOf2_32(Align) && "Alignment must be power of 2"); 14919e9b6dc3fd413f5341fab54b681420eeb21cd169Chris Lattner return std::make_pair(Width, Align); 1492a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner} 1493a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1494eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck/// toCharUnitsFromBits - Convert a size in bits to a size in characters. 1495eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen DyckCharUnits ASTContext::toCharUnitsFromBits(int64_t BitSize) const { 1496eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return CharUnits::fromQuantity(BitSize / getCharWidth()); 1497eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck} 1498eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck 1499dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck/// toBits - Convert a size in characters to a size in characters. 1500dd76a9ab9ea675671200f94b18ce95766841952bKen Dyckint64_t ASTContext::toBits(CharUnits CharSize) const { 1501dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck return CharSize.getQuantity() * getCharWidth(); 1502dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck} 1503dd76a9ab9ea675671200f94b18ce95766841952bKen Dyck 1504bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck/// getTypeSizeInChars - Return the size of the specified type, in characters. 1505bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck/// This method does not work on incomplete types. 15064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeSizeInChars(QualType T) const { 1507eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeSize(T)); 1508bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck} 15094ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeSizeInChars(const Type *T) const { 1510eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeSize(T)); 1511bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck} 1512bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck 151316e20cce43385001f33f8e3f90ee345609c805d1Ken Dyck/// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 151486fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck/// characters. This method does not work on incomplete types. 15154ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeAlignInChars(QualType T) const { 1516eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeAlign(T)); 151786fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck} 15184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getTypeAlignInChars(const Type *T) const { 1519eb6f5dc86531f794ba7746a2da4d28e37cf5da7eKen Dyck return toCharUnitsFromBits(getTypeAlign(T)); 152086fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck} 152186fa4311c8a330957ff5b765fbb0a7750ecd38c9Ken Dyck 152234ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// getPreferredTypeAlign - Return the "preferred" alignment of the specified 152334ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// type for the current target in bits. This can be different than the ABI 152434ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// alignment in cases where it is beneficial for performance to overalign 152534ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner/// a data type. 15264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::getPreferredTypeAlign(const Type *T) const { 152734ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner unsigned ABIAlign = getTypeAlign(T); 15281eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 15291eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman // Double and long long should be naturally aligned if possible. 1530183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType* CT = T->getAs<ComplexType>()) 15311eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman T = CT->getElementType().getTypePtr(); 15321eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman if (T->isSpecificBuiltinType(BuiltinType::Double) || 1533cde7a1dc68af2eb063a039b5a31c3b7dd92b1aa9Chad Rosier T->isSpecificBuiltinType(BuiltinType::LongLong) || 1534cde7a1dc68af2eb063a039b5a31c3b7dd92b1aa9Chad Rosier T->isSpecificBuiltinType(BuiltinType::ULongLong)) 15351eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman return std::max(ABIAlign, (unsigned)getTypeSize(T)); 15361eed60297ef4701b899c6a3b9680bf08f3403422Eli Friedman 153734ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner return ABIAlign; 153834ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner} 153934ebde404dc17d89487b07e6daaf1b47d5dfee39Chris Lattner 15402c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// DeepCollectObjCIvars - 15412c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// This routine first collects all declared, but not synthesized, ivars in 15422c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// super class and then collects all ivars, including those synthesized for 15432c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// current class. This routine is used for implementation of current class 15442c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian/// when all ivars, declared and synthesized are known. 15459820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian/// 15462c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanianvoid ASTContext::DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, 15472c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian bool leafClass, 1548db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const { 15492c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (const ObjCInterfaceDecl *SuperClass = OI->getSuperClass()) 15502c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian DeepCollectObjCIvars(SuperClass, false, Ivars); 15512c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (!leafClass) { 15522c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), 15532c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian E = OI->ivar_end(); I != E; ++I) 1554581deb3da481053c4993c7600f97acf7768caac5David Blaikie Ivars.push_back(*I); 15553060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 1556bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian ObjCInterfaceDecl *IDecl = const_cast<ObjCInterfaceDecl *>(OI); 1557db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose for (const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv; 1558bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian Iv= Iv->getNextIvar()) 1559bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian Ivars.push_back(Iv); 1560bf9eb88792e022e54a658657bf22e1925948e384Fariborz Jahanian } 15619820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian} 15629820074dd47d37681085e964cd3392ac0b3e67b9Fariborz Jahanian 1563e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// CollectInheritedProtocols - Collect all protocols in current class and 1564e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// those inherited by it. 1565e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianvoid ASTContext::CollectInheritedProtocols(const Decl *CDecl, 1566432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols) { 1567e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (const ObjCInterfaceDecl *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) { 156853b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek // We can use protocol_iterator here instead of 156953b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek // all_referenced_protocol_iterator since we are walking all categories. 157053b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek for (ObjCInterfaceDecl::all_protocol_iterator P = OI->all_referenced_protocol_begin(), 157153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek PE = OI->all_referenced_protocol_end(); P != PE; ++P) { 1572e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 15733fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1574e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1575b2f812165676230bce5d0215e49a4749c451ca9cFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) { 15763fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert((*P)->getCanonicalDecl()); 1577e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1578e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1579b2f812165676230bce5d0215e49a4749c451ca9cFariborz Jahanian } 1580e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 1581e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian // Categories of this Interface. 1582e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (const ObjCCategoryDecl *CDeclChain = OI->getCategoryList(); 1583e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CDeclChain; CDeclChain = CDeclChain->getNextClassCategory()) 1584e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(CDeclChain, Protocols); 1585e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (ObjCInterfaceDecl *SD = OI->getSuperClass()) 1586e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian while (SD) { 1587e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(SD, Protocols); 1588e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian SD = SD->getSuperClass(); 1589e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1590b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer } else if (const ObjCCategoryDecl *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) { 159153b9441b5a81a24fa1f66f3f6416f1e36baa9c2fTed Kremenek for (ObjCCategoryDecl::protocol_iterator P = OC->protocol_begin(), 1592e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = OC->protocol_end(); P != PE; ++P) { 1593e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 15943fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1595e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1596e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) 1597e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1598e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1599b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer } else if (const ObjCProtocolDecl *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) { 1600e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = OP->protocol_begin(), 1601e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = OP->protocol_end(); P != PE; ++P) { 1602e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian ObjCProtocolDecl *Proto = (*P); 16033fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor Protocols.insert(Proto->getCanonicalDecl()); 1604e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (ObjCProtocolDecl::protocol_iterator P = Proto->protocol_begin(), 1605e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian PE = Proto->protocol_end(); P != PE; ++P) 1606e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian CollectInheritedProtocols(*P, Protocols); 1607e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1608e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 1609e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian} 1610e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 16114ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::CountNonClassIvars(const ObjCInterfaceDecl *OI) const { 16123bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian unsigned count = 0; 16133bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // Count ivars declared in class extension. 161480aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian for (const ObjCCategoryDecl *CDecl = OI->getFirstClassExtension(); CDecl; 161580aa1cd7973561889e51c1c152c8990a8de9c953Fariborz Jahanian CDecl = CDecl->getNextClassExtension()) 1616b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer count += CDecl->ivar_size(); 1617b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer 16183bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // Count ivar defined in this class's implementation. This 16193bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian // includes synthesized ivars. 16203bfacdf6f0706987c1b33c625cd68fb880881c22Fariborz Jahanian if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) 1621b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer count += ImplDecl->ivar_size(); 1622b170ca5f4a8397c10e52050ff5df6885a3e6eca9Benjamin Kramer 16238e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian return count; 16248e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian} 16258e6ac1d80055fa37b9b84029c7e751624ba7f84cFariborz Jahanian 16268deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidisbool ASTContext::isSentinelNullExpr(const Expr *E) { 16278deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (!E) 16288deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return false; 16298deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 16308deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis // nullptr_t is always treated as null. 16318deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (E->getType()->isNullPtrType()) return true; 16328deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 16338deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (E->getType()->isAnyPointerType() && 16348deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis E->IgnoreParenCasts()->isNullPointerConstant(*this, 16358deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis Expr::NPC_ValueDependentIsNull)) 16368deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return true; 16378deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 16388deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis // Unfortunately, __null has type 'int'. 16398deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis if (isa<GNUNullExpr>(E)) return true; 16408deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 16418deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis return false; 16428deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis} 16438deabc133c121f6c5561d0b2171a41cb2c29b2ceArgyrios Kyrtzidis 16448a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 16458a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCImplementationDecl *ASTContext::getObjCImplementation(ObjCInterfaceDecl *D) { 16468a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 16478a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 16488a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 16498a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCImplementationDecl>(I->second); 16508a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 16518a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 16528a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 16538a1d722f13df383600f36d77f842957c8adb5f1bArgyrios KyrtzidisObjCCategoryImplDecl *ASTContext::getObjCImplementation(ObjCCategoryDecl *D) { 16548a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator 16558a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis I = ObjCImpls.find(D); 16568a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis if (I != ObjCImpls.end()) 16578a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return cast<ObjCCategoryImplDecl>(I->second); 16588a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis return 0; 16598a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 16608a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 16618a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCInterfaceDecl. 16628a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCInterfaceDecl *IFaceD, 16638a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImplementationDecl *ImplD) { 16648a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(IFaceD && ImplD && "Passed null params"); 16658a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[IFaceD] = ImplD; 16668a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 16678a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis/// \brief Set the implementation of ObjCCategoryDecl. 16688a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidisvoid ASTContext::setObjCImplementation(ObjCCategoryDecl *CatD, 16698a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCCategoryImplDecl *ImplD) { 16708a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis assert(CatD && ImplD && "Passed null params"); 16718a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis ObjCImpls[CatD] = ImplD; 16728a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis} 16738a1d722f13df383600f36d77f842957c8adb5f1bArgyrios Kyrtzidis 167487ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios KyrtzidisObjCInterfaceDecl *ASTContext::getObjContainingInterface(NamedDecl *ND) const { 167587ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ND->getDeclContext())) 167687ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return ID; 167787ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ND->getDeclContext())) 167887ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return CD->getClassInterface(); 167987ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(ND->getDeclContext())) 168087ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return IMD->getClassInterface(); 168187ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis 168287ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis return 0; 168387ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis} 168487ec9c257c99b4136af6c7f5be5a2d486906ba84Argyrios Kyrtzidis 16851ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// \brief Get the copy initialization expression of VarDecl,or NULL if 16861ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// none exists. 1687830937bc1100fba7682f7c32c40512085870f50cFariborz JahanianExpr *ASTContext::getBlockVarCopyInits(const VarDecl*VD) { 1688d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD && "Passed null params"); 1689d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD->hasAttr<BlocksAttr>() && 1690d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian "getBlockVarCopyInits - not __block var"); 1691830937bc1100fba7682f7c32c40512085870f50cFariborz Jahanian llvm::DenseMap<const VarDecl*, Expr*>::iterator 1692d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian I = BlockVarCopyInits.find(VD); 16931ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian return (I != BlockVarCopyInits.end()) ? cast<Expr>(I->second) : 0; 16941ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian} 16951ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian 16961ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian/// \brief Set the copy inialization expression of a block var decl. 16971ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanianvoid ASTContext::setBlockVarCopyInits(VarDecl*VD, Expr* Init) { 16981ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian assert(VD && Init && "Passed null params"); 1699d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian assert(VD->hasAttr<BlocksAttr>() && 1700d016ec204c54d766c4561d43548551ffde0e6b43Fariborz Jahanian "setBlockVarCopyInits - not __block var"); 17011ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian BlockVarCopyInits[VD] = Init; 17021ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian} 17031ceee5c42d5c410217f67d384eecc6ea4a2bba9bFariborz Jahanian 1704a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo *ASTContext::CreateTypeSourceInfo(QualType T, 17054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned DataSize) const { 1706109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall if (!DataSize) 1707109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall DataSize = TypeLoc::getFullDataSizeForType(T); 1708109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall else 1709109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall assert(DataSize == TypeLoc::getFullDataSizeForType(T) && 1710a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall "incorrect data size provided to CreateTypeSourceInfo!"); 1711109de5ead1dfcb3bc985cddb8cb3ed5bcecad88dJohn McCall 1712a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *TInfo = 1713a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall (TypeSourceInfo*)BumpAlloc.Allocate(sizeof(TypeSourceInfo) + DataSize, 8); 1714a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall new (TInfo) TypeSourceInfo(T); 1715a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TInfo; 1716b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis} 1717b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis 1718a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCallTypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T, 17196952f1e4256c5b43aee5e98cea4e9b663bd1d413Douglas Gregor SourceLocation L) const { 1720a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = CreateTypeSourceInfo(T); 1721c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor DI->getTypeLoc().initialize(const_cast<ASTContext &>(*this), L); 1722a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall return DI; 1723a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall} 1724a4eb74d4dfe126c686dc708fec444c85ffb73b47John McCall 1725b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 17264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const { 1727b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D, 0); 1728b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 1729b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 1730b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbarconst ASTRecordLayout & 17314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getASTObjCImplementationLayout( 17324ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const ObjCImplementationDecl *D) const { 1733b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar return getObjCLayout(D->getClassInterface(), D); 1734b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar} 1735b2dbbb99e12806eaaf53b7ccabc32f42b5719443Daniel Dunbar 1736a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1737a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner// Type creation/memoization methods 1738a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner//===----------------------------------------------------------------------===// 1739a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 17404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 17413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallASTContext::getExtQualType(const Type *baseType, Qualifiers quals) const { 17423b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned fastQuals = quals.getFastQualifiers(); 17433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall quals.removeFastQualifiers(); 17440953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 17450953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Check if we've already instantiated this type. 17460953e767ff7817f97b3ab20896b229891eeff45bJohn McCall llvm::FoldingSetNodeID ID; 17473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals::Profile(ID, baseType, quals); 17483b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 17493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) { 17503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(eq->getQualifiers() == quals); 17513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(eq, fastQuals); 17520953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 17530953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 17543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the base type is not canonical, make the appropriate canonical type. 17553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon; 17563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!baseType->isCanonicalUnqualified()) { 17573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = baseType->getCanonicalTypeInternal().split(); 1758200fa53fd420aa8369586f569dbece04930ad6a3John McCall canonSplit.Quals.addConsistentQualifiers(quals); 1759200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getExtQualType(canonSplit.Ty, canonSplit.Quals); 17603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 17613b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Re-find the insert position. 17623b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos); 17633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 17643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 17653b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQuals *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals); 17663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExtQualNodes.InsertNode(eq, insertPos); 17673b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(eq, fastQuals); 17680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall} 17690953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 17704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 17714ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getAddrSpaceQualType(QualType T, unsigned AddressSpace) const { 1772f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType CanT = getCanonicalType(T); 1773f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner if (CanT.getAddressSpace() == AddressSpace) 1774f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner return T; 1775b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner 17760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 17770953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 17780953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 17790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 17801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an address space specified, it cannot get 17820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 17830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasAddressSpace() && 17840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot be in multiple addr spaces!"); 17850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addAddressSpace(AddressSpace); 17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1788ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb} 1789ebb97e98c03f8d7034bd3748a10e35f39a95c289Christopher Lamb 1790b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris LattnerQualType ASTContext::getObjCGCQualType(QualType T, 17914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Qualifiers::GC GCAttr) const { 1792d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian QualType CanT = getCanonicalType(T); 1793b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner if (CanT.getObjCGCAttr() == GCAttr) 1794d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian return T; 17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17967f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall if (const PointerType *ptr = T->getAs<PointerType>()) { 17977f040a9d817cd1c72b565e92abff473510bf9e1dJohn McCall QualType Pointee = ptr->getPointeeType(); 179858f9f2c884af6b72d036b746a016d8031d31cb7aSteve Naroff if (Pointee->isAnyPointerType()) { 17994027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian QualType ResultType = getObjCGCQualType(Pointee, GCAttr); 18004027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian return getPointerType(ResultType); 18014027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 18024027cd1b924e29784a49085b1717f35cdd719146Fariborz Jahanian } 18031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18040953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If we are composing extended qualifiers together, merge together 18050953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // into one ExtQuals node. 18060953e767ff7817f97b3ab20896b229891eeff45bJohn McCall QualifierCollector Quals; 18070953e767ff7817f97b3ab20896b229891eeff45bJohn McCall const Type *TypeNode = Quals.strip(T); 18081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18090953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If this type already has an ObjCGC specified, it cannot get 18100953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // another one. 18110953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert(!Quals.hasObjCGCAttr() && 18120953e767ff7817f97b3ab20896b229891eeff45bJohn McCall "Type cannot have multiple ObjCGCs!"); 18130953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Quals.addObjCGCAttr(GCAttr); 18141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18150953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getExtQualType(TypeNode, Quals); 1816d33d9c0cc0cfdcd0b10f35a6acdfb25da4a64f19Fariborz Jahanian} 1817a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner 1818e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCallconst FunctionType *ASTContext::adjustFunctionType(const FunctionType *T, 1819e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionType::ExtInfo Info) { 1820e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (T->getExtInfo() == Info) 1821e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return T; 1822e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 1823e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall QualType Result; 1824e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall if (const FunctionNoProtoType *FNPT = dyn_cast<FunctionNoProtoType>(T)) { 1825e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Result = getFunctionNoProtoType(FNPT->getResultType(), Info); 1826e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } else { 1827e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall const FunctionProtoType *FPT = cast<FunctionProtoType>(T); 1828e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 1829e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall EPI.ExtInfo = Info; 1830e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall Result = getFunctionType(FPT->getResultType(), FPT->arg_type_begin(), 1831e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall FPT->getNumArgs(), EPI); 1832e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall } 1833e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 1834e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall return cast<FunctionType>(Result.getTypePtr()); 1835e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall} 1836e6a365d772a6b455f1e23ac9ae5f40d65a55a18cJohn McCall 18375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getComplexType - Return the uniqued reference to the type for a complex 18385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// number with the specified element type. 18394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getComplexType(QualType T) const { 18405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 18415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 18425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 18435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType::Profile(ID, T); 18441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 18465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos)) 18475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(CT, 0); 18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 18505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 18515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 1852467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 1853f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getComplexType(getCanonicalType(T)); 18541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 18565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos); 1857c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 18585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18596b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ComplexType *New = new (*this, TypeAlignment) ComplexType(T, Canonical); 18605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 18615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer ComplexTypes.InsertNode(New, InsertPos); 18625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 18635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 18645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getPointerType - Return the uniqued reference to the type for a pointer to 18665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the specified type. 18674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getPointerType(QualType T) const { 18685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 18695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 18705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 18715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType::Profile(ID, T); 18721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 18745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 18755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(PT, 0); 18761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the pointee type isn't canonical, this won't be a canonical type either, 18785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 18795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 1880467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 1881f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getPointerType(getCanonicalType(T)); 18821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 18845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1885c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 18865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 18876b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall PointerType *New = new (*this, TypeAlignment) PointerType(T, Canonical); 18885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 18895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer PointerTypes.InsertNode(New, InsertPos); 18905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 18915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 18925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 18931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getBlockPointerType - Return the uniqued reference to the type for 18945618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff/// a pointer to the specified block. 18954ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockPointerType(QualType T) const { 1896296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff assert(T->isFunctionType() && "block of function types only"); 1897296e8d5fdcf9946f51e866adc8d281379e51efe9Steve Naroff // Unique pointers, to guarantee there is only one block of a particular 18985618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // structure. 18995618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff llvm::FoldingSetNodeID ID; 19005618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType::Profile(ID, T); 19011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19025618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff void *InsertPos = 0; 19035618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff if (BlockPointerType *PT = 19045618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 19055618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(PT, 0); 19061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the block pointee type isn't canonical, this won't be a canonical 19085618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // type either so fill in the canonical type field. 19095618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff QualType Canonical; 1910467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!T.isCanonical()) { 19115618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Canonical = getBlockPointerType(getCanonicalType(T)); 19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19135618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff // Get the new insert position for the node we care about. 19145618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerType *NewIP = 19155618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 1916c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 19175618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff } 19186b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall BlockPointerType *New 19196b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) BlockPointerType(T, Canonical); 19205618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff Types.push_back(New); 19215618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff BlockPointerTypes.InsertNode(New, InsertPos); 19225618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff return QualType(New, 0); 19235618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff} 19245618bd4a52c45fbbb605e3ba885663b2164db8a3Steve Naroff 19257c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getLValueReferenceType - Return the uniqued reference to the type for an 19267c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// lvalue reference to the specified type. 19274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 19284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { 19299625e44c0252485277a340746ed8ac950686156fDouglas Gregor assert(getCanonicalType(T) != OverloadTy && 19309625e44c0252485277a340746ed8ac950686156fDouglas Gregor "Unresolved overloaded function type"); 19319625e44c0252485277a340746ed8ac950686156fDouglas Gregor 19325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique pointers, to guarantee there is only one pointer of a particular 19335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 19345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 193554e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType::Profile(ID, T, SpelledAsLValue); 19365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 19387c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (LValueReferenceType *RT = 19397c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 19405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(RT, 0); 19417c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 194254e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *InnerRef = T->getAs<ReferenceType>(); 194354e14c4db764c0636160d26c5bbf491637c83a76John McCall 19445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the referencee type isn't canonical, this won't be a canonical type 19455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // either, so fill in the canonical type field. 19465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 194754e14c4db764c0636160d26c5bbf491637c83a76John McCall if (!SpelledAsLValue || InnerRef || !T.isCanonical()) { 194854e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); 194954e14c4db764c0636160d26c5bbf491637c83a76John McCall Canonical = getLValueReferenceType(getCanonicalType(PointeeType)); 19507c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 19517c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Get the new insert position for the node we care about. 19527c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceType *NewIP = 19537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 1954c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 19557c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl } 19567c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 19576b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall LValueReferenceType *New 195854e14c4db764c0636160d26c5bbf491637c83a76John McCall = new (*this, TypeAlignment) LValueReferenceType(T, Canonical, 195954e14c4db764c0636160d26c5bbf491637c83a76John McCall SpelledAsLValue); 19607c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl Types.push_back(New); 19617c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl LValueReferenceTypes.InsertNode(New, InsertPos); 196254e14c4db764c0636160d26c5bbf491637c83a76John McCall 19637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(New, 0); 19647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl} 19657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 19667c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// getRValueReferenceType - Return the uniqued reference to the type for an 19677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl/// rvalue reference to the specified type. 19684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getRValueReferenceType(QualType T) const { 19697c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 19707c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // structure. 19717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl llvm::FoldingSetNodeID ID; 197254e14c4db764c0636160d26c5bbf491637c83a76John McCall ReferenceType::Profile(ID, T, false); 19737c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 19747c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl void *InsertPos = 0; 19757c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (RValueReferenceType *RT = 19767c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos)) 19777c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl return QualType(RT, 0); 19787c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 197954e14c4db764c0636160d26c5bbf491637c83a76John McCall const ReferenceType *InnerRef = T->getAs<ReferenceType>(); 198054e14c4db764c0636160d26c5bbf491637c83a76John McCall 19817c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // If the referencee type isn't canonical, this won't be a canonical type 19827c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // either, so fill in the canonical type field. 19837c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl QualType Canonical; 198454e14c4db764c0636160d26c5bbf491637c83a76John McCall if (InnerRef || !T.isCanonical()) { 198554e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T); 198654e14c4db764c0636160d26c5bbf491637c83a76John McCall Canonical = getRValueReferenceType(getCanonicalType(PointeeType)); 19877c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 19885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 19897c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceType *NewIP = 19907c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos); 1991c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 19925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 19935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 19946b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall RValueReferenceType *New 19956b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) RValueReferenceType(T, Canonical); 19965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 19977c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl RValueReferenceTypes.InsertNode(New, InsertPos); 19985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 19995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 20005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2001f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// getMemberPointerType - Return the uniqued reference to the type for a 2002f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl/// member pointer to the specified type, in the specified class. 20034ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getMemberPointerType(QualType T, const Type *Cls) const { 2004f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Unique pointers, to guarantee there is only one pointer of a particular 2005f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // structure. 2006f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl llvm::FoldingSetNodeID ID; 2007f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType::Profile(ID, T, Cls); 2008f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2009f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl void *InsertPos = 0; 2010f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl if (MemberPointerType *PT = 2011f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 2012f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(PT, 0); 2013f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2014f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // If the pointee or class type isn't canonical, this won't be a canonical 2015f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // type either, so fill in the canonical type field. 2016f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl QualType Canonical; 201787c12c4a4667279dacb3d4a93c64b49148a0ff79Douglas Gregor if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) { 2018f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls)); 2019f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 2020f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl // Get the new insert position for the node we care about. 2021f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerType *NewIP = 2022f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 2023c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 2024f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl } 20256b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall MemberPointerType *New 20266b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) MemberPointerType(T, Cls, Canonical); 2027f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl Types.push_back(New); 2028f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl MemberPointerTypes.InsertNode(New, InsertPos); 2029f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl return QualType(New, 0); 2030f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl} 2031f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 20321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getConstantArrayType - Return the unique reference to the type for an 2033fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff/// array of the specified element type. 20341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getConstantArrayType(QualType EltTy, 203538aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner const llvm::APInt &ArySizeIn, 2036c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 203763e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara unsigned IndexTypeQuals) const { 2038923d56d436f750bc1f29db50e641078725558a1bSebastian Redl assert((EltTy->isDependentType() || 2039923d56d436f750bc1f29db50e641078725558a1bSebastian Redl EltTy->isIncompleteType() || EltTy->isConstantSizeType()) && 2040587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman "Constant array of VLAs is illegal!"); 2041587cbdfd95f4b0aaccc14b31f5debe85d5daf7edEli Friedman 204238aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // Convert the array size into a canonical width matching the pointer size for 204338aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner // the target. 204438aeec7299c48cb79523f7f89776fb258c84aeeaChris Lattner llvm::APInt ArySize(ArySizeIn); 20459f71a8f4c7a182a5236da9e747d57cc1d1bd24c2Jay Foad ArySize = 2046bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor ArySize.zextOrTrunc(Target->getPointerWidth(getTargetAddressSpace(EltTy))); 20471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 204963e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ConstantArrayType::Profile(ID, EltTy, ArySize, ASM, IndexTypeQuals); 20501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 20521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (ConstantArrayType *ATP = 20537192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos)) 20545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(ATP, 0); 20551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If the element type isn't canonical or has qualifiers, this won't 20573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // be a canonical type either, so fill in the canonical type field. 20583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType Canon; 20593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { 20603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(EltTy).split(); 2061200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getConstantArrayType(QualType(canonSplit.Ty, 0), ArySize, 206263e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ASM, IndexTypeQuals); 2063200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getQualifiedType(Canon, canonSplit.Quals); 20643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 20655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 20661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ConstantArrayType *NewIP = 20677192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos); 2068c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 20695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 20701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20716b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ConstantArrayType *New = new(*this,TypeAlignment) 207263e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara ConstantArrayType(EltTy, Canon, ArySize, ASM, IndexTypeQuals); 20737192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek ConstantArrayTypes.InsertNode(New, InsertPos); 20745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 20755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 20765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 20775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2078ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// getVariableArrayDecayedType - Turns the given type, which may be 2079ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// variably-modified, into the corresponding type with all the known 2080ce8890371fcdb983ae487c87fa40606a34896ff7John McCall/// sizes replaced with [*]. 2081ce8890371fcdb983ae487c87fa40606a34896ff7John McCallQualType ASTContext::getVariableArrayDecayedType(QualType type) const { 2082ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Vastly most common case. 2083ce8890371fcdb983ae487c87fa40606a34896ff7John McCall if (!type->isVariablyModifiedType()) return type; 2084ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2085ce8890371fcdb983ae487c87fa40606a34896ff7John McCall QualType result; 2086ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2087ce8890371fcdb983ae487c87fa40606a34896ff7John McCall SplitQualType split = type.getSplitDesugaredType(); 2088200fa53fd420aa8369586f569dbece04930ad6a3John McCall const Type *ty = split.Ty; 2089ce8890371fcdb983ae487c87fa40606a34896ff7John McCall switch (ty->getTypeClass()) { 2090ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define TYPE(Class, Base) 2091ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define ABSTRACT_TYPE(Class, Base) 2092ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 2093ce8890371fcdb983ae487c87fa40606a34896ff7John McCall#include "clang/AST/TypeNodes.def" 2094ce8890371fcdb983ae487c87fa40606a34896ff7John McCall llvm_unreachable("didn't desugar past all non-canonical types?"); 2095ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2096ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types should never be variably-modified. 2097ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Builtin: 2098ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Complex: 2099ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Vector: 2100ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ExtVector: 2101ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentSizedExtVector: 2102ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCObject: 2103ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCInterface: 2104ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ObjCObjectPointer: 2105ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Record: 2106ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Enum: 2107ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::UnresolvedUsing: 2108ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TypeOfExpr: 2109ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TypeOf: 2110ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Decltype: 2111ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt case Type::UnaryTransform: 2112ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentName: 2113ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::InjectedClassName: 2114ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TemplateSpecialization: 2115ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentTemplateSpecialization: 2116ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::TemplateTypeParm: 2117ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::SubstTemplateTypeParmPack: 211834b41d939a1328f484511c6002ba2456db879a29Richard Smith case Type::Auto: 2119ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::PackExpansion: 2120ce8890371fcdb983ae487c87fa40606a34896ff7John McCall llvm_unreachable("type should never be variably-modified"); 2121ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2122ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types can be variably-modified but should never need to 2123ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // further decay. 2124ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::FunctionNoProto: 2125ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::FunctionProto: 2126ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::BlockPointer: 2127ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::MemberPointer: 2128ce8890371fcdb983ae487c87fa40606a34896ff7John McCall return type; 2129ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2130ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // These types can be variably-modified. All these modifications 2131ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // preserve structure except as noted by comments. 2132ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // TODO: if we ever care about optimizing VLAs, there are no-op 2133ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // optimizations available here. 2134ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::Pointer: 2135ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getPointerType(getVariableArrayDecayedType( 2136ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cast<PointerType>(ty)->getPointeeType())); 2137ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2138ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2139ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::LValueReference: { 2140ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const LValueReferenceType *lv = cast<LValueReferenceType>(ty); 2141ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getLValueReferenceType( 2142ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(lv->getPointeeType()), 2143ce8890371fcdb983ae487c87fa40606a34896ff7John McCall lv->isSpelledAsLValue()); 2144ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2145745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2146ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2147ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::RValueReference: { 2148ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const RValueReferenceType *lv = cast<RValueReferenceType>(ty); 2149ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getRValueReferenceType( 2150ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(lv->getPointeeType())); 2151ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2152745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2153745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2154b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: { 2155b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman const AtomicType *at = cast<AtomicType>(ty); 2156b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman result = getAtomicType(getVariableArrayDecayedType(at->getValueType())); 2157b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman break; 2158b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 2159b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 2160ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::ConstantArray: { 2161ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const ConstantArrayType *cat = cast<ConstantArrayType>(ty); 2162ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getConstantArrayType( 2163ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(cat->getElementType()), 2164ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getSize(), 2165ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getSizeModifier(), 2166ce8890371fcdb983ae487c87fa40606a34896ff7John McCall cat->getIndexTypeCVRQualifiers()); 2167ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2168745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian } 2169745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2170ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::DependentSizedArray: { 2171ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const DependentSizedArrayType *dat = cast<DependentSizedArrayType>(ty); 2172ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getDependentSizedArrayType( 2173ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(dat->getElementType()), 2174ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getSizeExpr(), 2175ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getSizeModifier(), 2176ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getIndexTypeCVRQualifiers(), 2177ce8890371fcdb983ae487c87fa40606a34896ff7John McCall dat->getBracketsRange()); 2178ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2179ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2180ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2181ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Turn incomplete types into [*] types. 2182ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::IncompleteArray: { 2183ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const IncompleteArrayType *iat = cast<IncompleteArrayType>(ty); 2184ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getVariableArrayType( 2185ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(iat->getElementType()), 2186ce8890371fcdb983ae487c87fa40606a34896ff7John McCall /*size*/ 0, 2187ce8890371fcdb983ae487c87fa40606a34896ff7John McCall ArrayType::Normal, 2188ce8890371fcdb983ae487c87fa40606a34896ff7John McCall iat->getIndexTypeCVRQualifiers(), 2189ce8890371fcdb983ae487c87fa40606a34896ff7John McCall SourceRange()); 2190ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2191ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2192ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2193ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Turn VLA types into [*] types. 2194ce8890371fcdb983ae487c87fa40606a34896ff7John McCall case Type::VariableArray: { 2195ce8890371fcdb983ae487c87fa40606a34896ff7John McCall const VariableArrayType *vat = cast<VariableArrayType>(ty); 2196ce8890371fcdb983ae487c87fa40606a34896ff7John McCall result = getVariableArrayType( 2197ce8890371fcdb983ae487c87fa40606a34896ff7John McCall getVariableArrayDecayedType(vat->getElementType()), 2198ce8890371fcdb983ae487c87fa40606a34896ff7John McCall /*size*/ 0, 2199ce8890371fcdb983ae487c87fa40606a34896ff7John McCall ArrayType::Star, 2200ce8890371fcdb983ae487c87fa40606a34896ff7John McCall vat->getIndexTypeCVRQualifiers(), 2201ce8890371fcdb983ae487c87fa40606a34896ff7John McCall vat->getBracketsRange()); 2202ce8890371fcdb983ae487c87fa40606a34896ff7John McCall break; 2203ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2204ce8890371fcdb983ae487c87fa40606a34896ff7John McCall } 2205ce8890371fcdb983ae487c87fa40606a34896ff7John McCall 2206ce8890371fcdb983ae487c87fa40606a34896ff7John McCall // Apply the top-level qualifiers from the original. 2207200fa53fd420aa8369586f569dbece04930ad6a3John McCall return getQualifiedType(result, split.Quals); 2208ce8890371fcdb983ae487c87fa40606a34896ff7John McCall} 2209745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian 2210bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// getVariableArrayType - Returns a non-unique reference to the type for a 2211bdbf7b030a3e0ddb95240076683830e6f78c79a5Steve Naroff/// variable array of the specified element type. 22127e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas GregorQualType ASTContext::getVariableArrayType(QualType EltTy, 22137e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor Expr *NumElts, 2214c9406125e2cac9208098655ac8058c095c2c3a65Steve Naroff ArrayType::ArraySizeModifier ASM, 221563e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara unsigned IndexTypeQuals, 22164ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceRange Brackets) const { 2217c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Since we don't unique expressions, it isn't possible to unique VLA's 2218c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // that have an expression provided for their size. 22193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType Canon; 2220715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor 22213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Be sure to pull qualifiers off the element type. 22223b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!EltTy.isCanonical() || EltTy.hasLocalQualifiers()) { 22233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(EltTy).split(); 2224200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getVariableArrayType(QualType(canonSplit.Ty, 0), NumElts, ASM, 222563e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara IndexTypeQuals, Brackets); 2226200fa53fd420aa8369586f569dbece04930ad6a3John McCall Canon = getQualifiedType(Canon, canonSplit.Quals); 2227715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor } 2228715e9c8a39437347e838aa108df443fe1086d359Douglas Gregor 22296b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VariableArrayType *New = new(*this, TypeAlignment) 223063e7d25d2e6036616b42f744fd4a39cd5f911960Abramo Bagnara VariableArrayType(EltTy, Canon, NumElts, ASM, IndexTypeQuals, Brackets); 2231c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2232c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman VariableArrayTypes.push_back(New); 2233c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman Types.push_back(New); 2234c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman return QualType(New, 0); 2235c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman} 2236c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2237898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// getDependentSizedArrayType - Returns a non-unique reference to 2238898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// the type for a dependently-sized array of the specified element 223904d4beee4b86af20a9e4457023d3925cab8f9908Douglas Gregor/// type. 22403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getDependentSizedArrayType(QualType elementType, 22413b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *numElements, 2242898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor ArrayType::ArraySizeModifier ASM, 22433b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned elementTypeQuals, 22443b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SourceRange brackets) const { 22453b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert((!numElements || numElements->isTypeDependent() || 22463b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall numElements->isValueDependent()) && 2247898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor "Size must be type- or value-dependent!"); 2248898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 22493b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Dependently-sized array types that do not have a specified number 22503b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // of elements will have their sizes deduced from a dependent 22513b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // initializer. We do no canonicalization here at all, which is okay 22523b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // because they can't be used in most locations. 22533b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!numElements) { 22543b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *newType 22553b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = new (*this, TypeAlignment) 22563b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType(*this, elementType, QualType(), 22573b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall numElements, ASM, elementTypeQuals, 22583b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall brackets); 22593b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(newType); 22603b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(newType, 0); 2261cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor } 2262cb78d8852a454684c987220132cdb5e54dd00121Douglas Gregor 22633b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Otherwise, we actually build a new type every time, but we 22643b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // also build a canonical type. 22651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22663b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonElementType = getCanonicalType(elementType).split(); 2267898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 22683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 22693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall llvm::FoldingSetNodeID ID; 22703b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType::Profile(ID, *this, 2271200fa53fd420aa8369586f569dbece04930ad6a3John McCall QualType(canonElementType.Ty, 0), 22723b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals, numElements); 22733b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22743b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Look for an existing type with these properties. 22753b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *canonTy = 22763b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos); 22773b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22783b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If we don't have one, build one. 22793b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!canonTy) { 22803b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall canonTy = new (*this, TypeAlignment) 2281200fa53fd420aa8369586f569dbece04930ad6a3John McCall DependentSizedArrayType(*this, QualType(canonElementType.Ty, 0), 22823b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType(), numElements, ASM, elementTypeQuals, 22833b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall brackets); 22843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayTypes.InsertNode(canonTy, insertPos); 22853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(canonTy); 22863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 22873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Apply qualifiers from the element type to the array. 22893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon = getQualifiedType(QualType(canonTy,0), 2290200fa53fd420aa8369586f569dbece04930ad6a3John McCall canonElementType.Quals); 22913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // If we didn't need extra canonicalization for the element type, 22933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // then just use that as our result. 2294200fa53fd420aa8369586f569dbece04930ad6a3John McCall if (QualType(canonElementType.Ty, 0) == elementType) 22953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return canon; 22963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 22973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Otherwise, we need to build a type which follows the spelling 22983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // of the element type. 22993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType *sugaredType 23003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = new (*this, TypeAlignment) 23013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall DependentSizedArrayType(*this, elementType, canon, numElements, 23023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals, brackets); 23033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(sugaredType); 23043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(sugaredType, 0); 23053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall} 23063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 23073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getIncompleteArrayType(QualType elementType, 2308c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman ArrayType::ArraySizeModifier ASM, 23093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall unsigned elementTypeQuals) const { 2310c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman llvm::FoldingSetNodeID ID; 23113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType::Profile(ID, elementType, ASM, elementTypeQuals); 2312c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 23133b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall void *insertPos = 0; 23143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (IncompleteArrayType *iat = 23153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos)) 23163b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(iat, 0); 2317c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2318c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // If the element type isn't canonical, this won't be a canonical type 23193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // either, so fill in the canonical type field. We also have to pull 23203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // qualifiers off the element type. 23213b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType canon; 2322c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 23233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!elementType.isCanonical() || elementType.hasLocalQualifiers()) { 23243b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType canonSplit = getCanonicalType(elementType).split(); 2325200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getIncompleteArrayType(QualType(canonSplit.Ty, 0), 23263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ASM, elementTypeQuals); 2327200fa53fd420aa8369586f569dbece04930ad6a3John McCall canon = getQualifiedType(canon, canonSplit.Quals); 2328c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 2329c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman // Get the new insert position for the node we care about. 23303b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType *existing = 23313b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos); 23323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(!existing && "Shouldn't be in the map!"); (void) existing; 23332bd24ba6d10f8c811c8e2a57c8397e07082ba497Ted Kremenek } 2334c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 23353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType *newType = new (*this, TypeAlignment) 23363b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayType(elementType, canon, ASM, elementTypeQuals); 2337c5773c4b8ce1ed6ed5c7112c9020c954a47dce96Eli Friedman 23383b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall IncompleteArrayTypes.InsertNode(newType, insertPos); 23393b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Types.push_back(newType); 23403b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return QualType(newType, 0); 2341fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff} 2342fb22d96692c5240fb8d611290dbf7eeed3759c73Steve Naroff 234373322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// getVectorType - Return the unique reference to a vector type of 234473322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 234582287d19ded35248c4ce6a425ce74116a13ce44eJohn ThompsonQualType ASTContext::getVectorType(QualType vecType, unsigned NumElts, 23464ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad VectorType::VectorKind VecKind) const { 23473b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall assert(vecType->isBuiltinType()); 23481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Check if we've already instantiated a vector of this type. 23505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 2351e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::Profile(ID, vecType, NumElts, Type::Vector, VecKind); 2352788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner 23535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 23545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 23555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(VTP, 0); 23565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 23575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the element type isn't canonical, this won't be a canonical type either, 23585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // so fill in the canonical type field. 23595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 2360255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor if (!vecType.isCanonical()) { 2361231da7eb3dd13007e5e40fffe48998e5ef284e06Bob Wilson Canonical = getVectorType(getCanonicalType(vecType), NumElts, VecKind); 23621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 23645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2365c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 23665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 23676b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall VectorType *New = new (*this, TypeAlignment) 2368e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType(vecType, NumElts, Canonical, VecKind); 23695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer VectorTypes.InsertNode(New, InsertPos); 23705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 23715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 23725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 23735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2374213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman/// getExtVectorType - Return the unique reference to an extended vector type of 237573322924127c873c13101b705dd823f5539ffa5fSteve Naroff/// the specified element type and size. VectorType must be a built-in type. 23764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 23774ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getExtVectorType(QualType vecType, unsigned NumElts) const { 23784ac01401b1ec602a1f58c217544d3dcb5fcbd7f1Douglas Gregor assert(vecType->isBuiltinType() || vecType->isDependentType()); 23791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 238073322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Check if we've already instantiated a vector of this type. 238173322924127c873c13101b705dd823f5539ffa5fSteve Naroff llvm::FoldingSetNodeID ID; 2382788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner VectorType::Profile(ID, vecType, NumElts, Type::ExtVector, 2383e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 238473322924127c873c13101b705dd823f5539ffa5fSteve Naroff void *InsertPos = 0; 238573322924127c873c13101b705dd823f5539ffa5fSteve Naroff if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos)) 238673322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(VTP, 0); 238773322924127c873c13101b705dd823f5539ffa5fSteve Naroff 238873322924127c873c13101b705dd823f5539ffa5fSteve Naroff // If the element type isn't canonical, this won't be a canonical type either, 238973322924127c873c13101b705dd823f5539ffa5fSteve Naroff // so fill in the canonical type field. 239073322924127c873c13101b705dd823f5539ffa5fSteve Naroff QualType Canonical; 2391467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall if (!vecType.isCanonical()) { 2392213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman Canonical = getExtVectorType(getCanonicalType(vecType), NumElts); 23931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 239473322924127c873c13101b705dd823f5539ffa5fSteve Naroff // Get the new insert position for the node we care about. 239573322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2396c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 239773322924127c873c13101b705dd823f5539ffa5fSteve Naroff } 23986b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType *New = new (*this, TypeAlignment) 23996b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall ExtVectorType(vecType, NumElts, Canonical); 240073322924127c873c13101b705dd823f5539ffa5fSteve Naroff VectorTypes.InsertNode(New, InsertPos); 240173322924127c873c13101b705dd823f5539ffa5fSteve Naroff Types.push_back(New); 240273322924127c873c13101b705dd823f5539ffa5fSteve Naroff return QualType(New, 0); 240373322924127c873c13101b705dd823f5539ffa5fSteve Naroff} 240473322924127c873c13101b705dd823f5539ffa5fSteve Naroff 24054ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 24064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getDependentSizedExtVectorType(QualType vecType, 24074ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad Expr *SizeExpr, 24084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceLocation AttrLoc) const { 24092ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor llvm::FoldingSetNodeID ID; 24101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), 24112ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SizeExpr); 24121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24132ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor void *InsertPos = 0; 24142ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *Canon 24152ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 24162ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorType *New; 24172ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (Canon) { 24182ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // We already have a canonical version of this array type; use it as 24192ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor // the canonical type for a newly-built type. 24206b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 24216b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(Canon, 0), 24226b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall SizeExpr, AttrLoc); 24232ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 24242ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType CanonVecTy = getCanonicalType(vecType); 24252ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor if (CanonVecTy == vecType) { 24266b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 24276b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, QualType(), SizeExpr, 24286b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall AttrLoc); 2429789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2430789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentSizedExtVectorType *CanonCheck 2431789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos); 2432789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CanonCheck && "Dependent-sized ext_vector canonical type broken"); 2433789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CanonCheck; 24342ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor DependentSizedExtVectorTypes.InsertNode(New, InsertPos); 24352ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } else { 24362ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr, 24372ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor SourceLocation()); 24386b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall New = new (*this, TypeAlignment) 24396b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall DependentSizedExtVectorType(*this, vecType, Canon, SizeExpr, AttrLoc); 24402ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 24412ec09f1dc123e1942ed756e8ee4fef86451eac9eDouglas Gregor } 24421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24439cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor Types.push_back(New); 24449cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor return QualType(New, 0); 24459cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor} 24469cdda0cf8528e3d595be9bfa002f0450074beb4dDouglas Gregor 244772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 24485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 24494ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 24504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getFunctionNoProtoType(QualType ResultTy, 24514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FunctionType::ExtInfo &Info) const { 2452cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv DefaultCC = Info.getCC(); 2453cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv CallConv = (LangOpts.MRTD && DefaultCC == CC_Default) ? 2454cfe9af250f466e7e38becea4428990448ae07737Roman Divacky CC_X86StdCall : DefaultCC; 24555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 24565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 24575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 2458264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionNoProtoType::Profile(ID, ResultTy, Info); 24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionNoProtoType *FT = 246272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 24635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FT, 0); 24641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 2466ab8bbf4ebd3e3e6eab913cb044772a62b7581941Douglas Gregor if (!ResultTy.isCanonical() || 246704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall getCanonicalCallConv(CallConv) != CallConv) { 2468264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Canonical = 2469264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola getFunctionNoProtoType(getCanonicalType(ResultTy), 2470264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola Info.withCallingConv(getCanonicalCallConv(CallConv))); 24711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 247372564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoType *NewIP = 247472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 2475c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 24765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2478cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionProtoType::ExtInfo newInfo = Info.withCallingConv(CallConv); 24796b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall FunctionNoProtoType *New = new (*this, TypeAlignment) 2480cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionNoProtoType(ResultTy, Canonical, newInfo); 24815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(New); 248272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionNoProtoTypes.InsertNode(New, InsertPos); 24835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(New, 0); 24845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 24855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFunctionType - Return a normal function type with a typed argument 24875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// list. isVariadic indicates whether the argument list includes '...'. 24884ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 24894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getFunctionType(QualType ResultTy, 24904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const QualType *ArgArray, unsigned NumArgs, 24914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FunctionProtoType::ExtProtoInfo &EPI) const { 24925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Unique functions, to guarantee there is only one function of a particular 24935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // structure. 24945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer llvm::FoldingSetNodeID ID; 24958026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl FunctionProtoType::Profile(ID, ResultTy, ArgArray, NumArgs, EPI, *this); 24965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 24975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void *InsertPos = 0; 24981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (FunctionProtoType *FTP = 249972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) 25005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 2501465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2502465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // Determine whether the type being created is already canonical or not. 2503eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool isCanonical = 2504eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith EPI.ExceptionSpecType == EST_None && ResultTy.isCanonical() && 2505eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith !EPI.HasTrailingReturn; 25065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs && isCanonical; ++i) 250754e14c4db764c0636160d26c5bbf491637c83a76John McCall if (!ArgArray[i].isCanonicalAsParam()) 25085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer isCanonical = false; 25095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2510cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv DefaultCC = EPI.ExtInfo.getCC(); 2511cfe9af250f466e7e38becea4428990448ae07737Roman Divacky const CallingConv CallConv = (LangOpts.MRTD && DefaultCC == CC_Default) ? 2512cfe9af250f466e7e38becea4428990448ae07737Roman Divacky CC_X86StdCall : DefaultCC; 2513e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 25145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this type isn't canonical, get the canonical version of it. 2515465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl // The exception spec is not part of the canonical type. 25165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer QualType Canonical; 251704a67a6aa3dfdc92d57f7f8d93ba397348c868a4John McCall if (!isCanonical || getCanonicalCallConv(CallConv) != CallConv) { 25185f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 16> CanonicalArgs; 25195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer CanonicalArgs.reserve(NumArgs); 25205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != NumArgs; ++i) 252154e14c4db764c0636160d26c5bbf491637c83a76John McCall CanonicalArgs.push_back(getCanonicalParamType(ArgArray[i])); 2522465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2523e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo CanonicalEPI = EPI; 2524eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith CanonicalEPI.HasTrailingReturn = false; 25258b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl CanonicalEPI.ExceptionSpecType = EST_None; 25268b5b4099c61a136e9a1714c4d8a593febe942268Sebastian Redl CanonicalEPI.NumExceptions = 0; 2527e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall CanonicalEPI.ExtInfo 2528e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall = CanonicalEPI.ExtInfo.withCallingConv(getCanonicalCallConv(CallConv)); 2529e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 2530f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner Canonical = getFunctionType(getCanonicalType(ResultTy), 2531beaaccd8e2a8748f77b66e2b330fb9136937e14cJay Foad CanonicalArgs.data(), NumArgs, 2532e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall CanonicalEPI); 2533465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 25345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get the new insert position for the node we care about. 253572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoType *NewIP = 253672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos); 2537c6ed729f669044f5072a49d79041f455d971ece3Jeffrey Yasskin assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 25385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 2539465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl 2540f85e193739c953358c865005855253af4f68a497John McCall // FunctionProtoType objects are allocated with extra bytes after 2541f85e193739c953358c865005855253af4f68a497John McCall // them for three variable size arrays at the end: 2542f85e193739c953358c865005855253af4f68a497John McCall // - parameter types 2543f85e193739c953358c865005855253af4f68a497John McCall // - exception types 2544f85e193739c953358c865005855253af4f68a497John McCall // - consumed-arguments flags 2545f85e193739c953358c865005855253af4f68a497John McCall // Instead of the exception types, there could be a noexcept 2546b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // expression, or information used to resolve the exception 2547b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith // specification. 2548e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall size_t Size = sizeof(FunctionProtoType) + 254960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl NumArgs * sizeof(QualType); 2550b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith if (EPI.ExceptionSpecType == EST_Dynamic) { 255160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl Size += EPI.NumExceptions * sizeof(QualType); 2552b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (EPI.ExceptionSpecType == EST_ComputedNoexcept) { 25538026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl Size += sizeof(Expr*); 2554e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith } else if (EPI.ExceptionSpecType == EST_Uninstantiated) { 255513bffc532bafd45d4a77867993c1afb83c7661beRichard Smith Size += 2 * sizeof(FunctionDecl*); 2556b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith } else if (EPI.ExceptionSpecType == EST_Unevaluated) { 2557b9d0b76e42fd2d4cdfd135220302458d03ad09feRichard Smith Size += sizeof(FunctionDecl*); 255860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl } 2559f85e193739c953358c865005855253af4f68a497John McCall if (EPI.ConsumedArguments) 2560f85e193739c953358c865005855253af4f68a497John McCall Size += NumArgs * sizeof(bool); 2561f85e193739c953358c865005855253af4f68a497John McCall 2562e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType *FTP = (FunctionProtoType*) Allocate(Size, TypeAlignment); 2563cfe9af250f466e7e38becea4428990448ae07737Roman Divacky FunctionProtoType::ExtProtoInfo newEPI = EPI; 2564cfe9af250f466e7e38becea4428990448ae07737Roman Divacky newEPI.ExtInfo = EPI.ExtInfo.withCallingConv(CallConv); 25658026f6d82f7fa544bc0453714fe94bca62a1196eSebastian Redl new (FTP) FunctionProtoType(ResultTy, ArgArray, NumArgs, Canonical, newEPI); 25665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Types.push_back(FTP); 256772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor FunctionProtoTypes.InsertNode(FTP, InsertPos); 25685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return QualType(FTP, 0); 25695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 25705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 25713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall#ifndef NDEBUG 25723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallstatic bool NeedsInjectedClassNameType(const RecordDecl *D) { 25733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!isa<CXXRecordDecl>(D)) return false; 25743cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const CXXRecordDecl *RD = cast<CXXRecordDecl>(D); 25753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (isa<ClassTemplatePartialSpecializationDecl>(RD)) 25763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return true; 25773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (RD->getDescribedClassTemplate() && 25783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall !isa<ClassTemplateSpecializationDecl>(RD)) 25793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return true; 25803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return false; 25813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 25823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall#endif 25833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 25843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// getInjectedClassNameType - Return the unique reference to the 25853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall/// injected class name type for the specified templated declaration. 25863cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType ASTContext::getInjectedClassNameType(CXXRecordDecl *Decl, 25874ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType TST) const { 25883cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(NeedsInjectedClassNameType(Decl)); 25893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (Decl->TypeForDecl) { 25903cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<InjectedClassNameType>(Decl->TypeForDecl)); 2591ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor } else if (CXXRecordDecl *PrevDecl = Decl->getPreviousDecl()) { 25923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(PrevDecl->TypeForDecl && "previous declaration has no type"); 25933cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl->TypeForDecl = PrevDecl->TypeForDecl; 25943cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall assert(isa<InjectedClassNameType>(Decl->TypeForDecl)); 25953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } else { 2596f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Type *newType = 259731f17ecbef57b5679c017c375db330546b7b5145John McCall new (*this, TypeAlignment) InjectedClassNameType(Decl, TST); 2598f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2599f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 26003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall } 26013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return QualType(Decl->TypeForDecl, 0); 26023cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 26033cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 26042ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// getTypeDeclType - Return the unique reference to the type for the 26052ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor/// specified type declaration. 26064ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeDeclTypeSlow(const TypeDecl *Decl) const { 26071e6759e9e33dcaa73ce14c8a908ac9f87ac16463Argyrios Kyrtzidis assert(Decl && "Passed null for Decl param"); 2608becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!Decl->TypeForDecl && "TypeForDecl present in slow case"); 26091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2610162e1c1b487352434552147967c3dd296ebee2f7Richard Smith if (const TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Decl)) 26112ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor return getTypedefType(Typedef); 2612becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall 2613becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!isa<TemplateTypeParmDecl>(Decl) && 2614becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "Template type parameter types are always available."); 2615becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall 261619c8576b7328f4dc2d07682f5da552875c1912efJohn McCall if (const RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) { 2617ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor assert(!Record->getPreviousDecl() && 2618becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "struct/union has previous declaration"); 2619becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall assert(!NeedsInjectedClassNameType(Record)); 2620400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return getRecordType(Record); 262119c8576b7328f4dc2d07682f5da552875c1912efJohn McCall } else if (const EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) { 2622ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor assert(!Enum->getPreviousDecl() && 2623becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall "enum has previous declaration"); 2624400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return getEnumType(Enum); 262519c8576b7328f4dc2d07682f5da552875c1912efJohn McCall } else if (const UnresolvedUsingTypenameDecl *Using = 2626ed97649e9574b9d854fa4d6109c9333ae0993554John McCall dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) { 2627f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Type *newType = new (*this, TypeAlignment) UnresolvedUsingType(Using); 2628f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2629f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 26309fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else 2631becb8d5a6ab5103393eac5344ae69bcb860601ddJohn McCall llvm_unreachable("TypeDecl without a type?"); 263249aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis 263349aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis return QualType(Decl->TypeForDecl, 0); 26342ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor} 26352ce52f3fb95bf544db6bd3d91a72bce7d9cceb6cDouglas Gregor 26365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTypedefType - Return the unique reference to the type for the 2637162e1c1b487352434552147967c3dd296ebee2f7Richard Smith/// specified typedef name decl. 26389763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisQualType 2639162e1c1b487352434552147967c3dd296ebee2f7Richard SmithASTContext::getTypedefType(const TypedefNameDecl *Decl, 2640162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType Canonical) const { 26415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 26421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 26439763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis if (Canonical.isNull()) 26449763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Canonical = getCanonicalType(Decl->getUnderlyingType()); 2645f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall TypedefType *newType = new(*this, TypeAlignment) 26466b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypedefType(Type::Typedef, Decl, Canonical); 2647f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2648f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2649f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 26505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 26515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 26524ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getRecordType(const RecordDecl *Decl) const { 2653400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 2654400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2655ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (const RecordDecl *PrevDecl = Decl->getPreviousDecl()) 2656400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (PrevDecl->TypeForDecl) 2657400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); 2658400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2659f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall RecordType *newType = new (*this, TypeAlignment) RecordType(Decl); 2660f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2661f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2662f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 2663400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis} 2664400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 26654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getEnumType(const EnumDecl *Decl) const { 2666400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 2667400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2668ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (const EnumDecl *PrevDecl = Decl->getPreviousDecl()) 2669400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis if (PrevDecl->TypeForDecl) 2670400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis return QualType(Decl->TypeForDecl = PrevDecl->TypeForDecl, 0); 2671400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 2672f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall EnumType *newType = new (*this, TypeAlignment) EnumType(Decl); 2673f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Decl->TypeForDecl = newType; 2674f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall Types.push_back(newType); 2675f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall return QualType(newType, 0); 2676400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis} 2677400f5125e2432d648f2c8a31b36a7f318a880c47Argyrios Kyrtzidis 26789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType ASTContext::getAttributedType(AttributedType::Kind attrKind, 26799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType, 26809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType) { 26819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall llvm::FoldingSetNodeID id; 26829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType::Profile(id, attrKind, modifiedType, equivalentType); 26839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 26849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall void *insertPos = 0; 26859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType *type = AttributedTypes.FindNodeOrInsertPos(id, insertPos); 26869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (type) return QualType(type, 0); 26879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 26889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType canon = getCanonicalType(equivalentType); 26899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall type = new (*this, TypeAlignment) 26909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedType(canon, attrKind, modifiedType, equivalentType); 26919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 26929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall Types.push_back(type); 26939d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypes.InsertNode(type, insertPos); 26949d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 26959d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(type, 0); 26969d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 26979d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 26989d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 269949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall/// \brief Retrieve a substitution-result type. 270049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType 270149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallASTContext::getSubstTemplateTypeParmType(const TemplateTypeParmType *Parm, 27024ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType Replacement) const { 2703467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(Replacement.isCanonical() 270449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall && "replacement types must always be canonical"); 270549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 270649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall llvm::FoldingSetNodeID ID; 270749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType::Profile(ID, Parm, Replacement); 270849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall void *InsertPos = 0; 270949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType *SubstParm 271049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall = SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 271149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 271249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall if (!SubstParm) { 271349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstParm = new (*this, TypeAlignment) 271449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmType(Parm, Replacement); 271549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall Types.push_back(SubstParm); 271649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); 271749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall } 271849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 271949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall return QualType(SubstParm, 0); 272049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 272149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 2722c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor/// \brief Retrieve a 2723c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType ASTContext::getSubstTemplateTypeParmPackType( 2724c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateTypeParmType *Parm, 2725c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor const TemplateArgument &ArgPack) { 2726c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor#ifndef NDEBUG 2727c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(), 2728c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor PEnd = ArgPack.pack_end(); 2729c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor P != PEnd; ++P) { 2730c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor assert(P->getKind() == TemplateArgument::Type &&"Pack contains a non-type"); 2731c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor assert(P->getAsType().isCanonical() && "Pack contains non-canonical type"); 2732c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 2733c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor#endif 2734c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2735c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor llvm::FoldingSetNodeID ID; 2736c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType::Profile(ID, Parm, ArgPack); 2737c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor void *InsertPos = 0; 2738c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor if (SubstTemplateTypeParmPackType *SubstParm 2739c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor = SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos)) 2740c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return QualType(SubstParm, 0); 2741c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2742c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor QualType Canon; 2743c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor if (!Parm->isCanonicalUnqualified()) { 2744c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Canon = getCanonicalType(QualType(Parm, 0)); 2745c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Canon = getSubstTemplateTypeParmPackType(cast<TemplateTypeParmType>(Canon), 2746c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ArgPack); 2747c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos); 2748c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor } 2749c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2750c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackType *SubstParm 2751c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon, 2752c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor ArgPack); 2753c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor Types.push_back(SubstParm); 2754c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos); 2755c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return QualType(SubstParm, 0); 2756c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 2757c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 2758fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor/// \brief Retrieve the template type parameter type for a template 27591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parameter or parameter pack with the given depth, index, and (optionally) 276076e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson/// name. 27611eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType ASTContext::getTemplateTypeParmType(unsigned Depth, unsigned Index, 276276e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson bool ParameterPack, 27634fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmDecl *TTPDecl) const { 2764fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor llvm::FoldingSetNodeID ID; 27654fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TemplateTypeParmType::Profile(ID, Depth, Index, ParameterPack, TTPDecl); 2766fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor void *InsertPos = 0; 27671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateTypeParmType *TypeParm 2768fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 2769fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2770fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor if (TypeParm) 2771fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 27721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27734fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth if (TTPDecl) { 277476e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson QualType Canon = getTemplateTypeParmType(Depth, Index, ParameterPack); 27754fb86f8c4585e53c21c847ad3de9e3b2de123cd9Chandler Carruth TypeParm = new (*this, TypeAlignment) TemplateTypeParmType(TTPDecl, Canon); 2776789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2777789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor TemplateTypeParmType *TypeCheck 2778789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos); 2779789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!TypeCheck && "Template type parameter canonical type broken"); 2780789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)TypeCheck; 278176e4ce42a30cee4dc40ce7c6014874fbc4f9baa7Anders Carlsson } else 27826b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeParm = new (*this, TypeAlignment) 27836b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TemplateTypeParmType(Depth, Index, ParameterPack); 2784fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2785fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor Types.push_back(TypeParm); 2786fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos); 2787fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 2788fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor return QualType(TypeParm, 0); 2789fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor} 2790fab9d67cebb87be968e7ae31a3b549a5279b5d51Douglas Gregor 27913cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallTypeSourceInfo * 27923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallASTContext::getTemplateSpecializationTypeInfo(TemplateName Name, 27933cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall SourceLocation NameLoc, 27943cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall const TemplateArgumentListInfo &Args, 27953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 27967c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Name.getAsDependentTemplateName() && 27977c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 27983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType TST = getTemplateSpecializationType(Name, Args, Underlying); 27993cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 28003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeSourceInfo *DI = CreateTypeSourceInfo(TST); 28013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TemplateSpecializationTypeLoc TL 28023cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall = cast<TemplateSpecializationTypeLoc>(DI->getTypeLoc()); 280355d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.setTemplateKeywordLoc(SourceLocation()); 28043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setTemplateNameLoc(NameLoc); 28053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setLAngleLoc(Args.getLAngleLoc()); 28063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setRAngleLoc(Args.getRAngleLoc()); 28073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) 28083cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.setArgLocInfo(i, Args[i].getLocInfo()); 28093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return DI; 28103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 28113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 28121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 28137532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas GregorASTContext::getTemplateSpecializationType(TemplateName Template, 2814d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Args, 28153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 28167c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 28177c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 28187c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 2819d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall unsigned NumArgs = Args.size(); 2820d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 28215f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 4> ArgVec; 2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall ArgVec.reserve(NumArgs); 2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0; i != NumArgs; ++i) 2824833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall ArgVec.push_back(Args[i].getArgument()); 2825833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 282631f17ecbef57b5679c017c375db330546b7b5145John McCall return getTemplateSpecializationType(Template, ArgVec.data(), NumArgs, 28273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Underlying); 2828833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2829833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2830b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor#ifndef NDEBUG 2831b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregorstatic bool hasAnyPackExpansions(const TemplateArgument *Args, 2832b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor unsigned NumArgs) { 2833b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor for (unsigned I = 0; I != NumArgs; ++I) 2834b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor if (Args[I].isPackExpansion()) 2835b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor return true; 2836b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 2837b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor return true; 2838b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor} 2839b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor#endif 2840b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor 2841833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType 2842833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallASTContext::getTemplateSpecializationType(TemplateName Template, 28437532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor const TemplateArgument *Args, 28447532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor unsigned NumArgs, 28453e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType Underlying) const { 28467c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 28477c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 28480f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor // Look through qualified template names. 28490f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 28500f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor Template = TemplateName(QTN->getTemplateDecl()); 28517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 2852b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor bool IsTypeAlias = 28533e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith Template.getAsTemplateDecl() && 28543e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith isa<TypeAliasTemplateDecl>(Template.getAsTemplateDecl()); 28553e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType CanonType; 28563e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (!Underlying.isNull()) 28573e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith CanonType = getCanonicalType(Underlying); 28583e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith else { 2859b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor // We can get here with an alias template when the specialization contains 2860b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor // a pack expansion that does not match up with a parameter pack. 2861b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor assert((!IsTypeAlias || hasAnyPackExpansions(Args, NumArgs)) && 2862b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor "Caller must compute aliased type"); 2863b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor IsTypeAlias = false; 28643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith CanonType = getCanonicalTemplateSpecializationType(Template, Args, 28653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NumArgs); 28663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 2867fc705b84347e6fb4746a1a7e26949f64c2f2f358Douglas Gregor 28681275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Allocate the (non-canonical) template specialization type, but don't 28691275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // try to unique it: these types typically have location information that 28701275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // we don't unique and don't want to lose. 28713e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith void *Mem = Allocate(sizeof(TemplateSpecializationType) + 28723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith sizeof(TemplateArgument) * NumArgs + 2873b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor (IsTypeAlias? sizeof(QualType) : 0), 28746b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeAlignment); 28751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateSpecializationType *Spec 2876b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor = new (Mem) TemplateSpecializationType(Template, Args, NumArgs, CanonType, 2877b70126a328f89937f46db42f9e3cba1592887c91Douglas Gregor IsTypeAlias ? Underlying : QualType()); 28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287955f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor Types.push_back(Spec); 28801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(Spec, 0); 288155f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor} 288255f6b14230c94272efbbcdd89a92224c8db9f225Douglas Gregor 28831eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 28849763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisASTContext::getCanonicalTemplateSpecializationType(TemplateName Template, 28859763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis const TemplateArgument *Args, 28864ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned NumArgs) const { 28877c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor assert(!Template.getAsDependentTemplateName() && 28887c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor "No dependent template names here!"); 28893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 28900f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor // Look through qualified template names. 28910f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 28920f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor Template = TemplateName(QTN->getTemplateDecl()); 28937c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor 28949763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Build the canonical template specialization type. 28959763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateName CanonTemplate = getCanonicalTemplateName(Template); 28965f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 4> CanonArgs; 28979763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.reserve(NumArgs); 28989763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis for (unsigned I = 0; I != NumArgs; ++I) 28999763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.push_back(getCanonicalTemplateArgument(Args[I])); 29009763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29019763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Determine whether this canonical template specialization type already 29029763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // exists. 29039763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis llvm::FoldingSetNodeID ID; 29049763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationType::Profile(ID, CanonTemplate, 29059763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.data(), NumArgs, *this); 29069763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29079763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis void *InsertPos = 0; 29089763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationType *Spec 29099763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 29109763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29119763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis if (!Spec) { 29129763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis // Allocate a new canonical template specialization type. 29139763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis void *Mem = Allocate((sizeof(TemplateSpecializationType) + 29149763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis sizeof(TemplateArgument) * NumArgs), 29159763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TypeAlignment); 29169763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Spec = new (Mem) TemplateSpecializationType(CanonTemplate, 29179763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis CanonArgs.data(), NumArgs, 29183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith QualType(), QualType()); 29199763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis Types.push_back(Spec); 29209763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis TemplateSpecializationTypes.InsertNode(Spec, InsertPos); 29219763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis } 29229763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29239763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis assert(Spec->isDependentType() && 29249763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis "Non-dependent template-id type must have a canonical type"); 29259763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis return QualType(Spec, 0); 29269763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis} 29279763e221e16026ddf487d2564ed349d2c874a1a1Argyrios Kyrtzidis 29289763e221e16026ddf487d2564ed349d2c874a1a1Argyrios KyrtzidisQualType 2929465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword, 2930465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, 29314ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType NamedType) const { 2932e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor llvm::FoldingSetNodeID ID; 2933465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType::Profile(ID, Keyword, NNS, NamedType); 2934e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2935e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor void *InsertPos = 0; 2936465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 2937e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor if (T) 2938e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 2939e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2940789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor QualType Canon = NamedType; 2941789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor if (!Canon.isCanonical()) { 2942789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor Canon = getCanonicalType(NamedType); 2943465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos); 2944465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara assert(!CheckT && "Elaborated canonical type broken"); 2945789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckT; 2946789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor } 2947789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 2948465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara T = new (*this) ElaboratedType(Keyword, NNS, NamedType, Canon); 2949e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor Types.push_back(T); 2950465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypes.InsertNode(T, InsertPos); 2951e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor return QualType(T, 0); 2952e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor} 2953e4e5b054b4917f0ee493bb2fda5b1ec749bfb9a1Douglas Gregor 2954075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 29554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getParenType(QualType InnerType) const { 2956075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara llvm::FoldingSetNodeID ID; 2957075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType::Profile(ID, InnerType); 2958075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 2959075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara void *InsertPos = 0; 2960075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType *T = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); 2961075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (T) 2962075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(T, 0); 2963075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 2964075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Canon = InnerType; 2965075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (!Canon.isCanonical()) { 2966075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Canon = getCanonicalType(InnerType); 2967075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(ID, InsertPos); 2968075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara assert(!CheckT && "Paren canonical type broken"); 2969075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara (void)CheckT; 2970075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 2971075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 2972075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara T = new (*this) ParenType(InnerType, Canon); 2973075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Types.push_back(T); 2974075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypes.InsertNode(T, InsertPos); 2975075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(T, 0); 2976075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 2977075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 29784a2023f5014e82389d5980d307b89c545dbbac81Douglas GregorQualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword, 29794a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 29804a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Name, 29814ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad QualType Canon) const { 2982d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor assert(NNS->isDependent() && "nested-name-specifier must be dependent"); 2983d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2984d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (Canon.isNull()) { 2985d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 29864a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor ElaboratedTypeKeyword CanonKeyword = Keyword; 29874a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor if (Keyword == ETK_None) 29884a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor CanonKeyword = ETK_Typename; 29894a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor 29904a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor if (CanonNNS != NNS || CanonKeyword != Keyword) 29914a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor Canon = getDependentNameType(CanonKeyword, CanonNNS, Name); 2992d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 2993d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2994d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor llvm::FoldingSetNodeID ID; 29954a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor DependentNameType::Profile(ID, Keyword, NNS, Name); 2996d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 2997d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor void *InsertPos = 0; 29984714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameType *T 29994714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor = DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos); 3000d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor if (T) 3001d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return QualType(T, 0); 3002d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 30034a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor T = new (*this) DependentNameType(Keyword, NNS, Name, Canon); 3004d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor Types.push_back(T); 30054714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameTypes.InsertNode(T, InsertPos); 30061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 3007d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 3008d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 30091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 301033500955d731c73717af52088b7fc0e7a85681e7John McCallASTContext::getDependentTemplateSpecializationType( 301133500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 30124a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 301333500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 30144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const TemplateArgumentListInfo &Args) const { 301533500955d731c73717af52088b7fc0e7a85681e7John McCall // TODO: avoid this copy 30165f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 16> ArgCopy; 301733500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = Args.size(); I != E; ++I) 301833500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.push_back(Args[I].getArgument()); 301933500955d731c73717af52088b7fc0e7a85681e7John McCall return getDependentTemplateSpecializationType(Keyword, NNS, Name, 302033500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.size(), 302133500955d731c73717af52088b7fc0e7a85681e7John McCall ArgCopy.data()); 302233500955d731c73717af52088b7fc0e7a85681e7John McCall} 302333500955d731c73717af52088b7fc0e7a85681e7John McCall 302433500955d731c73717af52088b7fc0e7a85681e7John McCallQualType 302533500955d731c73717af52088b7fc0e7a85681e7John McCallASTContext::getDependentTemplateSpecializationType( 302633500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 302733500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS, 302833500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 302933500955d731c73717af52088b7fc0e7a85681e7John McCall unsigned NumArgs, 30304ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const TemplateArgument *Args) const { 3031aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor assert((!NNS || NNS->isDependent()) && 3032aa2187de137e5b809dcbbe14f3b61ae907a3d8aaDouglas Gregor "nested-name-specifier must be dependent"); 30331734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 3034789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor llvm::FoldingSetNodeID ID; 303533500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType::Profile(ID, *this, Keyword, NNS, 303633500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, Args); 3037789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 3038789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor void *InsertPos = 0; 303933500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType *T 304033500955d731c73717af52088b7fc0e7a85681e7John McCall = DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 3041789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor if (T) 3042789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor return QualType(T, 0); 3043789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 304433500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 304533500955d731c73717af52088b7fc0e7a85681e7John McCall 304633500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword CanonKeyword = Keyword; 304733500955d731c73717af52088b7fc0e7a85681e7John McCall if (Keyword == ETK_None) CanonKeyword = ETK_Typename; 30481734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 304933500955d731c73717af52088b7fc0e7a85681e7John McCall bool AnyNonCanonArgs = false; 30505f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<TemplateArgument, 16> CanonArgs(NumArgs); 305133500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0; I != NumArgs; ++I) { 305233500955d731c73717af52088b7fc0e7a85681e7John McCall CanonArgs[I] = getCanonicalTemplateArgument(Args[I]); 305333500955d731c73717af52088b7fc0e7a85681e7John McCall if (!CanonArgs[I].structurallyEquals(Args[I])) 305433500955d731c73717af52088b7fc0e7a85681e7John McCall AnyNonCanonArgs = true; 3055789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor } 30561734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 305733500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Canon; 305833500955d731c73717af52088b7fc0e7a85681e7John McCall if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) { 305933500955d731c73717af52088b7fc0e7a85681e7John McCall Canon = getDependentTemplateSpecializationType(CanonKeyword, CanonNNS, 306033500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, 306133500955d731c73717af52088b7fc0e7a85681e7John McCall CanonArgs.data()); 306233500955d731c73717af52088b7fc0e7a85681e7John McCall 306333500955d731c73717af52088b7fc0e7a85681e7John McCall // Find the insert position again. 306433500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos); 306533500955d731c73717af52088b7fc0e7a85681e7John McCall } 306633500955d731c73717af52088b7fc0e7a85681e7John McCall 306733500955d731c73717af52088b7fc0e7a85681e7John McCall void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) + 306833500955d731c73717af52088b7fc0e7a85681e7John McCall sizeof(TemplateArgument) * NumArgs), 306933500955d731c73717af52088b7fc0e7a85681e7John McCall TypeAlignment); 3070ef99001908e799c388f1363b1e607dad5f5b57d3John McCall T = new (Mem) DependentTemplateSpecializationType(Keyword, NNS, 307133500955d731c73717af52088b7fc0e7a85681e7John McCall Name, NumArgs, Args, Canon); 30721734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor Types.push_back(T); 307333500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationTypes.InsertNode(T, InsertPos); 30741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return QualType(T, 0); 30751734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor} 30761734317845d60307d474b5da8a8d33adbaf5e723Douglas Gregor 3077cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas GregorQualType ASTContext::getPackExpansionType(QualType Pattern, 3078cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 30797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor llvm::FoldingSetNodeID ID; 3080cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor PackExpansionType::Profile(ID, Pattern, NumExpansions); 30817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 30827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor assert(Pattern->containsUnexpandedParameterPack() && 30837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor "Pack expansions must expand one or more parameter packs"); 30847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor void *InsertPos = 0; 30857536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionType *T 30867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor = PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); 30877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor if (T) 30887536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(T, 0); 30897536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 30907536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor QualType Canon; 30917536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor if (!Pattern.isCanonical()) { 3092d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith Canon = getCanonicalType(Pattern); 3093d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // The canonical type might not contain an unexpanded parameter pack, if it 3094d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // contains an alias template specialization which ignores one of its 3095d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // parameters. 3096d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith if (Canon->containsUnexpandedParameterPack()) { 3097d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith Canon = getPackExpansionType(getCanonicalType(Pattern), NumExpansions); 3098d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith 3099d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // Find the insert position again, in case we inserted an element into 3100d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith // PackExpansionTypes and invalidated our insert position. 3101d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith PackExpansionTypes.FindNodeOrInsertPos(ID, InsertPos); 3102d8672ef2d343a0dbfe838724fb2d9fb4efea6041Richard Smith } 31037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor } 31047536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 3105cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor T = new (*this) PackExpansionType(Pattern, Canon, NumExpansions); 31067536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor Types.push_back(T); 31077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypes.InsertNode(T, InsertPos); 31087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(T, 0); 31097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 31107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 311188cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// CmpProtocolNames - Comparison predicate for sorting protocols 311288cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner/// alphabetically. 311388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattnerstatic bool CmpProtocolNames(const ObjCProtocolDecl *LHS, 311488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner const ObjCProtocolDecl *RHS) { 31152e1cd4264d363ca869bf37ef160902f211d21b8cDouglas Gregor return LHS->getDeclName() < RHS->getDeclName(); 311688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 311788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3118c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallstatic bool areSortedAndUniqued(ObjCProtocolDecl * const *Protocols, 311954e14c4db764c0636160d26c5bbf491637c83a76John McCall unsigned NumProtocols) { 312054e14c4db764c0636160d26c5bbf491637c83a76John McCall if (NumProtocols == 0) return true; 312154e14c4db764c0636160d26c5bbf491637c83a76John McCall 312261cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor if (Protocols[0]->getCanonicalDecl() != Protocols[0]) 312361cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor return false; 312461cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor 312554e14c4db764c0636160d26c5bbf491637c83a76John McCall for (unsigned i = 1; i != NumProtocols; ++i) 312661cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor if (!CmpProtocolNames(Protocols[i-1], Protocols[i]) || 312761cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor Protocols[i]->getCanonicalDecl() != Protocols[i]) 312854e14c4db764c0636160d26c5bbf491637c83a76John McCall return false; 312954e14c4db764c0636160d26c5bbf491637c83a76John McCall return true; 313054e14c4db764c0636160d26c5bbf491637c83a76John McCall} 313154e14c4db764c0636160d26c5bbf491637c83a76John McCall 313254e14c4db764c0636160d26c5bbf491637c83a76John McCallstatic void SortAndUniqueProtocols(ObjCProtocolDecl **Protocols, 313388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner unsigned &NumProtocols) { 313488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ObjCProtocolDecl **ProtocolsEnd = Protocols+NumProtocols; 31351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 313688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Sort protocols, keyed by name. 313788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner std::sort(Protocols, Protocols+NumProtocols, CmpProtocolNames); 313888cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 313961cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor // Canonicalize. 314061cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor for (unsigned I = 0, N = NumProtocols; I != N; ++I) 314161cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor Protocols[I] = Protocols[I]->getCanonicalDecl(); 314261cc296de6c1f82fa84c0abb3ecd142a584838efDouglas Gregor 314388cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner // Remove duplicates. 314488cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner ProtocolsEnd = std::unique(Protocols, ProtocolsEnd); 314588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner NumProtocols = ProtocolsEnd-Protocols; 314688cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner} 314788cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3148c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType ASTContext::getObjCObjectType(QualType BaseType, 3149c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCProtocolDecl * const *Protocols, 31504ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned NumProtocols) const { 3151c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If the base type is an interface and there aren't any protocols 3152c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // to add, then the interface type will do just fine. 3153c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!NumProtocols && isa<ObjCInterfaceType>(BaseType)) 3154c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return BaseType; 3155d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 3156c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Look in the folding set for an existing type. 3157c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall llvm::FoldingSetNodeID ID; 3158c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl::Profile(ID, BaseType, Protocols, NumProtocols); 3159d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff void *InsertPos = 0; 3160c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjCObjectType *QT = ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos)) 3161c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return QualType(QT, 0); 3162d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff 3163c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Build the canonical type, which has the canonical base type and 3164c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // a sorted-and-uniqued list of protocols. 316554e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Canonical; 3166c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall bool ProtocolsSorted = areSortedAndUniqued(Protocols, NumProtocols); 3167c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ProtocolsSorted || !BaseType.isCanonical()) { 3168c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ProtocolsSorted) { 31695f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<ObjCProtocolDecl*, 8> Sorted(Protocols, 31700237941e0beb0c929934b66ad29443b484d987feBenjamin Kramer Protocols + NumProtocols); 317154e14c4db764c0636160d26c5bbf491637c83a76John McCall unsigned UniqueCount = NumProtocols; 317254e14c4db764c0636160d26c5bbf491637c83a76John McCall 317354e14c4db764c0636160d26c5bbf491637c83a76John McCall SortAndUniqueProtocols(&Sorted[0], UniqueCount); 3174c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectType(getCanonicalType(BaseType), 3175c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall &Sorted[0], UniqueCount); 317654e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 3177c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectType(getCanonicalType(BaseType), 3178c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Protocols, NumProtocols); 317954e14c4db764c0636160d26c5bbf491637c83a76John McCall } 318054e14c4db764c0636160d26c5bbf491637c83a76John McCall 318154e14c4db764c0636160d26c5bbf491637c83a76John McCall // Regenerate InsertPos. 3182c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypes.FindNodeOrInsertPos(ID, InsertPos); 318354e14c4db764c0636160d26c5bbf491637c83a76John McCall } 318454e14c4db764c0636160d26c5bbf491637c83a76John McCall 3185c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall unsigned Size = sizeof(ObjCObjectTypeImpl); 3186c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Size += NumProtocols * sizeof(ObjCProtocolDecl *); 3187fd6a0887a099256c35a5b23e9afd517ffe95fa0aDouglas Gregor void *Mem = Allocate(Size, TypeAlignment); 3188c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypeImpl *T = 3189c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall new (Mem) ObjCObjectTypeImpl(Canonical, BaseType, Protocols, NumProtocols); 31901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3191c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Types.push_back(T); 3192c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectTypes.InsertNode(T, InsertPos); 3193c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return QualType(T, 0); 3194d1b3c2dd5bc1f3103bee6137957aa7c5f8f2f0bcSteve Naroff} 319588cb27a160adc305783a44f922ee4b216006ebf9Chris Lattner 3196c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for 3197c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall/// the given object type. 31984ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getObjCObjectPointerType(QualType ObjectT) const { 31994b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian llvm::FoldingSetNodeID ID; 3200c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType::Profile(ID, ObjectT); 32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32024b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian void *InsertPos = 0; 3203c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (ObjCObjectPointerType *QT = 3204c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos)) 32054b6c9051c6522894978c9ba6a819a659d102db36Fariborz Jahanian return QualType(QT, 0); 32061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3207c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Find the canonical object type. 320854e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Canonical; 3209c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!ObjectT.isCanonical()) { 3210c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Canonical = getObjCObjectPointerType(getCanonicalType(ObjectT)); 321154e14c4db764c0636160d26c5bbf491637c83a76John McCall 3212c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Regenerate InsertPos. 3213c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos); 321454e14c4db764c0636160d26c5bbf491637c83a76John McCall } 321554e14c4db764c0636160d26c5bbf491637c83a76John McCall 3216c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // No match. 3217c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall void *Mem = Allocate(sizeof(ObjCObjectPointerType), TypeAlignment); 3218c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerType *QType = 3219c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall new (Mem) ObjCObjectPointerType(Canonical, ObjectT); 322024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 322124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis Types.push_back(QType); 3222c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypes.InsertNode(QType, InsertPos); 322324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis return QualType(QType, 0); 322424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 322524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 3226deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor/// getObjCInterfaceType - Return the unique reference to the type for the 3227deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor/// specified ObjC interface decl. The list of protocols is optional. 32280af550115df1f57f17a4f125ff0e8b34820c65d1Douglas GregorQualType ASTContext::getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 32290af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor ObjCInterfaceDecl *PrevDecl) const { 3230deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor if (Decl->TypeForDecl) 3231deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor return QualType(Decl->TypeForDecl, 0); 323274c730ad1f6818b676b0bad46d806a9176950328Sebastian Redl 32330af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor if (PrevDecl) { 32340af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 32350af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor Decl->TypeForDecl = PrevDecl->TypeForDecl; 32360af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor return QualType(PrevDecl->TypeForDecl, 0); 32370af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor } 32380af550115df1f57f17a4f125ff0e8b34820c65d1Douglas Gregor 32398d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor // Prefer the definition, if there is one. 32408d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor if (const ObjCInterfaceDecl *Def = Decl->getDefinition()) 32418d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor Decl = Def; 32428d2dbbf9ddfd9d762a341d83f83d840ff68ce03dDouglas Gregor 3243deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor void *Mem = Allocate(sizeof(ObjCInterfaceType), TypeAlignment); 3244deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor ObjCInterfaceType *T = new (Mem) ObjCInterfaceType(Decl); 3245deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Decl->TypeForDecl = T; 3246deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor Types.push_back(T); 3247deacbdca554298ccdf636f19c6094a8825ec6b34Douglas Gregor return QualType(T, 0); 3248c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3249c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 325072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// getTypeOfExprType - Unlike many "get<Type>" functions, we can't unique 325172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor/// TypeOfExprType AST's (since expression's are never shared). For example, 32529752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// multiple declarations that refer to "typeof(x)" all contain different 32531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// DeclRefExpr's. This doesn't effect the type checker, since it operates 32549752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 32554ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeOfExprType(Expr *tofExpr) const { 3256dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor TypeOfExprType *toe; 3257b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (tofExpr->isTypeDependent()) { 3258b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor llvm::FoldingSetNodeID ID; 3259b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType::Profile(ID, *this, tofExpr); 32601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3261b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor void *InsertPos = 0; 3262b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprType *Canon 3263b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor = DependentTypeOfExprTypes.FindNodeOrInsertPos(ID, InsertPos); 3264b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor if (Canon) { 3265b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // We already have a "canonical" version of an identical, dependent 3266b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // typeof(expr) type. Use that as our canonical type. 32676b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, 3268b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor QualType((TypeOfExprType*)Canon, 0)); 32693060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 3270b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor // Build a new, canonical typeof(expr) type. 32716b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon 32726b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall = new (*this, TypeAlignment) DependentTypeOfExprType(*this, tofExpr); 3273b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor DependentTypeOfExprTypes.InsertNode(Canon, InsertPos); 3274b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor toe = Canon; 3275b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } 3276b197572cf1cd70a817a1f546478cb2cb9112c48eDouglas Gregor } else { 3277dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor QualType Canonical = getCanonicalType(tofExpr->getType()); 32786b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall toe = new (*this, TypeAlignment) TypeOfExprType(tofExpr, Canonical); 3279dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 32809752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(toe); 32819752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(toe, 0); 3282d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 3283d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 32849752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// getTypeOfType - Unlike many "get<Type>" functions, we don't unique 32859752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// TypeOfType AST's. The only motivation to unique these nodes would be 32869752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be 32871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 32889752f25748d954df99087d741ea35db37ff16beaSteve Naroff/// on canonical type's (which are always unique). 32894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTypeOfType(QualType tofType) const { 3290f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner QualType Canonical = getCanonicalType(tofType); 32916b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall TypeOfType *tot = new (*this, TypeAlignment) TypeOfType(tofType, Canonical); 32929752f25748d954df99087d741ea35db37ff16beaSteve Naroff Types.push_back(tot); 32939752f25748d954df99087d741ea35db37ff16beaSteve Naroff return QualType(tot, 0); 3294d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff} 3295d1861fd633d5096a00777c918eb8575ea7162fe7Steve Naroff 329660a9a2a404a4cf259d39133383e922aa00ca9043Anders Carlsson 3297395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// getDecltypeType - Unlike many "get<Type>" functions, we don't unique 3298395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// DecltypeType AST's. The only motivation to unique these nodes would be 3299395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson/// memory savings. Since decltype(t) is fairly uncommon, space shouldn't be 33001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// an issue. This doesn't effect the type checker, since it operates 330139e02032b01874a0d02ba85a4cd3922adda81376David Blaikie/// on canonical types (which are always unique). 3302f8af98286022f72157d84951b48fde5fb369ab29Douglas GregorQualType ASTContext::getDecltypeType(Expr *e, QualType UnderlyingType) const { 3303dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor DecltypeType *dt; 3304561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor 3305561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // C++0x [temp.type]p2: 3306561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // If an expression e involves a template parameter, decltype(e) denotes a 3307561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // unique dependent type. Two such decltype-specifiers refer to the same 3308561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor // type only if their expressions are equivalent (14.5.6.1). 3309561f81243f665cf2001caadc45df505f826b72d6Douglas Gregor if (e->isInstantiationDependent()) { 33109d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor llvm::FoldingSetNodeID ID; 33119d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType::Profile(ID, *this, e); 33121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33139d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor void *InsertPos = 0; 33149d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeType *Canon 33159d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos); 33169d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor if (Canon) { 33179d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // We already have a "canonical" version of an equivalent, dependent 33189d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // decltype type. Use that as our canonical type. 33190d729105ecb50a7e3cbe6e57c29149edfa5cf05aRichard Smith dt = new (*this, TypeAlignment) DecltypeType(e, UnderlyingType, 33209d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor QualType((DecltypeType*)Canon, 0)); 33213060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 33229d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor // Build a new, canonical typeof(expr) type. 33236b304a0254a13f42390b865ff5ba668a49cc58aeJohn McCall Canon = new (*this, TypeAlignment) DependentDecltypeType(*this, e); 33249d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor DependentDecltypeTypes.InsertNode(Canon, InsertPos); 33259d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor dt = Canon; 33269d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } 33279d702ae1cd5cfa19d884cbef77e1df99395138bbDouglas Gregor } else { 3328f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor dt = new (*this, TypeAlignment) DecltypeType(e, UnderlyingType, 3329f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregor getCanonicalType(UnderlyingType)); 3330dd0257c77719a13d4acd513df40b04300cbfc871Douglas Gregor } 3331395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson Types.push_back(dt); 3332395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson return QualType(dt, 0); 3333395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson} 3334395b475a4474f1c7574d927ad142ca0c7997cbcaAnders Carlsson 3335ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// getUnaryTransformationType - We don't unique these, since the memory 3336ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt/// savings are minimal and these are rare. 3337ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType ASTContext::getUnaryTransformType(QualType BaseType, 3338ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType UnderlyingType, 3339ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind Kind) 3340ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const { 3341ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType *Ty = 334269d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor new (*this, TypeAlignment) UnaryTransformType (BaseType, UnderlyingType, 334369d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor Kind, 334469d9775da47a4b9f165dbc33277f02982928a94eDouglas Gregor UnderlyingType->isDependentType() ? 334512fc4b0624706b474fa10308631fa8daf92f340fPeter Collingbourne QualType() : getCanonicalType(UnderlyingType)); 3346ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Types.push_back(Ty); 3347ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(Ty, 0); 3348ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 3349ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 3350483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith/// getAutoType - We only unique auto types after they've been deduced. 335134b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType ASTContext::getAutoType(QualType DeducedType) const { 3352483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith void *InsertPos = 0; 3353483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (!DeducedType.isNull()) { 3354483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith // Look in the folding set for an existing type. 3355483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith llvm::FoldingSetNodeID ID; 3356483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoType::Profile(ID, DeducedType); 3357483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos)) 3358483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith return QualType(AT, 0); 3359483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith } 3360483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith 3361483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoType *AT = new (*this, TypeAlignment) AutoType(DeducedType); 3362483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith Types.push_back(AT); 3363483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith if (InsertPos) 3364483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith AutoTypes.InsertNode(AT, InsertPos); 3365483b9f3bc05c5409e2c6643f1c9d91e21c8ff9d2Richard Smith return QualType(AT, 0); 336634b41d939a1328f484511c6002ba2456db879a29Richard Smith} 336734b41d939a1328f484511c6002ba2456db879a29Richard Smith 3368b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman/// getAtomicType - Return the uniqued reference to the atomic type for 3369b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman/// the given value type. 3370b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType ASTContext::getAtomicType(QualType T) const { 3371b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Unique pointers, to guarantee there is only one pointer of a particular 3372b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // structure. 3373b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman llvm::FoldingSetNodeID ID; 3374b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType::Profile(ID, T); 3375b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3376b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman void *InsertPos = 0; 3377b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (AtomicType *AT = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos)) 3378b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(AT, 0); 3379b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3380b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // If the atomic value type isn't canonical, this won't be a canonical type 3381b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // either, so fill in the canonical type field. 3382b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Canonical; 3383b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (!T.isCanonical()) { 3384b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Canonical = getAtomicType(getCanonicalType(T)); 3385b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3386b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Get the new insert position for the node we care about. 3387b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType *NewIP = AtomicTypes.FindNodeOrInsertPos(ID, InsertPos); 3388b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP; 3389b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 3390b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicType *New = new (*this, TypeAlignment) AtomicType(T, Canonical); 3391b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Types.push_back(New); 3392b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypes.InsertNode(New, InsertPos); 3393b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(New, 0); 3394b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 3395b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 3396ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// getAutoDeductType - Get type pattern for deducing against 'auto'. 3397ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithQualType ASTContext::getAutoDeductType() const { 3398ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (AutoDeductTy.isNull()) 3399ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AutoDeductTy = getAutoType(QualType()); 3400ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert(!AutoDeductTy.isNull() && "can't build 'auto' pattern"); 3401ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return AutoDeductTy; 3402ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 3403ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 3404ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith/// getAutoRRefDeductType - Get type pattern for deducing against 'auto &&'. 3405ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithQualType ASTContext::getAutoRRefDeductType() const { 3406ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (AutoRRefDeductTy.isNull()) 3407ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith AutoRRefDeductTy = getRValueReferenceType(getAutoDeductType()); 3408ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith assert(!AutoRRefDeductTy.isNull() && "can't build 'auto &&' pattern"); 3409ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return AutoRRefDeductTy; 3410ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 3411ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 34125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getTagDeclType - Return the unique reference to the type for the 34135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// specified TagDecl (struct/union/class/enum) decl. 34144ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getTagDeclType(const TagDecl *Decl) const { 3415d778f88d32b96a74c9edb7342c81357606a7cdc0Ted Kremenek assert (Decl); 3416e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // FIXME: What is the design on getTagDeclType when it requires casting 3417e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump // away const? mutable? 3418e607ed068334bacb8d7b093996b4671c6ca79e25Mike Stump return getTypeDeclType(const_cast<TagDecl*>(Decl)); 34195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 34205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 34211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getSizeType - Return the unique type for "size_t" (C99 7.17), the result 34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// of the sizeof operator (C99 6.5.3.4p4). The value is target dependent and 34231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// needs to agree with the definition in <stddef.h>. 3424a3ccda58913cc1a4b8564e349448b12acc462da7Anders CarlssonCanQualType ASTContext::getSizeType() const { 3425bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return getFromTargetType(Target->getSizeType()); 34265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 34275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 342829e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5). 342929e97cb35fab314388f62b68fefa78947e93c1dcHans WennborgCanQualType ASTContext::getIntMaxType() const { 343029e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg return getFromTargetType(Target->getIntMaxType()); 343129e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg} 343229e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg 343329e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getUIntMaxType - Return the unique type for "uintmax_t" (C99 7.18.1.5). 343429e97cb35fab314388f62b68fefa78947e93c1dcHans WennborgCanQualType ASTContext::getUIntMaxType() const { 343529e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg return getFromTargetType(Target->getUIntMaxType()); 343629e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg} 343729e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg 343864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getSignedWCharType - Return the type of "signed wchar_t". 343964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 344064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getSignedWCharType() const { 344164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 344264c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return WCharTy; 344364c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 344464c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 344564c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// getUnsignedWCharType - Return the type of "unsigned wchar_t". 344664c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis/// Used when in C++, as a GCC extension. 344764c438a4be2a871fa43c78264663ba1e9788b94dArgyrios KyrtzidisQualType ASTContext::getUnsignedWCharType() const { 344864c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis // FIXME: derive from "Target" ? 344964c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis return UnsignedIntTy; 345064c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis} 345164c438a4be2a871fa43c78264663ba1e9788b94dArgyrios Kyrtzidis 345229e97cb35fab314388f62b68fefa78947e93c1dcHans Wennborg/// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17) 34538b9023ba35a86838789e2c9034a6128728c547aaChris Lattner/// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 34548b9023ba35a86838789e2c9034a6128728c547aaChris LattnerQualType ASTContext::getPointerDiffType() const { 3455bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor return getFromTargetType(Target->getPtrDiffType(0)); 34568b9023ba35a86838789e2c9034a6128728c547aaChris Lattner} 34578b9023ba35a86838789e2c9034a6128728c547aaChris Lattner 3458e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 3459e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner// Type Operators 3460e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner//===----------------------------------------------------------------------===// 3461e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 34624ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCanQualType ASTContext::getCanonicalParamType(QualType T) const { 346354e14c4db764c0636160d26c5bbf491637c83a76John McCall // Push qualifiers into arrays, and then discard any remaining 346454e14c4db764c0636160d26c5bbf491637c83a76John McCall // qualifiers. 346554e14c4db764c0636160d26c5bbf491637c83a76John McCall T = getCanonicalType(T); 3466745da3a5bb4ea35f93f50301e7fbbb7d78d3b6bbFariborz Jahanian T = getVariableArrayDecayedType(T); 346754e14c4db764c0636160d26c5bbf491637c83a76John McCall const Type *Ty = T.getTypePtr(); 346854e14c4db764c0636160d26c5bbf491637c83a76John McCall QualType Result; 346954e14c4db764c0636160d26c5bbf491637c83a76John McCall if (isa<ArrayType>(Ty)) { 347054e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = getArrayDecayedType(QualType(Ty,0)); 347154e14c4db764c0636160d26c5bbf491637c83a76John McCall } else if (isa<FunctionType>(Ty)) { 347254e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = getPointerType(QualType(Ty, 0)); 347354e14c4db764c0636160d26c5bbf491637c83a76John McCall } else { 347454e14c4db764c0636160d26c5bbf491637c83a76John McCall Result = QualType(Ty, 0); 347554e14c4db764c0636160d26c5bbf491637c83a76John McCall } 347654e14c4db764c0636160d26c5bbf491637c83a76John McCall 347754e14c4db764c0636160d26c5bbf491637c83a76John McCall return CanQualType::CreateUnsafe(Result); 347854e14c4db764c0636160d26c5bbf491637c83a76John McCall} 347954e14c4db764c0636160d26c5bbf491637c83a76John McCall 348062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCallQualType ASTContext::getUnqualifiedArrayType(QualType type, 348162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall Qualifiers &quals) { 348262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall SplitQualType splitType = type.getSplitUnqualifiedType(); 348362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 348462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // FIXME: getSplitUnqualifiedType() actually walks all the way to 348562c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // the unqualified desugared type and then drops it on the floor. 348662c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // We then have to strip that sugar back off with 348762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // getUnqualifiedDesugaredType(), which is silly. 348862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall const ArrayType *AT = 3489200fa53fd420aa8369586f569dbece04930ad6a3John McCall dyn_cast<ArrayType>(splitType.Ty->getUnqualifiedDesugaredType()); 349062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 349162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // If we don't have an array, just use the results in splitType. 34929dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (!AT) { 3493200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals = splitType.Quals; 3494200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(splitType.Ty, 0); 349528e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 349628e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 349762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, recurse on the array's element type. 349862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType elementType = AT->getElementType(); 349962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall QualType unqualElementType = getUnqualifiedArrayType(elementType, quals); 350062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 350162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // If that didn't change the element type, AT has no qualifiers, so we 350262c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // can just use the results in splitType. 350362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall if (elementType == unqualElementType) { 350462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall assert(quals.empty()); // from the recursive call 3505200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals = splitType.Quals; 3506200fa53fd420aa8369586f569dbece04930ad6a3John McCall return QualType(splitType.Ty, 0); 350762c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall } 350862c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall 350962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // Otherwise, add in the qualifiers from the outermost type, then 351062c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall // build the type back up. 3511200fa53fd420aa8369586f569dbece04930ad6a3John McCall quals.addConsistentQualifiers(splitType.Quals); 351228e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 35139dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) { 351462c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getConstantArrayType(unqualElementType, CAT->getSize(), 351528e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth CAT->getSizeModifier(), 0); 351628e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 351728e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 35189dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) { 351962c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getIncompleteArrayType(unqualElementType, IAT->getSizeModifier(), 0); 352028e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth } 352128e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 35229dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(AT)) { 352362c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getVariableArrayType(unqualElementType, 35243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall VAT->getSizeExpr(), 35259dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getSizeModifier(), 35269dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getIndexTypeCVRQualifiers(), 35279dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor VAT->getBracketsRange()); 35289dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor } 35299dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor 35309dadd94e1c17fa030d1f88d8f2113ff59ccc6714Douglas Gregor const DependentSizedArrayType *DSAT = cast<DependentSizedArrayType>(AT); 353162c28c831bbf207cc36e683e7c321fc33bf8928cJohn McCall return getDependentSizedArrayType(unqualElementType, DSAT->getSizeExpr(), 353228e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth DSAT->getSizeModifier(), 0, 353328e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth SourceRange()); 353428e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth} 353528e318cc6008c2bc008f0caee70dc736a03d6289Chandler Carruth 35365a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// UnwrapSimilarPointerTypes - If T1 and T2 are pointer types that 35375a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// may be similar (C++ 4.4), replaces T1 and T2 with the type that 35385a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// they point to and return true. If T1 and T2 aren't pointer types 35395a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// or pointer-to-member types, or if they are not similar at this 35405a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// level, returns false and leaves T1 and T2 unchanged. Top-level 35415a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// qualifiers on T1 and T2 are ignored. This function will typically 35425a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// be called in a loop that successively "unwraps" pointer and 35435a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor/// pointer-to-member types to compare them at each level. 35445a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregorbool ASTContext::UnwrapSimilarPointerTypes(QualType &T1, QualType &T2) { 35455a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const PointerType *T1PtrType = T1->getAs<PointerType>(), 35465a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2PtrType = T2->getAs<PointerType>(); 35475a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1PtrType && T2PtrType) { 35485a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1PtrType->getPointeeType(); 35495a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2PtrType->getPointeeType(); 35505a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 35515a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 35525a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 35535a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const MemberPointerType *T1MPType = T1->getAs<MemberPointerType>(), 35545a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2MPType = T2->getAs<MemberPointerType>(); 35555a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1MPType && T2MPType && 35565a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor hasSameUnqualifiedType(QualType(T1MPType->getClass(), 0), 35575a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor QualType(T2MPType->getClass(), 0))) { 35585a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1MPType->getPointeeType(); 35595a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2MPType->getPointeeType(); 35605a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 35615a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 35625a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 35634e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().ObjC1) { 35645a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor const ObjCObjectPointerType *T1OPType = T1->getAs<ObjCObjectPointerType>(), 35655a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor *T2OPType = T2->getAs<ObjCObjectPointerType>(); 35665a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor if (T1OPType && T2OPType) { 35675a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T1 = T1OPType->getPointeeType(); 35685a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor T2 = T2OPType->getPointeeType(); 35695a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return true; 35705a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 35715a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor } 35725a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 35735a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor // FIXME: Block pointers, too? 35745a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 35755a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor return false; 35765a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor} 35775a57efd7bf88a4a13018e0471ded8063a4abe8afDouglas Gregor 35784ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadDeclarationNameInfo 35794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getNameForTemplate(TemplateName Name, 35804ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad SourceLocation NameLoc) const { 3581146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall switch (Name.getKind()) { 3582146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::QualifiedTemplate: 3583146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::Template: 35842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // DNInfo work in progress: CHECKME: what about DNLoc? 3585146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(Name.getAsTemplateDecl()->getDeclName(), 3586146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 35872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 3588146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::OverloadedTemplate: { 3589146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall OverloadedTemplateStorage *Storage = Name.getAsOverloadedTemplate(); 3590146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall // DNInfo work in progress: CHECKME: what about DNLoc? 3591146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo((*Storage->begin())->getDeclName(), NameLoc); 3592146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3593146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3594146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::DependentTemplate: { 3595146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 35962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName DName; 359780ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall if (DTN->isIdentifier()) { 35982577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DName = DeclarationNames.getIdentifier(DTN->getIdentifier()); 35992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(DName, NameLoc); 360080ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } else { 36012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DName = DeclarationNames.getCXXOperatorName(DTN->getOperator()); 36022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // DNInfo work in progress: FIXME: source locations? 36032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameLoc DNLoc; 36042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNLoc.CXXOperatorName.BeginOpNameLoc = SourceLocation().getRawEncoding(); 36052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DNLoc.CXXOperatorName.EndOpNameLoc = SourceLocation().getRawEncoding(); 36062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(DName, NameLoc, DNLoc); 360780ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } 360880ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall } 360980ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall 3610146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 3611146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 3612146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 3613146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(subst->getParameter()->getDeclName(), 3614146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 3615146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3616146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3617146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParmPack: { 3618146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmPackStorage *subst 3619146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParmPack(); 3620146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DeclarationNameInfo(subst->getParameterPack()->getDeclName(), 3621146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall NameLoc); 3622146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3623146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3624146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3625146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("bad template name kind!"); 362680ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall} 362780ad16f4b2b350ddbaae21a52975e63df5aafc2cJohn McCall 36284ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName ASTContext::getCanonicalTemplateName(TemplateName Name) const { 3629146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall switch (Name.getKind()) { 3630146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::QualifiedTemplate: 3631146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::Template: { 3632146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateDecl *Template = Name.getAsTemplateDecl(); 36333e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (TemplateTemplateParmDecl *TTP 3634146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = dyn_cast<TemplateTemplateParmDecl>(Template)) 36353e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Template = getCanonicalTemplateTemplateParmDecl(TTP); 36363e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 36373e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor // The canonical template name is the canonical template declaration. 363897fbaa2a38804268a024f1a104b43fcf8b4411b0Argyrios Kyrtzidis return TemplateName(cast<TemplateDecl>(Template->getCanonicalDecl())); 36393e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 364025a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 3641146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::OverloadedTemplate: 3642146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("cannot canonicalize overloaded template"); 3643146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3644146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::DependentTemplate: { 3645146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall DependentTemplateName *DTN = Name.getAsDependentTemplateName(); 3646146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall assert(DTN && "Non-dependent template names must refer to template decls."); 3647146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return DTN->CanonicalTemplateName; 3648146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3649146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3650146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParm: { 3651146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 3652146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParm(); 3653146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return getCanonicalTemplateName(subst->getReplacement()); 36541aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 36551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3656146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall case TemplateName::SubstTemplateTemplateParmPack: { 3657146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmPackStorage *subst 3658146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = Name.getAsSubstTemplateTemplateParmPack(); 3659146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateTemplateParmDecl *canonParameter 3660146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = getCanonicalTemplateTemplateParmDecl(subst->getParameterPack()); 3661146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateArgument canonArgPack 3662146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = getCanonicalTemplateArgument(subst->getArgumentPack()); 3663146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return getSubstTemplateTemplateParmPack(canonParameter, canonArgPack); 3664146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3665146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 3666146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 3667146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm_unreachable("bad template name!"); 366825a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor} 366925a3ef7cc5fd55dc8cc67c6e6770c8595657e082Douglas Gregor 3670db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregorbool ASTContext::hasSameTemplateName(TemplateName X, TemplateName Y) { 3671db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor X = getCanonicalTemplateName(X); 3672db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor Y = getCanonicalTemplateName(Y); 3673db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor return X.getAsVoidPointer() == Y.getAsVoidPointer(); 3674db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor} 3675db0d4b751e83b8841b8f48f913f17e50467f13d4Douglas Gregor 36761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateArgument 36774ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const { 36781275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor switch (Arg.getKind()) { 36791275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Null: 36801275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 36811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36821275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Expression: 36831275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor return Arg; 36841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3685d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor case TemplateArgument::Declaration: { 3686d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor if (Decl *D = Arg.getAsDecl()) 3687d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor return TemplateArgument(D->getCanonicalDecl()); 3688d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor return TemplateArgument((Decl*)0); 3689d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor } 36901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3691788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 3692788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return TemplateArgument(getCanonicalTemplateName(Arg.getAsTemplate())); 3693a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3694a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3695a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgument(getCanonicalTemplateName( 3696a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Arg.getAsTemplateOrTemplatePattern()), 36972be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor Arg.getNumTemplateExpansions()); 3698a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 36991275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Integral: 3700855243789cb44799c03f4c7216d3d6308805f549Benjamin Kramer return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType())); 37011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37021275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Type: 3703833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return TemplateArgument(getCanonicalType(Arg.getAsType())); 37041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37051275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor case TemplateArgument::Pack: { 370687dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor if (Arg.pack_size() == 0) 370787dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor return Arg; 370887dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor 3709910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *CanonArgs 3710910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (*this) TemplateArgument[Arg.pack_size()]; 37111275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor unsigned Idx = 0; 37121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 37131275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor AEnd = Arg.pack_end(); 37141275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor A != AEnd; (void)++A, ++Idx) 37151275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor CanonArgs[Idx] = getCanonicalTemplateArgument(*A); 37161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3717910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor return TemplateArgument(CanonArgs, Arg.pack_size()); 37181275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 37191275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor } 37201275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 37211275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor // Silence GCC warning 3722b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unhandled template argument kind"); 37231275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor} 37241275ae098acda31fe0e434510c729fcfed0458a1Douglas Gregor 3725d57959af02b4af695276f4204443afe6e5d86bd8Douglas GregorNestedNameSpecifier * 37264ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const { 37271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!NNS) 3728d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return 0; 3729d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3730d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor switch (NNS->getKind()) { 3731d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Identifier: 3732d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // Canonicalize the prefix but keep the identifier the same. 37331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return NestedNameSpecifier::Create(*this, 3734d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor getCanonicalNestedNameSpecifier(NNS->getPrefix()), 3735d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor NNS->getAsIdentifier()); 3736d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3737d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Namespace: 3738d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 3739d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // this namespace and no prefix. 374014aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(*this, 0, 374114aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespace()->getOriginalNamespace()); 374214aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor 374314aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor case NestedNameSpecifier::NamespaceAlias: 374414aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor // A namespace is canonical; build a nested-name-specifier with 374514aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor // this namespace and no prefix. 374614aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor return NestedNameSpecifier::Create(*this, 0, 374714aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor NNS->getAsNamespaceAlias()->getNamespace() 374814aba76042e041b2c5e439bf4ae353a0a3c7fd73Douglas Gregor ->getOriginalNamespace()); 3749d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3750d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpec: 3751d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: { 3752d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor QualType T = getCanonicalType(QualType(NNS->getAsType(), 0)); 3753264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor 3754264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // If we have some kind of dependent-named type (e.g., "typename T::type"), 3755264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // break it apart into its prefix and identifier, then reconsititute those 3756264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // as the canonical nested-name-specifier. This is required to canonicalize 3757264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // a dependent nested-name-specifier involving typedefs of dependent-name 3758264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // types, e.g., 3759264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // typedef typename T::type T1; 3760264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor // typedef typename T1::type T2; 376116412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman if (const DependentNameType *DNT = T->getAs<DependentNameType>()) 376216412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman return NestedNameSpecifier::Create(*this, DNT->getQualifier(), 3763264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor const_cast<IdentifierInfo *>(DNT->getIdentifier())); 3764264bf66d55563dd86a3d7e06738aa427de512d2cDouglas Gregor 376516412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // Otherwise, just canonicalize the type, and force it to be a TypeSpec. 376616412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the 376716412ef25a2203b7066d0db2b41f944631e5cf79Eli Friedman // first place? 37683b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return NestedNameSpecifier::Create(*this, 0, false, 37693b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall const_cast<Type*>(T.getTypePtr())); 3770d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3771d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3772d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor case NestedNameSpecifier::Global: 3773d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor // The global specifier is canonical and unique. 3774d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor return NNS; 3775d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor } 3776d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 37777530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid NestedNameSpecifier::Kind!"); 3778d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor} 3779d57959af02b4af695276f4204443afe6e5d86bd8Douglas Gregor 3780c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 37814ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadconst ArrayType *ASTContext::getAsArrayType(QualType T) const { 3782c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the non-qualified case efficiently. 3783a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor if (!T.hasLocalQualifiers()) { 3784c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Handle the common positive case fast. 3785c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ArrayType *AT = dyn_cast<ArrayType>(T)) 3786c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return AT; 3787c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner } 37881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Handle the common negative case fast. 37903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!isa<ArrayType>(T.getCanonicalType())) 3791c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return 0; 37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Apply any qualifiers from the array type to the element type. This 3794c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // implements C99 6.7.3p8: "If the specification of an array type includes 3795c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // any type qualifiers, the element type is so qualified, not the array type." 37961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3797c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we get here, we either have type qualifiers on the type, or we have 3798c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // sugar such as a typedef in the way. If we have type qualifiers on the type 379950d62d1b4a98adbc83de8f8cd1379ea1c25656f7Douglas Gregor // we must propagate them down into the element type. 38000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 38013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split = T.getSplitDesugaredType(); 3802200fa53fd420aa8369586f569dbece04930ad6a3John McCall Qualifiers qs = split.Quals; 38031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3804c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // If we have a simple case, just return now. 3805200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ArrayType *ATy = dyn_cast<ArrayType>(split.Ty); 38063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (ATy == 0 || qs.empty()) 3807c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return ATy; 38081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3809c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Otherwise, we have an array and we have qualifiers on it. Push the 3810c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // qualifiers into the array element type and return a new array type. 38113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall QualType NewEltTy = getQualifiedType(ATy->getElementType(), qs); 38121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3813c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(ATy)) 3814c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getConstantArrayType(NewEltTy, CAT->getSize(), 3815c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner CAT->getSizeModifier(), 38160953e767ff7817f97b3ab20896b229891eeff45bJohn McCall CAT->getIndexTypeCVRQualifiers())); 3817c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(ATy)) 3818c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner return cast<ArrayType>(getIncompleteArrayType(NewEltTy, 3819c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner IAT->getSizeModifier(), 38200953e767ff7817f97b3ab20896b229891eeff45bJohn McCall IAT->getIndexTypeCVRQualifiers())); 3821898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 38221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const DependentSizedArrayType *DSAT 3823898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor = dyn_cast<DependentSizedArrayType>(ATy)) 3824898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return cast<ArrayType>( 38251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDependentSizedArrayType(NewEltTy, 38263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall DSAT->getSizeExpr(), 3827898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor DSAT->getSizeModifier(), 38280953e767ff7817f97b3ab20896b229891eeff45bJohn McCall DSAT->getIndexTypeCVRQualifiers(), 38297e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor DSAT->getBracketsRange())); 38301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3831c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const VariableArrayType *VAT = cast<VariableArrayType>(ATy); 38327e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return cast<ArrayType>(getVariableArrayType(NewEltTy, 38333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall VAT->getSizeExpr(), 3834c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner VAT->getSizeModifier(), 38350953e767ff7817f97b3ab20896b229891eeff45bJohn McCall VAT->getIndexTypeCVRQualifiers(), 38367e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor VAT->getBracketsRange())); 383777c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner} 383877c9647cae939104c6cb2b6a4dd8ca859d2e5770Chris Lattner 3839ad9689f3531c49e4bff467d9469993606800068cAbramo BagnaraQualType ASTContext::getAdjustedParameterType(QualType T) const { 384079e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // C99 6.7.5.3p7: 384179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // A declaration of a parameter as "array of type" shall be 384279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // adjusted to "qualified pointer to type", where the type 384379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // qualifiers (if any) are those specified within the [ and ] of 384479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // the array type derivation. 384579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor if (T->isArrayType()) 384679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return getArrayDecayedType(T); 384779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 384879e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // C99 6.7.5.3p8: 384979e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // A declaration of a parameter as "function returning type" 385079e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // shall be adjusted to "pointer to function returning type", as 385179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor // in 6.3.2.1. 385279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor if (T->isFunctionType()) 385379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return getPointerType(T); 385479e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 385579e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return T; 385679e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor} 385779e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 3858ad9689f3531c49e4bff467d9469993606800068cAbramo BagnaraQualType ASTContext::getSignatureParameterType(QualType T) const { 385979e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor T = getVariableArrayDecayedType(T); 386079e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor T = getAdjustedParameterType(T); 386179e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor return T.getUnqualifiedType(); 386279e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor} 386379e6bd379773447a74cc3e579d9081e4c5cb6d63Douglas Gregor 3864e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// getArrayDecayedType - Return the properly qualified result of decaying the 3865e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// specified array type to a pointer. This operation is non-trivial when 3866e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// handling typedefs etc. The canonical type of "T" must be an array type, 3867e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// this returns a pointer to a properly qualified element of the array. 3868e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// 3869e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner/// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 38704ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getArrayDecayedType(QualType Ty) const { 3871c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // Get the element type with 'getAsArrayType' so that we don't lose any 3872c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // typedefs in the element type of the array. This also handles propagation 3873c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // of type qualifiers from the array type into the element type if present 3874c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner // (C99 6.7.3p8). 3875c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner const ArrayType *PrettyArrayType = getAsArrayType(Ty); 3876c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner assert(PrettyArrayType && "Not an array type!"); 38771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3878c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType PtrTy = getPointerType(PrettyArrayType->getElementType()); 3879e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 3880e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner // int x[restrict 4] -> int *restrict 38810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return getQualifiedType(PtrTy, PrettyArrayType->getIndexTypeQualifiers()); 3882e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner} 3883e6327747b72bb687c948270f702ff53c30f411a6Chris Lattner 38843b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getBaseElementType(const ArrayType *array) const { 38853b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getBaseElementType(array->getElementType()); 38865e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor} 38875e03f9ea8174ae588c5e69ec6b5ef4c68f8fd766Douglas Gregor 38883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCallQualType ASTContext::getBaseElementType(QualType type) const { 38893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Qualifiers qs; 38903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall while (true) { 38913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall SplitQualType split = type.getSplitDesugaredType(); 3892200fa53fd420aa8369586f569dbece04930ad6a3John McCall const ArrayType *array = split.Ty->getAsArrayTypeUnsafe(); 38933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!array) break; 38941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall type = array->getElementType(); 3896200fa53fd420aa8369586f569dbece04930ad6a3John McCall qs.addConsistentQualifiers(split.Quals); 38973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall } 38981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall return getQualifiedType(type, qs); 39006183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson} 39016183a99b064b397d98297904fbd6cf00fe1f453dAnders Carlsson 39020de78998e7bda473b408437053e48661b510d453Fariborz Jahanian/// getConstantArrayElementCount - Returns number of constant array elements. 39031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpuint64_t 39040de78998e7bda473b408437053e48661b510d453Fariborz JahanianASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { 39050de78998e7bda473b408437053e48661b510d453Fariborz Jahanian uint64_t ElementCount = 1; 39060de78998e7bda473b408437053e48661b510d453Fariborz Jahanian do { 39070de78998e7bda473b408437053e48661b510d453Fariborz Jahanian ElementCount *= CA->getSize().getZExtValue(); 39080de78998e7bda473b408437053e48661b510d453Fariborz Jahanian CA = dyn_cast<ConstantArrayType>(CA->getElementType()); 39090de78998e7bda473b408437053e48661b510d453Fariborz Jahanian } while (CA); 39100de78998e7bda473b408437053e48661b510d453Fariborz Jahanian return ElementCount; 39110de78998e7bda473b408437053e48661b510d453Fariborz Jahanian} 39120de78998e7bda473b408437053e48661b510d453Fariborz Jahanian 39135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getFloatingRank - Return a relative rank for floating point types. 39145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// This routine will assert if passed a built-in type that isn't a float. 3915a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattnerstatic FloatingRank getFloatingRank(QualType T) { 3916183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) 39175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getFloatingRank(CT->getElementType()); 3918a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner 3919183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall assert(T->getAs<BuiltinType>() && "getFloatingRank(): not a floating type"); 3920183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall switch (T->getAs<BuiltinType>()->getKind()) { 3921b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("getFloatingRank(): not a floating type"); 3922aa4a99b4a62615db243f7a5c433169f2fc704420Anton Korobeynikov case BuiltinType::Half: return HalfRank; 39235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Float: return FloatRank; 39245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::Double: return DoubleRank; 39255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BuiltinType::LongDouble: return LongDoubleRank; 39265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 39275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 39285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 39291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getFloatingTypeOfSizeWithinDomain - Returns a real floating 39301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// point or a complex type (based on typeDomain/typeSize). 3931716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeDomain' is a real floating point or complex type. 3932716c7304ff5d27a95e1e7823acd1d09d5ec3e37fSteve Naroff/// 'typeSize' is a real floating point or complex type. 39331361b11066239ea15764a2a844405352d87296b3Chris LattnerQualType ASTContext::getFloatingTypeOfSizeWithinDomain(QualType Size, 39341361b11066239ea15764a2a844405352d87296b3Chris Lattner QualType Domain) const { 39351361b11066239ea15764a2a844405352d87296b3Chris Lattner FloatingRank EltRank = getFloatingRank(Size); 39361361b11066239ea15764a2a844405352d87296b3Chris Lattner if (Domain->isComplexType()) { 39371361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 3938561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie case HalfRank: llvm_unreachable("Complex half is not supported"); 3939f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case FloatRank: return FloatComplexTy; 3940f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case DoubleRank: return DoubleComplexTy; 3941f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff case LongDoubleRank: return LongDoubleComplexTy; 3942f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 3943f1448a0e4a1e868ff873a8530a61a09cb68666ccSteve Naroff } 39441361b11066239ea15764a2a844405352d87296b3Chris Lattner 39451361b11066239ea15764a2a844405352d87296b3Chris Lattner assert(Domain->isRealFloatingType() && "Unknown domain!"); 39461361b11066239ea15764a2a844405352d87296b3Chris Lattner switch (EltRank) { 3947561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie case HalfRank: llvm_unreachable("Half ranks are not valid here"); 39481361b11066239ea15764a2a844405352d87296b3Chris Lattner case FloatRank: return FloatTy; 39491361b11066239ea15764a2a844405352d87296b3Chris Lattner case DoubleRank: return DoubleTy; 39501361b11066239ea15764a2a844405352d87296b3Chris Lattner case LongDoubleRank: return LongDoubleTy; 39515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 3952561d3abc881033776ece385a01a510e1cbc1fa92David Blaikie llvm_unreachable("getFloatingRank(): illegal value for rank"); 39535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 39545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 39557cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// getFloatingTypeOrder - Compare the rank of the two specified floating 39567cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// point types, ignoring the domain of the type (i.e. 'double' == 39577cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 39581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 39594ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadint ASTContext::getFloatingTypeOrder(QualType LHS, QualType RHS) const { 3960a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank LHSR = getFloatingRank(LHS); 3961a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner FloatingRank RHSR = getFloatingRank(RHS); 39621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3963a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR == RHSR) 3964fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 0; 3965a75cea3f6be0daa8054d36af81a6ffda1713f82dChris Lattner if (LHSR > RHSR) 3966fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return 1; 3967fb0d49669aa370b4c0993c5cee60275ef9fd6518Steve Naroff return -1; 39685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 39695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 3970f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// getIntegerRank - Return an integer conversion rank (C99 6.3.1.1p1). This 3971f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// routine will assert if passed a built-in type that isn't an integer or enum, 3972f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner/// or if it is not canonicalized. 3973f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCallunsigned ASTContext::getIntegerRank(const Type *T) const { 3974467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(T->isCanonicalUnqualified() && "T should be canonicalized"); 3975f5c209d23b20ada4a9b6235db50317239cbf6ae1Alisdair Meredith 3976f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner switch (cast<BuiltinType>(T)->getKind()) { 3977b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("getIntegerRank(): not a built-in integer"); 39787cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Bool: 3979f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 1 + (getIntWidth(BoolTy) << 3); 39807cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_S: 39817cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Char_U: 39827cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::SChar: 39837cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UChar: 3984f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 2 + (getIntWidth(CharTy) << 3); 39857cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Short: 39867cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UShort: 3987f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 3 + (getIntWidth(ShortTy) << 3); 39887cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Int: 39897cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::UInt: 3990f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 4 + (getIntWidth(IntTy) << 3); 39917cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::Long: 39927cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULong: 3993f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 5 + (getIntWidth(LongTy) << 3); 39947cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::LongLong: 39957cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner case BuiltinType::ULongLong: 3996f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman return 6 + (getIntWidth(LongLongTy) << 3); 39972df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 39982df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::UInt128: 39992df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return 7 + (getIntWidth(Int128Ty) << 3); 4000f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner } 4001f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner} 4002f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner 400304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \brief Whether this is a promotable bitfield reference according 400404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 400504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// 400604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// \returns the type this bit-field will promote to, or NULL if no 400704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman/// promotion occurs. 40084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::isPromotableBitField(Expr *E) const { 4009ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor if (E->isTypeDependent() || E->isValueDependent()) 4010ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor return QualType(); 4011ceafbdeb93ecf323cca74e660bf54504c86f3b71Douglas Gregor 401204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman FieldDecl *Field = E->getBitField(); 401304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (!Field) 401404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 401504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 401604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman QualType FT = Field->getType(); 401704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 4018a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith uint64_t BitWidth = Field->getBitWidthValue(*this); 401904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 402004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // GCC extension compatibility: if the bit-field size is less than or equal 402104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // to the size of int, it gets promoted no matter what its type is. 402204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // For instance, unsigned long bf : 4 gets promoted to signed int. 402304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth < IntSize) 402404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return IntTy; 402504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 402604e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman if (BitWidth == IntSize) 402704e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return FT->isSignedIntegerType() ? IntTy : UnsignedIntTy; 402804e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 402904e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // Types bigger than int are not subject to promotions, and therefore act 403004e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // like the base type. 403104e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // FIXME: This doesn't quite match what gcc does, but what gcc does here 403204e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman // is ridiculous. 403304e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman return QualType(); 403404e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman} 403504e8357f6801e9ff52673e7e899a67bbabf9de93Eli Friedman 4036a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// getPromotedIntegerType - Returns the type that Promotable will 4037a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 4038a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman/// integer type. 40394ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getPromotedIntegerType(QualType Promotable) const { 4040a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(!Promotable.isNull()); 4041a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isPromotableIntegerType()); 4042842aef8d942a880eeb9535d40de31a86838264cbJohn McCall if (const EnumType *ET = Promotable->getAs<EnumType>()) 4043842aef8d942a880eeb9535d40de31a86838264cbJohn McCall return ET->getDecl()->getPromotionType(); 404468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman 404568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (const BuiltinType *BT = Promotable->getAs<BuiltinType>()) { 404668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // C++ [conv.prom]: A prvalue of type char16_t, char32_t, or wchar_t 404768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // (3.9.1) can be converted to a prvalue of the first of the following 404868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // types that can represent all the values of its underlying type: 404968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // int, unsigned int, long int, unsigned long int, long long int, or 405068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // unsigned long long int [...] 405168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // FIXME: Is there some better way to compute this? 405268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (BT->getKind() == BuiltinType::WChar_S || 405368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::WChar_U || 405468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::Char16 || 405568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman BT->getKind() == BuiltinType::Char32) { 405668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman bool FromIsSigned = BT->getKind() == BuiltinType::WChar_S; 405768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman uint64_t FromSize = getTypeSize(BT); 405868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman QualType PromoteTypes[] = { IntTy, UnsignedIntTy, LongTy, UnsignedLongTy, 405968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman LongLongTy, UnsignedLongLongTy }; 406068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman for (size_t Idx = 0; Idx < llvm::array_lengthof(PromoteTypes); ++Idx) { 406168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman uint64_t ToSize = getTypeSize(PromoteTypes[Idx]); 406268a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman if (FromSize < ToSize || 406368a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman (FromSize == ToSize && 406468a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman FromIsSigned == PromoteTypes[Idx]->isSignedIntegerType())) 406568a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman return PromoteTypes[Idx]; 406668a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 406768a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman llvm_unreachable("char type should fit into long long"); 406868a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 406968a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman } 407068a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman 407168a2dc446fe6d32d5da3557902100ed06b21b12bEli Friedman // At this point, we should have a signed or unsigned integer type. 4072a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman if (Promotable->isSignedIntegerType()) 4073a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return IntTy; 4074a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t PromotableSize = getTypeSize(Promotable); 4075a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman uint64_t IntSize = getTypeSize(IntTy); 4076a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman assert(Promotable->isUnsignedIntegerType() && PromotableSize <= IntSize); 4077a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy; 4078a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman} 4079a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 408031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis/// \brief Recurses in pointer/array types until it finds an objc retainable 408131862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis/// type and returns its ownership. 408231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios KyrtzidisQualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const { 408331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis while (!T.isNull()) { 408431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (T.getObjCLifetime() != Qualifiers::OCL_None) 408531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return T.getObjCLifetime(); 408631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis if (T->isArrayType()) 408731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis T = getBaseElementType(T); 408831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else if (const PointerType *PT = T->getAs<PointerType>()) 408931862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis T = PT->getPointeeType(); 409031862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 409128445f0b62f6aed851ff87ce64d9b19200d3211fArgyrios Kyrtzidis T = RT->getPointeeType(); 409231862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis else 409331862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis break; 409431862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis } 409531862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 409631862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis return Qualifiers::OCL_None; 409731862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis} 409831862ba5ea70b1f2c81d03f8a0100b61cd6f06f6Argyrios Kyrtzidis 40991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// getIntegerTypeOrder - Returns the highest ranked integer type: 41007cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 41011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// LHS < RHS, return -1. 41024ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadint ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { 4103f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *LHSC = getCanonicalType(LHS).getTypePtr(); 4104f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const Type *RHSC = getCanonicalType(RHS).getTypePtr(); 41057cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSC == RHSC) return 0; 41061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4107f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool LHSUnsigned = LHSC->isUnsignedIntegerType(); 4108f52ab250ff92bc51a9ac9a8e19bd43b63a5f844fChris Lattner bool RHSUnsigned = RHSC->isUnsignedIntegerType(); 41091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41107cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned LHSRank = getIntegerRank(LHSC); 41117cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner unsigned RHSRank = getIntegerRank(RHSC); 41121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41137cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned == RHSUnsigned) { // Both signed or both unsigned. 41147cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank == RHSRank) return 0; 41157cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return LHSRank > RHSRank ? 1 : -1; 41167cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 41171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41187cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // Otherwise, the LHS is signed and the RHS is unsigned or visa versa. 41197cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSUnsigned) { 41207cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [LHS] type is larger, return it. 41217cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (LHSRank >= RHSRank) 41227cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 41231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41247cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 41257cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 41261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 41277cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 41287cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner } 41297cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner 41307cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the unsigned [RHS] type is larger, return it. 41317cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner if (RHSRank >= LHSRank) 41327cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return -1; 41331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 41347cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // If the signed type can represent all values of the unsigned type, it 41357cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner // wins. Because we are dealing with 2's complement and types that are 41361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // powers of two larger than each other, this is always safe. 41377cfeb08f2466d6263ec6ff1402298f93f6d6991fChris Lattner return 1; 41385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 413971993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson 414079cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlssonstatic RecordDecl * 4141ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo BagnaraCreateRecordDecl(const ASTContext &Ctx, RecordDecl::TagKind TK, 4142ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara DeclContext *DC, IdentifierInfo *Id) { 4143ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara SourceLocation Loc; 41444e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (Ctx.getLangOpts().CPlusPlus) 4145ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara return CXXRecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id); 414679cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson else 4147ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara return RecordDecl::Create(Ctx, TK, DC, Loc, Loc, Id); 414879cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson} 4149ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara 41501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// getCFConstantStringType - Return the type used for constant CFStrings. 41514ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getCFConstantStringType() const { 415271993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson if (!CFConstantStringTypeDecl) { 41531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump CFConstantStringTypeDecl = 4154ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara CreateRecordDecl(*this, TTK_Struct, TUDecl, 415579cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("NSConstantString")); 41565cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall CFConstantStringTypeDecl->startDefinition(); 415779cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson 4158f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson QualType FieldTypes[4]; 41591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 416071993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const int *isa; 41610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[0] = getPointerType(IntTy.withConst()); 4162f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson // int flags; 4163f06273f8bbacb086a46bde456429c8d08f6d07eeAnders Carlsson FieldTypes[1] = IntTy; 416471993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // const char *str; 41650953e767ff7817f97b3ab20896b229891eeff45bJohn McCall FieldTypes[2] = getPointerType(CharTy.withConst()); 416671993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson // long length; 41671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldTypes[3] = LongTy; 41681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 416944b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor // Create fields 417044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor for (unsigned i = 0; i < 4; ++i) { 41711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump FieldDecl *Field = FieldDecl::Create(*this, CFConstantStringTypeDecl, 4172ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 417344b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor SourceLocation(), 0, 4174a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 41751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /*BitWidth=*/0, 41767a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4177ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 41782888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 417917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis CFConstantStringTypeDecl->addDecl(Field); 418044b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor } 418144b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor 4182838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor CFConstantStringTypeDecl->completeDefinition(); 418371993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson } 41841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 418571993dd85eed9cc42c6b2fa61ee5c53026b74817Anders Carlsson return getTagDeclType(CFConstantStringTypeDecl); 41868467583c2704e7a9691ea56939a029015f0ade0aGabor Greif} 4187b2cf3573d7351094f6247fcca94703ce88eb9ee0Anders Carlsson 4188319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregorvoid ASTContext::setCFConstantStringType(QualType T) { 41896217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek const RecordType *Rec = T->getAs<RecordType>(); 4190319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor assert(Rec && "Invalid CFConstantStringType"); 4191319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor CFConstantStringTypeDecl = Rec->getDecl(); 4192319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor} 4193319ac896a0fef7365d5589b8021db7e41207fe42Douglas Gregor 41944ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockDescriptorType() const { 4195adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump if (BlockDescriptorType) 4196adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump return getTagDeclType(BlockDescriptorType); 4197adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4198adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump RecordDecl *T; 4199adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump // FIXME: Needs the FlagAppleBlock bit. 4200ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, 420179cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("__block_descriptor")); 42025cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall T->startDefinition(); 4203adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4204adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump QualType FieldTypes[] = { 4205adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump UnsignedLongTy, 4206adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump UnsignedLongTy, 4207adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump }; 4208adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4209adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump const char *FieldNames[] = { 4210adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump "reserved", 4211083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "Size" 4212adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump }; 4213adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4214adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump for (size_t i = 0; i < 2; ++i) { 4215ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4216adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump SourceLocation(), 4217adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump &Idents.get(FieldNames[i]), 4218a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 4219adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump /*BitWidth=*/0, 42207a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4221ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 42222888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4223adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump T->addDecl(Field); 4224adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump } 4225adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4226838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4227adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4228adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump BlockDescriptorType = T; 4229adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 4230adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump return getTagDeclType(BlockDescriptorType); 4231adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump} 4232adaaad3715c9c26cdcfdfe3401a13d7b4423ddcfMike Stump 42334ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType ASTContext::getBlockDescriptorExtendedType() const { 4234083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump if (BlockDescriptorExtendedType) 4235083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump return getTagDeclType(BlockDescriptorExtendedType); 4236083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4237083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump RecordDecl *T; 4238083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump // FIXME: Needs the FlagAppleBlock bit. 4239ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, 424079cbc7dd2aacd85a28f469b5dc73c4ea296e7072Anders Carlsson &Idents.get("__block_descriptor_withcopydispose")); 42415cfa011e61e14e6f2e1659047d809706c0e4c6a3John McCall T->startDefinition(); 4242083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4243083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump QualType FieldTypes[] = { 4244083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump UnsignedLongTy, 4245083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump UnsignedLongTy, 4246083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump getPointerType(VoidPtrTy), 4247083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump getPointerType(VoidPtrTy) 4248083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump }; 4249083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4250083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump const char *FieldNames[] = { 4251083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "reserved", 4252083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "Size", 4253083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "CopyFuncPtr", 4254083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump "DestroyFuncPtr" 4255083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump }; 4256083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4257083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump for (size_t i = 0; i < 4; ++i) { 4258ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4259083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump SourceLocation(), 4260083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump &Idents.get(FieldNames[i]), 4261a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 4262083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump /*BitWidth=*/0, 42637a614d8380297fcd2bc23986241905d97222948cRichard Smith /*Mutable=*/false, 4264ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 42652888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4266083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump T->addDecl(Field); 4267083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump } 4268083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4269838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4270083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4271083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump BlockDescriptorExtendedType = T; 4272083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 4273083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump return getTagDeclType(BlockDescriptorExtendedType); 4274083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump} 4275083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump 42764ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ASTContext::BlockRequiresCopying(QualType Ty) const { 4277f85e193739c953358c865005855253af4f68a497John McCall if (Ty->isObjCRetainableType()) 4278af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return true; 42794e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) { 4280e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian if (const RecordType *RT = Ty->getAs<RecordType>()) { 4281e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); 4282ffe37fdda5b4b4f162a45155c30d9f60ce110c12Sean Hunt return RD->hasConstCopyConstructor(); 4283e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian 4284e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian } 4285e38be617437ccdcc180c5a49e447cbcd07539292Fariborz Jahanian } 4286af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return false; 4287af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump} 4288af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 42894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadQualType 42905f9e272e632e951b1efe824cd16acb4d96077930Chris LattnerASTContext::BuildByRefType(StringRef DeclName, QualType Ty) const { 4291af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // type = struct __Block_byref_1_X { 4292ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // void *__isa; 4293af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // struct __Block_byref_1_X *__forwarding; 4294ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // unsigned int __flags; 4295ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // unsigned int __size; 4296a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman // void *__copy_helper; // as needed 4297a7e6845660f91ec611427e1db842780e1ec12bdbEli Friedman // void *__destroy_help // as needed 4298af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // int X; 4299ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump // } * 4300ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump 4301af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump bool HasCopyAndDispose = BlockRequiresCopying(Ty); 4302af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4303af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump // FIXME: Move up 4304f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<36> Name; 4305f5942a44880be26878592eb052b737579349411eBenjamin Kramer llvm::raw_svector_ostream(Name) << "__Block_byref_" << 4306f5942a44880be26878592eb052b737579349411eBenjamin Kramer ++UniqueBlockByRefTypeID << '_' << DeclName; 4307af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump RecordDecl *T; 4308ba877adeb49ed6dc17f27fa3a3bcd0cca713fd68Abramo Bagnara T = CreateRecordDecl(*this, TTK_Struct, TUDecl, &Idents.get(Name.str())); 4309af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump T->startDefinition(); 4310af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump QualType Int32Ty = IntTy; 4311af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump assert(getIntWidth(IntTy) == 32 && "non-32bit int not supported"); 4312af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump QualType FieldTypes[] = { 4313af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4314af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(getTagDeclType(T)), 4315af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Int32Ty, 4316af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Int32Ty, 4317af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4318af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump getPointerType(VoidPtrTy), 4319af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump Ty 4320af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump }; 4321af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 43225f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef FieldNames[] = { 4323af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__isa", 4324af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__forwarding", 4325af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__flags", 4326af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__size", 4327af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__copy_helper", 4328af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump "__destroy_helper", 4329af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump DeclName, 4330af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump }; 4331af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4332af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump for (size_t i = 0; i < 7; ++i) { 4333af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump if (!HasCopyAndDispose && i >=4 && i <= 5) 4334af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump continue; 4335af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump FieldDecl *Field = FieldDecl::Create(*this, T, SourceLocation(), 4336ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation(), 4337af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump &Idents.get(FieldNames[i]), 4338a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall FieldTypes[i], /*TInfo=*/0, 43397a614d8380297fcd2bc23986241905d97222948cRichard Smith /*BitWidth=*/0, /*Mutable=*/false, 4340ca5233044ef679840d1ad1c46a36b16e2ee8a6e1Richard Smith ICIS_NoInit); 43412888b65aae768f54062505330df7be230a0510c7John McCall Field->setAccess(AS_public); 4342af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump T->addDecl(Field); 4343af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump } 4344af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4345838db383b69b9fb55f55c8e9546477df198a4faaDouglas Gregor T->completeDefinition(); 4346af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump 4347af7b44d847d3e44c43346d508b2e55a6254b6e9dMike Stump return getPointerType(getTagDeclType(T)); 4348ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump} 4349ea26cb522e88fc86b0d1cae61dcefcfe4cc20231Mike Stump 4350e97179c675b341927807c718be215c8d1aab8acbDouglas GregorTypedefDecl *ASTContext::getObjCInstanceTypeDecl() { 4351e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor if (!ObjCInstanceTypeDecl) 4352e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor ObjCInstanceTypeDecl = TypedefDecl::Create(*this, 4353e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor getTranslationUnitDecl(), 4354e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor SourceLocation(), 4355e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor SourceLocation(), 4356e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor &Idents.get("instancetype"), 4357e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor getTrivialTypeSourceInfo(getObjCIdType())); 4358e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor return ObjCInstanceTypeDecl; 4359e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor} 4360e97179c675b341927807c718be215c8d1aab8acbDouglas Gregor 4361e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// This returns true if a type has been typedefed to BOOL: 4362e8c49533521c40643653f943d47229e62d277f88Anders Carlsson// typedef <type> BOOL; 43632d99833e8c956775f2183601cd120b65b569c867Chris Lattnerstatic bool isTypeTypedefedAsBOOL(QualType T) { 4364e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (const TypedefType *TT = dyn_cast<TypedefType>(T)) 4365bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner if (IdentifierInfo *II = TT->getDecl()->getIdentifier()) 4366bb49c3ee5d270485f4b273691fd14bc97403fa5dChris Lattner return II->isStr("BOOL"); 43671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 436885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return false; 436985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 437085f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 4371a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingTypeSize returns size of type for objective-c encoding 437233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// purpose. 43734ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadCharUnits ASTContext::getObjCEncodingTypeSize(QualType type) const { 4374f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (!type->isIncompleteArrayType() && type->isIncompleteType()) 4375f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return CharUnits::Zero(); 4376f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4377199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits sz = getTypeSizeInChars(type); 43781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 437933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Make all integer and enum types at least as large as an int 43802ade35e2cfd554e49d35a52047cea98a82787af9Douglas Gregor if (sz.isPositive() && type->isIntegralOrEnumerationType()) 4381199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck sz = std::max(sz, getTypeSizeInChars(IntTy)); 438233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Treat arrays as pointers, since that's how they're passed in. 438333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian else if (type->isArrayType()) 4384199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck sz = getTypeSizeInChars(VoidPtrTy); 4385aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck return sz; 4386199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck} 4387199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck 4388199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyckstatic inline 4389199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyckstd::string charUnitsToString(const CharUnits &CU) { 4390199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck return llvm::itostr(CU.getQuantity()); 439133e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 439233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 43936b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall/// getObjCEncodingForBlock - Return the encoded type for this block 43945e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall/// declaration. 43956b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCallstd::string ASTContext::getObjCEncodingForBlock(const BlockExpr *Expr) const { 43966b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall std::string S; 43976b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall 43985e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall const BlockDecl *Decl = Expr->getBlockDecl(); 43995e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType BlockTy = 44005e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall Expr->getType()->getAs<BlockPointerType>()->getPointeeType(); 44015e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Encode result type. 4402c71a4915ca216847599d03cab4ed1c5086b0eb43John McCall getObjCEncodingForType(BlockTy->getAs<FunctionType>()->getResultType(), S); 44035e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Compute size of all parameters. 44045e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Start with computing size of a pointer in number of bytes. 44055e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // FIXME: There might(should) be a better way of doing this computation! 44065e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall SourceLocation Loc; 4407199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); 4408199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits ParmOffset = PtrSize; 44096f46c2653c1545cc3fef0c0df996d18160160ce8Fariborz Jahanian for (BlockDecl::param_const_iterator PI = Decl->param_begin(), 44105e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall E = Decl->param_end(); PI != E; ++PI) { 44115e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType PType = (*PI)->getType(); 4412aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck CharUnits sz = getObjCEncodingTypeSize(PType); 4413075a54354dc6e3644b12206e5127855091783fd6Fariborz Jahanian if (sz.isZero()) 4414075a54354dc6e3644b12206e5127855091783fd6Fariborz Jahanian continue; 4415199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck assert (sz.isPositive() && "BlockExpr - Incomplete param type"); 44165e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmOffset += sz; 44175e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } 44185e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Size of the argument frame 4419199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 44205e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Block pointer and offset. 44215e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall S += "@?0"; 44225e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall 44235e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Argument types. 44245e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmOffset = PtrSize; 44255e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall for (BlockDecl::param_const_iterator PI = Decl->param_begin(), E = 44265e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall Decl->param_end(); PI != E; ++PI) { 44275e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall ParmVarDecl *PVDecl = *PI; 44285e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall QualType PType = PVDecl->getOriginalType(); 44295e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall if (const ArrayType *AT = 44305e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 44315e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // Use array's original type only if it has known number of 44325389f48b24937ad7b4093307128b3cbf25235654David Chisnall // elements. 44335389f48b24937ad7b4093307128b3cbf25235654David Chisnall if (!isa<ConstantArrayType>(AT)) 44345389f48b24937ad7b4093307128b3cbf25235654David Chisnall PType = PVDecl->getType(); 44355389f48b24937ad7b4093307128b3cbf25235654David Chisnall } else if (PType->isFunctionType()) 44365389f48b24937ad7b4093307128b3cbf25235654David Chisnall PType = PVDecl->getType(); 44375389f48b24937ad7b4093307128b3cbf25235654David Chisnall getObjCEncodingForType(PType, S); 44385389f48b24937ad7b4093307128b3cbf25235654David Chisnall S += charUnitsToString(ParmOffset); 44395389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset += getObjCEncodingTypeSize(PType); 44405389f48b24937ad7b4093307128b3cbf25235654David Chisnall } 44416b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall 44426b5a61b6dc400027fd793dcadceeb9da944a37eaJohn McCall return S; 44435389f48b24937ad7b4093307128b3cbf25235654David Chisnall} 44445389f48b24937ad7b4093307128b3cbf25235654David Chisnall 4445f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregorbool ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, 44465389f48b24937ad7b4093307128b3cbf25235654David Chisnall std::string& S) { 44475389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Encode result type. 44485389f48b24937ad7b4093307128b3cbf25235654David Chisnall getObjCEncodingForType(Decl->getResultType(), S); 44495389f48b24937ad7b4093307128b3cbf25235654David Chisnall CharUnits ParmOffset; 44505389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Compute size of all parameters. 44515389f48b24937ad7b4093307128b3cbf25235654David Chisnall for (FunctionDecl::param_const_iterator PI = Decl->param_begin(), 44525389f48b24937ad7b4093307128b3cbf25235654David Chisnall E = Decl->param_end(); PI != E; ++PI) { 44535389f48b24937ad7b4093307128b3cbf25235654David Chisnall QualType PType = (*PI)->getType(); 44545389f48b24937ad7b4093307128b3cbf25235654David Chisnall CharUnits sz = getObjCEncodingTypeSize(PType); 4455f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (sz.isZero()) 44567e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian continue; 44577e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian 44585389f48b24937ad7b4093307128b3cbf25235654David Chisnall assert (sz.isPositive() && 4459f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor "getObjCEncodingForFunctionDecl - Incomplete param type"); 44605389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset += sz; 44615389f48b24937ad7b4093307128b3cbf25235654David Chisnall } 44625389f48b24937ad7b4093307128b3cbf25235654David Chisnall S += charUnitsToString(ParmOffset); 44635389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmOffset = CharUnits::Zero(); 44645389f48b24937ad7b4093307128b3cbf25235654David Chisnall 44655389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Argument types. 44665389f48b24937ad7b4093307128b3cbf25235654David Chisnall for (FunctionDecl::param_const_iterator PI = Decl->param_begin(), 44675389f48b24937ad7b4093307128b3cbf25235654David Chisnall E = Decl->param_end(); PI != E; ++PI) { 44685389f48b24937ad7b4093307128b3cbf25235654David Chisnall ParmVarDecl *PVDecl = *PI; 44695389f48b24937ad7b4093307128b3cbf25235654David Chisnall QualType PType = PVDecl->getOriginalType(); 44705389f48b24937ad7b4093307128b3cbf25235654David Chisnall if (const ArrayType *AT = 44715389f48b24937ad7b4093307128b3cbf25235654David Chisnall dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 44725389f48b24937ad7b4093307128b3cbf25235654David Chisnall // Use array's original type only if it has known number of 44735e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall // elements. 44745e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall if (!isa<ConstantArrayType>(AT)) 44755e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall PType = PVDecl->getType(); 44765e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } else if (PType->isFunctionType()) 44775e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall PType = PVDecl->getType(); 44785e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall getObjCEncodingForType(PType, S); 4479199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 4480aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck ParmOffset += getObjCEncodingTypeSize(PType); 44815e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall } 4482f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4483f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return false; 44845e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall} 44855e530af5d51572a0ed5dbe50da54bd333840c63dDavid Chisnall 4486dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// getObjCEncodingForMethodParameter - Return the encoded type for a single 4487dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// method parameter or return type. If Extended, include class names and 4488dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson/// block object types. 4489dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilsonvoid ASTContext::getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, 4490dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson QualType T, std::string& S, 4491dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool Extended) const { 4492dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode type qualifer, 'in', 'inout', etc. for the parameter. 4493dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeQualifier(QT, S); 4494dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode parameter type. 4495dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(T, S, true, true, 0, 4496dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson true /*OutermostType*/, 4497dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /*EncodingProperty*/, 4498dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /*StructField*/, 4499dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Extended /*EncodeBlockParameters*/, 4500dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Extended /*EncodeClassNames*/); 4501dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson} 4502dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson 4503a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek/// getObjCEncodingForMethodDecl - Return the encoded type for this method 450433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian/// declaration. 4505f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregorbool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, 4506dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson std::string& S, 4507dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool Extended) const { 4508c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 4509dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Encode return type. 4510dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForMethodParameter(Decl->getObjCDeclQualifier(), 4511dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson Decl->getResultType(), S, Extended); 451233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Compute size of all parameters. 451333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Start with computing size of a pointer in number of bytes. 451433e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // FIXME: There might(should) be a better way of doing this computation! 451533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian SourceLocation Loc; 4516199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits PtrSize = getTypeSizeInChars(VoidPtrTy); 451733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // The first two arguments (self and _cmd) are pointers; account for 451833e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // their size. 4519199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck CharUnits ParmOffset = 2 * PtrSize; 4520491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), 45217732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian E = Decl->sel_param_end(); PI != E; ++PI) { 452289951a86b594513c2a013532ed45d197413b1087Chris Lattner QualType PType = (*PI)->getType(); 4523aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck CharUnits sz = getObjCEncodingTypeSize(PType); 4524f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor if (sz.isZero()) 45257e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian continue; 45267e68ba5660a9b2b854df4ae7a556e6b91d738c6cFariborz Jahanian 4527199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck assert (sz.isPositive() && 4528199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck "getObjCEncodingForMethodDecl - Incomplete param type"); 452933e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset += sz; 453033e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 4531199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 453233e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian S += "@0:"; 4533199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(PtrSize); 45341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 453533e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian // Argument types. 453633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian ParmOffset = 2 * PtrSize; 4537491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis for (ObjCMethodDecl::param_const_iterator PI = Decl->param_begin(), 45387732cc9c0fdc97a2f8cce4e5933d8103213d1aefFariborz Jahanian E = Decl->sel_param_end(); PI != E; ++PI) { 4539491306a83c4f0f49f95a3bcbca8580cb98a91c7aArgyrios Kyrtzidis const ParmVarDecl *PVDecl = *PI; 45401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType PType = PVDecl->getOriginalType(); 45414306d3cb9116605728252e2738df24b9f6ab53c3Fariborz Jahanian if (const ArrayType *AT = 4542ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff dyn_cast<ArrayType>(PType->getCanonicalTypeInternal())) { 4543ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // Use array's original type only if it has known number of 4544ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff // elements. 4545bb3fde337fb712c0e6da8790d431621be4793048Steve Naroff if (!isa<ConstantArrayType>(AT)) 4546ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 4547ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff } else if (PType->isFunctionType()) 4548ab76d45e023fc5ae966968344e180cd09fdcc746Steve Naroff PType = PVDecl->getType(); 4549dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForMethodParameter(PVDecl->getObjCDeclQualifier(), 4550dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson PType, S, Extended); 4551199c3d6cd16aebbb9c7f0d42af9d922c9628bf70Ken Dyck S += charUnitsToString(ParmOffset); 4552aa8741a1db98eef05f09b1200dba94aa5dc3bc3dKen Dyck ParmOffset += getObjCEncodingTypeSize(PType); 455333e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian } 4554f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor 4555f968d8374791c37bc464efd9168c2d33dd73605fDouglas Gregor return false; 455633e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian} 455733e1d64ab5cd5d27f8530ccd056191fe2c9f3f2eFariborz Jahanian 4558c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// getObjCEncodingForPropertyDecl - Return the encoded type for this 455983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// property declaration. If non-NULL, Container must be either an 4560c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// ObjCCategoryImplDecl or ObjCImplementationDecl; it should only be 4561c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar/// NULL when getting encodings for protocol properties. 45621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Property attributes are stored as a comma-delimited C string. The simple 45631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// attributes readonly and bycopy are encoded as single characters. The 45641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// parametrized attributes, getter=name, setter=name, and ivar=name, are 45651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// encoded as single characters, followed by an identifier. Property types 45661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// are also encoded as a parametrized attribute. The characters used to encode 456783bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// these attributes are defined by the following enumeration: 456883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @code 456983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// enum PropertyAttributes { 457083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyReadOnly = 'R', // property is read-only. 457183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyBycopy = 'C', // property is a copy of the value last assigned 457283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyByref = '&', // property is a reference to the value last assigned 457383bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyDynamic = 'D', // property is dynamic 457483bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyGetter = 'G', // followed by getter selector name 457583bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertySetter = 'S', // followed by setter selector name 457683bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyInstanceVariable = 'V' // followed by instance variable name 45770d4cb85130d91da61c45aecb9fd31c7097a7cfccBob Wilson/// kPropertyType = 'T' // followed by old-style type encoding. 457883bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyWeak = 'W' // 'weak' property 457983bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyStrong = 'P' // property GC'able 458083bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// kPropertyNonAtomic = 'N' // property non-atomic 458183bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// }; 458283bccb85ff4b9981c4250c45494b439df8cbf983Fariborz Jahanian/// @endcode 45831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 4584c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const Decl *Container, 45854ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad std::string& S) const { 4586c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Collect information from the property implementation decl(s). 4587c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar bool Dynamic = false; 4588c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar ObjCPropertyImplDecl *SynthesizePID = 0; 4589c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4590c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: Duplicated code due to poor abstraction. 4591c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Container) { 45921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCCategoryImplDecl *CID = 4593c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar dyn_cast<ObjCCategoryImplDecl>(Container)) { 4594c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 459517945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = CID->propimpl_begin(), e = CID->propimpl_end(); 4596653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 4597581deb3da481053c4993c7600f97acf7768caac5David Blaikie ObjCPropertyImplDecl *PID = *i; 4598c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 4599c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 4600c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 4601c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4602c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 4603c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4604c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4605c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4606c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 460761710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner const ObjCImplementationDecl *OID=cast<ObjCImplementationDecl>(Container); 4608c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar for (ObjCCategoryImplDecl::propimpl_iterator 460917945a0f64fe03ff6ec0c2146005a87636e3ac12Argyrios Kyrtzidis i = OID->propimpl_begin(), e = OID->propimpl_end(); 4610653f1b1bf293a9bd96fd4dd6372e779cc7af1597Douglas Gregor i != e; ++i) { 4611581deb3da481053c4993c7600f97acf7768caac5David Blaikie ObjCPropertyImplDecl *PID = *i; 4612c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyDecl() == PD) { 4613c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PID->getPropertyImplementation()==ObjCPropertyImplDecl::Dynamic) { 4614c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar Dynamic = true; 4615c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4616c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar SynthesizePID = PID; 4617c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4618c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 46191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 4620c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4621c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4622c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4623c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: This is not very efficient. 4624c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S = "T"; 4625c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4626c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // Encode result type. 4627090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // GCC has some special rules regarding encoding of properties which 4628090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian // closely resembles encoding of ivars. 46291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PD->getType(), S, true, true, 0, 4630090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* outermost type */, 4631090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian true /* encoding for property */); 4632c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4633c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->isReadOnly()) { 4634c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",R"; 4635c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } else { 4636c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar switch (PD->getSetterKind()) { 4637c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Assign: break; 4638c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar case ObjCPropertyDecl::Copy: S += ",C"; break; 46391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump case ObjCPropertyDecl::Retain: S += ",&"; break; 46403a02b44e3948f7762dbfba94b7961281ca29d022Fariborz Jahanian case ObjCPropertyDecl::Weak: S += ",W"; break; 4641c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4642c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4643c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4644c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // It really isn't clear at all what this means, since properties 4645c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // are "dynamic by default". 4646c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (Dynamic) 4647c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",D"; 4648c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4649090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic) 4650090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian S += ",N"; 46511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4652c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { 4653c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",G"; 4654077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getGetterName().getAsString(); 4655c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4656c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4657c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { 4658c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",S"; 4659077bf5e2f48acfa9e7d69429b6e4ba86ea14896dChris Lattner S += PD->getSetterName().getAsString(); 4660c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4661c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4662c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar if (SynthesizePID) { 4663c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar const ObjCIvarDecl *OID = SynthesizePID->getPropertyIvarDecl(); 4664c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar S += ",V"; 466539f34e97d6a468f0a7dfa5664c61217cffc65b74Chris Lattner S += OID->getNameAsString(); 4666c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar } 4667c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4668c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar // FIXME: OBJCGC: weak & strong 4669c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar} 4670c56f34a1c1779de15330bdb3eec39b3418802d47Daniel Dunbar 4671a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// getLegacyIntegralTypeEncoding - 46721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Another legacy compatibility encoding: 32-bit longs are encoded as 46731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// 'l' or 'L' , but not always. For typedefs, we need to use 4674a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 'i' or 'I' instead if encoding a struct field, or a pointer! 4675a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian/// 4676a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanianvoid ASTContext::getLegacyIntegralTypeEncoding (QualType &PointeeTy) const { 46778e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(PointeeTy.getTypePtr())) { 4678183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const BuiltinType *BT = PointeeTy->getAs<BuiltinType>()) { 46794ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad if (BT->getKind() == BuiltinType::ULong && getIntWidth(PointeeTy) == 32) 4680a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = UnsignedIntTy; 46811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else 46824ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad if (BT->getKind() == BuiltinType::Long && getIntWidth(PointeeTy) == 32) 4683a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian PointeeTy = IntTy; 4684a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4685a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4686a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian} 4687a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 46887d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanianvoid ASTContext::getObjCEncodingForType(QualType T, std::string& S, 46894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const FieldDecl *Field) const { 469082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // We follow the behavior of gcc, expanding structures which are 469182a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // directly pointed to, and expanding embedded structures. Note that 469282a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // these rules are sufficient to prevent recursive encoding of the 469382a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar // same type. 46941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(T, S, true, true, Field, 46955b8c7d9fb620ba3a71e996d61e7b9bdf763b5c09Fariborz Jahanian true /* outermost type */); 469682a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar} 469782a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar 469864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnallstatic char ObjCEncodingForPrimitiveKind(const ASTContext *C, QualType T) { 469964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall switch (T->getAs<BuiltinType>()->getKind()) { 4700b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unhandled builtin type kind"); 470164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Void: return 'v'; 470264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Bool: return 'B'; 470364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Char_U: 470464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UChar: return 'C'; 470564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UShort: return 'S'; 470664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UInt: return 'I'; 470764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::ULong: 47084ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad return C->getIntWidth(T) == 32 ? 'L' : 'Q'; 470964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::UInt128: return 'T'; 471064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::ULongLong: return 'Q'; 471164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Char_S: 471264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::SChar: return 'c'; 471364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Short: return 's'; 47143f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_S: 47153f59c975aa5d047f7edd1b900b5e885c38af0ef7Chris Lattner case BuiltinType::WChar_U: 471664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Int: return 'i'; 471764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Long: 47184ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad return C->getIntWidth(T) == 32 ? 'l' : 'q'; 471964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::LongLong: return 'q'; 472064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Int128: return 't'; 472164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Float: return 'f'; 472264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall case BuiltinType::Double: return 'd'; 47233a0be84b2aed8563150cdbd976a98838afa261ebDaniel Dunbar case BuiltinType::LongDouble: return 'D'; 472464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall } 472564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall} 472664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall 47275471bc85b69912e3b448de004498a80c0de32296Douglas Gregorstatic char ObjCEncodingForEnumType(const ASTContext *C, const EnumType *ET) { 47285471bc85b69912e3b448de004498a80c0de32296Douglas Gregor EnumDecl *Enum = ET->getDecl(); 47295471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 47305471bc85b69912e3b448de004498a80c0de32296Douglas Gregor // The encoding of an non-fixed enum type is always 'i', regardless of size. 47315471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (!Enum->isFixed()) 47325471bc85b69912e3b448de004498a80c0de32296Douglas Gregor return 'i'; 47335471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 47345471bc85b69912e3b448de004498a80c0de32296Douglas Gregor // The encoding of a fixed enum type matches its fixed underlying type. 47355471bc85b69912e3b448de004498a80c0de32296Douglas Gregor return ObjCEncodingForPrimitiveKind(C, Enum->getIntegerType()); 47365471bc85b69912e3b448de004498a80c0de32296Douglas Gregor} 47375471bc85b69912e3b448de004498a80c0de32296Douglas Gregor 47384ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadstatic void EncodeBitField(const ASTContext *Ctx, std::string& S, 473964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall QualType T, const FieldDecl *FD) { 4740a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith assert(FD->isBitField() && "not a bitfield - getObjCEncodingForTypeImpl"); 47418b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian S += 'b'; 474264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // The NeXT runtime encodes bit fields as b followed by the number of bits. 474364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // The GNU runtime requires more information; bitfields are encoded as b, 474464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // then the offset (in bits) of the first element, then the type of the 474564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // bitfield, then the size in bits. For example, in this structure: 474664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // 474764fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // struct 474864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // { 474964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // int integer; 475064fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // int flags:2; 475164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // }; 475264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // On a 32-bit system, the encoding for flags would be b2 for the NeXT 475364fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // runtime, but b32i2 for the GNU runtime. The reason for this extra 475464fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // information is not especially sensible, but we're stuck with it for 475564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // compatibility with GCC, although providing it breaks anything that 475664fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall // actually uses runtime introspection and wants to work on both runtimes... 4757260611a32535c851237926bfcf78869b13c07d5bJohn McCall if (Ctx->getLangOpts().ObjCRuntime.isGNUFamily()) { 475864fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall const RecordDecl *RD = FD->getParent(); 475964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD); 476082905749d5c8d8b4edec11de754a73349cb96603Eli Friedman S += llvm::utostr(RL.getFieldOffset(FD->getFieldIndex())); 47615471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (const EnumType *ET = T->getAs<EnumType>()) 47625471bc85b69912e3b448de004498a80c0de32296Douglas Gregor S += ObjCEncodingForEnumType(Ctx, ET); 4763c7ff82c2040f45eaad2eddea0e4461dddc972cd1David Chisnall else 47644ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad S += ObjCEncodingForPrimitiveKind(Ctx, T); 476564fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall } 4766a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith S += llvm::utostr(FD->getBitWidthValue(*Ctx)); 47678b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian} 47688b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian 476901eb9b9683535d8a65c704ad2c545903409e2d36Daniel Dunbar// FIXME: Use SmallString for accumulating string. 477082a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbarvoid ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, 477182a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandPointedToStructures, 477282a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar bool ExpandStructures, 4773153bfe5795e2c1a5a738e73d3784964e082237fcDaniel Dunbar const FieldDecl *FD, 4774090b3f71702c5626d8520f9608d77c6f26dcfa15Fariborz Jahanian bool OutermostType, 47752636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis bool EncodingProperty, 4776dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool StructField, 4777dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool EncodeBlockParameters, 4778dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson bool EncodeClassNames) const { 477964fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall if (T->getAs<BuiltinType>()) { 4780ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (FD && FD->isBitField()) 478164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall return EncodeBitField(this, S, T, FD); 478264fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall S += ObjCEncodingForPrimitiveKind(this, T); 4783ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4784ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 47851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4786183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ComplexType *CT = T->getAs<ComplexType>()) { 4787c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson S += 'j'; 47881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(CT->getElementType(), S, false, false, 0, false, 4789c612f7bc9a6379cd7e7c2dd306d05938e890051bAnders Carlsson false); 4790ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4791ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 479260bce3ef20a4c9684e3825cdd739fefb9810327dFariborz Jahanian 4793aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian // encoding for pointer or r3eference types. 4794aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian QualType PointeeTy; 47956217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = T->getAs<PointerType>()) { 47968d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian if (PT->isObjCSelType()) { 47978d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian S += ':'; 47988d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian return; 47998d2c0a9814e56c2b22e22d1045181c735aef62fdFariborz Jahanian } 4800aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian PointeeTy = PT->getPointeeType(); 4801aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian } 4802aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian else if (const ReferenceType *RT = T->getAs<ReferenceType>()) 4803aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian PointeeTy = RT->getPointeeType(); 4804aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian if (!PointeeTy.isNull()) { 4805a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian bool isReadOnly = false; 4806a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // For historical/compatibility reasons, the read-only qualifier of the 4807a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // pointee gets emitted _before_ the '^'. The read-only qualifier of 4808a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // the pointer itself gets ignored, _unless_ we are looking at a typedef! 48091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Also, do not emit the 'r' for anything but the outermost type! 48108e1fab243ab8023b7ee3899745386b3b3a4258f8Mike Stump if (isa<TypedefType>(T.getTypePtr())) { 4811a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (OutermostType && T.isConstQualified()) { 4812a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 4813a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 4814a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 48159fdbab3cbc2fc04bcaf5768023d83707f3151144Mike Stump } else if (OutermostType) { 4816a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian QualType P = PointeeTy; 48176217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek while (P->getAs<PointerType>()) 48186217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek P = P->getAs<PointerType>()->getPointeeType(); 4819a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (P.isConstQualified()) { 4820a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian isReadOnly = true; 4821a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian S += 'r'; 4822a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4823a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 4824a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian if (isReadOnly) { 4825a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Another legacy compatibility encoding. Some ObjC qualifier and type 4826a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // combinations need to be rearranged. 4827a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian // Rewrite "in const" from "nr" to "rn" 48285f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner if (StringRef(S).endswith("nr")) 48290237941e0beb0c929934b66ad29443b484d987feBenjamin Kramer S.replace(S.end()-2, S.end(), "rn"); 4830a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian } 48311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 483285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson if (PointeeTy->isCharType()) { 483385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // char pointer types should be encoded as '*' unless it is a 483485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson // type that has been typedef'd to 'BOOL'. 4835e8c49533521c40643653f943d47229e62d277f88Anders Carlsson if (!isTypeTypedefedAsBOOL(PointeeTy)) { 483685f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '*'; 483785f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson return; 483885f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 48396217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek } else if (const RecordType *RTy = PointeeTy->getAs<RecordType>()) { 48409533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_class *" to "#". 48419533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_class")) { 48429533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '#'; 48439533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 48449533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 48459533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // GCC binary compat: Need to convert "struct objc_object *" to "@". 48469533a7fdb8397421f3be52e879442460a87389f6Steve Naroff if (RTy->getDecl()->getIdentifier() == &Idents.get("objc_object")) { 48479533a7fdb8397421f3be52e879442460a87389f6Steve Naroff S += '@'; 48489533a7fdb8397421f3be52e879442460a87389f6Steve Naroff return; 48499533a7fdb8397421f3be52e879442460a87389f6Steve Naroff } 48509533a7fdb8397421f3be52e879442460a87389f6Steve Naroff // fall through... 485185f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson } 485285f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson S += '^'; 4853a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian getLegacyIntegralTypeEncoding(PointeeTy); 4854a1c033e9514865f3a7b0d8b3b20e6de926cfec6cFariborz Jahanian 48551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, false, ExpandPointedToStructures, 485643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian NULL); 4857ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4858ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 4859aa1d76163e4b0b1cc54e222be67379f8c02e8ffaFariborz Jahanian 4860ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (const ArrayType *AT = 4861ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Ignore type qualifiers etc. 4862ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { 48632636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (isa<IncompleteArrayType>(AT) && !StructField) { 4864559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson // Incomplete arrays are encoded as a pointer to the array element. 4865559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '^'; 4866559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson 48671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 4868559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 4869559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } else { 4870559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '['; 48711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48722636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) { 48732636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (getTypeSize(CAT->getElementType()) == 0) 48742636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '0'; 48752636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis else 48762636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += llvm::utostr(CAT->getSize().getZExtValue()); 48772636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 4878559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson //Variable length arrays are encoded as a regular array with 0 elements. 48792636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert((isa<VariableArrayType>(AT) || isa<IncompleteArrayType>(AT)) && 48802636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis "Unknown array type!"); 4881559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += '0'; 4882559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 48831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(AT->getElementType(), S, 4885559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson false, ExpandStructures, FD); 4886559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson S += ']'; 4887559a83330416affb0e341a2c53800cbf924a5178Anders Carlsson } 4888ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4889ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4891183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (T->getAs<FunctionType>()) { 4892c0a87b7db06643178ad2cbce0767548c139ea387Anders Carlsson S += '?'; 4893ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4894ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 48951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48966217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *RTy = T->getAs<RecordType>()) { 489782a6cfbc421cc99c5b7313271f399f7ef95056ecDaniel Dunbar RecordDecl *RDecl = RTy->getDecl(); 4898d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? '(' : '{'; 4899502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar // Anonymous structures print as '?' 4900502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar if (const IdentifierInfo *II = RDecl->getIdentifier()) { 4901502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += II->getName(); 49026fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian if (ClassTemplateSpecializationDecl *Spec 49036fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian = dyn_cast<ClassTemplateSpecializationDecl>(RDecl)) { 49046fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); 49056fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian std::string TemplateArgsStr 49066fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian = TemplateSpecializationType::PrintTemplateArgumentList( 4907910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgs.data(), 4908910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgs.size(), 490930c42404202d2e2512e51efc6066bd614cfdb5a4Douglas Gregor (*this).getPrintingPolicy()); 49106fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian 49116fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian S += TemplateArgsStr; 49126fb94391dc7cb11fd4bbdb969bbab11b6b48c223Fariborz Jahanian } 4913502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } else { 4914502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar S += '?'; 4915502a4a1ce4c34cf78c8182d9798da0a51d9b7302Daniel Dunbar } 49160d504c1da852e58ff802545c823ecff3b6c654b8Daniel Dunbar if (ExpandStructures) { 49177d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian S += '='; 49182636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->isUnion()) { 49192636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForStructureImpl(RDecl, S, FD); 49202636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 49212636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 49222636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 49232636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis Field != FieldEnd; ++Field) { 49242636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 49252636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 49262636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += Field->getNameAsString(); 49272636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 49282636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 49291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49302636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // Special case bit-fields. 49312636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (Field->isBitField()) { 49322636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(Field->getType(), S, false, true, 4933581deb3da481053c4993c7600f97acf7768caac5David Blaikie *Field); 49342636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 49352636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis QualType qt = Field->getType(); 49362636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getLegacyIntegralTypeEncoding(qt); 49372636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(qt, S, false, true, 49382636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FD, /*OutermostType*/false, 49392636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*EncodingProperty*/false, 49402636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*StructField*/true); 49412636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 4942d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar } 49437d6b46d9a9d75dea8ef9f6973dd50633c1f37963Fariborz Jahanian } 49446de88a873a4cbe06d72602eef57d68006730a80bFariborz Jahanian } 4945d96b35bc6becf8db00d140c11e3d0e53f27567a1Daniel Dunbar S += RDecl->isUnion() ? ')' : '}'; 4946ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4947ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 4948e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 49495471bc85b69912e3b448de004498a80c0de32296Douglas Gregor if (const EnumType *ET = T->getAs<EnumType>()) { 49508b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian if (FD && FD->isBitField()) 495164fd7e86c1a90d9ff78e4a0bd79f69499667a4e3David Chisnall EncodeBitField(this, S, T, FD); 49528b4bf90eb6d3d08cf3bfb86705f0fdb20b9c5875Fariborz Jahanian else 49535471bc85b69912e3b448de004498a80c0de32296Douglas Gregor S += ObjCEncodingForEnumType(this, ET); 4954ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4955ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 49561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4957dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) { 495821a98b188857d690aa4510c52ac4317ffa0908a8Steve Naroff S += "@?"; // Unlike a pointer-to-function, which is "^?". 4959dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (EncodeBlockParameters) { 4960dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson const FunctionType *FT = BT->getPointeeType()->getAs<FunctionType>(); 4961dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson 4962dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += '<'; 4963dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block return type 4964dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(FT->getResultType(), S, 4965dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandPointedToStructures, ExpandStructures, 4966dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson FD, 4967dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* OutermostType */, 4968dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodingProperty, 4969dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* StructField */, 4970dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeBlockParameters, 4971dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeClassNames); 4972dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block self 4973dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += "@?"; 4974dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson // Block parameters 4975dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FT)) { 4976dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson for (FunctionProtoType::arg_type_iterator I = FPT->arg_type_begin(), 4977dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson E = FPT->arg_type_end(); I && (I != E); ++I) { 4978dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson getObjCEncodingForTypeImpl(*I, S, 4979dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandPointedToStructures, 4980dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson ExpandStructures, 4981dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson FD, 4982dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* OutermostType */, 4983dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodingProperty, 4984dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson false /* StructField */, 4985dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeBlockParameters, 4986dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson EncodeClassNames); 4987dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 4988dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 4989dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson S += '>'; 4990dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson } 4991ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 4992ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 49931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4994c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Ignore protocol qualifiers when mangling at this level. 4995c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (const ObjCObjectType *OT = T->getAs<ObjCObjectType>()) 4996c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall T = OT->getBaseType(); 4997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 49980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) { 499943822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian // @encode(class_name) 50000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall ObjCInterfaceDecl *OI = OIT->getDecl(); 500143822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '{'; 500243822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian const IdentifierInfo *II = OI->getIdentifier(); 500343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += II->getName(); 500443822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '='; 5005db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose SmallVector<const ObjCIvarDecl*, 32> Ivars; 50062c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian DeepCollectObjCIvars(OI, true, Ivars); 50072c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { 5008db8264e4c5ffd7af6fbad4ca4306bd382bb02691Jordy Rose const FieldDecl *Field = cast<FieldDecl>(Ivars[i]); 50092c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian if (Field->isBitField()) 50102c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, Field); 501143822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian else 50122c18bb7c9fca66c30b6eabbdcbc6399d24a54fa9Fariborz Jahanian getObjCEncodingForTypeImpl(Field->getType(), S, false, true, FD); 501343822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 501443822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian S += '}'; 5015ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 501643822eaeddeaa419b90f23c68af6b23c46788a58Fariborz Jahanian } 50171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5018183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) { 501914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (OPT->isObjCIdType()) { 502014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '@'; 502114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 5022ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 50231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 502427d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType()) { 502527d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // FIXME: Consider if we need to output qualifiers for 'Class<p>'. 502627d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // Since this is a binary compatibility issue, need to consult with runtime 502727d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff // folks. Fortunately, this is a *very* obsure construct. 502814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '#'; 502914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 5030ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 50311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5032ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (OPT->isObjCQualifiedIdType()) { 50331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(getObjCIdType(), S, 503414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandPointedToStructures, 503514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff ExpandStructures, FD); 5036dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (FD || EncodingProperty || EncodeClassNames) { 503714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Note that we do extended encoding of protocol qualifer list 503814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff // Only when doing ivar or property encoding. 503914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 504067ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 504167ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 504214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '<'; 504314108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += (*I)->getNameAsString(); 504414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '>'; 504514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 504614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff S += '"'; 504714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 504814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 5049ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 50501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5051ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner QualType PointeeTy = OPT->getPointeeType(); 5052ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner if (!EncodingProperty && 5053ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner isa<TypedefType>(PointeeTy.getTypePtr())) { 5054ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // Another historical/compatibility reason. 50551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // We encode the underlying type which comes out as 5056ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner // {...}; 5057ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '^'; 50581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getObjCEncodingForTypeImpl(PointeeTy, S, 50591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump false, ExpandPointedToStructures, 5060ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner NULL); 506114108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return; 506214108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff } 5063ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner 5064ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '@'; 5065dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson if (OPT->getInterfaceDecl() && 5066dc8dab6fabf4bfd4f4b94bf572ac3342a5bbfcd7Bob Wilson (FD || EncodingProperty || EncodeClassNames)) { 5067ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 506827d20a24a1b816cecbd142727d2c81af5a6a111bSteve Naroff S += OPT->getInterfaceDecl()->getIdentifier()->getName(); 506967ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff for (ObjCObjectPointerType::qual_iterator I = OPT->qual_begin(), 507067ef8eaea8a0a2073147a8d863f0e3f30d525802Steve Naroff E = OPT->qual_end(); I != E; ++I) { 5071ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '<'; 5072ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += (*I)->getNameAsString(); 5073ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '>'; 50741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 5075ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner S += '"'; 5076ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 5077ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner return; 5078ce7b38c4f1ea9c51e2f46a82e3f57456b74269d5Chris Lattner } 50791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5080532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall // gcc just blithely ignores member pointers. 5081532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall // TODO: maybe there should be a mangling for these 5082532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall if (T->getAs<MemberPointerType>()) 5083532ec7baf2d0791abc9551ef856a537711c5774aJohn McCall return; 5084e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 5085e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian if (T->isVectorType()) { 5086e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // This matches gcc's encoding, even though technically it is 5087e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // insufficient. 5088e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian // FIXME. We should do a better job than gcc. 5089e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian return; 5090e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian } 5091e6012c7ecb9d848f4091c8c48e7d9946cc36b23fFariborz Jahanian 5092b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("@encode for type not implemented!"); 509385f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson} 509485f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson 50952636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidisvoid ASTContext::getObjCEncodingForStructureImpl(RecordDecl *RDecl, 50962636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::string &S, 50972636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis const FieldDecl *FD, 50982636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis bool includeVBases) const { 50992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(RDecl && "Expected non-null RecordDecl"); 51002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(!RDecl->isUnion() && "Should not be called for unions"); 51012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->getDefinition()) 51022636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis return; 51032636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *CXXRec = dyn_cast<CXXRecordDecl>(RDecl); 51052636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::multimap<uint64_t, NamedDecl *> FieldOrBaseOffsets; 51062636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis const ASTRecordLayout &layout = getASTRecordLayout(RDecl); 51072636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51082636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec) { 51092636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (CXXRecordDecl::base_class_iterator 51102636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BI = CXXRec->bases_begin(), 51112636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BE = CXXRec->bases_end(); BI != BE; ++BI) { 51122636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!BI->isVirtual()) { 51132636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl(); 5114829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis if (base->isEmpty()) 5115829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis continue; 5116d4f5198ae07d9a4958d8191bac694ded12173ad9Benjamin Kramer uint64_t offs = toBits(layout.getBaseClassOffset(base)); 51172636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 51182636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::make_pair(offs, base)); 51192636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51202636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51212636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51222636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51232636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis unsigned i = 0; 51242636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (RecordDecl::field_iterator Field = RDecl->field_begin(), 51252636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldEnd = RDecl->field_end(); 51262636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis Field != FieldEnd; ++Field, ++i) { 51272636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t offs = layout.getFieldOffset(i); 51282636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 5129581deb3da481053c4993c7600f97acf7768caac5David Blaikie std::make_pair(offs, *Field)); 51302636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51312636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51322636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec && includeVBases) { 51332636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (CXXRecordDecl::base_class_iterator 51342636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BI = CXXRec->vbases_begin(), 51352636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis BE = CXXRec->vbases_end(); BI != BE; ++BI) { 51362636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CXXRecordDecl *base = BI->getType()->getAsCXXRecordDecl(); 5137829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis if (base->isEmpty()) 5138829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis continue; 5139d4f5198ae07d9a4958d8191bac694ded12173ad9Benjamin Kramer uint64_t offs = toBits(layout.getVBaseClassOffset(base)); 514019aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis if (FieldOrBaseOffsets.find(offs) == FieldOrBaseOffsets.end()) 514119aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.end(), 514219aa8609a5d04eed9b81aa1c4608e8a4f3df6ccdArgyrios Kyrtzidis std::make_pair(offs, base)); 51432636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51442636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51452636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51462636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CharUnits size; 51472636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRec) { 51482636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis size = includeVBases ? layout.getSize() : layout.getNonVirtualSize(); 51492636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 51502636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis size = layout.getSize(); 51512636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51522636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51532636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t CurOffs = 0; 51542636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::multimap<uint64_t, NamedDecl *>::iterator 51552636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurLayObj = FieldOrBaseOffsets.begin(); 51562636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 515758db7a575efc9a2f35266fe240feac3cf317753dDouglas Gregor if (CXXRec && CXXRec->isDynamicClass() && 515858db7a575efc9a2f35266fe240feac3cf317753dDouglas Gregor (CurLayObj == FieldOrBaseOffsets.end() || CurLayObj->first != 0)) { 51592636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 51602636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += "\"_vptr$"; 51612636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::string recname = CXXRec->getNameAsString(); 51622636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (recname.empty()) recname = "?"; 51632636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += recname; 51642636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 51652636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51662636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += "^^?"; 51672636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += getTypeSize(VoidPtrTy); 51682636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51692636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51702636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (!RDecl->hasFlexibleArrayMember()) { 51712636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // Mark the end of the structure. 51722636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t offs = toBits(size); 51732636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldOrBaseOffsets.insert(FieldOrBaseOffsets.upper_bound(offs), 51742636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis std::make_pair(offs, (NamedDecl*)0)); 51752636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51762636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51772636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis for (; CurLayObj != FieldOrBaseOffsets.end(); ++CurLayObj) { 51782636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis assert(CurOffs <= CurLayObj->first); 51792636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51802636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CurOffs < CurLayObj->first) { 51812636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis uint64_t padding = CurLayObj->first - CurOffs; 51822636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // FIXME: There doesn't seem to be a way to indicate in the encoding that 51832636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // packing/alignment of members is different that normal, in which case 51842636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // the encoding will be out-of-sync with the real layout. 51852636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // If the runtime switches to just consider the size of types without 51862636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // taking into account alignment, we could make padding explicit in the 51872636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // encoding (e.g. using arrays of chars). The encoding strings would be 51882636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // longer then though. 51892636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += padding; 51902636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 51912636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51922636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis NamedDecl *dcl = CurLayObj->second; 51932636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (dcl == 0) 51942636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis break; // reached end of structure. 51952636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 51962636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (CXXRecordDecl *base = dyn_cast<CXXRecordDecl>(dcl)) { 51972636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // We expand the bases without their virtual bases since those are going 51982636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // in the initial structure. Note that this differs from gcc which 51992636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // expands virtual bases each time one is encountered in the hierarchy, 52002636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis // making the encoding type bigger than it really is. 52012636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForStructureImpl(base, S, FD, /*includeVBases*/false); 5202829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis assert(!base->isEmpty()); 5203829f20097e030229fd4c234b84948f53312eaf55Argyrios Kyrtzidis CurOffs += toBits(getASTRecordLayout(base).getNonVirtualSize()); 52042636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 52052636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis FieldDecl *field = cast<FieldDecl>(dcl); 52062636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (FD) { 52072636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 52082636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += field->getNameAsString(); 52092636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis S += '"'; 52102636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52112636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52122636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis if (field->isBitField()) { 52132636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis EncodeBitField(this, S, field->getType(), field); 5214a6b8b2c09610b8bc4330e948ece8b940c2386406Richard Smith CurOffs += field->getBitWidthValue(*this); 52152636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } else { 52162636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis QualType qt = field->getType(); 52172636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getLegacyIntegralTypeEncoding(qt); 52182636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis getObjCEncodingForTypeImpl(qt, S, false, true, FD, 52192636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*OutermostType*/false, 52202636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*EncodingProperty*/false, 52212636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis /*StructField*/true); 52222636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis CurOffs += getTypeSize(field->getType()); 52232636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52242636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52252636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis } 52262636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis} 52272636197098e02fd7c90f9496056b8ab886dcbff0Argyrios Kyrtzidis 52281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpvoid ASTContext::getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 5229ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian std::string& S) const { 5230ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_In) 5231ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'n'; 5232ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Inout) 5233ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'N'; 5234ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Out) 5235ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'o'; 5236ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Bycopy) 5237ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'O'; 5238ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Byref) 5239ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'R'; 5240ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian if (QT & Decl::OBJC_TQ_Oneway) 5241ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian S += 'V'; 5242ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian} 5243ecb01e666665efabd2aa76a76f6080e2a78965faFariborz Jahanian 52444dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas GregorTypedefDecl *ASTContext::getObjCIdDecl() const { 52454dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor if (!ObjCIdDecl) { 52464dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0); 52474dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor T = getObjCObjectPointerType(T); 52484dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor TypeSourceInfo *IdInfo = getTrivialTypeSourceInfo(T); 52494dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor ObjCIdDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 52504dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor getTranslationUnitDecl(), 52514dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor SourceLocation(), SourceLocation(), 52524dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor &Idents.get("id"), IdInfo); 52534dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor } 52544dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor 52554dfd02a17c6d604c72e6936527c5e1c56d3ecb7aDouglas Gregor return ObjCIdDecl; 52567e219e47de26346885d667131977bd9ca2d7662aSteve Naroff} 52577e219e47de26346885d667131977bd9ca2d7662aSteve Naroff 52587a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas GregorTypedefDecl *ASTContext::getObjCSelDecl() const { 52597a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor if (!ObjCSelDecl) { 52607a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor QualType SelT = getPointerType(ObjCBuiltinSelTy); 52617a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor TypeSourceInfo *SelInfo = getTrivialTypeSourceInfo(SelT); 52627a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor ObjCSelDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 52637a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor getTranslationUnitDecl(), 52647a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor SourceLocation(), SourceLocation(), 52657a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor &Idents.get("SEL"), SelInfo); 52667a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor } 52677a27ea52b7bd635c89bec5a9c521a3bf7d204238Douglas Gregor return ObjCSelDecl; 5268b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian} 5269b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 527079d6726921897811232554ed94c5d77b5b7b3fc0Douglas GregorTypedefDecl *ASTContext::getObjCClassDecl() const { 527179d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor if (!ObjCClassDecl) { 527279d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0); 527379d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor T = getObjCObjectPointerType(T); 527479d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor TypeSourceInfo *ClassInfo = getTrivialTypeSourceInfo(T); 527579d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor ObjCClassDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), 527679d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor getTranslationUnitDecl(), 527779d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor SourceLocation(), SourceLocation(), 527879d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor &Idents.get("Class"), ClassInfo); 527979d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor } 528079d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor 528179d6726921897811232554ed94c5d77b5b7b3fc0Douglas Gregor return ObjCClassDecl; 5282a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor} 5283a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor 5284a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas GregorObjCInterfaceDecl *ASTContext::getObjCProtocolDecl() const { 5285a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor if (!ObjCProtocolClassDecl) { 5286a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor ObjCProtocolClassDecl 5287a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor = ObjCInterfaceDecl::Create(*this, getTranslationUnitDecl(), 5288a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor SourceLocation(), 5289a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor &Idents.get("Protocol"), 5290a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor /*PrevDecl=*/0, 5291a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor SourceLocation(), true); 5292a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor } 5293a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor 5294a6ea10e22b600d92e084f6b11b9b9a92d0eb2412Douglas Gregor return ObjCProtocolClassDecl; 52958baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson} 52968baaca50f07d0c10bba69c8d88c1b9078c92d06dAnders Carlsson 5297c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge//===----------------------------------------------------------------------===// 5298c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge// __builtin_va_list Construction Functions 5299c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge//===----------------------------------------------------------------------===// 5300c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5301c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateCharPtrBuiltinVaListDecl(const ASTContext *Context) { 5302c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef char* __builtin_va_list; 5303c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType CharPtrType = Context->getPointerType(Context->CharTy); 5304c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5305c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(CharPtrType); 5306c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5307c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypeDecl 5308c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5309c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5310c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5311c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5312c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5313c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypeDecl; 5314c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5315c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5316c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateVoidPtrBuiltinVaListDecl(const ASTContext *Context) { 5317c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef void* __builtin_va_list; 5318c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VoidPtrType = Context->getPointerType(Context->VoidTy); 5319c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5320c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VoidPtrType); 5321c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5322c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypeDecl 5323c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5324c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5325c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5326c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5327c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5328c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypeDecl; 5329c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5330c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5331c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreatePowerABIBuiltinVaListDecl(const ASTContext *Context) { 5332c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef struct __va_list_tag { 5333c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge RecordDecl *VaListTagDecl; 5334c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5335c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct, 5336c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5337c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag")); 5338c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->startDefinition(); 5339c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5340c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const size_t NumFields = 5; 5341c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType FieldTypes[NumFields]; 5342c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const char *FieldNames[NumFields]; 5343c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5344c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned char gpr; 5345c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[0] = Context->UnsignedCharTy; 5346c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[0] = "gpr"; 5347c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5348c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned char fpr; 5349c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[1] = Context->UnsignedCharTy; 5350c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[1] = "fpr"; 5351c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5352c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned short reserved; 5353c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[2] = Context->UnsignedShortTy; 5354c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[2] = "reserved"; 5355c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5356c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* overflow_arg_area; 5357c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[3] = Context->getPointerType(Context->VoidTy); 5358c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[3] = "overflow_arg_area"; 5359c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5360c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* reg_save_area; 5361c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[4] = Context->getPointerType(Context->VoidTy); 5362c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[4] = "reg_save_area"; 5363c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5364c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // Create fields 5365c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge for (unsigned i = 0; i < NumFields; ++i) { 5366c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldDecl *Field = FieldDecl::Create(*Context, VaListTagDecl, 5367c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5368c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5369c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get(FieldNames[i]), 5370c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[i], /*TInfo=*/0, 5371c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*BitWidth=*/0, 5372c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*Mutable=*/false, 5373c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge ICIS_NoInit); 5374c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Field->setAccess(AS_public); 5375c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->addDecl(Field); 5376c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5377c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->completeDefinition(); 5378c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagType = Context->getRecordType(VaListTagDecl); 5379fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge Context->VaListTagTy = VaListTagType; 5380c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5381c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // } __va_list_tag; 5382c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTagTypedefDecl 5383c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5384c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5385c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5386c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag"), 5387c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(VaListTagType)); 5388c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagTypedefType = 5389c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTypedefType(VaListTagTypedefDecl); 5390c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5391c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef __va_list_tag __builtin_va_list[1]; 5392c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); 5393c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagArrayType 5394c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(VaListTagTypedefType, 5395c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal, 0); 5396c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5397c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VaListTagArrayType); 5398c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5399c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5400c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5401c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5402c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5403c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5404c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5405c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5406c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5407c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5408c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl * 5409c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador IngeCreateX86_64ABIBuiltinVaListDecl(const ASTContext *Context) { 5410c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef struct __va_list_tag { 5411c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge RecordDecl *VaListTagDecl; 5412c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl = CreateRecordDecl(*Context, TTK_Struct, 5413c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5414c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag")); 5415c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->startDefinition(); 5416c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5417c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const size_t NumFields = 4; 5418c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType FieldTypes[NumFields]; 5419c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge const char *FieldNames[NumFields]; 5420c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5421c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned gp_offset; 5422c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[0] = Context->UnsignedIntTy; 5423c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[0] = "gp_offset"; 5424c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5425c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // unsigned fp_offset; 5426c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[1] = Context->UnsignedIntTy; 5427c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[1] = "fp_offset"; 5428c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5429c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* overflow_arg_area; 5430c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[2] = Context->getPointerType(Context->VoidTy); 5431c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[2] = "overflow_arg_area"; 5432c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5433c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // void* reg_save_area; 5434c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[3] = Context->getPointerType(Context->VoidTy); 5435c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldNames[3] = "reg_save_area"; 5436c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5437c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // Create fields 5438c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge for (unsigned i = 0; i < NumFields; ++i) { 5439c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldDecl *Field = FieldDecl::Create(const_cast<ASTContext &>(*Context), 5440c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl, 5441c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5442c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), 5443c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get(FieldNames[i]), 5444c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge FieldTypes[i], /*TInfo=*/0, 5445c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*BitWidth=*/0, 5446c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge /*Mutable=*/false, 5447c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge ICIS_NoInit); 5448c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Field->setAccess(AS_public); 5449c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->addDecl(Field); 5450c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5451c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge VaListTagDecl->completeDefinition(); 5452c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagType = Context->getRecordType(VaListTagDecl); 5453fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge Context->VaListTagTy = VaListTagType; 5454c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5455c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // } __va_list_tag; 5456c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTagTypedefDecl 5457c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5458c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5459c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5460c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__va_list_tag"), 5461c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(VaListTagType)); 5462c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagTypedefType = 5463c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTypedefType(VaListTagTypedefDecl); 5464c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5465c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef __va_list_tag __builtin_va_list[1]; 5466c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 1); 5467c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType VaListTagArrayType 5468c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(VaListTagTypedefType, 5469c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal,0); 5470c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypeSourceInfo *TInfo 5471c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getTrivialTypeSourceInfo(VaListTagArrayType); 5472c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5473c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5474c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5475c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5476c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5477c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TInfo); 5478c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5479c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5480c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5481c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5482c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreatePNaClABIBuiltinVaListDecl(const ASTContext *Context) { 5483c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge // typedef int __builtin_va_list[4]; 5484c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm::APInt Size(Context->getTypeSize(Context->getSizeType()), 4); 5485c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge QualType IntArrayType 5486c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = Context->getConstantArrayType(Context->IntTy, 5487c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Size, ArrayType::Normal, 0); 5488c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TypedefDecl *VaListTypedefDecl 5489c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge = TypedefDecl::Create(const_cast<ASTContext &>(*Context), 5490c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTranslationUnitDecl(), 5491c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge SourceLocation(), SourceLocation(), 5492c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge &Context->Idents.get("__builtin_va_list"), 5493c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge Context->getTrivialTypeSourceInfo(IntArrayType)); 5494c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5495c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return VaListTypedefDecl; 5496c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5497c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5498c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Ingestatic TypedefDecl *CreateVaListDecl(const ASTContext *Context, 5499c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge TargetInfo::BuiltinVaListKind Kind) { 5500c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge switch (Kind) { 5501c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::CharPtrBuiltinVaList: 5502c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateCharPtrBuiltinVaListDecl(Context); 5503c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::VoidPtrBuiltinVaList: 5504c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateVoidPtrBuiltinVaListDecl(Context); 5505c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::PowerABIBuiltinVaList: 5506c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreatePowerABIBuiltinVaListDecl(Context); 5507c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::X86_64ABIBuiltinVaList: 5508c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreateX86_64ABIBuiltinVaListDecl(Context); 5509c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge case TargetInfo::PNaClABIBuiltinVaList: 5510c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return CreatePNaClABIBuiltinVaListDecl(Context); 5511c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge } 5512c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5513c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge llvm_unreachable("Unhandled __builtin_va_list type kind"); 5514c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5515c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5516c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador IngeTypedefDecl *ASTContext::getBuiltinVaListDecl() const { 5517c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge if (!BuiltinVaListDecl) 5518c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge BuiltinVaListDecl = CreateVaListDecl(this, Target->getBuiltinVaListKind()); 5519c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5520c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge return BuiltinVaListDecl; 5521c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge} 5522c5613b26a24a33d7450e3d0bf315c6ccc920ce7bMeador Inge 5523fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador IngeQualType ASTContext::getVaListTagType() const { 5524fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // Force the creation of VaListTagTy by building the __builtin_va_list 5525fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge // declaration. 5526fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge if (VaListTagTy.isNull()) 5527fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge (void) getBuiltinVaListDecl(); 5528fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 5529fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge return VaListTagTy; 5530fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge} 5531fb40e3f10ccef93c4f8fb6bd4fe5a108fa6cd369Meador Inge 5532a526c5c67e5a0473c340903ee542ce570119665fTed Kremenekvoid ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) { 55331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert(ObjCConstantStringType.isNull() && 55342198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff "'NSConstantString' type already set!"); 55351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5536a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek ObjCConstantStringType = getObjCInterfaceType(Decl); 55372198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff} 55382198891824c38d45b2279de5d5e3ef9394eb457cSteve Naroff 55390bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall/// \brief Retrieve the template name that corresponds to a non-empty 55400bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall/// lookup. 55414ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 55424ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin, 55434ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad UnresolvedSetIterator End) const { 55440bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall unsigned size = End - Begin; 55450bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall assert(size > 1 && "set is not overloaded!"); 55467532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 55470bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall void *memory = Allocate(sizeof(OverloadedTemplateStorage) + 55480bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall size * sizeof(FunctionTemplateDecl*)); 55490bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall OverloadedTemplateStorage *OT = new(memory) OverloadedTemplateStorage(size); 55500bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall 55510bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall NamedDecl **Storage = OT->getStorage(); 5552eec51cf1ba5f0e62c9cdb81b5c63babdd6e649abJohn McCall for (UnresolvedSetIterator I = Begin; I != End; ++I) { 55530bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall NamedDecl *D = *I; 55540bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall assert(isa<FunctionTemplateDecl>(D) || 55550bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall (isa<UsingShadowDecl>(D) && 55560bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall isa<FunctionTemplateDecl>(D->getUnderlyingDecl()))); 55570bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall *Storage++ = D; 55587532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 55597532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 55600bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall return TemplateName(OT); 55617532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 55627532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 5563d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// \brief Retrieve the template name that represents a qualified 5564d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor/// template name such as \c std::vector. 55654ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 55664ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getQualifiedTemplateName(NestedNameSpecifier *NNS, 55674ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad bool TemplateKeyword, 55684ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad TemplateDecl *Template) const { 55690f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor assert(NNS && "Missing nested-name-specifier in qualified template name"); 55700f0ea2a96534c615ff5fdd81363989b23cf2164aDouglas Gregor 5571789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor // FIXME: Canonicalization? 5572d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor llvm::FoldingSetNodeID ID; 5573d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName::Profile(ID, NNS, TemplateKeyword, Template); 55741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5575d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor void *InsertPos = 0; 5576d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateName *QTN = 55770bd6feb9e9d40fc889fd47e899985125a43dfed8John McCall QualifiedTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5578d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor if (!QTN) { 55792f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<QualifiedTemplateName>()) 55802f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QualifiedTemplateName(NNS, TemplateKeyword, Template); 5581d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor QualifiedTemplateNames.InsertNode(QTN, InsertPos); 5582d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor } 55831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5584d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor return TemplateName(QTN); 5585d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor} 5586d99cbe66403ee39c2ee58024b9582b95649a4fc5Douglas Gregor 55877532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// \brief Retrieve the template name that represents a dependent 55887532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor/// template name such as \c MetaFun::template apply. 55894ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadTemplateName 55904ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 55914ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad const IdentifierInfo *Name) const { 55921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((!NNS || NNS->isDependent()) && 55933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor "Nested name specifier must be dependent"); 55947532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 55957532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor llvm::FoldingSetNodeID ID; 55967532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName::Profile(ID, NNS, Name); 55977532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 55987532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor void *InsertPos = 0; 55997532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateName *QTN = 56007532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 56017532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 56027532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (QTN) 56037532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 56047532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 56057532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 56067532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor if (CanonNNS == NNS) { 56072f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 56082f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Name); 56097532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } else { 56107532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Name); 56112f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 56122f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Name, Canon); 5613789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *CheckQTN = 5614789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5615789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CheckQTN && "Dependent type name canonicalization broken"); 5616789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckQTN; 56177532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor } 56187532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 56197532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 56207532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor return TemplateName(QTN); 56217532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor} 56227532dc66648cfe7432c9fe66dec5225f0ab301c6Douglas Gregor 5623ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// \brief Retrieve the template name that represents a dependent 5624ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor/// template name such as \c MetaFun::template operator+. 5625ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 5626ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorASTContext::getDependentTemplateName(NestedNameSpecifier *NNS, 56274ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad OverloadedOperatorKind Operator) const { 5628ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor assert((!NNS || NNS->isDependent()) && 5629ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor "Nested name specifier must be dependent"); 5630ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5631ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor llvm::FoldingSetNodeID ID; 5632ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor DependentTemplateName::Profile(ID, NNS, Operator); 5633ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5634ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor void *InsertPos = 0; 5635789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *QTN 5636789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5637ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5638ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (QTN) 5639ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return TemplateName(QTN); 5640ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5641ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor NestedNameSpecifier *CanonNNS = getCanonicalNestedNameSpecifier(NNS); 5642ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor if (CanonNNS == NNS) { 56432f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 56442f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Operator); 5645ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } else { 5646ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TemplateName Canon = getDependentTemplateName(CanonNNS, Operator); 56472f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith QTN = new (*this, llvm::alignOf<DependentTemplateName>()) 56482f47cab092cd2dcbfe7e003fa865499caf198dc2Richard Smith DependentTemplateName(NNS, Operator, Canon); 5649789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor 5650789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor DependentTemplateName *CheckQTN 5651789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor = DependentTemplateNames.FindNodeOrInsertPos(ID, InsertPos); 5652789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor assert(!CheckQTN && "Dependent template name canonicalization broken"); 5653789b1f640205e81b5af250693246120f1ce9d147Douglas Gregor (void)CheckQTN; 5654ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor } 5655ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 5656ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor DependentTemplateNames.InsertNode(QTN, InsertPos); 5657ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor return TemplateName(QTN); 5658ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 5659ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor 56601aee05d08b2184acadeb36de300e216390780d6cDouglas GregorTemplateName 5661146060435c3efce95c95a092c7a1eb651cfb9ae0John McCallASTContext::getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 5662146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall TemplateName replacement) const { 5663146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall llvm::FoldingSetNodeID ID; 5664146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage::Profile(ID, param, replacement); 5665146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5666146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall void *insertPos = 0; 5667146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParmStorage *subst 5668146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall = SubstTemplateTemplateParms.FindNodeOrInsertPos(ID, insertPos); 5669146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5670146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall if (!subst) { 5671146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall subst = new (*this) SubstTemplateTemplateParmStorage(param, replacement); 5672146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall SubstTemplateTemplateParms.InsertNode(subst, insertPos); 5673146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall } 5674146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5675146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall return TemplateName(subst); 5676146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall} 5677146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall 5678146060435c3efce95c95a092c7a1eb651cfb9ae0John McCallTemplateName 56791aee05d08b2184acadeb36de300e216390780d6cDouglas GregorASTContext::getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 56801aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) const { 56811aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ASTContext &Self = const_cast<ASTContext &>(*this); 56821aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor llvm::FoldingSetNodeID ID; 56831aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage::Profile(ID, Self, Param, ArgPack); 56841aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 56851aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor void *InsertPos = 0; 56861aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPackStorage *Subst 56871aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor = SubstTemplateTemplateParmPacks.FindNodeOrInsertPos(ID, InsertPos); 56881aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 56891aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor if (!Subst) { 5690146060435c3efce95c95a092c7a1eb651cfb9ae0John McCall Subst = new (*this) SubstTemplateTemplateParmPackStorage(Param, 56911aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ArgPack.pack_size(), 56921aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor ArgPack.pack_begin()); 56931aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor SubstTemplateTemplateParmPacks.InsertNode(Subst, InsertPos); 56941aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 56951aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 56961aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return TemplateName(Subst); 56971aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor} 56981aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 5699b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor/// getFromTargetType - Given one of the integer types provided by 5700d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// TargetInfo, produce the corresponding type. The unsigned @p Type 5701d934112e6170b0fd940d8e40db6936cea2cdcf62Douglas Gregor/// is actually a value of type @c TargetInfo::IntType. 5702e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCallCanQualType ASTContext::getFromTargetType(unsigned Type) const { 5703b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor switch (Type) { 5704e27ec8ad56dbf1efb2de004b90fbbb86f740e3f1John McCall case TargetInfo::NoInt: return CanQualType(); 5705b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedShort: return ShortTy; 5706b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedShort: return UnsignedShortTy; 5707b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedInt: return IntTy; 5708b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedInt: return UnsignedIntTy; 5709b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLong: return LongTy; 5710b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLong: return UnsignedLongTy; 5711b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::SignedLongLong: return LongLongTy; 5712b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor case TargetInfo::UnsignedLongLong: return UnsignedLongLongTy; 5713b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor } 5714b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor 5715b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unhandled TargetInfo::IntType value"); 5716b4e66d5259f90e9aae4d40fc5de801e046c7df94Douglas Gregor} 5717b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 5718b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 5719b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek// Type Predicates. 5720b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek//===----------------------------------------------------------------------===// 5721b6ccaac65ca72f72954eb3893bbd940bedd23f00Ted Kremenek 57224fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 57234fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// garbage collection attribute. 57244fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian/// 5725ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCallQualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const { 57264e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().getGC() == LangOptions::NonGC) 5727ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return Qualifiers::GCNone; 5728ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall 57294e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie assert(getLangOpts().ObjC1); 5730ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall Qualifiers::GC GCAttrs = Ty.getObjCGCAttr(); 5731ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall 5732ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // Default behaviour under objective-C's gc is for ObjC pointers 5733ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // (or pointers to them) be treated as though they were declared 5734ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // as __strong. 5735ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall if (GCAttrs == Qualifiers::GCNone) { 5736ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) 5737ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return Qualifiers::Strong; 5738ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall else if (Ty->isPointerType()) 5739ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall return getObjCGCAttrKind(Ty->getAs<PointerType>()->getPointeeType()); 5740ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall } else { 5741ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // It's not valid to set GC attributes on anything that isn't a 5742ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall // pointer. 5743ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall#ifndef NDEBUG 5744ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall QualType CT = Ty->getCanonicalTypeInternal(); 5745ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall while (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 5746ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall CT = AT->getElementType(); 5747ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall assert(CT->isAnyPointerType() || CT->isBlockPointerType()); 5748ae278a3a57595349a411f6474938d4dd1b263a0eJohn McCall#endif 57494fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian } 5750b7d2553edd2532d29b98b9e76bcf6a62bc48b417Chris Lattner return GCAttrs; 57514fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian} 57524fd83ea566f4a0c083001c84b75da6cc8c99c1d6Fariborz Jahanian 57536ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 57546ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner// Type Compatibility Testing 57556ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner//===----------------------------------------------------------------------===// 5756770951b5bb6028a8d326ddb4a13cef7d4a128162Chris Lattner 57571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// areCompatVectorTypes - Return true if the two specified vector types are 57586ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner/// compatible. 57596ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattnerstatic bool areCompatVectorTypes(const VectorType *LHS, 57606ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner const VectorType *RHS) { 5761467b27b9a24bdc823218ad1ad0e37673b6cc1e83John McCall assert(LHS->isCanonicalUnqualified() && RHS->isCanonicalUnqualified()); 57626ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return LHS->getElementType() == RHS->getElementType() && 576361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner LHS->getNumElements() == RHS->getNumElements(); 57646ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 57656ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 5766255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregorbool ASTContext::areCompatibleVectorTypes(QualType FirstVec, 5767255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor QualType SecondVec) { 5768255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor assert(FirstVec->isVectorType() && "FirstVec should be a vector type"); 5769255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor assert(SecondVec->isVectorType() && "SecondVec should be a vector type"); 5770255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5771255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor if (hasSameUnqualifiedType(FirstVec, SecondVec)) 5772255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return true; 5773255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5774f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson // Treat Neon vector types and most AltiVec vector types as if they are the 5775f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson // equivalent GCC vector types. 5776255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor const VectorType *First = FirstVec->getAs<VectorType>(); 5777255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor const VectorType *Second = SecondVec->getAs<VectorType>(); 5778f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson if (First->getNumElements() == Second->getNumElements() && 5779255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor hasSameType(First->getElementType(), Second->getElementType()) && 5780f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson First->getVectorKind() != VectorType::AltiVecPixel && 5781f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson First->getVectorKind() != VectorType::AltiVecBool && 5782f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson Second->getVectorKind() != VectorType::AltiVecPixel && 5783f69eb7cf8e616b5aad7911ec6f79b24b0a009227Bob Wilson Second->getVectorKind() != VectorType::AltiVecBool) 5784255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return true; 5785255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 5786255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor return false; 5787255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor} 5788255210ef415b9893f0e3794e8d9a704194c12f3cDouglas Gregor 57894084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 57904084c306635b70f37029dca938444e6013f08684Steve Naroff// ObjCQualifiedIdTypesAreCompatible - Compatibility testing for qualified id's. 57914084c306635b70f37029dca938444e6013f08684Steve Naroff//===----------------------------------------------------------------------===// 57924084c306635b70f37029dca938444e6013f08684Steve Naroff 57934084c306635b70f37029dca938444e6013f08684Steve Naroff/// ProtocolCompatibleWithProtocol - return 'true' if 'lProto' is in the 57944084c306635b70f37029dca938444e6013f08684Steve Naroff/// inheritance hierarchy of 'rProto'. 57954ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool 57964ba2a17694148e16eaa8d3917f657ffcd3667be4Jay FoadASTContext::ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 57974ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad ObjCProtocolDecl *rProto) const { 57983fc73ee0c613715ebce78e30b4d050ea715a007dDouglas Gregor if (declaresSameEntity(lProto, rProto)) 579914108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return true; 58004084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCProtocolDecl::protocol_iterator PI = rProto->protocol_begin(), 58014084c306635b70f37029dca938444e6013f08684Steve Naroff E = rProto->protocol_end(); PI != E; ++PI) 58024084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lProto, *PI)) 58034084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 58044084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 58054084c306635b70f37029dca938444e6013f08684Steve Naroff} 580614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 58074c3b8a3ed28c52dc56d3a1b9670d71e5f7070c62Dmitri Gribenko/// QualifiedIdConformsQualifiedId - compare id<pr,...> with id<pr1,...> 58084084c306635b70f37029dca938444e6013f08684Steve Naroff/// return true if lhs's protocols conform to rhs's protocol; false 58094084c306635b70f37029dca938444e6013f08684Steve Naroff/// otherwise. 58104084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::QualifiedIdConformsQualifiedId(QualType lhs, QualType rhs) { 58114084c306635b70f37029dca938444e6013f08684Steve Naroff if (lhs->isObjCQualifiedIdType() && rhs->isObjCQualifiedIdType()) 58124084c306635b70f37029dca938444e6013f08684Steve Naroff return ObjCQualifiedIdTypesAreCompatible(lhs, rhs, false); 58134084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 58144084c306635b70f37029dca938444e6013f08684Steve Naroff} 58154084c306635b70f37029dca938444e6013f08684Steve Naroff 58164c3b8a3ed28c52dc56d3a1b9670d71e5f7070c62Dmitri Gribenko/// ObjCQualifiedClassTypesAreCompatible - compare Class<pr,...> and 58174c3b8a3ed28c52dc56d3a1b9670d71e5f7070c62Dmitri Gribenko/// Class<pr1, ...>. 5818a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanianbool ASTContext::ObjCQualifiedClassTypesAreCompatible(QualType lhs, 5819a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian QualType rhs) { 5820a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian const ObjCObjectPointerType *lhsQID = lhs->getAs<ObjCObjectPointerType>(); 5821a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 5822a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian assert ((lhsQID && rhsOPT) && "ObjCQualifiedClassTypesAreCompatible"); 5823a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5824a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 5825a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian E = lhsQID->qual_end(); I != E; ++I) { 5826a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian bool match = false; 5827a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian ObjCProtocolDecl *lhsProto = *I; 5828a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 5829a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian E = rhsOPT->qual_end(); J != E; ++J) { 5830a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian ObjCProtocolDecl *rhsProto = *J; 5831a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto)) { 5832a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian match = true; 5833a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian break; 5834a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5835a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5836a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (!match) 5837a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return false; 5838a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian } 5839a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return true; 5840a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian} 5841a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 58424084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an 58434084c306635b70f37029dca938444e6013f08684Steve Naroff/// ObjCQualifiedIDType. 58444084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, 58454084c306635b70f37029dca938444e6013f08684Steve Naroff bool compare) { 58464084c306635b70f37029dca938444e6013f08684Steve Naroff // Allow id<P..> and an 'id' or void* type in all cases. 58471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (lhs->isVoidPointerType() || 58484084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->isObjCIdType() || lhs->isObjCClassType()) 58494084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 58501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump else if (rhs->isVoidPointerType() || 58514084c306635b70f37029dca938444e6013f08684Steve Naroff rhs->isObjCIdType() || rhs->isObjCClassType()) 58524084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 58534084c306635b70f37029dca938444e6013f08684Steve Naroff 58544084c306635b70f37029dca938444e6013f08684Steve Naroff if (const ObjCObjectPointerType *lhsQID = lhs->getAsObjCQualifiedIdType()) { 5855183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *rhsOPT = rhs->getAs<ObjCObjectPointerType>(); 58561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58574084c306635b70f37029dca938444e6013f08684Steve Naroff if (!rhsOPT) return false; 58581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58594084c306635b70f37029dca938444e6013f08684Steve Naroff if (rhsOPT->qual_empty()) { 58601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a unqualified interface pointer "NSString*", 58614084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 58624084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 58634084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 58644084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 58654084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 58664084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 58674084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 58680fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (!rhsID->ClassImplementsProtocol(*I, true)) 58694084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 58704084c306635b70f37029dca938444e6013f08684Steve Naroff } 58714084c306635b70f37029dca938444e6013f08684Steve Naroff } 58724084c306635b70f37029dca938444e6013f08684Steve Naroff // If there are no qualifiers and no interface, we have an 'id'. 58734084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 58744084c306635b70f37029dca938444e6013f08684Steve Naroff } 58751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Both the right and left sides have qualifiers. 58764084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 58774084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 58784084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 58794084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 5880de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff 5881de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // when comparing an id<P> on lhs with a static type on rhs, 5882de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // see if static class implements all of id's protocols, directly or 5883de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff // through its super class and categories. 58844084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsOPT->qual_begin(), 58854084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsOPT->qual_end(); J != E; ++J) { 58864084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 58874084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 58884084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 58894084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 58908f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 58918f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 5892de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 58931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // If the RHS is a qualified interface pointer "NSString<P>*", 58944084c306635b70f37029dca938444e6013f08684Steve Naroff // make sure we check the class hierarchy. 58954084c306635b70f37029dca938444e6013f08684Steve Naroff if (ObjCInterfaceDecl *rhsID = rhsOPT->getInterfaceDecl()) { 58964084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsQID->qual_begin(), 58974084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsQID->qual_end(); I != E; ++I) { 58984084c306635b70f37029dca938444e6013f08684Steve Naroff // when comparing an id<P> on lhs with a static type on rhs, 58994084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 59004084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 59010fd8904c5f71a11d29f67716c3ebdf7ad1c855fbFariborz Jahanian if (rhsID->ClassImplementsProtocol(*I, true)) { 59024084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 59034084c306635b70f37029dca938444e6013f08684Steve Naroff break; 59044084c306635b70f37029dca938444e6013f08684Steve Naroff } 59054084c306635b70f37029dca938444e6013f08684Steve Naroff } 59064084c306635b70f37029dca938444e6013f08684Steve Naroff } 59074084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 5908de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return false; 5909de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 59101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5911de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff return true; 5912de2e22d33afec98324a66a358dfe0951b3c7259aSteve Naroff } 59131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59144084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *rhsQID = rhs->getAsObjCQualifiedIdType(); 59154084c306635b70f37029dca938444e6013f08684Steve Naroff assert(rhsQID && "One of the LHS/RHS should be id<x>"); 59164084c306635b70f37029dca938444e6013f08684Steve Naroff 59171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (const ObjCObjectPointerType *lhsOPT = 59184084c306635b70f37029dca938444e6013f08684Steve Naroff lhs->getAsObjCInterfacePointerType()) { 5919de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // If both the right and left sides have qualifiers. 59204084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator I = lhsOPT->qual_begin(), 59214084c306635b70f37029dca938444e6013f08684Steve Naroff E = lhsOPT->qual_end(); I != E; ++I) { 59224084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *lhsProto = *I; 59234084c306635b70f37029dca938444e6013f08684Steve Naroff bool match = false; 59244084c306635b70f37029dca938444e6013f08684Steve Naroff 5925de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // when comparing an id<P> on rhs with a static type on lhs, 59264084c306635b70f37029dca938444e6013f08684Steve Naroff // see if static class implements all of id's protocols, directly or 59274084c306635b70f37029dca938444e6013f08684Steve Naroff // through its super class and categories. 5928de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // First, lhs protocols in the qualifier list must be found, direct 5929de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // or indirect in rhs's qualifier list or it is a mismatch. 59304084c306635b70f37029dca938444e6013f08684Steve Naroff for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 59314084c306635b70f37029dca938444e6013f08684Steve Naroff E = rhsQID->qual_end(); J != E; ++J) { 59324084c306635b70f37029dca938444e6013f08684Steve Naroff ObjCProtocolDecl *rhsProto = *J; 59334084c306635b70f37029dca938444e6013f08684Steve Naroff if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 59344084c306635b70f37029dca938444e6013f08684Steve Naroff (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 59354084c306635b70f37029dca938444e6013f08684Steve Naroff match = true; 59364084c306635b70f37029dca938444e6013f08684Steve Naroff break; 59374084c306635b70f37029dca938444e6013f08684Steve Naroff } 59384084c306635b70f37029dca938444e6013f08684Steve Naroff } 59394084c306635b70f37029dca938444e6013f08684Steve Naroff if (!match) 59404084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 59414084c306635b70f37029dca938444e6013f08684Steve Naroff } 5942de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian 5943de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // Static class's protocols, or its super class or category protocols 5944de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // must be found, direct or indirect in rhs's qualifier list or it is a mismatch. 5945de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { 5946de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; 5947de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian CollectInheritedProtocols(lhsID, LHSInheritedProtocols); 5948de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // This is rather dubious but matches gcc's behavior. If lhs has 5949de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // no type qualifier and its class has no static protocol(s) 5950de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian // assume that it is mismatch. 5951de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (LHSInheritedProtocols.empty() && lhsOPT->qual_empty()) 5952de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian return false; 5953de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 5954de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian LHSInheritedProtocols.begin(), 5955de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian E = LHSInheritedProtocols.end(); I != E; ++I) { 5956de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian bool match = false; 5957de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian ObjCProtocolDecl *lhsProto = (*I); 5958de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian for (ObjCObjectPointerType::qual_iterator J = rhsQID->qual_begin(), 5959de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian E = rhsQID->qual_end(); J != E; ++J) { 5960de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian ObjCProtocolDecl *rhsProto = *J; 5961de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (ProtocolCompatibleWithProtocol(lhsProto, rhsProto) || 5962de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian (compare && ProtocolCompatibleWithProtocol(rhsProto, lhsProto))) { 5963de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian match = true; 5964de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian break; 5965de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 5966de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 5967de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian if (!match) 5968de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian return false; 5969de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 5970de5b17ea3c74d2844ed035a1edfa6479866139b5Fariborz Jahanian } 59714084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 59724084c306635b70f37029dca938444e6013f08684Steve Naroff } 59734084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 59744084c306635b70f37029dca938444e6013f08684Steve Naroff} 59754084c306635b70f37029dca938444e6013f08684Steve Naroff 59764084c306635b70f37029dca938444e6013f08684Steve Naroff/// canAssignObjCInterfaces - Return true if the two interface types are 59774084c306635b70f37029dca938444e6013f08684Steve Naroff/// compatible for assignment from RHS to LHS. This handles validation of any 59784084c306635b70f37029dca938444e6013f08684Steve Naroff/// protocol qualifiers on the LHS or RHS. 59794084c306635b70f37029dca938444e6013f08684Steve Naroff/// 59804084c306635b70f37029dca938444e6013f08684Steve Naroffbool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 59814084c306635b70f37029dca938444e6013f08684Steve Naroff const ObjCObjectPointerType *RHSOPT) { 5982c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHS = LHSOPT->getObjectType(); 5983c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHS = RHSOPT->getObjectType(); 5984c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 59854084c306635b70f37029dca938444e6013f08684Steve Naroff // If either type represents the built-in 'id' or 'Class' types, return true. 5986c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->isObjCUnqualifiedIdOrClass() || 5987c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHS->isObjCUnqualifiedIdOrClass()) 59884084c306635b70f37029dca938444e6013f08684Steve Naroff return true; 59894084c306635b70f37029dca938444e6013f08684Steve Naroff 5990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->isObjCQualifiedId() || RHS->isObjCQualifiedId()) 59911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 59921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType(RHSOPT,0), 59934084c306635b70f37029dca938444e6013f08684Steve Naroff false); 5994a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5995a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass()) 5996a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian return ObjCQualifiedClassTypesAreCompatible(QualType(LHSOPT,0), 5997a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian QualType(RHSOPT,0)); 5998a8f8dac6a29f6d33474a38a32ce9dd859b696da9Fariborz Jahanian 5999c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // If we have 2 user-defined types, fall into that path. 6000c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHS->getInterface() && RHS->getInterface()) 60014084c306635b70f37029dca938444e6013f08684Steve Naroff return canAssignObjCInterfaces(LHS, RHS); 60021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60034084c306635b70f37029dca938444e6013f08684Steve Naroff return false; 600414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff} 600514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 6006132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// canAssignObjCInterfacesInBlockPointer - This routine is specifically written 6007fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner/// for providing type-safety for objective-c pointers used to pass/return 6008132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// arguments in block literals. When passed as arguments, passing 'A*' where 6009132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// 'id' is expected is not OK. Passing 'Sub *" where 'Super *" is expected is 6010132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian/// not OK. For the return type, the opposite is not OK. 6011132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanianbool ASTContext::canAssignObjCInterfacesInBlockPointer( 6012132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCObjectPointerType *LHSOPT, 6013a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian const ObjCObjectPointerType *RHSOPT, 6014a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian bool BlockReturnType) { 6015a98344869c278295f38e106583906377520079b8Fariborz Jahanian if (RHSOPT->isObjCBuiltinType() || LHSOPT->isObjCIdType()) 6016132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return true; 6017132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6018132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHSOPT->isObjCBuiltinType()) { 6019132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return RHSOPT->isObjCBuiltinType() || RHSOPT->isObjCQualifiedIdType(); 6020132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6021132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6022a98344869c278295f38e106583906377520079b8Fariborz Jahanian if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) 6023132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), 6024132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian QualType(RHSOPT,0), 6025132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian false); 6026132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6027132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); 6028132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); 6029132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS && RHS) { // We have 2 user-defined types. 6030132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS != RHS) { 6031132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (LHS->getDecl()->isSuperClassOf(RHS->getDecl())) 6032a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian return BlockReturnType; 6033132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (RHS->getDecl()->isSuperClassOf(LHS->getDecl())) 6034a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian return !BlockReturnType; 6035132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6036132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian else 6037132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return true; 6038132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6039132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return false; 6040132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian} 6041132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 6042e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// getIntersectionOfProtocols - This routine finds the intersection of set 6043e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// of protocols inherited from two distinct objective-c pointer objects. 6044e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// It is used to build composite qualifier list of the composite type of 6045e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian/// the conditional expression involving two objective-c pointer objects. 6046e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianstatic 6047e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanianvoid getIntersectionOfProtocols(ASTContext &Context, 6048e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian const ObjCObjectPointerType *LHSOPT, 6049e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian const ObjCObjectPointerType *RHSOPT, 60505f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVectorImpl<ObjCProtocolDecl *> &IntersectionOfProtocols) { 6051e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6052c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHS = LHSOPT->getObjectType(); 6053c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHS = RHSOPT->getObjectType(); 6054c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(LHS->getInterface() && "LHS must have an interface base"); 6055c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(RHS->getInterface() && "RHS must have an interface base"); 6056e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6057e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> InheritedProtocolSet; 6058e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian unsigned LHSNumProtocols = LHS->getNumProtocols(); 6059e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (LHSNumProtocols > 0) 6060e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian InheritedProtocolSet.insert(LHS->qual_begin(), LHS->qual_end()); 6061e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian else { 6062432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> LHSInheritedProtocols; 6063c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Context.CollectInheritedProtocols(LHS->getInterface(), 6064c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHSInheritedProtocols); 6065e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian InheritedProtocolSet.insert(LHSInheritedProtocols.begin(), 6066e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian LHSInheritedProtocols.end()); 6067e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 6068e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6069e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian unsigned RHSNumProtocols = RHS->getNumProtocols(); 6070e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (RHSNumProtocols > 0) { 6071cb421fa690da545b58a720abe5f1c49b166dbde7Dan Gohman ObjCProtocolDecl **RHSProtocols = 6072cb421fa690da545b58a720abe5f1c49b166dbde7Dan Gohman const_cast<ObjCProtocolDecl **>(RHS->qual_begin()); 6073e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian for (unsigned i = 0; i < RHSNumProtocols; ++i) 6074e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (InheritedProtocolSet.count(RHSProtocols[i])) 6075e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian IntersectionOfProtocols.push_back(RHSProtocols[i]); 60763060178ad9df29789505c1e6debcfc80a3a13587Chad Rosier } else { 6077432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> RHSInheritedProtocols; 6078c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Context.CollectInheritedProtocols(RHS->getInterface(), 6079c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHSInheritedProtocols); 6080432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 6081432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian RHSInheritedProtocols.begin(), 6082432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian E = RHSInheritedProtocols.end(); I != E; ++I) 6083432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian if (InheritedProtocolSet.count((*I))) 6084432a8893f7e30d141d7f279bd00b741a3cdac81fFariborz Jahanian IntersectionOfProtocols.push_back((*I)); 6085e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 6086e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian} 6087e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian 6088db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// areCommonBaseCompatible - Returns common base class of the two classes if 6089db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// one found. Note that this is O'2 algorithm. But it will be called as the 6090db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// last type comparison in a ?-exp of ObjC pointer types before a 6091db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian/// warning is issued. So, its invokation is extremely rare. 6092db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz JahanianQualType ASTContext::areCommonBaseCompatible( 6093c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectPointerType *Lptr, 6094c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectPointerType *Rptr) { 6095c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *LHS = Lptr->getObjectType(); 6096c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *RHS = Rptr->getObjectType(); 6097c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCInterfaceDecl* LDecl = LHS->getInterface(); 6098c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCInterfaceDecl* RDecl = RHS->getInterface(); 609960ef308e51c71b760d7f598c1b763ceb7b768148Douglas Gregor if (!LDecl || !RDecl || (declaresSameEntity(LDecl, RDecl))) 6100db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian return QualType(); 6101db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 61027c2bdcb4d30f2d370b4367664e6a11b075ce2cb3Fariborz Jahanian do { 6103c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHS = cast<ObjCInterfaceType>(getObjCInterfaceType(LDecl)); 6104e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian if (canAssignObjCInterfaces(LHS, RHS)) { 61055f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<ObjCProtocolDecl *, 8> Protocols; 6106c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall getIntersectionOfProtocols(*this, Lptr, Rptr, Protocols); 6107c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 6108c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall QualType Result = QualType(LHS, 0); 6109c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!Protocols.empty()) 6110c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = getObjCObjectType(Result, Protocols.data(), Protocols.size()); 6111c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = getObjCObjectPointerType(Result); 6112c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return Result; 6113e23fa2d0e84d1b878e012442a726c664216a9adfFariborz Jahanian } 61147c2bdcb4d30f2d370b4367664e6a11b075ce2cb3Fariborz Jahanian } while ((LDecl = LDecl->getSuperClass())); 6115db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 6116db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian return QualType(); 6117db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian} 6118db07b3f7cdcb505329c1280d7cf70791739a7cadFariborz Jahanian 6119c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallbool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, 6120c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType *RHS) { 6121c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(LHS->getInterface() && "LHS is not an interface type"); 6122c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall assert(RHS->getInterface() && "RHS is not an interface type"); 6123c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 61246ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // Verify that the base decls are compatible: the RHS must be a subclass of 61256ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // the LHS. 6126c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (!LHS->getInterface()->isSuperClassOf(RHS->getInterface())) 61276ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return false; 61281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61296ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // RHS must have a superset of the protocols in the LHS. If the LHS is not 61306ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner // protocol qualified at all, then we are good. 6131c15cb2af27514ecc879daba9aa01389c5203685dSteve Naroff if (LHS->getNumProtocols() == 0) 61326ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner return true; 61331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6134b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // Okay, we know the LHS has protocol qualifiers. If the RHS doesn't, 6135b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // more detailed analysis is required. 6136b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (RHS->getNumProtocols() == 0) { 6137b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // OK, if LHS is a superclass of RHS *and* 6138b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // this superclass is assignment compatible with LHS. 6139b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // false otherwise. 6140627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian bool IsSuperClass = 6141627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian LHS->getInterface()->isSuperClassOf(RHS->getInterface()); 6142627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian if (IsSuperClass) { 6143b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // OK if conversion of LHS to SuperClass results in narrowing of types 6144b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // ; i.e., SuperClass may implement at least one of the protocols 6145b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // in LHS's protocol list. Example, SuperObj<P1> = lhs<P1,P2> is ok. 6146b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // But not SuperObj<P1,P2,P3> = lhs<P1,P2>. 6147b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian llvm::SmallPtrSet<ObjCProtocolDecl *, 8> SuperClassInheritedProtocols; 6148627788c29976fbeb4ad47bcfcb3576889070e357Fariborz Jahanian CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols); 6149b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian // If super class has no protocols, it is not a match. 6150b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (SuperClassInheritedProtocols.empty()) 6151b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 6152b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian 6153b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian for (ObjCObjectType::qual_iterator LHSPI = LHS->qual_begin(), 6154b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian LHSPE = LHS->qual_end(); 6155b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian LHSPI != LHSPE; LHSPI++) { 6156b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian bool SuperImplementsProtocol = false; 6157b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian ObjCProtocolDecl *LHSProto = (*LHSPI); 6158b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian 6159b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian for (llvm::SmallPtrSet<ObjCProtocolDecl*,8>::iterator I = 6160b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian SuperClassInheritedProtocols.begin(), 6161b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian E = SuperClassInheritedProtocols.end(); I != E; ++I) { 6162b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian ObjCProtocolDecl *SuperClassProto = (*I); 6163b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (SuperClassProto->lookupProtocolNamed(LHSProto->getIdentifier())) { 6164b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian SuperImplementsProtocol = true; 6165b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian break; 6166b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6167b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6168b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian if (!SuperImplementsProtocol) 6169b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 6170b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6171b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return true; 6172b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 6173b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian return false; 6174b7bc34a83aff8af09f2a78aa6d1dcafe18ad8619Fariborz Jahanian } 61751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6176c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator LHSPI = LHS->qual_begin(), 6177c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall LHSPE = LHS->qual_end(); 617891b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff LHSPI != LHSPE; LHSPI++) { 617991b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff bool RHSImplementsProtocol = false; 618091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff 618191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // If the RHS doesn't implement the protocol on the left, the types 618291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // are incompatible. 6183c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall for (ObjCObjectType::qual_iterator RHSPI = RHS->qual_begin(), 6184c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall RHSPE = RHS->qual_end(); 61858f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff RHSPI != RHSPE; RHSPI++) { 61868f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff if ((*RHSPI)->lookupProtocolNamed((*LHSPI)->getIdentifier())) { 618791b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff RHSImplementsProtocol = true; 61888f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff break; 61898f16756441450ed9fb39316e47d107fc2a1ef35bSteve Naroff } 619091b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 619191b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // FIXME: For better diagnostics, consider passing back the protocol name. 619291b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff if (!RHSImplementsProtocol) 619391b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return false; 619491b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff } 619591b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff // The RHS implements all protocols listed on the LHS. 619691b0b0cf6b537cbcbca0038c7032f87161a41d31Steve Naroff return true; 61976ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner} 61986ac46a4a521366d7ab36ebe2ce4e624ab96b06f9Chris Lattner 6199389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroffbool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { 6200389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff // get the "pointed to" types 6201183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *LHSOPT = LHS->getAs<ObjCObjectPointerType>(); 6202183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const ObjCObjectPointerType *RHSOPT = RHS->getAs<ObjCObjectPointerType>(); 62031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 620414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff if (!LHSOPT || !RHSOPT) 6205389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff return false; 620614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 620714108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return canAssignObjCInterfaces(LHSOPT, RHSOPT) || 620814108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff canAssignObjCInterfaces(RHSOPT, LHSOPT); 6209389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff} 6210389bf46ae41241a656ed71b00ac2177d7f385651Steve Naroff 6211569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregorbool ASTContext::canBindObjCObjectType(QualType To, QualType From) { 6212569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor return canAssignObjCInterfaces( 6213569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor getObjCObjectPointerType(To)->getAs<ObjCObjectPointerType>(), 6214569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor getObjCObjectPointerType(From)->getAs<ObjCObjectPointerType>()); 6215569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor} 6216569c3166874324c24011f8ade6978421f0d39b3cDouglas Gregor 62171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, 6218ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// both shall have the identically qualified version of a compatible type. 62191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// C99 6.2.7p1: Two types have compatible types if their types are the 6220ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff/// same. See 6.7.[2,3,5] for additional rules. 6221447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregorbool ASTContext::typesAreCompatible(QualType LHS, QualType RHS, 6222447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool CompareUnqualified) { 62234e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (getLangOpts().CPlusPlus) 62240e709abafbd939326850501f795cc7a92c88a354Douglas Gregor return hasSameType(LHS, RHS); 62250e709abafbd939326850501f795cc7a92c88a354Douglas Gregor 6226447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor return !mergeTypes(LHS, RHS, false, CompareUnqualified).isNull(); 62273d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 62283d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6229c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanianbool ASTContext::propertyTypesAreCompatible(QualType LHS, QualType RHS) { 623082378391dfc3b2fc22f63dbf1552bd9aed39dc42Fariborz Jahanian return typesAreCompatible(LHS, RHS); 6231c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanian} 6232c286f3835eb6001c61664cef5d610dfaf80a6e9bFariborz Jahanian 6233132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanianbool ASTContext::typesAreBlockPointerCompatible(QualType LHS, QualType RHS) { 6234132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return !mergeTypes(LHS, RHS, true).isNull(); 6235132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian} 6236132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian 62374846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// mergeTransparentUnionType - if T is a transparent union type and a member 62384846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// of T is compatible with SubType, return the merged type, else return 62394846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// QualType() 62404846675e0e42d1802b0ffd8972a45e72aeb3758dPeter CollingbourneQualType ASTContext::mergeTransparentUnionType(QualType T, QualType SubType, 62414846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool OfBlockPointer, 62424846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool Unqualified) { 62434846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (const RecordType *UT = T->getAsUnionType()) { 62444846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne RecordDecl *UD = UT->getDecl(); 62454846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (UD->hasAttr<TransparentUnionAttr>()) { 62464846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne for (RecordDecl::field_iterator it = UD->field_begin(), 62474846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne itend = UD->field_end(); it != itend; ++it) { 6248f91d7572ee7fa6f2926c8e7e816039a1154a59f8Peter Collingbourne QualType ET = it->getType().getUnqualifiedType(); 62494846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType MT = mergeTypes(ET, SubType, OfBlockPointer, Unqualified); 62504846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!MT.isNull()) 62514846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return MT; 62524846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 62534846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 62544846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne } 62554846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 62564846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return QualType(); 62574846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne} 62584846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 62594846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// mergeFunctionArgumentTypes - merge two types which appear as function 62604846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne/// argument types 62614846675e0e42d1802b0ffd8972a45e72aeb3758dPeter CollingbourneQualType ASTContext::mergeFunctionArgumentTypes(QualType lhs, QualType rhs, 62624846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool OfBlockPointer, 62634846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne bool Unqualified) { 62644846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // GNU extension: two types are compatible if they appear as a function 62654846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // argument, one of the types is a transparent union type and the other 62664846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne // type is compatible with a union member 62674846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType lmerge = mergeTransparentUnionType(lhs, rhs, OfBlockPointer, 62684846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 62694846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!lmerge.isNull()) 62704846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return lmerge; 62714846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 62724846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType rmerge = mergeTransparentUnionType(rhs, lhs, OfBlockPointer, 62734846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 62744846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne if (!rmerge.isNull()) 62754846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return rmerge; 62764846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 62774846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne return mergeTypes(lhs, rhs, OfBlockPointer, Unqualified); 62784846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne} 62794846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne 6280132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz JahanianQualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs, 6281447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool OfBlockPointer, 6282447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool Unqualified) { 6283183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *lbase = lhs->getAs<FunctionType>(); 6284183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall const FunctionType *rbase = rhs->getAs<FunctionType>(); 628572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *lproto = dyn_cast<FunctionProtoType>(lbase); 628672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *rproto = dyn_cast<FunctionProtoType>(rbase); 62873d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allLTypes = true; 62883d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman bool allRTypes = true; 62893d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 62903d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check return type 6291132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian QualType retType; 6292d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian if (OfBlockPointer) { 6293d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian QualType RHS = rbase->getResultType(); 6294d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian QualType LHS = lbase->getResultType(); 6295d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian bool UnqualifiedResult = Unqualified; 6296d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian if (!UnqualifiedResult) 6297d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian UnqualifiedResult = (!RHS.hasQualifiers() && LHS.hasQualifiers()); 6298a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian retType = mergeTypes(LHS, RHS, true, UnqualifiedResult, true); 6299d263fd1451299b1e5f5f1acb2bb13b0a4119aee8Fariborz Jahanian } 6300132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian else 63018cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall retType = mergeTypes(lbase->getResultType(), rbase->getResultType(), false, 63028cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall Unqualified); 63033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (retType.isNull()) return QualType(); 6304447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6305447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) 6306447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor retType = retType.getUnqualifiedType(); 6307447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6308447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor CanQualType LRetType = getCanonicalType(lbase->getResultType()); 6309447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor CanQualType RRetType = getCanonicalType(rbase->getResultType()); 6310447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6311447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LRetType = LRetType.getUnqualifiedType(); 6312447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RRetType = RRetType.getUnqualifiedType(); 6313447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6314447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6315447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (getCanonicalType(retType) != LRetType) 631661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 6317447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (getCanonicalType(retType) != RRetType) 631861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 63198cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 63206a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // FIXME: double check this 63216a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // FIXME: should we error if lbase->getRegParmAttr() != 0 && 63226a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // rbase->getRegParmAttr() != 0 && 63236a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar // lbase->getRegParmAttr() != rbase->getRegParmAttr()? 6324264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo lbaseInfo = lbase->getExtInfo(); 6325264ba48dc98f3f843935a485d5b086f7e0fdc4f1Rafael Espindola FunctionType::ExtInfo rbaseInfo = rbase->getExtInfo(); 63268cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 63278cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall // Compatible functions must have compatible calling conventions 63288cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall if (!isSameCallConv(lbaseInfo.getCC(), rbaseInfo.getCC())) 63298cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return QualType(); 63308cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 63318cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall // Regparm is part of the calling convention. 6332a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman if (lbaseInfo.getHasRegParm() != rbaseInfo.getHasRegParm()) 6333a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman return QualType(); 63348cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall if (lbaseInfo.getRegParm() != rbaseInfo.getRegParm()) 63358cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return QualType(); 63368cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall 6337f85e193739c953358c865005855253af4f68a497John McCall if (lbaseInfo.getProducesResult() != rbaseInfo.getProducesResult()) 6338f85e193739c953358c865005855253af4f68a497John McCall return QualType(); 6339f85e193739c953358c865005855253af4f68a497John McCall 634053c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian // functypes which return are preferred over those that do not. 634153c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian if (lbaseInfo.getNoReturn() && !rbaseInfo.getNoReturn()) 63426a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar allLTypes = false; 634353c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian else if (!lbaseInfo.getNoReturn() && rbaseInfo.getNoReturn()) 63446a15c8586cc3e5d6e01c4c4e8b4374584569b58fDaniel Dunbar allRTypes = false; 634553c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'. 634653c8167d7a007daae87f342c0fedd03f1dcf1b62Fariborz Jahanian bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn(); 63471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6348f85e193739c953358c865005855253af4f68a497John McCall FunctionType::ExtInfo einfo = lbaseInfo.withNoReturn(NoReturn); 6349e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 63503d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto && rproto) { // two C99 style function prototypes 6351465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() && 6352465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl "C++ shouldn't be here"); 63533d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned lproto_nargs = lproto->getNumArgs(); 63543d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned rproto_nargs = rproto->getNumArgs(); 63553d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 63563d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Compatible functions must have the same number of arguments 63573d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto_nargs != rproto_nargs) 63583d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 63593d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 63603d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Variadic and non-variadic functions aren't compatible 63613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto->isVariadic() != rproto->isVariadic()) 63623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 63633d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 63647fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis if (lproto->getTypeQuals() != rproto->getTypeQuals()) 63657fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis return QualType(); 63667fb5e4888221cd36652d078c6b171ac55e7f406dArgyrios Kyrtzidis 636778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (LangOpts.ObjCAutoRefCount && 636878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian !FunctionTypesMatchOnNSConsumedAttrs(rproto, lproto)) 636978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return QualType(); 637078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 63713d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check argument compatibility 63725f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 10> types; 63733d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < lproto_nargs; i++) { 63743d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType largtype = lproto->getArgType(i).getUnqualifiedType(); 63753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType rargtype = rproto->getArgType(i).getUnqualifiedType(); 63764846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne QualType argtype = mergeFunctionArgumentTypes(largtype, rargtype, 63774846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne OfBlockPointer, 63784846675e0e42d1802b0ffd8972a45e72aeb3758dPeter Collingbourne Unqualified); 63793d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argtype.isNull()) return QualType(); 6380447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6381447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) 6382447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor argtype = argtype.getUnqualifiedType(); 6383447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 63843d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman types.push_back(argtype); 6385447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6386447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor largtype = largtype.getUnqualifiedType(); 6387447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor rargtype = rargtype.getUnqualifiedType(); 6388447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6389447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 639061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(largtype)) 639161710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allLTypes = false; 639261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (getCanonicalType(argtype) != getCanonicalType(rargtype)) 639361710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner allRTypes = false; 63943d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 639578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 63963d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 63973d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 6398e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6399e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = lproto->getExtProtoInfo(); 6400e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = einfo; 6401e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return getFunctionType(retType, types.begin(), types.size(), EPI); 64023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 64033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64043d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (lproto) allRTypes = false; 64053d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (rproto) allLTypes = false; 64063d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 640772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor const FunctionProtoType *proto = lproto ? lproto : rproto; 64083d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto) { 6409465226e23a3008bd68973513dda1f9e3cd27dbddSebastian Redl assert(!proto->hasExceptionSpec() && "C++ shouldn't be here"); 64103d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (proto->isVariadic()) return QualType(); 64113d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Check that the types are compatible with the types that 64123d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // would result from default argument promotions (C99 6.7.5.3p15). 64133d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // The only types actually affected are promotable integer 64143d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // types and floats, which would be passed as a different 64153d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // type depending on whether the prototype is visible. 64163d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman unsigned proto_nargs = proto->getNumArgs(); 64173d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman for (unsigned i = 0; i < proto_nargs; ++i) { 64183d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType argTy = proto->getArgType(i); 6419b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 6420c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman // Look at the converted type of enum types, since that is the type used 6421b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor // to pass enum values. 6422c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman if (const EnumType *Enum = argTy->getAs<EnumType>()) { 6423c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman argTy = Enum->getDecl()->getIntegerType(); 6424c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman if (argTy.isNull()) 6425c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman return QualType(); 6426c586d5dd7a997321ea96d1d28213315f86778fc8Eli Friedman } 6427b0f8eacfdcd0d43f51e669f2d723992d4af9f746Douglas Gregor 64283d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (argTy->isPromotableIntegerType() || 64293d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman getCanonicalType(argTy).getUnqualifiedType() == FloatTy) 64303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 64313d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 64323d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64333d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 64343d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 6435e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 6436e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = proto->getExtProtoInfo(); 6437e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = einfo; 64383d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getFunctionType(retType, proto->arg_type_begin(), 6439e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall proto->getNumArgs(), EPI); 64403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 64413d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64423d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allLTypes) return lhs; 64433d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (allRTypes) return rhs; 64448cc246c9a68c783a5b90d2e8b8927521cb3a49b7John McCall return getFunctionNoProtoType(retType, einfo); 64453d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman} 64463d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6447132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz JahanianQualType ASTContext::mergeTypes(QualType LHS, QualType RHS, 6448447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor bool OfBlockPointer, 6449a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian bool Unqualified, bool BlockReturnType) { 645043d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // C++ [expr]: If an expression initially has the type "reference to T", the 645143d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // type is adjusted to "T" prior to any further analysis, the expression 645243d69750e7f7b26076e7474dec8839bb777b260fBill Wendling // designates the object or function denoted by the reference, and the 64537c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // expression is an lvalue unless the reference is an rvalue reference and 64547c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // the expression is a function call (possibly inside parentheses). 64550e709abafbd939326850501f795cc7a92c88a354Douglas Gregor assert(!LHS->getAs<ReferenceType>() && "LHS is a reference type?"); 64560e709abafbd939326850501f795cc7a92c88a354Douglas Gregor assert(!RHS->getAs<ReferenceType>() && "RHS is a reference type?"); 6457447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6458447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6459447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHS = LHS.getUnqualifiedType(); 6460447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHS = RHS.getUnqualifiedType(); 6461447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 64620e709abafbd939326850501f795cc7a92c88a354Douglas Gregor 64633d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSCan = getCanonicalType(LHS), 64643d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman RHSCan = getCanonicalType(RHS); 64653d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6466f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner // If two types are identical, they are compatible. 64673d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LHSCan == RHSCan) 64683d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 64693d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 64700953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If the qualifiers are different, the types aren't compatible... mostly. 6471a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers LQuals = LHSCan.getLocalQualifiers(); 6472a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers RQuals = RHSCan.getLocalQualifiers(); 64730953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals != RQuals) { 64740953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // If any of these qualifiers are different, we have a type 64750953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // mismatch. 64760953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 6477f85e193739c953358c865005855253af4f68a497John McCall LQuals.getAddressSpace() != RQuals.getAddressSpace() || 6478f85e193739c953358c865005855253af4f68a497John McCall LQuals.getObjCLifetime() != RQuals.getObjCLifetime()) 64790953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 64800953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 64810953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Exactly one GC qualifier difference is allowed: __strong is 64820953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // okay if the other type has no GC qualifier but is an Objective 64830953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // C object pointer (i.e. implicitly strong by default). We fix 64840953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // this by pretending that the unqualified type was actually 64850953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // qualified __strong. 64860953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 64870953e767ff7817f97b3ab20896b229891eeff45bJohn McCall Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 64880953e767ff7817f97b3ab20896b229891eeff45bJohn McCall assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 64890953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 64900953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 64910953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return QualType(); 64920953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 64930953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_L == Qualifiers::Strong && RHSCan->isObjCObjectPointerType()) { 64940953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(LHS, getObjCGCQualType(RHS, Qualifiers::Strong)); 64950953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 64960953e767ff7817f97b3ab20896b229891eeff45bJohn McCall if (GC_R == Qualifiers::Strong && LHSCan->isObjCObjectPointerType()) { 64970953e767ff7817f97b3ab20896b229891eeff45bJohn McCall return mergeTypes(getObjCGCQualType(LHS, Qualifiers::Strong), RHS); 64980953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 64993d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 65000953e767ff7817f97b3ab20896b229891eeff45bJohn McCall } 65010953e767ff7817f97b3ab20896b229891eeff45bJohn McCall 65020953e767ff7817f97b3ab20896b229891eeff45bJohn McCall // Okay, qualifiers are equal. 65033d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 6504852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass LHSClass = LHSCan->getTypeClass(); 6505852d63b806c5cbd730c6b9d696e2e27d02546b49Eli Friedman Type::TypeClass RHSClass = RHSCan->getTypeClass(); 6506f3692dc4a47dc48d10cec0415c6e9e39b7a39707Chris Lattner 65071adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // We want to consider the two function types to be the same for these 65081adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // comparisons, just force one to the other. 65091adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (LHSClass == Type::FunctionProto) LHSClass = Type::FunctionNoProto; 65101adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner if (RHSClass == Type::FunctionProto) RHSClass = Type::FunctionNoProto; 65114c721d381fb279899337d120edd4a24d405e56b2Eli Friedman 65124c721d381fb279899337d120edd4a24d405e56b2Eli Friedman // Same as above for arrays 6513a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (LHSClass == Type::VariableArray || LHSClass == Type::IncompleteArray) 6514a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner LHSClass = Type::ConstantArray; 6515a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner if (RHSClass == Type::VariableArray || RHSClass == Type::IncompleteArray) 6516a36a61f218b9f7a97f2c0f511e0b29eb42e8f78bChris Lattner RHSClass = Type::ConstantArray; 65171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6518c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCInterfaces are just specialized ObjCObjects. 6519c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (LHSClass == Type::ObjCInterface) LHSClass = Type::ObjCObject; 6520c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (RHSClass == Type::ObjCInterface) RHSClass = Type::ObjCObject; 6521c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 6522213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman // Canonicalize ExtVector -> Vector. 6523213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (LHSClass == Type::ExtVector) LHSClass = Type::Vector; 6524213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (RHSClass == Type::ExtVector) RHSClass = Type::Vector; 65251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65264e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff // If the canonical type classes don't match. 65274e78fd0a960eaa7e97467f2e8f390f3a57da279bSteve Naroff if (LHSClass != RHSClass) { 65281adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, 65291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // a signed integer type, or an unsigned integer type. 6530842aef8d942a880eeb9535d40de31a86838264cbJohn McCall // Compatibility is based on the underlying type, not the promotion 6531842aef8d942a880eeb9535d40de31a86838264cbJohn McCall // type. 6532183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = LHS->getAs<EnumType>()) { 6533b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian QualType TINT = ETy->getDecl()->getIntegerType(); 6534b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian if (!TINT.isNull() && hasSameType(TINT, RHSCan.getUnqualifiedType())) 65353d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 6536bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 6537183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (const EnumType* ETy = RHS->getAs<EnumType>()) { 6538b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian QualType TINT = ETy->getDecl()->getIntegerType(); 6539b918d6b1f794266e126e5445d69233462087d764Fariborz Jahanian if (!TINT.isNull() && hasSameType(TINT, LHSCan.getUnqualifiedType())) 65403d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 6541bab96968886f4b77083f4e26a28986ddb1e42d67Eli Friedman } 6542e7cff2c00c3d74e38984a4db5c48d7e303d3ab8eFariborz Jahanian // allow block pointer type to match an 'id' type. 6543419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (OfBlockPointer && !BlockReturnType) { 6544419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (LHS->isObjCIdType() && RHS->isBlockPointerType()) 6545419636316c04d570c183b4797fc811932c588358Fariborz Jahanian return LHS; 6546419636316c04d570c183b4797fc811932c588358Fariborz Jahanian if (RHS->isObjCIdType() && LHS->isBlockPointerType()) 6547419636316c04d570c183b4797fc811932c588358Fariborz Jahanian return RHS; 6548419636316c04d570c183b4797fc811932c588358Fariborz Jahanian } 6549e7cff2c00c3d74e38984a4db5c48d7e303d3ab8eFariborz Jahanian 65503d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 6551ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 65523d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 65534a74678ed6c3dedac05d02b1ee341f1db869f049Steve Naroff // The canonical type classes match. 65541adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner switch (LHSClass) { 655572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define TYPE(Class, Base) 655672564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define ABSTRACT_TYPE(Class, Base) 6557ad5e73887052193afda72db8efcb812bd083a4a8John McCall#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class: 655872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define NON_CANONICAL_TYPE(Class, Base) case Type::Class: 655972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#define DEPENDENT_TYPE(Class, Base) case Type::Class: 656072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor#include "clang/AST/TypeNodes.def" 6561b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Non-canonical and dependent types shouldn't get here"); 656272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 65637c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::LValueReference: 65647c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl case Type::RValueReference: 656572564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::MemberPointer: 6566b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("C++ should never be in mergeTypes"); 656772564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 6568c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCInterface: 656972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::IncompleteArray: 657072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::VariableArray: 657172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::FunctionProto: 657272564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::ExtVector: 6573b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Types are eliminated above"); 657472564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 65751adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Pointer: 65763d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 65773d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // Merge two pointer types, while trying to preserve typedef info 65786217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<PointerType>()->getPointeeType(); 65796217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<PointerType>()->getPointeeType(); 6580447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6581447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSPointee = LHSPointee.getUnqualifiedType(); 6582447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSPointee = RHSPointee.getUnqualifiedType(); 6583447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6584447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSPointee, RHSPointee, false, 6585447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor Unqualified); 65863d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 658707d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 658861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 658907d258756dc856c6987c394a0972884e6ed46765Eli Friedman if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 659061710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 65913d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return getPointerType(ResultType); 65923d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 6593c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff case Type::BlockPointer: 6594c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff { 6595c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff // Merge two block pointer types, while trying to preserve typedef info 65966217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType LHSPointee = LHS->getAs<BlockPointerType>()->getPointeeType(); 65976217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek QualType RHSPointee = RHS->getAs<BlockPointerType>()->getPointeeType(); 6598447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6599447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSPointee = LHSPointee.getUnqualifiedType(); 6600447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSPointee = RHSPointee.getUnqualifiedType(); 6601447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6602447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSPointee, RHSPointee, OfBlockPointer, 6603447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor Unqualified); 6604c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (ResultType.isNull()) return QualType(); 6605c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType)) 6606c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return LHS; 6607c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType)) 6608c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return RHS; 6609c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff return getBlockPointerType(ResultType); 6610c0febd58f5cbf4a93fd12f461863564dba0af76dSteve Naroff } 6611b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman case Type::Atomic: 6612b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman { 6613b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman // Merge two pointer types, while trying to preserve typedef info 6614b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType LHSValue = LHS->getAs<AtomicType>()->getValueType(); 6615b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RHSValue = RHS->getAs<AtomicType>()->getValueType(); 6616b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Unqualified) { 6617b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman LHSValue = LHSValue.getUnqualifiedType(); 6618b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman RHSValue = RHSValue.getUnqualifiedType(); 6619b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 6620b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ResultType = mergeTypes(LHSValue, RHSValue, false, 6621b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Unqualified); 6622b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ResultType.isNull()) return QualType(); 6623b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getCanonicalType(LHSValue) == getCanonicalType(ResultType)) 6624b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return LHS; 6625b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getCanonicalType(RHSValue) == getCanonicalType(ResultType)) 6626b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return RHS; 6627b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return getAtomicType(ResultType); 6628b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 66291adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::ConstantArray: 66303d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman { 66313d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* LCAT = getAsConstantArrayType(LHS); 66323d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const ConstantArrayType* RCAT = getAsConstantArrayType(RHS); 66333d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LCAT && RCAT && RCAT->getSize() != LCAT->getSize()) 66343d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 66353d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman 66363d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType LHSElem = getAsArrayType(LHS)->getElementType(); 66373d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman QualType RHSElem = getAsArrayType(RHS)->getElementType(); 6638447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor if (Unqualified) { 6639447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor LHSElem = LHSElem.getUnqualifiedType(); 6640447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor RHSElem = RHSElem.getUnqualifiedType(); 6641447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor } 6642447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor 6643447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor QualType ResultType = mergeTypes(LHSElem, RHSElem, false, Unqualified); 66443d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (ResultType.isNull()) return QualType(); 664561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LCAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 664661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 664761710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RCAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 664861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 66493bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (LCAT) return getConstantArrayType(ResultType, LCAT->getSize(), 66503bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 66513bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (RCAT) return getConstantArrayType(ResultType, RCAT->getSize(), 66523bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman ArrayType::ArraySizeModifier(), 0); 66533d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* LVAT = getAsVariableArrayType(LHS); 66543d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman const VariableArrayType* RVAT = getAsVariableArrayType(RHS); 665561710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (LVAT && getCanonicalType(LHSElem) == getCanonicalType(ResultType)) 665661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return LHS; 665761710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner if (RVAT && getCanonicalType(RHSElem) == getCanonicalType(ResultType)) 665861710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return RHS; 66593d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (LVAT) { 66603d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 66613d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of LHS, but the type 66623d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 66633d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 66643d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 66653d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman if (RVAT) { 66663d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // FIXME: This isn't correct! But tricky to implement because 66673d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // the array's size has to be the size of RHS, but the type 66683d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman // has to be different. 66693d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return RHS; 66703d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 66713bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(LHSElem) == getCanonicalType(ResultType)) return LHS; 66723bc0f45a5e65814f42b22dcdf7249d1120d16f36Eli Friedman if (getCanonicalType(RHSElem) == getCanonicalType(ResultType)) return RHS; 66737e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor return getIncompleteArrayType(ResultType, 66747e7eb3da052a6d80ddf2377cab0384c798f73f75Douglas Gregor ArrayType::ArraySizeModifier(), 0); 66753d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman } 66761adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::FunctionNoProto: 6677447234dd459a00a5ed9b7c3e066162cd7a75bf2dDouglas Gregor return mergeFunctionTypes(LHS, RHS, OfBlockPointer, Unqualified); 667872564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Record: 667972564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor case Type::Enum: 66803d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 66811adb88370beab45af2f065afe86b51ccd59ec50dChris Lattner case Type::Builtin: 66823cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner // Only exactly equal builtin types are compatible, which is tested above. 66833d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 668464cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar case Type::Complex: 668564cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar // Distinct complex types are incompatible. 668664cfdb7da3cb744642fe8a99ad5c851ad3c930b2Daniel Dunbar return QualType(); 66873cc4c0c3058a788689b8fc73c0ac139544435c97Chris Lattner case Type::Vector: 66885a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: The merged type should be an ExtVector! 66891c471f3e1c0ec8cbc82447bb35908dfc55463e46John McCall if (areCompatVectorTypes(LHSCan->getAs<VectorType>(), 66901c471f3e1c0ec8cbc82447bb35908dfc55463e46John McCall RHSCan->getAs<VectorType>())) 66913d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return LHS; 669261710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner return QualType(); 6693c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall case Type::ObjCObject: { 6694c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // Check if the types are assignment compatible. 66955a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // FIXME: This should be type compatibility, e.g. whether 66965a61f0e5c5aaecd5713c3fa4b78be7167a7eeff2Eli Friedman // "LHS x; RHS x;" at global scope is legal. 6697c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* LHSIface = LHS->getAs<ObjCObjectType>(); 6698c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall const ObjCObjectType* RHSIface = RHS->getAs<ObjCObjectType>(); 6699c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (canAssignObjCInterfaces(LHSIface, RHSIface)) 67005fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff return LHS; 67015fd659db11922fc12a58e478f7b745f9656b15a7Steve Naroff 67023d815e7eb56c25d7ed812eced32e41df43039f9aEli Friedman return QualType(); 670361490e9a965cfee8a78c12c6802138844f04250dCedric Venet } 670414108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case Type::ObjCObjectPointer: { 6705132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (OfBlockPointer) { 6706132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian if (canAssignObjCInterfacesInBlockPointer( 6707132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian LHS->getAs<ObjCObjectPointerType>(), 6708a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian RHS->getAs<ObjCObjectPointerType>(), 6709a4fdbfad150ae37bddaa4094d3925a27a1a1cf3fFariborz Jahanian BlockReturnType)) 67107530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie return LHS; 6711132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian return QualType(); 6712132f2a2da34f378fc675b9e174564b0f52c31d98Fariborz Jahanian } 6713183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall if (canAssignObjCInterfaces(LHS->getAs<ObjCObjectPointerType>(), 6714183700f494ec9b6701b6efe82bcb25f4c79ba561John McCall RHS->getAs<ObjCObjectPointerType>())) 671514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff return LHS; 671614108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 6717bc76dd06eb881c70c9775b74bab8b88cd747f173Steve Naroff return QualType(); 67187530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie } 6719ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff } 672072564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor 67217530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid Type::Class!"); 6722ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff} 67237192f8e9592729882a09d84d77838db26e39ebd4Ted Kremenek 672478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanianbool ASTContext::FunctionTypesMatchOnNSConsumedAttrs( 672578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian const FunctionProtoType *FromFunctionType, 672678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian const FunctionProtoType *ToFunctionType) { 672778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromFunctionType->hasAnyConsumedArgs() != 672878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToFunctionType->hasAnyConsumedArgs()) 672978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return false; 673078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FunctionProtoType::ExtProtoInfo FromEPI = 673178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FromFunctionType->getExtProtoInfo(); 673278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian FunctionProtoType::ExtProtoInfo ToEPI = 673378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToFunctionType->getExtProtoInfo(); 673478213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromEPI.ConsumedArguments && ToEPI.ConsumedArguments) 673578213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumArgs(); 673678213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ArgIdx != NumArgs; ++ArgIdx) { 673778213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian if (FromEPI.ConsumedArguments[ArgIdx] != 673878213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian ToEPI.ConsumedArguments[ArgIdx]) 673978213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return false; 674078213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian } 674178213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian return true; 674278213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian} 674378213e4aec6d8d22b5828dd2687fa19116ebaa26Fariborz Jahanian 67442390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and 67452390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// 'RHS' attributes and returns the merged version; including for function 67462390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian/// return types. 67472390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz JahanianQualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) { 67482390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType LHSCan = getCanonicalType(LHS), 67492390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian RHSCan = getCanonicalType(RHS); 67502390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If two types are identical, they are compatible. 67512390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LHSCan == RHSCan) 67522390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 67532390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (RHSCan->isFunctionType()) { 67542390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (!LHSCan->isFunctionType()) 67552390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 67562390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType OldReturnType = 67572390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian cast<FunctionType>(RHSCan.getTypePtr())->getResultType(); 67582390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType NewReturnType = 67592390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian cast<FunctionType>(LHSCan.getTypePtr())->getResultType(); 67602390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResReturnType = 67612390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian mergeObjCGCQualifiers(NewReturnType, OldReturnType); 67622390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResReturnType.isNull()) 67632390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 67642390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResReturnType == NewReturnType || ResReturnType == OldReturnType) { 67652390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // id foo(); ... __strong id foo(); or: __strong id foo(); ... id foo(); 67662390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // In either case, use OldReturnType to build the new function type. 67672390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian const FunctionType *F = LHS->getAs<FunctionType>(); 67682390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (const FunctionProtoType *FPT = cast<FunctionProtoType>(F)) { 6769e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); 6770e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall EPI.ExtInfo = getFunctionExtInfo(LHS); 67712390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResultType 67722390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian = getFunctionType(OldReturnType, FPT->arg_type_begin(), 6773e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FPT->getNumArgs(), EPI); 67742390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return ResultType; 67752390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 67762390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 67772390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 67782390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 67792390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 67802390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If the qualifiers are different, the types can still be merged. 67812390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers LQuals = LHSCan.getLocalQualifiers(); 67822390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers RQuals = RHSCan.getLocalQualifiers(); 67832390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LQuals != RQuals) { 67842390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // If any of these qualifiers are different, we have a type mismatch. 67852390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() || 67862390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian LQuals.getAddressSpace() != RQuals.getAddressSpace()) 67872390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 67882390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 67892390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // Exactly one GC qualifier difference is allowed: __strong is 67902390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // okay if the other type has no GC qualifier but is an Objective 67912390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // C object pointer (i.e. implicitly strong by default). We fix 67922390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // this by pretending that the unqualified type was actually 67932390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian // qualified __strong. 67942390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers::GC GC_L = LQuals.getObjCGCAttr(); 67952390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian Qualifiers::GC GC_R = RQuals.getObjCGCAttr(); 67962390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements"); 67972390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 67982390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_L == Qualifiers::Weak || GC_R == Qualifiers::Weak) 67992390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 68002390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 68012390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_L == Qualifiers::Strong) 68022390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 68032390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (GC_R == Qualifiers::Strong) 68042390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return RHS; 68052390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 68062390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 68072390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 68082390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (LHSCan->isObjCObjectPointerType() && RHSCan->isObjCObjectPointerType()) { 68092390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType LHSBaseQT = LHS->getAs<ObjCObjectPointerType>()->getPointeeType(); 68102390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType RHSBaseQT = RHS->getAs<ObjCObjectPointerType>()->getPointeeType(); 68112390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian QualType ResQT = mergeObjCGCQualifiers(LHSBaseQT, RHSBaseQT); 68122390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResQT == LHSBaseQT) 68132390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return LHS; 68142390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian if (ResQT == RHSBaseQT) 68152390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return RHS; 68162390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian } 68172390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian return QualType(); 68182390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian} 68192390a72a3ebd37737fec5ba1385db9c3bb22fc59Fariborz Jahanian 68205426bf6456a5aeac416a9150de157904d101c819Chris Lattner//===----------------------------------------------------------------------===// 6821ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman// Integer Predicates 6822ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman//===----------------------------------------------------------------------===// 682388054dee0402e4d3c1f64e6b697acc47195c0d72Chris Lattner 68244ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadunsigned ASTContext::getIntWidth(QualType T) const { 6825f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall if (const EnumType *ET = dyn_cast<EnumType>(T)) 682629a7f3342c3c6dd15d914c61ae22246c36d51ce7Eli Friedman T = ET->getDecl()->getIntegerType(); 68271274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor if (T->isBooleanType()) 68281274ccd90aec0b205fc838c3d504821ccfb55482Douglas Gregor return 1; 6829f98aba35e6c3da5aae61843fc01334939e4e12ecEli Friedman // For builtin types, just use the standard type sizing method 6830ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return (unsigned)getTypeSize(T); 6831ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 6832ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 6833ad74a758189180b8ab8faea648e4766c3bfd7fcbEli FriedmanQualType ASTContext::getCorrespondingUnsignedType(QualType T) { 6834f60946222721d9ba3c059563935c17b84703187aDouglas Gregor assert(T->hasSignedIntegerRepresentation() && "Unexpected type"); 68356a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 68366a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner // Turn <4 x signed int> -> <4 x unsigned int> 68376a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner if (const VectorType *VTy = T->getAs<VectorType>()) 68386a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner return getVectorType(getCorrespondingUnsignedType(VTy->getElementType()), 6839e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VTy->getNumElements(), VTy->getVectorKind()); 68406a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 68416a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner // For enums, we return the unsigned version of the base type. 68426a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner if (const EnumType *ETy = T->getAs<EnumType>()) 6843ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman T = ETy->getDecl()->getIntegerType(); 68446a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner 68456a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner const BuiltinType *BTy = T->getAs<BuiltinType>(); 68466a2b9261bf9c973c7122d9d1febce24a38fa862dChris Lattner assert(BTy && "Unexpected signed integer type"); 6847ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman switch (BTy->getKind()) { 6848ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Char_S: 6849ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::SChar: 6850ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedCharTy; 6851ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Short: 6852ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedShortTy; 6853ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Int: 6854ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedIntTy; 6855ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::Long: 6856ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongTy; 6857ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman case BuiltinType::LongLong: 6858ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman return UnsignedLongLongTy; 68592df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner case BuiltinType::Int128: 68602df9ced9fd1e8c7d7b38443db07e0e811de22571Chris Lattner return UnsignedInt128Ty; 6861ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman default: 6862b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unexpected signed integer type"); 6863ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman } 6864ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman} 6865ad74a758189180b8ab8faea648e4766c3bfd7fcbEli Friedman 68667b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios KyrtzidisASTMutationListener::~ASTMutationListener() { } 68677b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 686886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 686986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 687086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner// Builtin Type Computation 687186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner//===----------------------------------------------------------------------===// 687286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 687386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// DecodeTypeFromStr - This decodes one type descriptor from Str, advancing the 687433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// pointer over the consumed characters. This returns the resultant type. If 687533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// AllowTypeModifiers is false then modifier like * are not parsed, just basic 687633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// types. This allows "v2i*" to be parsed as a pointer to a v2i instead of 687733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner/// a vector of "i*". 687814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// 687914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// RequiresICE is filled in on return to indicate whether the value is required 688014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner/// to be an Integer Constant Expression. 68814ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadstatic QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, 688286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ASTContext::GetBuiltinTypeError &Error, 688314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner bool &RequiresICE, 688433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner bool AllowTypeModifiers) { 688586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Modifiers. 688686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner int HowLong = 0; 688786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Signed = false, Unsigned = false; 688814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE = false; 6889393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner 689033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // Read the prefixed modifiers first. 689186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner bool Done = false; 689286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 689386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 68941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump default: Done = true; --Str; break; 6895393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner case 'I': 689614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE = true; 6897393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner break; 689886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'S': 689986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use both 'S' and 'U' modifiers!"); 690086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use 'S' modifier multiple times!"); 690186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Signed = true; 690286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 690386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'U': 690486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Signed && "Can't use both 'S' and 'U' modifiers!"); 690586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Unsigned && "Can't use 'S' modifier multiple times!"); 690686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Unsigned = true; 690786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 690886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'L': 690986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong <= 2 && "Can't have LLLL modifier"); 691086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ++HowLong; 691186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 691286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 691386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 691486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 691586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner QualType Type; 69161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 691786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Read the base type. 691886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner switch (*Str++) { 6919b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie default: llvm_unreachable("Unknown builtin type letter!"); 692086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'v': 692186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 692286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'v'!"); 692386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.VoidTy; 692486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 692586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'f': 692686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && 692786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'f'!"); 692886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.FloatTy; 692986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 693086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'd': 693186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong < 2 && !Signed && !Unsigned && 693286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "Bad modifiers used with 'd'!"); 693386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong) 693486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.LongDoubleTy; 693586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 693686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.DoubleTy; 693786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 693886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 's': 693986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 's'!"); 694086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Unsigned) 694186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedShortTy; 694286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 694386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.ShortTy; 694486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 694586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'i': 694686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (HowLong == 3) 694786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty; 694886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 2) 694986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy; 695086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (HowLong == 1) 695186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy; 695286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 695386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy; 695486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 695586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'c': 695686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && "Bad modifiers used with 'c'!"); 695786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Signed) 695886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.SignedCharTy; 695986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else if (Unsigned) 696086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.UnsignedCharTy; 696186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner else 696286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.CharTy; 696386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 696486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'b': // boolean 696586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'b'!"); 696686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.BoolTy; 696786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 696886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'z': // size_t. 696986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!"); 697086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getSizeType(); 697186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 697286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'F': 697386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getCFConstantStringType(); 697486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 6975ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian case 'G': 6976ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian Type = Context.getObjCIdType(); 6977ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian break; 6978ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian case 'H': 6979ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian Type = Context.getObjCSelType(); 6980ba8bda05fefd3bb2f1ef201784b685f715bdde29Fariborz Jahanian break; 698186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'a': 698286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 698386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 698486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 698586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'A': 698686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // This is a "reference" to a va_list; however, what exactly 698786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // this means depends on how va_list is defined. There are two 698886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // different kinds of va_list: ones passed by value, and ones 698986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // passed by reference. An example of a by-value va_list is 699086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // x86, where va_list is a char*. An example of by-ref va_list 699186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // is x86-64, where va_list is a __va_list_tag[1]. For x86, 699286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // we want this argument to be a char*&; for x86-64, we want 699386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // it to be a __va_list_tag*. 699486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getBuiltinVaListType(); 699586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(!Type.isNull() && "builtin va list type not initialized!"); 699614e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner if (Type->isArrayType()) 699786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getArrayDecayedType(Type); 699814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner else 699986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Type = Context.getLValueReferenceType(Type); 700086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 700186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner case 'V': { 700286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner char *End; 700386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner unsigned NumElements = strtoul(Str, &End, 10); 700486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert(End != Str && "Missing vector size"); 700586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Str = End; 70061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 700714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, 700814e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE, false); 700914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Can't require vector ICE"); 701033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner 701133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // TODO: No way to make AltiVec vectors in builtins yet. 7012788b0fd67e1992f23555454efcdb16a19dfefac3Chris Lattner Type = Context.getVectorType(ElementType, NumElements, 7013e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::GenericVector); 701486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner break; 701586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 7016b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor case 'E': { 7017b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor char *End; 7018b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 7019b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor unsigned NumElements = strtoul(Str, &End, 10); 7020b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor assert(End != Str && "Missing vector size"); 7021b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 7022b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor Str = End; 7023b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor 7024b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, 7025b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor false); 7026b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor Type = Context.getExtVectorType(ElementType, NumElements); 7027b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor break; 7028b4bc99ba5540a618c86c136c9112ead8fb1d9866Douglas Gregor } 7029d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor case 'X': { 703014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ElementType = DecodeTypeFromStr(Str, Context, Error, RequiresICE, 703114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner false); 703214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Can't require complex ICE"); 7033d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor Type = Context.getComplexType(ElementType); 7034d3a23b238a2b2c0f11e6ac4951c7410a8c5717bfDouglas Gregor break; 7035cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian } 7036cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian case 'Y' : { 7037cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian Type = Context.getPointerDiffType(); 7038cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian break; 7039cc075e4092900ac9eec9dc92e35096eae1ee29c7Fariborz Jahanian } 70409a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'P': 7041c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor Type = Context.getFILEType(); 7042c29f77b769bcc5b6dc85e72c8e3cc2e348e5cf25Douglas Gregor if (Type.isNull()) { 7043f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_stdio; 704486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 704586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 7046fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 70479a5a7e7351f78345a72c4956af25590f6d40ebcdChris Lattner case 'J': 7048f711c41dd9412a8182793259d355c4f6979ed5edMike Stump if (Signed) 7049782fa308a765aeac2acb39c4e697c937ec21185bMike Stump Type = Context.getsigjmp_bufType(); 7050f711c41dd9412a8182793259d355c4f6979ed5edMike Stump else 7051f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Type = Context.getjmp_bufType(); 7052f711c41dd9412a8182793259d355c4f6979ed5edMike Stump 7053fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump if (Type.isNull()) { 7054f711c41dd9412a8182793259d355c4f6979ed5edMike Stump Error = ASTContext::GE_Missing_setjmp; 7055fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump return QualType(); 7056fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump } 7057fd612dbb23cd31c03c898ae53ff18d0dfd8488f9Mike Stump break; 7058e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola case 'K': 7059e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'K'!"); 7060e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola Type = Context.getucontext_tType(); 7061e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola 7062e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola if (Type.isNull()) { 7063e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola Error = ASTContext::GE_Missing_ucontext; 7064e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola return QualType(); 7065e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola } 7066e2d4f4ed44a32f179c6d48cd1dba8346ab2129d9Rafael Espindola break; 7067782fa308a765aeac2acb39c4e697c937ec21185bMike Stump } 70681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 706933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // If there are modifiers and if we're allowed to parse them, go for it. 707033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Done = !AllowTypeModifiers; 707186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (!Done) { 7072187ab37a05b8f7015b9f39cc8cd9129a0c6d0b48John McCall switch (char c = *Str++) { 707333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner default: Done = true; --Str; break; 707433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case '*': 707533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case '&': { 707633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // Both pointers and references can have their pointee types 707733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // qualified with an address space. 707833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner char *End; 707933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner unsigned AddrSpace = strtoul(Str, &End, 10); 708033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner if (End != Str && AddrSpace != 0) { 708133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getAddrSpaceQualType(Type, AddrSpace); 708233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Str = End; 708333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner } 708433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner if (c == '*') 708533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getPointerType(Type); 708633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner else 708733daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getLValueReferenceType(Type); 708833daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 708933daae66462e8f51ee153463b32bdefd60c801aaChris Lattner } 709033daae66462e8f51ee153463b32bdefd60c801aaChris Lattner // FIXME: There's no way to have a built-in with an rvalue ref arg. 709133daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case 'C': 709233daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Type.withConst(); 709333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 709433daae66462e8f51ee153463b32bdefd60c801aaChris Lattner case 'D': 709533daae66462e8f51ee153463b32bdefd60c801aaChris Lattner Type = Context.getVolatileType(Type); 709633daae66462e8f51ee153463b32bdefd60c801aaChris Lattner break; 709718932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek case 'R': 709818932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek Type = Type.withRestrict(); 709918932a0f2a94a7813ec461d1118c39ecf8aa936fTed Kremenek break; 710086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 710186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 7102393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner 710314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert((!RequiresICE || Type->isIntegralOrEnumerationType()) && 7104393bd8e185692a451b2ba16bdfc9e7d3543b4217Chris Lattner "Integer constant 'I' type must be an integer"); 71051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 710686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return Type; 710786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 710886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 710986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner/// GetBuiltinType - Return the type for the specified builtin. 711033daae66462e8f51ee153463b32bdefd60c801aaChris LattnerQualType ASTContext::GetBuiltinType(unsigned Id, 711114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner GetBuiltinTypeError &Error, 71124ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad unsigned *IntegerConstantArgs) const { 711333daae66462e8f51ee153463b32bdefd60c801aaChris Lattner const char *TypeStr = BuiltinInfo.GetTypeString(Id); 71141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71155f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<QualType, 8> ArgTypes; 71161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 711714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner bool RequiresICE = false; 711886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Error = GE_None; 711914e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType ResType = DecodeTypeFromStr(TypeStr, *this, Error, 712014e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner RequiresICE, true); 712186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 712286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 712314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 712414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner assert(!RequiresICE && "Result of intrinsic cannot be required to be an ICE"); 712514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 712686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner while (TypeStr[0] && TypeStr[0] != '.') { 712714e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner QualType Ty = DecodeTypeFromStr(TypeStr, *this, Error, RequiresICE, true); 712886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Error != GE_None) 712986df27bbdbb98c39ec2184695c0561209f91beddChris Lattner return QualType(); 713086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 713114e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner // If this argument is required to be an IntegerConstantExpression and the 713214e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner // caller cares, fill in the bitmask we return. 713314e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner if (RequiresICE && IntegerConstantArgs) 713414e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner *IntegerConstantArgs |= 1 << ArgTypes.size(); 713514e0e7436cf6650a72052baea1f8ebe644cef489Chris Lattner 713686df27bbdbb98c39ec2184695c0561209f91beddChris Lattner // Do array -> pointer decay. The builtin should use the decayed type. 713786df27bbdbb98c39ec2184695c0561209f91beddChris Lattner if (Ty->isArrayType()) 713886df27bbdbb98c39ec2184695c0561209f91beddChris Lattner Ty = getArrayDecayedType(Ty); 71391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 714086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner ArgTypes.push_back(Ty); 714186df27bbdbb98c39ec2184695c0561209f91beddChris Lattner } 714286df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 714386df27bbdbb98c39ec2184695c0561209f91beddChris Lattner assert((TypeStr[0] != '.' || TypeStr[1] == 0) && 714486df27bbdbb98c39ec2184695c0561209f91beddChris Lattner "'.' should only occur at end of builtin type list!"); 714586df27bbdbb98c39ec2184695c0561209f91beddChris Lattner 714600ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall FunctionType::ExtInfo EI; 714700ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true); 714800ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall 714900ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall bool Variadic = (TypeStr[0] == '.'); 715000ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall 715100ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall // We really shouldn't be making a no-proto type here, especially in C++. 715200ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall if (ArgTypes.empty() && Variadic) 715300ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall return getFunctionNoProtoType(ResType, EI); 7154ce056bcaa1c97b89a4b2de2112c62d060863be2bDouglas Gregor 7155e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall FunctionProtoType::ExtProtoInfo EPI; 715600ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall EPI.ExtInfo = EI; 715700ccbefcffeb88ea3e2e6323e594fa968753ad14John McCall EPI.Variadic = Variadic; 7158e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall 7159e23cf437fe76b1ed02d63c3f61b456fd48a915f5John McCall return getFunctionType(ResType, ArgTypes.data(), ArgTypes.size(), EPI); 716086df27bbdbb98c39ec2184695c0561209f91beddChris Lattner} 7161a95d75769edae299816ec7fd9bbcdf1ef617c5c9Eli Friedman 716290e99a84ddd020e8fda79643748243725a2ed071Argyrios KyrtzidisGVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) { 716390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage External = GVA_StrongExternal; 716490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 716590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis Linkage L = FD->getLinkage(); 716690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (L) { 716790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case NoLinkage: 716890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case InternalLinkage: 716990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case UniqueExternalLinkage: 717090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_Internal; 717190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 717290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case ExternalLinkage: 717390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (FD->getTemplateSpecializationKind()) { 717490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_Undeclared: 717590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitSpecialization: 717690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis External = GVA_StrongExternal; 717790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis break; 717890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 717990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDefinition: 718090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_ExplicitTemplateInstantiation; 718190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 718290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDeclaration: 718390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ImplicitInstantiation: 718490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis External = GVA_TemplateInstantiation; 718590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis break; 718690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 718790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 718890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 718990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!FD->isInlined()) 719090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return External; 719190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 71924e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (!getLangOpts().CPlusPlus || FD->hasAttr<GNUInlineAttr>()) { 719390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // GNU or C99 inline semantics. Determine whether this symbol should be 719490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // externally visible. 719590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->isInlineDefinitionExternallyVisible()) 719690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return External; 719790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 719890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // C99 inline semantics, where the symbol is not externally visible. 719990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_C99Inline; 720090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 720190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 720290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // C++0x [temp.explicit]p9: 720390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // [ Note: The intent is that an inline function that is the subject of 720490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // an explicit instantiation declaration will still be implicitly 720590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // instantiated when used so that the body can be considered for 720690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // inlining, but that no out-of-line copy of the inline function would be 720790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // generated in the translation unit. -- end note ] 720890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->getTemplateSpecializationKind() 720990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis == TSK_ExplicitInstantiationDeclaration) 721090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_C99Inline; 721190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 721290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_CXXInline; 721390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 721490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 721590e99a84ddd020e8fda79643748243725a2ed071Argyrios KyrtzidisGVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) { 721690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // If this is a static data member, compute the kind of template 721790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // specialization. Otherwise, this variable is not part of a 721890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // template. 721990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis TemplateSpecializationKind TSK = TSK_Undeclared; 722090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (VD->isStaticDataMember()) 722190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis TSK = VD->getTemplateSpecializationKind(); 722290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 722390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis Linkage L = VD->getLinkage(); 72244e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie if (L == ExternalLinkage && getLangOpts().CPlusPlus && 722590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis VD->getType()->getLinkage() == UniqueExternalLinkage) 722690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis L = UniqueExternalLinkage; 722790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 722890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (L) { 722990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case NoLinkage: 723090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case InternalLinkage: 723190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case UniqueExternalLinkage: 723290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_Internal; 723390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 723490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case ExternalLinkage: 723590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis switch (TSK) { 723690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_Undeclared: 723790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitSpecialization: 723890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_StrongExternal; 723990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 724090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDeclaration: 724190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis llvm_unreachable("Variable should not be instantiated"); 724290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Fall through to treat this like any other instantiation. 724390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 724490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ExplicitInstantiationDefinition: 724590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_ExplicitTemplateInstantiation; 724690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 724790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis case TSK_ImplicitInstantiation: 724890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return GVA_TemplateInstantiation; 724990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 725090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 725190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 72527530c034c0c71a64c5a9173206d9742ae847af8bDavid Blaikie llvm_unreachable("Invalid Linkage!"); 725390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 725490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 72554ac7c0bb39696e92fd220118fedc484c09a69870Argyrios Kyrtzidisbool ASTContext::DeclMustBeEmitted(const Decl *D) { 725690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 725790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!VD->isFileVarDecl()) 725890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 7259144b38a7995cbe0928e34fbcc865bb2d2be4f7a3Argyrios Kyrtzidis } else if (!isa<FunctionDecl>(D)) 726090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 726190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 7262ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis // Weak references don't produce any output by themselves. 7263ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis if (D->hasAttr<WeakRefAttr>()) 7264ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis return false; 7265ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis 726690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Aliases and used decls are required. 726790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>()) 726890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 726990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 727090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 727190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Forward declarations aren't required. 727210620eb5164e31208fcbf0437cd79ae535ed0559Sean Hunt if (!FD->doesThisDeclarationHaveABody()) 7273dce67a70a86db8758c926a76fdd980f5369d5746Nick Lewycky return FD->doesDeclarationForceExternallyVisibleDefinition(); 727490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 727590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Constructors and destructors are required. 727690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>()) 727790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 727890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 727990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // The key function for a class is required. 728090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { 728190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const CXXRecordDecl *RD = MD->getParent(); 728290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (MD->isOutOfLine() && RD->isDynamicClass()) { 728390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const CXXMethodDecl *KeyFunc = getKeyFunction(RD); 728490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (KeyFunc && KeyFunc->getCanonicalDecl() == MD->getCanonicalDecl()) 728590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 728690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 728790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 728890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 728990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage Linkage = GetGVALinkageForFunction(FD); 729090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 729190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // static, static inline, always_inline, and extern inline functions can 729290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // always be deferred. Normal inline functions can be deferred in C99/C++. 729390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Implicit template instantiations can also be deferred in C++. 729490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (Linkage == GVA_Internal || Linkage == GVA_C99Inline || 72953a5aca8112e03814f78906dc5d032287adb272b5Anton Yartsev Linkage == GVA_CXXInline || Linkage == GVA_TemplateInstantiation) 729690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 729790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 729890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 729994da1587f7d584fc61df793229d197969f204cd9Douglas Gregor 730090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis const VarDecl *VD = cast<VarDecl>(D); 730190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis assert(VD->isFileVarDecl() && "Expected file scoped var"); 730290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 7303ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) 7304ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis return false; 7305ab411c8c2efed8f2403bf8596e780c0f2f905a19Argyrios Kyrtzidis 730690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // Structs that have non-trivial constructors or destructors are required. 730790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 730890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis // FIXME: Handle references. 7309023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt // FIXME: Be more selective about which constructors we care about. 731090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const RecordType *RT = VD->getType()->getAs<RecordType>()) { 731190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) { 7312023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt if (RD->hasDefinition() && !(RD->hasTrivialDefaultConstructor() && 7313023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialCopyConstructor() && 7314023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialMoveConstructor() && 7315023df37c27ee8035664fb62f206ca58f4e2a169dSean Hunt RD->hasTrivialDestructor())) 731690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 731790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 731890e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 731990e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 732090e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis GVALinkage L = GetGVALinkageForVariable(VD); 732190e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (L == GVA_Internal || L == GVA_TemplateInstantiation) { 732290e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis if (!(VD->getInit() && VD->getInit()->HasSideEffects(*this))) 732390e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return false; 732490e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis } 732590e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis 732690e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis return true; 732790e99a84ddd020e8fda79643748243725a2ed071Argyrios Kyrtzidis} 7328071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 73298f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur IskhodzhanovCallingConv ASTContext::getDefaultCXXMethodCallConv(bool isVariadic) { 7330ee743f903858e337434ac0335f147f4de4ecae05Charles Davis // Pass through to the C++ ABI object 73318f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return ABI->getDefaultMethodCallConv(isVariadic); 73328f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov} 73338f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov 73348f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur IskhodzhanovCallingConv ASTContext::getCanonicalCallConv(CallingConv CC) const { 73358f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov if (CC == CC_C && !LangOpts.MRTD && getTargetInfo().getCXXABI() != CXXABI_Microsoft) 73368f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return CC_Default; 73378f88a1dcc57cfe8580eb1558a783ad8499bfe8e0Timur Iskhodzhanov return CC; 7338ee743f903858e337434ac0335f147f4de4ecae05Charles Davis} 7339ee743f903858e337434ac0335f147f4de4ecae05Charles Davis 73404ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foadbool ASTContext::isNearlyEmpty(const CXXRecordDecl *RD) const { 7341dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson // Pass through to the C++ ABI object 7342dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson return ABI->isNearlyEmpty(RD); 7343dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson} 7344dae0cb52e4e3d46bbfc9a4510909522197a92e54Anders Carlsson 734514110477887e3dc168ffc6c191e72d705051f99ePeter CollingbourneMangleContext *ASTContext::createMangleContext() { 7346bcfd1f55bfbb3e5944cd5e03d07b343e280838c4Douglas Gregor switch (Target->getCXXABI()) { 734714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_ARM: 734814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_Itanium: 734914110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return createItaniumMangleContext(*this, getDiagnostics()); 735014110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne case CXXABI_Microsoft: 735114110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return createMicrosoftMangleContext(*this, getDiagnostics()); 735214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne } 7353b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unsupported ABI"); 735414110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne} 735514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne 7356071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCXXABI::~CXXABI() {} 7357ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremenek 7358ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremeneksize_t ASTContext::getSideTableAllocatedMemory() const { 73590c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek return ASTRecordLayouts.getMemorySize() 73600c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(ObjCLayouts) 73610c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(KeyFunctions) 73620c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(ObjCImpls) 73630c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(BlockVarCopyInits) 73640c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(DeclAttrs) 73650c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromStaticDataMember) 73660c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUsingDecl) 73670c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUsingShadowDecl) 73680c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(InstantiatedFromUnnamedFieldDecl) 73690c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(OverriddenMethods) 73700c8cd1ac55720276ad41fa7b4f8785bead5afd32Ted Kremenek + llvm::capacity_in_bytes(Types) 7371af0f4d0b2e38c810effc8b024ad2fb6604eec5d3Francois Pichet + llvm::capacity_in_bytes(VariableArrayTypes) 73720d95f0d7b81110f77e99e833f766d19be7b7e072Francois Pichet + llvm::capacity_in_bytes(ClassScopeSpecializationPattern); 7373ba29bd25515fbd99e98ba0fedb9d93617b27609eTed Kremenek} 7374d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek 73759e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregorunsigned ASTContext::getLambdaManglingNumber(CXXMethodDecl *CallOperator) { 73769e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor CXXRecordDecl *Lambda = CallOperator->getParent(); 73779e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor return LambdaMangleContexts[Lambda->getDeclContext()] 73789e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor .getManglingNumber(CallOperator); 73799e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor} 73809e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 73819e8c92a9c9b949bbb0408fbbd9a58e34894b6efcDouglas Gregor 7382d211cb709510fbe7e75167b9feee0050851d001aTed Kremenekvoid ASTContext::setParameterIndex(const ParmVarDecl *D, unsigned int index) { 7383d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek ParamIndices[D] = index; 7384d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek} 7385d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek 7386d211cb709510fbe7e75167b9feee0050851d001aTed Kremenekunsigned ASTContext::getParameterIndex(const ParmVarDecl *D) const { 7387d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek ParameterIndexTable::const_iterator I = ParamIndices.find(D); 7388d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek assert(I != ParamIndices.end() && 7389d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek "ParmIndices lacks entry set by ParmVarDecl"); 7390d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek return I->second; 7391d211cb709510fbe7e75167b9feee0050851d001aTed Kremenek} 7392